Skip to content

Add checkQorMetrics.py inline check script - #4458

Open
migueldalberto wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:add-check-qor-metrics
Open

Add checkQorMetrics.py inline check script#4458
migueldalberto wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:add-check-qor-metrics

Conversation

@migueldalberto

Copy link
Copy Markdown
Contributor

Summary

  • Adds flow/util/checkQorMetrics.py, a local inline check: sweeps reports/<platform>/<design>/<variant>/metadata.json, POSTs each run's numeric metrics to the QoR dashboard's /compare/check/inline endpoint, and reports which rules would fail against the latest baseline build (or a pinned --base-commit).
  • Differs from checkMetadata.py: compares against a real baseline build + the dashboard's live rule_configs thresholds instead of the committed rules-<variant>.json goldens, so metric drift that moves with master doesn't false-positive.
  • Always exits 0 — reports, does not gate a local build on network/dashboard availability.

Sweeps flow/reports for metadata.json files, POSTs metrics to the QoR
dashboard's /compare/check/inline endpoint, and reports which rules a
local change would fail against the latest baseline build. Always
exits 0 since it reports rather than gates.

Signed-off-by: Miguel Dalberto Pedro <miguel.pedro@precisioninno.com>

Send JobName so the local baseline resolves to the right pipeline

Empty PipelineId/BranchName don't leave the baseline "unscoped" as
assumed -- the dashboard's PipelineClassification.Classify("") falls
through to null just like Classify(null), and
ResolveLocalBaselineAsync then filters on PipelineName == null,
matching whatever stale/legacy master build has no pipeline recorded
instead of the real latest master build.

