/r2g-skills:def-graphfrom r2g-skills
Converts signed-off physical-design files (DEF/LEF/liberty/SPEF) from ORFS backend runs into PyTorch-Geometric graph datasets with five graph views, node/edge features, and per-cell/per-net labels for congestion, RC parasitics, wirelength, timing, and IR drop.
Ships in r2g-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Turn a completed, signed-off backend run into a training-ready graph dataset. This is the
X/Y dataset-construction half of the RTL→GDS→Graph pipeline: it reads the physical-design
artifacts a signoff flow produces (6_final.def, 6_final.odb, optional 6_final.spef, plus
the platform liberty/LEF) and emits per-node/per-edge features (X), per-cell/per-net
labels (Y), and five PyTorch-Geometric graph topologies (b–f).
Produce the inputs with the signoff-loop skill (or any ORFS run that leaves a
6_final.def); this skill consumes them. It never runs place-and-route.
Every stage sources scripts/flow/_env.sh on entry, which autodetects ORFS + tool paths
(shared resolver, identical contract to the signoff-loop skill). Nothing to source manually.
Resolution order (first hit wins, per value): caller env → $R2G_ENV_FILE → in-skill
references/env.local.sh → $ORFS_ROOT/env.sh → /opt/openroad_tools_env.sh → autodetect.
The graph-assembly stage additionally needs a torch venv (torch + torch_geometric +
pandas). Point R2G_GRAPH_PYTHON at its bin/python; the label/feature/techlib stages do not
need it. Install on /proj, never $HOME:
python3 -m venv /proj/<you>/pyenvs/r2g-graph
/proj/<you>/pyenvs/r2g-graph/bin/pip install torch --index-url https://download.pytorch.org/whl/cpu
/proj/<you>/pyenvs/r2g-graph/bin/pip install torch_geometric pandas
The three stages compose. Each takes a <project-dir> that already holds a signed-off backend
run (a 6_final.def reachable via ORFS results or $R2G_DEF) and [platform].
Platform authority (failure-patterns.md #30): explicit [platform] arg > build provenance >
config.mk. When the arg is omitted, each stage consults the discovered backend's run-meta.json
(via the shared scripts/flow/_provenance.sh) before trusting constraints/config.mk — a campaign
re-point (setup_rtl_designs.py --platform X --force) rewrites config.mk for the whole corpus, and
cell_type_id/*_type_id vocabularies are per-platform, so keying an existing DEF to the re-pointed
platform is a silent-value defect. build_graphs.py stamps the resolved platform into
graph_manifest.json; tools/verify_graph_dataset.py trusts manifest > run-meta.json > config.mk.
Signoff gate (failure-patterns.md #34): a 6_final.def alone is NOT sign-off. Before
building, every stage runs the shared scripts/flow/signoff_gate.py against
reports/{drc,lvs,route}.json + the DEF-run's stage_log.jsonl: required checks (fail-closed —
a MISSING report blocks) are drc ∈ {clean, clean_beol}, lvs ∈ {clean, skipped}, ORFS complete,
route/antenna residuals 0 when provable; timing is recorded but never blocks (negative slack is a
legitimate training label). run_graphs.sh — the dataset builder — enforces by default and
SKIPs a not-signed-off design; run_labels.sh/run_features.sh default to warn (record +
proceed). Override with R2G_SIGNOFF_GATE=strict|enforce|warn|off; an explicit R2G_DEF override
downgrades to warn (a deliberate, recorded operator decision). The verdict always lands in
reports/signoff_gate.json and rides the manifest as signoff_health — the verifier fails a
dataset whose provenance is unrecorded or whose gate verdict is dirty.
ORFS completion requires a reconstructable SIX-STAGE lineage, not merely a clean finish row —
a repair/resume generation is attributed via resume_meta.json's recorded parent_lineage or
sibling ledgers (the latter as the orfs_lineage=reconstructed caveat); an orphan repair-only
run blocks (round-2 pilot P0-4). A recorded lineage is DIGEST-VERIFIED at gate time
(RMD2-P0-02, failure-patterns #55): valid non-null sha256 per reused stage, canonical artifact
names (stage contract v2), a same-identity parent with a matching stage-manifest digest, an
acyclic chain, and preserved bytes re-hashed against the record — any failure is a hard
blocker, and the verdict's lineage_root_digest rides the manifest. Strict tier (R2G_SIGNOFF_GATE=strict, pilot P0-1): only
the exact verdict pass builds; pass_with_caveats blocks. Every manifest carries
dataset_tier — strict_clean iff the gate verdict was exactly pass, else research — and a
clean dataset index must filter on it. Each build also stamps a stable corpus-level graph_id
(sha1(platform:design) in [1, 2^24), R2G_GRAPH_ID overrides; pilot P0-5) into the manifest and
every x1 slot; verify_graph_dataset.py --batch enforces corpus-wide uniqueness and reports
BLOCKED / not_applicable (exit 3 single-case) for intentionally denied designs instead of
crashing (pilot H2).
scripts/flow/run_labels.sh <project-dir> [platform]Per-cell / per-net regression targets into <project-dir>/labels/, plus a per-design
reports/labels_stats.json:
6_final.spef, via extract_rc.py): ground cap
(net_ground_cap.csv, per-net node label), coupling cap (coupling_cap.csv, net-pair edge
label), equivalent resistance (equiv_res.csv, same-net pin-pair edge label), + net_driver.csv
(places net↔net coupling edges on driver pins). No SPEF (RCX not run) → header-only RC CSVs.Fail-soft: a missing input or per-label tool error is recorded in the stats file, not fatal.
Platform-agnostic — liberty/LEF/supply-voltage come from the ORFS platform config. Batch
backfill across completed designs: tools/run_labels_batch.sh. See
references/label-extraction.md.
scripts/flow/run_features.sh <project-dir> [platform]Graph-feature CSVs into <project-dir>/features/: metadata.csv (graph-level),
nodes_{gate,net,iopin,pin}.csv, edges_{gate_pin,pin_net,iopin_net}.csv, plus a per-design
reports/features_stats.json. Reads the same 6_final.def (+ optional 6_final.spef) as
the labels, so feature rows join label rows on graph_id+inst_name/net_name. Fail-soft;
SPEF absence degrades cap/RC columns to 0. Batch backfill: tools/run_features_batch.sh. See
references/feature-extraction.md.
scripts/flow/run_graphs.sh <project-dir> [platform]Assembles the five topologies into <project-dir>/dataset/{b..f}_graph.pt — heterogeneous
HeteroData by default (R2G_GRAPH_KIND=homo for the legacy homogeneous format, both for
both) — plus the synthesis-netlist bipartite graph (netlist_graph.pt, always homogeneous) and a
manifest (dataset/graph_manifest.json, mirrored to reports/graph_dataset.json). Runs stages 1–2
automatically when their CSVs are missing or older than the DEF (freshness judged by the
reports/{features,labels}_stats.json stage-completion markers, not an early CSV).
R2G_GRAPH_PYTHON=/proj/<you>/pyenvs/r2g-graph/bin/python \
scripts/flow/run_graphs.sh <project-dir> [platform]
Needs torch + torch_geometric + pandas; machines without them SKIP cleanly with a HINT.
A configured R2G_GRAPH_PYTHON that cannot start fails loud (exit 4), never a skip.
R2G_GRAPH_VARIANTS selects variants (default bcdef); R2G_GRAPH_KIND picks the output
(hetero default / homo / both); GRAPH_TIMEOUT (default 2400s);
R2G_DEF/R2G_ODB/R2G_SPEF pin the DEF/ODB/SPEF for both the feature and label stages
(so X and Y stay joined on the same DEF), enabling a backend-less reference-DEF build.
See references/graph-dataset.md.
Check status + label_health + signoff_health in the manifest before training. status: "ok_with_label_gaps" means ≥1 label file couldn't join (its y slot is all-NaN); the per-file
reason is in label_health. signoff_health.status outside {pass, pass_with_caveats} means the
dataset was built past the signoff gate (warn/off mode) on a design that is not signed off — the
blockers list says why.
scripts/flow/run_stage_dataset.sh <project-dir>The second dataset product, built from the same backend run but answering a different question.
Stages 1–3 above fold one finished layout (6_final.def) into five views; this builder emits four
HeteroData graphs per design — floorplan, placement, cts, route — that share one
canonical post-synthesis topology and one set of post-route labels, and differ only in what was
legally knowable before that stage ran. It is the vendored, manually-verified R2G2.0 pipeline
(scripts/r2g2/, upstream contract in scripts/r2g2/upstream_docs/B_VIEW_DATASET_STRUCTURE.md).
R2G_GRAPH_PYTHON=/proj/<you>/pyenvs/r2g-graph/bin/python \
scripts/flow/run_stage_dataset.sh <project-dir> [--run-dir DIR] [--out-dir DIR]
Needs a backend run with all four stage .odb (2_floorplan/3_place/4_cts/5_route) plus
6_final.spef; the runner picks the newest such run, passes the signoff gate, exports the stage
DEFs from ODB, then runs 01…05 and both upstream checkers. See
references/four-stage-dataset.md.
Key differences from b–f — do not "harmonize" them:
1_2_yosys.v, not the DEF. The node set is identical in all four graphs;
a gate the resizer deleted stays a node with placement_valid=0.y[N,2] with an
explicit boolean y_valid_mask. 04 refuses a graph where isfinite(y) != y_valid_mask.edge_attr is [E, 0]; only the three
logical incidence relations (plus gate|congestion_geom|gate at cts/route) are encoder input.5_route.def/SPEF/STA are label-only. Stage 02 forks one subprocess per prediction stage so a
stage can only open its own DEF, and checks/validate_four_stage.py re-checks leakage independently.Both checkers must PASS, and a built heterograph.pt is not evidence on its own —
checks/validate_four_stage.py --config <cfg> (contract + leakage) and
checks/summarize_four_stage_graph_data.py --root <generated> (structural_issues=0).
Editing scripts/r2g2/ requires reading scripts/r2g2/R2G2_UPSTREAM.md first. That tree is a
vendored upstream drop plus eighteen recorded deltas (D1–D18); a new drop is re-vendored and the deltas
re-applied, never hand-merged. scripts/stage_dataset/ is our glue and is edited normally.
scripts/flow/run_images.sh <project-dir> [platform]The GCell-raster companion of the graph datasets, CircuitNet style (2026-10-22). Same guards
as run_graphs.sh (newest run, platform provenance, sign-off gate enforce, labels re-made
unless their marker records THIS DEF's digest). Writes images/{features,labels}.npz (one
[x][y] array per channel), images/image_meta.json, colour previews images/png/, and
reports/image_dataset.json (status: ok|invalid|skipped + the verifier's result).
labels/congestion_grid.json), so every channel
is pixel-aligned with the congestion label by construction.R2G_IMAGE_FEATURE_STAGE=place
(default, 3_place.odb) | cts | floorplan, exported with write_def. The builder REFUSES
a DEF with routed wires (leakage guard). Channels: cell_density, macro_region, rudy
(net bbox spread of (w+h)/(w·h), sides floored at one GCell), pin_rudy, pin_density.congestion / congestion_raw (= congestion_grid.csv, the same values the graph
label averages) and ir_drop (per-GCell worst of ir_drop.csv, mV).scripts/extract/images/verify_images.py re-parses DEF/LEF with
its own readers and re-derives the occupancy arrays, area conservation, pin count, the RUDY
integral, the exact label grids, the per-cell join with the graph label (cell_congestion.csv)
and IR drop — 17 checks; any failure marks the dataset invalid (exit 6).
tests/test_image_dataset.py holds hand-computed values on a non-square toy and one negative
control per channel.scripts/flow/run_stage_images.sh <project-dir> [platform]The image twin of the four-stage graph dataset (2026-11-17). One image set per prediction stage, cut exactly like the graph's: a stage may read only the layout that existed before it.
| Stage | Features read | Channels can contain |
|---|---|---|
floorplan | no layout (R2G_IMAGE_FEATURE_STAGE=none) | all zeros: the no-spatial-information baseline |
placement | 2_floorplan.odb | fixed cells (taps) and macros; std cells are UNPLACED and skipped; IO pins only if the flow placed them by then |
cts | 3_place.odb | all five channels |
route | 4_cts.odb | all five channels, clock-tree buffers included |
run_images.sh call (R2G_IMAGE_OUT_DIR / R2G_IMAGE_REPORT relocate it), so
run selection, provenance, the sign-off gate, label freshness and the independent verifier are
identical to the single-stage dataset.labels.npz arrays and grid digest, and fails (exit 6) on any difference.none stage's verifier checks are: no feature DEF recorded, every feature channel exactly zero,
and the label checks. A non-zero feature there is leakage and fails none.features_all_zero.stage_images/<stage>/{features,labels}.npz + image_meta.json + png/ + verify.json,
stage_images/reports/<stage>.json, and the manifest stage_images/stage_images.json (also
reports/stage_image_dataset.json).2_floorplan / 3_place / 4_cts .odb in the run's results/. Corpora
that kept only 3_place.odb can build the single default stage, not the four.| Variant | Nodes kept | Folded into edges |
|---|---|---|
| b | gate, net, iopin, pin | — (gate-pin, pin-net, iopin-net edges) |
| c | gate, net, iopin | pins → gate-net edges (pin features on edge_attr) |
| d | gate, iopin, pin | nets → pin-clique edges (net features on edge_attr) |
| e | iopin, pin | gates AND nets → pin-clique edges |
| f | gate, iopin | nets → gate-clique edges |
Default output is heterogeneous (HeteroData): per-type node stores (gate/net/iopin/pin)
(src_type, relation, dst_type) edge stores (relation = the folded entity — b connects; c/d/e/f
from edge_schema; RC → rc_coupling/rc_resistance). It is a value-preserving re-view of the
homogeneous source of truth below (graph_lib.homo_to_hetero, exact inverse hetero_to_homo).Homogeneous tensor schema (the source of truth; hetero stores re-view it — see
references/graph-dataset.md § Heterogeneous graphs): x[N,10] (node_type, graph_id, 8 per-type
feature slots), y[N,6] (node_type, congestion, IR drop, timing, wirelength, RC ground cap; NaN
where a label doesn't apply). Folded entities carry their features/labels on edge_attr[E,8] /
edge_y[E,6], interleaved [fwd0,rev0,fwd1,rev1,...]. RC coupling-cap + resistance labels ride a
separate parasitic edge set (rc_edge_index / rc_edge_type / rc_edge_y[E,3]), distinct from the
physical-topology edges (present-but-empty where RC doesn't apply, so the schema is uniform). Every
label tensor has a RAW twin (y_raw / edge_y_raw / rc_edge_y_raw) carrying the raw physical
value (EDA-Schema convention) beside the normalized target, so a trainer picks either. Full
schema + per-variant node/edge counts: references/graph-dataset.md.
scripts/extract/techlib/)The shared per-platform tech layer every stage consumes:
profile.py — supply voltage, tap patterns, cell-type strategy per ORFS platform.resolve.py — Python backend for scripts/flow/resolve_platform_paths.sh (same
KEY=VALUE contract): resolves liberty/LEF/tech paths for a platform.def_parse.py — the single DEF/SDC parser (instances, nets, pins, routed segments).lef.py — routing-layer names, pitch/direction, the layer regex matcher.liberty.py — cell / pin / net classifiers (direction, clock, capacitance).cell_types.py — the cell_type_id map (curated for nangate45, runtime-built for all
other platforms; MACRO gets a dedicated id).| Read this | When |
|---|---|
references/graph-dataset.md | Building/reading the PyG b–f graphs, tensor schema, RC-parasitic label views, torch venv, provenance + audit notes. |
references/four-stage-dataset.md | Building/reading the four-stage causal HeteroData graphs (run_stage_dataset.sh), the causal input whitelist, the ORFS adapters, and the two mandatory checkers. |
scripts/r2g2/R2G2_UPSTREAM.md | Before editing anything under scripts/r2g2/ — upstream provenance, SHA256s, and the eighteen local deltas (D1–D18) that must be re-applied on a new drop. |
references/label-extraction.md | Building the Y side (per-cell/per-net labels + stats). |
references/feature-extraction.md | Building the X side (per-node/per-edge/metadata CSVs + stats). |
scripts/extract/techlib/ | Per-platform tech/LEF/liberty/DEF parsing internals. |
tools/verify_graph_dataset.py (repo-level) | Independently verifying a built dataset against raw DEF/LEF/liberty/SPEF + OpenDB ground truth (--batch over many designs). Three named check groups — topology_checks (all 5 views b–f), feature_stat_checks (column re-derivation + stats-gate honesty + vocab), signoff_report_checks (DRC/LVS gate, ppa geometry, timing↔SDC, C_total/equiv_res vs SPEF; opt-in --signoff-recheck re-runs PDNSim for the IR-drop label). Run it after any corpus regeneration; see references/graph-dataset.md "Comprehensive verification". |
design_cases/<design-name>/
├── labels/ # Y: congestion / wirelength / timing / irdrop CSVs (run_labels.sh)
├── features/ # X: metadata.csv, nodes_{gate,net,iopin,pin}.csv, edges_*.csv (run_features.sh)
├── dataset/ # PyG graphs: {b..f}_graph.pt, netlist_graph.pt, graph_manifest.json (run_graphs.sh)
└── reports/
├── labels_stats.json # per-design label stage stats
├── features_stats.json # per-design feature stage stats
└── graph_dataset.json # mirror of dataset/graph_manifest.json
6_final.def/.odb/.spef with the signoff-loop skill first.tools/verify_graph_dataset.py
against raw DEF/LEF/liberty ground truth — silent value defects (transposed congestion
demand, all-NaN IR-drop, quoted-unit cap scaling) have shipped before and are invisible in
the manifest's row counts. See references/graph-dataset.md audit notes and
the signoff-loop references/failure-patterns.md "Dataset-Extraction Silent-Value Defects".reports/{labels,features}_stats.json and the manifest label_health for degraded columns
rather than assuming a non-empty CSV means correct values.references/README.md (opens in a new tab)references/env.local.sh.template (opens in a new tab)references/feature-extraction.md (opens in a new tab)references/four-stage-dataset.md (opens in a new tab)references/graph-dataset.md (opens in a new tab)references/label-extraction.md (opens in a new tab)scripts/extract/features/case_paths.py (opens in a new tab)scripts/extract/features/compute_feature_stats.py (opens in a new tab)scripts/extract/features/edges_gate_pin.py (opens in a new tab)scripts/extract/features/edges_iopin_net.py (opens in a new tab)scripts/extract/features/edges_pin_net.py (opens in a new tab)scripts/extract/features/metadata.py (opens in a new tab)scripts/extract/features/nodes_gate.py (opens in a new tab)scripts/extract/features/nodes_iopin.py (opens in a new tab)scripts/extract/features/nodes_net.py (opens in a new tab)scripts/extract/features/nodes_pin.py (opens in a new tab)scripts/extract/graph/build_graphs.py (opens in a new tab)scripts/extract/graph/graph_lib.py (opens in a new tab)scripts/extract/graph/netlist_graph.py (opens in a new tab)scripts/extract/graph/odb_to_def.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
graph-dataset, physical-design, machine-learning, eda, pytorch-geometric
Claude Code refuses to install this plugin
.claude-plugin/plugin.json: skills.0: Invalid string: must start with "./", skills.1: Invalid string: must start with "./", skills.2: Invalid string: must start with "./", skills.3: Invalid string: must start with "./"
.claude-plugin/plugin.json: skills.0: Invalid string: must start with "./", skills.1: Invalid string: must start with "./", skills.2: Invalid string: must start with "./", skills.3: Invalid string: must start with "./"
Checked against Claude Code 2.1.332's install rules. The listing below is what the repository ships; Claude Code cannot install it as published.
4 skills in this plugin
/eda-installDetect a machine's environment and install + verify the open-source EDA toolchain that the signoff-loop and def-graph skills need — OpenROAD-flow-scripts (openroad/yosys), iverilog, KLayout, Magic, Netgen, OpenSTA, the sky130A PDK, and the torch+torch_geometric graph venv. Use when setting up a new machine, when `check_env.sh` reports missing tools, when the user asks to install/bootstrap/provision the EDA tools or "set up the environment", or when a flow fails because a tool or PDK is absent. Without root it automatically installs a no-sudo path (the pinned r2g openroad+yosys bundle, conda litex-hub for the other tools, and a venv — all on a big volume). Produces references/env.local.sh so a bootstrapped toolchain is auto-discovered by the flow skills./rtl-acquireDiscover, screen, and acquire RTL at corpus scale (local trees, repo manifests, keyword search) and expand it — synthesis-only, MANY designs per round — into pre-layout netlist_graph.pt PyG graphs with dedup, quality scoring, and publish gating. Use for growing a training corpus of netlist graphs from found RTL. NOT for taking one design to GDS/signoff (that is signoff-loop) and NOT for post-layout graph datasets from DEF/SPEF (that is def-graph)./signoff-loopDrive an open-source EDA workflow from RTL to GDS with full signoff (DRC, LVS, RCX) using OpenROAD-flow-scripts (ORFS), Yosys, KLayout, Magic, Netgen, and OpenRCX — plus a self-improving observation→ingest→act loop that learns repair recipes to eliminate DRC/LVS violations and close timing at the best Fmax. Use when the user wants to turn a hardware spec or RTL into synthesis, place-and-route, GDS output, signoff verification, parasitic extraction, PPA iteration, flow-failure diagnosis, autonomous fix/learn campaigns, or a multi-project dashboard. The clean, signed-off DEF/LEF/SPEF it produces are the inputs to the companion def-graph skill (graph dataset construction).Other plugins' skills for the same job