JobName (the canonical Jenkins job-folder name, e.g.
jenkins-ci's utilGetJobFolderName()) takes priority over that
classification and scopes the baseline to the actual pipeline.
Default it to OpenROAD-flow-scripts-Public, the pipeline that
uploads master's dashboard metrics, and let --job-name/
$DASHBOARD_JOB_NAME override it for secure/private branches.

Verified end to end: re-running against the same real Jenkins
artifact that previously reported a bogus FAIL against baseline
build 4 now resolves to the real latest master build and reports
PASS with 0% deltas, matching the actual CI result.

Signed-off-by: Miguel Dalberto Pedro <miguel.pedro@precisioninno.com>

Fix the usage docs and narrow the command-line surface

The docstring claimed a plain `make` leaves a metadata.json behind. It
does not: the default goal stops at `finish`, and only `make metadata`
runs genMetrics.py, so a developer following it found nothing to check.

Drop --reports and --log. The sibling report scripts (genReport.py,
genReportTable.py, uploadMetadata.py) all chdir to flow/ and walk a
literal "reports"; making the root configurable here only let the sweep
diverge from what ingestion sees, and needed an INVOCATION_DIR dance to
keep relative paths meaning what the user typed. The log path is now
fixed and reported as an absolute path -- it was printed relative to
flow/, naming a path that does not exist from where the script was run.

Drop --target/--api-url for a --beta flag over two fixed https URLs. An
arbitrary --api-url could send DASHBOARD_API_KEY over a plaintext hop;
with both URLs baked in, that is structurally impossible rather than
guarded at runtime.

Drop the -v alias: genReport.py reads it as --verbose and genMetrics.py
binds it to the variant, so either meaning surprises half the callers.

Report a run directory with no metadata.json from the caller instead of
from the walk, so the warning respects --platform/--design/--variant and
reaches the log file. A scoped run no longer warns about designs it was
never asked to check.

Retry transient request failures three times with linear backoff. One
blip previously cost a design its entire check across a 61-design sweep.
Non-transient HTTP statuses return at once, since re-sending the same
payload only earns the same answer.

Signed-off-by: Miguel Dalberto Pedro <miguel.pedro@precisioninno.com>
@migueldalberto migueldalberto self-assigned this Aug 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new script, checkQorMetrics.py, designed to validate local flow runs against QoR dashboard rules by posting numeric metrics to an API. The feedback focuses on improving the script's robustness and portability. Key recommendations include wrapping check_run and fmt_value in try-except blocks to handle unexpected API responses or non-numeric values gracefully, and explicitly specifying encoding='utf-8' when reading and writing files to prevent platform-dependent encoding issues.

Comment on lines +204 to +231
metrics, commit = load_metadata(metadata_path)
if not metrics:
result["error"] = f"no numeric metrics in {metadata_path}"
return result
result["metric_count"] = len(metrics)

payload = {
"CommitSha": commit,
"BranchName": "",
"PipelineId": "",
"JobName": job_name,
"PlatformName": platform,
"DesignName": design,
"VariantName": variant,
"Metrics": metrics,
"IsLocal": True,
}
if base_commit:
payload["BaseCommitSha"] = base_commit

response, error = post_check(endpoint, api_key, payload)
if error is not None:
result["error"] = error
return result

result["response"] = response
result["status"] = response.get("status", "unknown")
return result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

To ensure the script's guarantee of always exiting with status 0, wrap the core execution of check_run in a try-except block. Additionally, validate that the API response is a dictionary before accessing .get() to prevent AttributeError crashes if the server returns an unexpected payload format (e.g., a list or string).

    try:
        metrics, commit = load_metadata(metadata_path)
        if not metrics:
            result[\"error\"] = f\"no numeric metrics in {metadata_path}\"
            return result
        result[\"metric_count\"] = len(metrics)

        payload = {
            \"CommitSha\": commit,
            \"BranchName\": \"\",
            \"PipelineId\": \"\",
            \"JobName\": job_name,
            \"PlatformName\": platform,
            \"DesignName\": design,
            \"VariantName\": variant,
            \"Metrics\": metrics,
            \"IsLocal\": True,
        }
        if base_commit:
            payload[\"BaseCommitSha\"] = base_commit

        response, error = post_check(endpoint, api_key, payload)
        if error is not None:
            result[\"error\"] = error
            return result

        if not isinstance(response, dict):
            result[\"error\"] = f\"unexpected response type: {type(response).__name__}\"
            return result

        result[\"response\"] = response
        result[\"status\"] = response.get(\\

Comment on lines +76 to +83
def fmt_value(value):
"""Render a metric value without inventing precision it does not have."""
if value is None:
return "n/a"
number = float(value)
if number == int(number) and abs(number) < 1e15:
return str(int(number))
return f"{number:.4f}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime crashes if the dashboard returns non-numeric values (or unexpected types), wrap the float conversion in a try-except block to handle ValueError or TypeError gracefully.

def fmt_value(value):
    \"\"\"Render a metric value without inventing precision it does not have.\"\"\"
    if value is None:
        return \"n/a\"
    try:
        number = float(value)
        if number == int(number) and abs(number) < 1e15:
            return str(int(number))
        return f\"{number:.4f}\"
    except (ValueError, TypeError):
        return str(value)

Comment on lines +123 to +124
with open(path) as metadata_file:
raw = json.load(metadata_file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Specify encoding='utf-8' when opening files to ensure portability and avoid platform-dependent encoding issues (e.g., on Windows or environments with non-UTF-8 defaults).

        with open(path, encoding=\"utf-8\") as metadata_file:
            raw = json.load(metadata_file)

Comment on lines +482 to +484
os.makedirs(os.path.dirname(log_path), exist_ok=True)
with open(log_path, "w") as log_file:
log_file.write("\n".join(lines) + "\n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Specify encoding='utf-8' when writing the log file to ensure consistent UTF-8 output across all execution environments.

        os.makedirs(os.path.dirname(log_path), exist_ok=True)
        with open(log_path, \"w\", encoding=\"utf-8\") as log_file:
            log_file.write(\"\\n\".join(lines) + \"\\n\")

@openroad-ci

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch. Advisory — results are log-only and do not affect build status. The authoritative QoR gate remains the local rules-file check.

Commit 2e8efb2 · Jenkins build #1 · Baseline: build

62 design(s) checked — 0 with regression(s), 0 without a comparable baseline.
Design Variant Verdict local vs inline passed / failed / missing
asap7/aes base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/aes-block base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/aes-mbff base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/aes_lvt base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/cva6 base ✅ pass ✅ MATCH 12 / 0 / 0
asap7/ethmac base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/ethmac_lvt base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/gcd-ccs base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/jpeg_lvt base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/mock-alu base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/mock-cpu base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/riscv32i base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/riscv32i-mock-sram base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/swerv_wrapper base ✅ pass ✅ MATCH 25 / 0 / 0
asap7/uart base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/aes base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/aes-hybrid base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/riscv32i base ✅ pass ✅ MATCH 25 / 0 / 0
gf180/uart-blocks base ✅ pass ✅ MATCH 25 / 0 / 0
gt2n/aes base ✅ pass ✅ MATCH 25 / 0 / 0
gt2n/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
gt2n/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/aes base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/i2c-gpio-expander base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/riscv32i base ✅ pass ✅ MATCH 25 / 0 / 0
ihp-sg13g2/spi base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/aes base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/ariane133 base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/ariane136 base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/black_parrot base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/bp_be_top base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/bp_fe_top base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/bp_multi_top base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/cva6 base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/dynamic_node base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/mempool_group base ✅ pass ✅ MATCH 12 / 0 / 0
nangate45/swerv base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/swerv_wrapper base ✅ pass ✅ MATCH 25 / 0 / 0
nangate45/tinyRocket base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/aes base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/chameleon base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/microwatt base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hd/riscv32i base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hs/aes base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hs/gcd base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hs/ibex base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hs/jpeg base ✅ pass ✅ MATCH 25 / 0 / 0
sky130hs/riscv32i base ✅ pass ✅ MATCH 25 / 0 / 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants