Procedural Layout API

Procedural layouts are Python scripts that generate a static layout cell from parameters. A procedural layout is stored as a script plus a parameter set; its generated cell is a read-only child that is replaced whenever the script or a parameter changes. The same generated cell feeds the GUI canvas, GDS export, LVS, PEX, and hierarchy instances.

The script runs in a separate Python process with a single injected object named layout. Scripts build geometry through that builder; they do not mutate the project database directly. OpenVLSI validates the builder output before applying it, so a failed script leaves the previous generated geometry untouched.

Quick start

# Declared parameters are strings; convert them with layout.um/length/float.
width = layout.um(layout.parameter("width", "4", "Metal width in micrometers"))

metal1 = layout.layer("Metal1", 1)
metal1.rectangle(0, 0, width, layout.um(0.6), name="M1", net="VDD")
metal1.rectangle(0, layout.um(2.4), width, layout.um(0.6), name="M2", net="VSS")

layout.port(
    "VDD", "Metal1", 0, 0, width, layout.um(0.6),
    direction="power", side="left", net="VDD",
)

Create and regenerate the layout from the GUI (+ in the Layout Hierarchy → Procedural Layout), the CLI, openvlsipy, or MCP. The generated child is read-only; edit the script or parameter form and regenerate instead of drawing over it.

Discover and validate the live API

Do not guess the script API. The MCP tools layout_api and layout_validate_script are generated from the running Python runner:

layout_api(pdk="sky130A")                 # classes + key methods + device names
layout_api(name="device")                 # exact signature, parameters, example
layout_api(name="nfet")                   # device parameters and defaults
layout_api(class_name="Layout")           # every public Layout method
layout_api(query="route")                 # search methods, parameters, devices
layout_validate_script(script=..., pdk="sky130A", layout="ota")

layout_api reports api_version, public classes, method signatures, parameter descriptions, return types, and minimal examples. When pdk is given it also lists the PDK’s layout device names, so a script can use the right cell name (for example nfet instead of a guessed nmos).

layout_validate_script parses the Python AST without executing package code. It reports Python syntax errors, unknown layout.* methods, wrong keywords or argument counts, missing layout.plan(...) or layout.finish_placement(), layout.add(... w=..., l=...) misuse, and planned devices that are never created or never added. It is advisory, but call it before layout_regenerate and fix every error: a lint error is much cheaper than a failed regeneration.

Metal fill and block-level DRC

Metal density can be handled with the PDK fill provider:

layout.add_dummy_fill(
    layers=["Metal1", "Metal2", "Metal3", "Metal4", "Metal5",
            "TopMetal1", "TopMetal2"],
    density=50,
    deviation=10,
)

The request runs after the script finishes, so the fill sees the complete layout. IHP’s provider supports those metal layers only; it does not fill Activ, GatPoly, or passivation and does not repair PCell geometry.

For gdscheck PDKs, drc_run exposes gdscheck suites:

main       full DRC, including full-chip density and antenna
core       geometric DRC: main minus antenna and density/fill
precheck   IHP open-source precheck subset
density    density/fill checks only
antenna    antenna checks only

Use suite="core" for a bare block that is not yet dummy-filled; use suite="density" separately as an advisory check. suite="main" is the full-chip signoff deck and is not a fair block-level gate without filler and seal-ring integration.

The IHP nmos, pmos, rhigh, rppd, and cmim PCells are core-clean once their stream layers are preserved. Standalone MOS devices still need a well/substrate tie for latch-up: place ptap near NMOS, ntap near PMOS, or use the guard-ring rfnmos/rfpmos variants. Without a tie, core reports LU.a/LU.b even though the device geometry is otherwise clean. RF guard-ring devices also need at least 3.5 um between adjacent devices; their NWell/nBuLay rings require 1.8/3.2 um spacing, so 0.5 um is not enough. After the final layout_regenerate, bind every PCell whose model differs from the schematic device type with layout_bind_device: rhigh, rppd, cmim, and RF guard-ring MOS. Regeneration rebuilds the generated cell and clears the bindings, so bind last and re-run LVS.

Passive ports and IHP resistor extraction

Use the device port names reported by layout_api(name=...) in the nets mapping: MOS devices use D/G/S/B; IHP rhigh, rppd, and cmim use PLUS/MINUS.

IHP resistor geometry is controlled by w and l. The R and Calculate parameters are CDF-only and do not resize the PCell, so set the body length explicitly:

# rhigh: Rspec = 1300 ohm/sq, rppd: Rspec = 260 ohm/sq
R1 = layout.device("rhigh", name="R1", w="1u", l="153.846u",
                   nets={"PLUS": "in", "MINUS": "n1"})

The IHP extraction rules recognize rhigh and rppd from the PolyRes body, require the pSD implant, and distinguish high-res by nSD. PEX reports R = Rspec * L / W; verify the extracted value against the schematic value. Both formulas are first-order and ignore contact resistance, so very small resistors should be checked against PEX.

Pass the target value as R (or C for capacitors) in addition to the geometry. IHP ignores those fields when drawing, but the planned-device metadata is what PEX prefers when both planned and polygon devices exist. Round passive dimensions to the 5 nm grid; off-grid PCell edges trigger off-grid DRC. For cmim, C = Cspec * w * l; the m parameter multiplies the netlist value but does not draw additional capacitor area. IHP MIM is about 1.5 fF/um^2, so a 10 kHz RC filter should use pF capacitors with MOhm resistors, not nF capacitors. MIM.g limits a single cmim to 5625 um^2, so split larger values into parallel units in both the schematic and the layout (for example, 10 pF as two 5 pF capacitors). The procedural runner rejects planned R/C values that differ from Rspec*l/w or Cspec*w*l by more than 10%.

PEX parasitics and finite buffer/op-amp gain typically lower the measured bandwidth by several percent. For a bandwidth target, aim for the upper half of the allowed tolerance band or add about 5% design margin, then check the PEX re-simulation.

Entry point

Create

Regenerate

GUI

Layout Hierarchy → + → Procedural Layout

Regenerate layout button or context menu

CLI

openvlsi-cli layout-add-procedural <project> <name> [pdk] [script-file] [stack]

openvlsi-cli layout-regenerate <project> <procedural> [timeout-seconds]

openvlsipy

project.create_procedural_layout(...)

project.regenerate_procedural_layout(name)

MCP

layout_create_procedural

layout_regenerate

The GUI runs scripts with a 60-second timeout. The CLI and MCP regeneration operations accept a timeout override. Set OPENVLSI_PYTHON to choose the interpreter; otherwise python3 is used.

Coordinates and units

Geometry methods take integer database units. A new project normally uses a 1 nm database unit, so an explicit number is a nanometer count. Prefer the unit helpers so scripts remain readable and adapt to the project unit:

Helper

Meaning

layout.db(value)

Round a value to integer database units.

layout.nm(value)

Convert nanometers to database units.

layout.um(value)

Convert micrometers to database units.

layout.snap(value)

Snap a database-unit value to the project grid.

layout.length(value)

Parse a suffix such as 2.5u, 150n, or 1mm.

The builder also exposes layout.grid (snap grid in database units) and layout.db_unit_nm (database unit size). All emitted geometry is rounded to integer database units.

Layers

layout.layer(name, number=None, datatype=None) registers or resolves a layer and returns a reusable procedural_runner.Layer handle. When the stream values are omitted, OpenVLSI resolves the layer from the active PDK package or from layers already present in the project. Explicit values are used as a fallback.

Purpose-specific layers keep their own datatype. For example, a pin layer can be declared independently of its drawing layer:

m1 = layout.layer("Metal1")
m1_pin = layout.layer("Metal1.pin", 8, 2)

m1.rectangle(0, 0, 4000, 600)
m1_pin.rectangle(0, 0, 400, 600)

The same calls are available as layout.rectangle("Metal1", ...) and layout.polygon("Metal1", ...) when a handle is not convenient. Layout.rect and Layout.poly are aliases for Layout.rectangle and Layout.polygon; Layer.rect and Layer.poly are the matching layer-handle aliases.

Geometry

Rectangle, polygon, path, text, and boolean methods return a procedural_runner.Shape handle whose name and net attributes can be edited after creation. The net is used by connectivity checks and by the autorouter to distinguish connectable geometry from obstacles.

Rectangles, polygons, and holes

metal = layout.layer("Metal2")

metal.rectangle(0, 0, 4000, 600, name="body", net="OUT")
metal.polygon(
    [(0, 1000), (4000, 1000), (4000, 3000), (2000, 4000), (0, 3000)],
    holes=[[(1000, 1500), (3000, 1500), (3000, 2500), (1000, 2500)]],
    name="shield",
    net="VSS",
)

Polygon points may be (x, y) tuples or mappings with x and y keys. Widths and heights must be positive; invalid geometry raises an error and aborts the run.

Paths and text

metal.path([(0, 0), (4000, 0), (4000, 2000)], width=layout.um(0.5), net="VDD")
metal.text(0, 2500, "M2", height=layout.um(0.5), net="VDD")

A path stores its centerline and width; OpenVLSI expands it to polygons for display, bounds, and layout.iter_polygons(). Text is stored as a bounding rectangle with text metadata. When width is omitted, the text width is estimated from the label length and height.

Boolean operations

layout.boolean(operation, layer, *operands) combines shapes, rectangles, or point lists on the output layer. The helpers union, intersection, subtract, and xor are convenience wrappers:

left = metal.rectangle(0, 0, 3000, 1000)
right = metal.rectangle(1000, 500, 3000, 1000)
merged = layout.union("Metal2", left, right, name="merged", net="VDD")

Operands may be consumed by the operation, so create fresh shapes when the original geometry is still needed.

Inspection helpers

PDK extensions such as dummy fill can inspect the completed builder:

  • layout.iter_polygons(layer=None) yields (layer_name, [(x, y), ...]) for rectangles, polygons, and expanded path segments.

  • layout.bounds(layer=None) returns (min_x, min_y, max_x, max_y) or None when no geometry matches. Without a layer filter it includes ports and child instances; pass a layer name to restrict the result to shapes on that layer.

  • layout.cells is the project layout-cell catalog keyed by cell name. Each entry carries the cell bounds and ports when OpenVLSI supplied the catalog.

  • layout.layer_number(name) returns the registered GDS layer number.

Ports

layout.port(...) adds an intrinsic OpenVLSI port to the generated cell. Ports participate in hierarchy wiring, connectivity checks, and LVS. OpenVLSI uses port for a layout-cell terminal and pin for a schematic-symbol terminal; LEF/DEF keep their PIN keyword at the file-format boundary.

layout.port(
    "OUT",
    "Metal1",
    3000,
    0,
    1000,
    600,
    direction="output",
    side="right",
    net="OUT",
    label="OUT",
)

The layer argument is required. It is stored as the port’s layer association and is used by the router. It does not make the port process-layer geometry, and the named layer may be a routing layer rather than a PDK pin purpose. The port rectangle, name, direction, side, label, net, and layer are saved in the generated cell’s ports.

  • direction is input, output, inout, power, or ground.

  • side is left, right, top, or bottom.

  • label defaults to the port name.

  • visible and locked control editor behavior.

  • net binds the port to a layout net.

Instances and arrays

Use layout.instance(cell, x, y, orientation="r0", name=None) to place an existing layout cell by name. The generated cell references the target cell; geometry is not copied. Targets may be static layout cells, other generated cells, imported digital devices, or package fixed-device cells.

layout.instance(...) returns a LayoutInstancePlacement handle. It reports the referenced cell’s real bounds, width, height, ports, and port_info, and it can be moved, mirrored, added to rows/columns/grids, or used as a routing endpoint:

block = layout.instance("top_impl device", 0, 0, name="DIGITAL")
pad = layout.layer("Metal1", 34).rectangle(0, 0, 100, 100)

row = layout.row(gap=0)
row.add(pad)
row.add(block)          # packed using the digital cell's real width
layout.add(row)

print(block.bounds)     # {"x": ..., "y": ..., "width": ..., "height": ...}
print(block.ports["clk"])
layout.connect(device, "G", block, "clk", layer="Metal1")

Digital devices imported from an implementation run (implementation-import or implementation_import_layout) are read-only layout cells. The import copies the top-level DEF pins, directions, and pin nets onto the flattened device, so layout.instance(...).ports and layout.connect(...) can route to them. Use the cell name reported by the import, for example "top_impl device".

layout.array(cell, count, pitch, ...) places a rectangular array and returns the instance names. count and pitch are (columns, rows) and (x_pitch, y_pitch).

Supported instance orientations are r0, r90, r180, r270, mx, my, m45, and m135. Device placement supports r0, r90, r180, r270, mx, and my.

Parameters

Declare a parameter with layout.parameter(name, default, description). The method returns the current value as a string, using the default only when the project has no stored value.

length = layout.um(layout.parameter("length", "10", "Channel length in um"))
fingers = int(layout.parameter("nf", "2", "Number of fingers"))

Declared parameters appear in the GUI parameter form above the script editor. They can also be changed before regeneration through:

  • CLI: openvlsi-cli layout-set-parameter <project> <procedural> <name> <value>

  • openvlsipy: project.set_procedural_parameter(layout_name, parameter_name, value)

  • MCP: layout_set_parameter

A procedural layout reports needs_regeneration when its script hash or parameter hash differs from the last successful run.

Devices

layout.device(...) places a device from the active package’s layout device library. The library may contain generated PCells and fixed .ovlay cells. Device geometry is flattened into the generated cell, while a planned-device record preserves the model, parameters, and terminal nets for LVS and PEX.

m1 = layout.device(
    "nfet", name="M1", x=0, y=0,
    w="2", l="0.15", nf="1",
    nets={"G": "GATE", "D": "OUT", "S": "VSS", "B": "VSS"},
)
m2 = layout.device(
    "nfet", name="M2", x=layout.um(12), y=0,
    w="4", l="0.15", nf="1",
    nets={"G": "GATE", "D": "OUT", "S": "VSS", "B": "VSS"},
)

The returned procedural_runner.DevicePlacement exposes absolute port rectangles as attributes (m1.G) and as a mapping (m1.ports["G"]). It also reports device, model, parameters, bounds, and per-port port_info. Emitted device ports are prefixed with the instance name and marked internal, so multiple copies can coexist.

Device parameters are passed as keyword strings. Matching is case-insensitive and falls back to a substring match against the library index. A missing package library, unknown device, or failed PCell generator raises an error.

Composition

Rows, columns, grids, stacks, and repeats compose existing handles without manual coordinate arithmetic. Each composition is itself a handle with bounds, ports, anchor, move, and mirror, so compositions can be nested and placed into a group or the root builder.

pair = layout.group("input_pair")
m1 = pair.device("nfet", name="M1", w="2", l="0.15",
                 nets={"G": "IN", "D": "OUTN", "S": "VSS"})
m2 = pair.device("nfet", name="M2", w="2", l="0.15",
                 nets={"G": "IN", "D": "OUTP", "S": "VSS"})
m2.mirror("y")

core = layout.row(gap=0, align="bottom")
core.add(m1)
core.add(m2)
core.add(layout.spacer(layout.um(0.5)))
core.add(layout.generate("rail", width=layout.um(8), height=layout.um(0.4)))
layout.add(core, x=layout.um(2), y=layout.um(1))

Method

Purpose

layout.group(name=None)

Local-coordinate fragment with the full builder API.

layout.row(gap, align, distribute, width)

Horizontal composition.

layout.column(gap, align, distribute, height)

Vertical composition.

layout.grid(columns, x_gap, y_gap, align)

Fixed-column grid. layout.grid remains the integer snap grid, but is callable for grid composition.

layout.stack(items, align)

Overlay items on a common origin.

layout.repeat(unit, count, axis, pitch, mirror, alternate)

Repeated, optionally mirrored copies.

layout.spacer(distance)

Fixed gap in a row or column.

layout.stretch(weight=1)

Flexible gap that consumes slack.

layout.add(item, x, y, mirror, prefix)

Copy a composition into the current builder.

Row and column alignment accepts top, bottom, center, left, and right. distribute="space-between" or "equal" distributes slack when an explicit width or height is given; layout.stretch() participates in the same slack distribution. repeat(..., pitch="abut") places copies edge to edge, and mirror=True, alternate=True produces alternating mirrored copies for interdigitated structures.

Composition copies groups and repetitions, but consumes concrete shapes, devices, and routes: adding m1 to a row removes m1’s records from its previous builder while keeping the m1 handle valid. Port names from repeated copies are suffixed (P, P_2, P_3, …). Use layout.add(..., prefix=...) when embedding a fragment with names that already exist.

Inspection and measurement

layout.extents([m1, m2])       # union bounds or None
layout.clearance(m1, m2)       # edge-to-edge gap; negative when overlapping
layout.overlaps(m1, m2)
layout.contains(frame, core)
layout.distance(m1, m2, axis="x")
layout.measure(core)           # bounds, width, height, area

Every handle also exposes bounds, width, height, ports, port(name), anchor(name), move(dx, dy), mirror(axis), and is_empty. Composition and shape bounds are (x0, y0, x1, y1) tuples; DevicePlacement.bounds keeps the existing x/y/width/height mapping for router compatibility. mirror(axis="y") flips horizontally; use axis="x" to flip vertically.

Constraints

Constraints express local placement intent that is awkward to encode as nested rows and columns. They resolve deterministically and modify the involved records in place:

layout.constraint("Order", items=[m1, m2, m3],
                  direction="left_to_right", abut=True)
layout.constraint("Align", items=[m1, m2, m3], line="h_center")
layout.constraint("Symmetric", pairs=[[m1, m2]], axis="vertical")
layout.constraint("Spread", items=[m1, m2, m3],
                  direction="horizontal", distance=layout.um(0.4))
layout.constraint("Boundary", max_width=layout.um(60), max_height=layout.um(40))
layout.constraint("PortLocation", port="IN", side="left", align="center")

Convenience wrappers are available for the common cases: layout.align, layout.order, layout.abut, layout.symmetric, layout.distribute, and layout.boundary. Supported constraints are Align, AlignInOrder, Order, Symmetric, Group, Boundary, AspectRatio, Spread, Grid, PortLocation, and Generator. Invalid handles, unknown ports, and unsatisfiable boundaries or aspect ratios raise an error before geometry is committed.

Cell generators

A generator is a reusable function that builds a local group. Declare an inline generator with @layout.generator and instantiate it with layout.generate:

@layout.generator(
    name="nmos_pair",
    description="Matched NMOS pair",
    parameters={"device": "nfet", "w": "2", "l": "0.15"},
    ports=["D1", "G1", "S", "D2", "G2", "B"],
)
def nmos_pair(ctx, device, w, l):
    row = ctx.row(gap=0, align="center")
    left = ctx.device(device, name="M1", w=w, l=l, nets={"S": "VSS"})
    right = ctx.device(device, name="M2", w=w, l=l, nets={"S": "VSS"})
    right.mirror("y")
    row.add(left)
    row.add(right)
    return row

pair = layout.generate("nmos_pair", w="4")
layout.add(pair)

Built-in generators are available without a package: mos, mos_pair, resistor, resistor_bank, cap, cap_array, via_stack, guard_ring, rail, and route_bundle. Device-based built-ins accept the package device name and pass remaining parameters to layout.device. Packages may provide additional generators under <pdk>/layout/generators/; a package entry with the same name replaces the built-in one. Generator metadata is reported in the generated JSON for GUI, CLI, and MCP discovery. python3 assets/layout/procedural_runner.py --list-generators prints the built-in metadata as JSON.

Area quality check

A layout that routes correctly can still waste most of its area. Use the smallest DRC-safe gap: gap=0 is only for isolated devices with no DRC interaction, while abutting active devices, wells, and guard rings usually need about 0.5 um or the PDK minimum. Prefer one shared routing channel over fixed padding between every device.

Planning and the compaction gate

Declare a plan before placing devices:

layout.plan(
    devices=["M1", "M2", "M3", "M4"],
    rows=2,
    target_utilization=0.25,
    max_gap_um=10,
    require_composition=True,
)

# Place and compact the devices.
layout.finish_placement()   # or layout.compact()

layout.finish_placement() runs the quality report and verifies the declared device set, row count, utilization, maximum row gap, and composition requirements. When the plan sets require_gate=True (the default), route() and connect() are blocked until the gate passes. A failed gate raises an error with the failing metrics; compact the placement and call finish_placement() again.

Quality report

Call layout.report() after placement and routing:

layout.report(print_report=True)

The report includes:

  • cell_area_um2, device_area_um2, instance_area_um2, occupied_area_um2, and utilization;

  • device_utilization for device-only area, and macro-aware utilization that includes placed child instances;

  • row-grouped rows, row_count, max_horizontal_gap_um, and large_gaps;

  • composition_used, placement_style, manual_move_count, and composition counters;

  • plan_present, plan_passed, shape, port, device, and instance counts;

  • warnings for low utilization and large gaps inside one row.

The plan gate and review use utilization, so an imported digital block counts toward the area budget even when the layout has no planned devices.

Devices are grouped into row bands by vertical center and similar height before gaps are measured. This keeps tall passives such as MIM capacitors from being compared with every small transistor in the cell.

Separate review

After routing and verification, run the independent review step:

layout.review(
    min_utilization=0.25,
    max_gap_um=10,
    require_composition=True,
    require_plan=True,
)

review() returns passed, issues, the placement quality, the final cell_quality, and the declared plan. It is also exposed as the MCP tool layout_review and the CLI command layout-review.

The generated JSON now carries layout_quality, layout_plan, and layout_review. MCP layout_regenerate and CLI layout-regenerate return those objects directly, so agents do not need to parse the generation log to see whether the compaction gate passed. A good first target is utilization above roughly 20–25% with no unexplained row gap above roughly 10 µm.

Routing

The builder includes a deterministic Manhattan router for both points and placed device or layout-instance ports.

Point and rectangle routing

route = layout.route(
    (0, 0),
    (layout.um(20), 0),
    layer="Metal1",
    width=layout.um(0.4),
    net="VDD",
)
print(route.length, route.bends, route.via_count)

start and end may be (x, y) points, (x, y, width, height) port rectangles, or port tuples from a DevicePlacement or LayoutInstancePlacement. Rectangle endpoints escape from start_side / end_side (or the side nearest the other endpoint) by escape. The router avoids placed device and instance bounds and other-net shapes by default and raises an error rather than emitting a short when no legal path exists.

Connecting device and instance ports

layout.connect(m1, "G", m2, "G", layer="Metal1", net="GATE")
layout.connect(m1, "D", digital, "out", layer="Metal1", net="OUT")

connect(device_a, pin_a, device_b, pin_b, ...) reads port layers, sides, and nets from the placements. Same-layer ports can use layer; ports on different layers require layers=[...] in vertical stack order. The router inserts via stacks between adjacent layers when the package exposes via metadata.

Multi-layer routing and vias

route = layout.route(
    m2.D,
    (layout.um(20), layout.um(2), layout.um(1), layout.um(0.6)),
    layers=["Metal1", "Metal2"],
    width=layout.um(0.4),
    net="OUT",
)

When layer and layers are both omitted, layout.routing_stack() supplies the package’s declared stack. technology/connectivity.json declares layer roles, and via rules provide the cut layer, size, and enclosure. The router falls back to common names such as via/via2, Via1/Via2, and Metal1/Metal2 when no explicit mapping is available. Use via_layers to override the mapping, and via_size, via_enclosure, and via_cost to tune transition geometry and cost.

Additional routing controls:

Argument

Effect

width

Trace width; default 0.4 µm.

clearance

Edge-to-edge clearance; default max(width, 0.2 µm).

escape

Port escape distance; default max(2 * width, 0.5 µm).

obstacles

Extra rectangles, a list, or per-layer obstacle mappings.

bend_penalty

Extra cost per bend; default max(2 * width, 1 µm).

include_devices

Treat other device bounds as obstacles.

include_shapes

Treat other-net layout shapes as obstacles.

start_layer / end_layer

Explicit endpoints in a layer stack.

The returned procedural_runner.Route reports net, layer, width, points, point_layers, segments, vias, shapes, length, bends, layer_stack, and via_count. Its metal and via shapes are already part of the generated layout.

PDK-provided operations

Procedural scripts can request process-specific work through generic builder calls. OpenVLSI dispatches the request to the active package after the user script finishes.

Dummy fill

layout.add_dummy_fill(layers=["Metal1", "Metal2"], density=50, deviation=10)

The package implementation lives at layout/dummy_fill.py and receives the completed builder. The IHP SG13G2 package implements dummy metal fill for its stack. A package without the implementation reports a clear error. See Package and PDK Authoring for the package contract and routing connectivity schema.

Routing stack and device library

The router consults technology/connectivity.json for the declared vertical stack and via rules. Device placement consults layout/devices/index.json, generated PCells, and fixed device cells. Both are package-owned, so switching the active layout to another PDK switches the available devices and routing metadata.

Execution and validation

A run is isolated from the project database:

  1. OpenVLSI writes the script and parameter JSON to a temporary directory.

  2. Python executes the script with the layout builder.

  3. The builder emits a versioned JSON document with layers, parameters, shapes, ports, instances, and devices.

  4. OpenVLSI parses and validates the document, then applies it to the project.

  5. The generated child replaces its previous contents; its script/output hashes and stale state are updated.

If the script fails, times out, emits no output, or produces invalid geometry, the run reports the Python error or validation message and leaves the previous generated cell unchanged. The generated cell is read-only and is never a place for manual edits.

API reference

The reference below is generated by Sphinx autodoc from the public docstrings in assets/layout/procedural_runner.py.

Run an OpenVLSI procedural layout script and emit generated geometry as JSON.

The user script is executed with a single injected object named layout. It builds an in-memory description of the generated static layout. OpenVLSI parses the resulting JSON, validates it, and applies it to the project’s layout database.

Coordinates are integer database units (one nanometer by default). Use layout.nm(...), layout.um(...), layout.db(...), and layout.snap(...) to work in physical units.

The public script-facing API is documented on the procedural layout API page. Scripts should normally use Layout, Layer, Shape, DevicePlacement, and Route; composition helpers return Group, Row, Column, Grid, Stack, and Repeat handles. The remaining names in this module are runner internals.

class procedural_runner.Layout(pdk=None, pdk_root=None, db_unit_nm=1.0, grid=1, parameters=None, cells=None)

Builder exposed to procedural layout scripts as layout.

A script writes geometry by calling methods on this object. OpenVLSI executes the script in a temporary directory, reads the builder’s output, validates it, and replaces the read-only generated child of the procedural layout. Coordinates are integer database units by default; use nm(), um(), db(), or snap() for physical values.

Variables:
  • pdk – Active PDK package id, or None for a generic layout.

  • pdk_root – Installed package root used for device and connectivity lookups, or None when no package is active.

  • db_unit_nm – Size of one database unit in nanometers.

  • grid – Project manufacturing/snap grid in database units.

  • params – Current parameter values keyed by parameter name.

  • parameter_specs – Declared parameter metadata keyed by name.

  • cells – Project layout-cell catalog keyed by cell name. Entries carry bounds and ports when OpenVLSI supplied the catalog.

  • layers – Registered layer specs keyed by layer name.

  • shapes – Emitted shape records in creation order.

  • ports – Emitted port records in creation order.

  • instances – Emitted child-instance records in creation order.

  • devices – Planned-device metadata used by LVS and extraction.

  • dummy_fill_requests – Queued PDK dummy-fill requests.

layer(name, number=None, datatype=None)

Register or resolve a layer and return a reusable handle.

When number/datatype are omitted, OpenVLSI resolves the layer from the active PDK package or the project’s existing layers. Explicit values win when no matching PDK/project layer exists. A purpose suffix such as Metal1.pin is preserved, so pin layers can carry their own datatype.

Parameters:
  • name – Non-empty layer name.

  • number – Optional GDS layer number.

  • datatype – Optional GDS datatype.

Returns:

A Layer handle bound to the resolved name.

Raises:

ValueError – If the name is empty or the stream values are negative.

rectangle(layer, x, y, width, height, name=None, net=None)

Draw an axis-aligned filled rectangle.

Parameters:
  • layer – Layer name or Layer handle.

  • x – Left edge in database units.

  • y – Bottom edge in database units.

  • width – Positive width in database units.

  • height – Positive height in database units.

  • name – Optional shape name.

  • net – Optional net name for connectivity checks and routing.

Returns:

The created Shape.

polygon(layer, points, holes=None, name=None, net=None)

Draw a filled polygon, optionally with hole contours.

Points may be (x, y) tuples or mappings with x and y keys. Holes use the same point format and must contain at least three points.

Parameters:
  • layer – Layer name or Layer handle.

  • points – Outer contour with at least three points.

  • holes – Optional list of hole contours.

  • name – Optional shape name.

  • net – Optional net name for connectivity checks and routing.

Returns:

The created Shape.

Raises:

ValueError – If the contour has fewer than three points.

boolean(operation, layer, *operands, name=None, net=None)

Combine two or more rectangles/polygons with a boolean operation.

Supported operations are union, intersection, difference and xor. Operands can be Shape handles, (x, y, width, height) rectangles, or point lists. The result is emitted on layer and the operand shapes are consumed by the operation.

Parameters:
  • operation – union, intersection, difference, or xor (aliases such as or, and, subtract, and minus are accepted).

  • layer – Output layer name or Layer handle.

  • operands – Two or more shapes or geometry operands.

  • name – Optional shape name.

  • net – Optional net name.

Returns:

The created Shape.

union(layer, *operands, name=None, net=None)

Alias for boolean("union", ...).

intersection(layer, *operands, name=None, net=None)

Alias for boolean("intersection", ...).

subtract(layer, *operands, name=None, net=None)

Alias for boolean("difference", ...).

xor(layer, *operands, name=None, net=None)

Alias for boolean("xor", ...).

path(layer, points, width, name=None, net=None)

Draw a stroked polyline as a path shape.

The path stores its centerline and width. OpenVLSI expands it to polygons for display and for iter_polygons().

Parameters:
  • layer – Layer name or Layer handle.

  • points – Two or more centerline (x, y) points.

  • width – Positive path width in database units.

  • name – Optional shape name.

  • net – Optional net name for connectivity checks and routing.

Returns:

The created Shape.

text(layer, x, y, text, height=1000, width=None, name=None, net=None)

Place a text label on a layer.

Text is represented as a bounding rectangle with text metadata. When width is omitted, a readable width is estimated from the label length and text height.

Parameters:
  • layer – Layer name or Layer handle.

  • x – Left edge in database units.

  • y – Bottom edge in database units.

  • text – Non-empty label.

  • height – Text height in database units (default 1000).

  • width – Optional explicit text width in database units.

  • name – Optional shape name.

  • net – Optional net name.

Returns:

The created text Shape.

via(layers, x, y, size=1000, width=None, height=None, name=None, net=None)

Draw one rectangle on each of layers to form a via stack.

This is a geometry convenience helper; it does not emit router via metadata. Use route() or connect() when the via must be included in an autorouted connection.

Parameters:
  • layers – Layer name or list of layer names, ordered bottom-up.

  • x – Left edge of the via cut in database units.

  • y – Bottom edge of the via cut in database units.

  • size – Default square size in database units.

  • width – Optional width override.

  • height – Optional height override.

  • name – Optional name prefix; each layer gets name_<index>.

  • net – Optional net name applied to every shape.

Returns:

List of created Shape handles.

array(cell, count, pitch, x=0, y=0, orientation='r0', name=None)

Place a rectangular array of copies of an existing layout cell.

Instances are named <name>_<column>_<row> and reference cell rather than copying its geometry. The target may be a static layout cell, another generated cell, an imported digital device, or a package fixed-device cell.

Parameters:
  • cell – Layout cell name.

  • count – (columns, rows), both positive.

  • pitch – (x_pitch, y_pitch) in database units.

  • x – Optional x offset in database units.

  • y – Optional y offset in database units.

  • orientation – Placement orientation (see instance()).

  • name – Optional instance-name prefix (default array).

Returns:

List of placed instance names.

port(name, layer, x, y, width, height, direction='inout', side='left', net=None, label=None, visible=True, locked=False)

Add an intrinsic port to the generated layout cell.

Ports are part of the generated cell’s interface and can be used for hierarchy wiring, connectivity checks, LVS, and routing.

Parameters:
  • name – Non-empty port name.

  • layer – Layer name or Layer handle.

  • x – Left edge in database units.

  • y – Bottom edge in database units.

  • width – Positive port width in database units.

  • height – Positive port height in database units.

  • direction – input, output, inout, power, or ground.

  • side – left, right, top, or bottom.

  • net – Optional net name bound to the port.

  • label – Optional display label; defaults to name.

  • visible – Whether the port is visible in the layout editor.

  • locked – Whether the port is protected from editing.

Returns:

None. The port is stored on the builder.

pin(name)

Return a port rectangle (x, y, width, height) by name.

instance(cell, x, y, orientation='r0', name=None)

Place an instance of an existing layout cell.

The instance references another cell in the project, including static layouts, other generated procedurals, imported digital devices, and package fixed devices. Geometry is not copied into the generated cell. The returned handle is already part of the builder and can be moved, mirrored, composed with add()/row/column helpers, or used as a routing endpoint.

Cell names are validated against the project cell catalog when OpenVLSI supplies one. Matching is case-insensitive and the canonical project name is stored in the instance.

Parameters:
  • cell – Non-empty layout cell name.

  • x – Placement x origin in database units.

  • y – Placement y origin in database units.

  • orientation – r0, r90, r180, r270, mx, my, m45, or m135.

  • name – Optional instance name.

Returns:

A LayoutInstancePlacement handle.

parameter(name, default='', description='')

Declare a user-editable parameter and return its current value.

Parameter values are always strings. Use um(), nm(), length(), or int()/float conversions in the script. Declared parameters appear in the GUI parameter form and can be changed with the CLI, openvlsipy, or MCP before regeneration.

Parameters:
  • name – Non-empty parameter name.

  • default – Value used when the project has no stored value.

  • description – Human-readable description shown by the editor.

Returns:

The current value as a string.

device(device_name, x=0, y=0, orientation='r0', name=None, nets=None, **parameters)

Place a package layout device (PCell or fixed cell) into this layout.

The device geometry is flattened into the generated layout, while a device record preserves its model, parameters, and terminal nets for LVS and extraction. Ports are prefixed with the instance name so multiple copies can coexist. nets maps device port names to layout net names, for example nets={"G": "GATE", "S": "VSS"}.

Parameters:
  • device_name – Device-library cell name; matching is case-insensitive and falls back to a substring match.

  • x – Placement x origin in database units.

  • y – Placement y origin in database units.

  • orientation – r0, r90, r180, r270, mx, or my.

  • name – Optional instance name; defaults to device_<n>.

  • nets – Optional mapping of port names to layout net names.

  • parameters – Device parameters as keyword arguments, for example w="2u" or nf="2".

Returns:

A DevicePlacement with absolute port rectangles.

Raises:

RuntimeError – If the active package has no device library, the device cannot be found, or its generator fails.

routing_stack()

Return the vertical routing stack declared by the PDK package.

Names are resolved to the layer spellings registered by the device library when possible, so the returned list can be passed directly to route() or connect(). When the package does not declare a stack, conductor layers are inferred from names such as met1, Metal2, or m3.

Returns:

Ordered list of layer names, bottom to top.

route(start, end, layer=None, width=None, net=None, start_side=None, end_side=None, obstacles=None, clearance=None, escape=None, bend_penalty=None, include_devices=True, include_shapes=True, exclude_device_bounds=None, layers=None, via_layers=None, via_size=None, via_enclosure=None, via_cost=None, start_layer=None, end_layer=None)

Route one Manhattan connection between two points or rectangles.

Use layer for a single-layer route, or layers=[...] to route through a vertical layer stack. When both are omitted, the PDK package’s declared routing stack is used. In a multi-layer route the router may insert via stacks between adjacent layers. via_layers maps a (lower, upper) pair to one cut layer or a list of cut layers; when omitted, the package connectivity document is consulted first and common names such as via/via2, Via1/Via2 and Metal1/Metal2 are used as a fallback.

Endpoints may be (x, y) points, (x, y, width, height) port rectangles, or port tuples from a DevicePlacement. Rectangle endpoints escape from the requested or nearest side by escape. The router is deterministic and raises an error instead of emitting a short when no legal path exists.

Parameters:
  • start – Start point or port rectangle.

  • end – End point or port rectangle.

  • layer – Single routing layer name or Layer handle.

  • width – Route width in database units (default 0.4 µm).

  • net – Optional net name carried by the emitted shapes.

  • start_side – Preferred escape side for a start rectangle: left, right, top, or bottom.

  • end_side – Preferred escape side for an end rectangle.

  • obstacles – Extra obstacle rectangle(s), a list, or a mapping from layer name to obstacle rectangles.

  • clearance – Edge-to-edge clearance in database units (default max(width, 0.2 µm)).

  • escape – Port escape distance (default max(2 * width, 0.5 µm)).

  • bend_penalty – Extra cost per bend (default max(2 * width, 1 µm)).

  • include_devices – Treat placed device bounds as obstacles.

  • include_shapes – Treat other-net layout shapes as obstacles.

  • exclude_device_bounds – Device bounds that should not block the route even when include_devices is true.

  • layers – Vertical layer stack, bottom to top.

  • via_layers – Mapping of adjacent layer pairs to via cut layer(s).

  • via_size – Via cut size in database units (default 0.15 µm).

  • via_enclosure – Via enclosure in database units (default 0.1 µm).

  • via_cost – Cost of changing layers (default max(4 * width, 1 µm)).

  • start_layer – Explicit start layer when using a stack.

  • end_layer – Explicit end layer when using a stack.

Returns:

A Route describing the emitted path.

Raises:
  • RuntimeError – If no legal path or via transition exists.

  • ValueError – If endpoints, layers, or side arguments are invalid.

connect(device_a, pin_a, device_b, pin_b, layer=None, width=None, net=None, obstacles=None, clearance=None, escape=None, bend_penalty=None, include_devices=True, include_shapes=True, layers=None, via_layers=None, via_size=None, via_enclosure=None, via_cost=None)

Route directly between two ports of placed devices or layout instances.

device_a and device_b may be DevicePlacement objects returned by device() or LayoutInstancePlacement handles returned by instance(). For a single-layer connection, layer is optional when both ports already share a layer. For ports on different layers, pass layers=[...] in vertical stack order and, if the package does not expose inferable via names, a via_layers mapping. The net is inferred from the port metadata when net is omitted, and connecting ports on different nets is rejected.

Parameters:
  • device_a – First placed device or layout instance.

  • pin_a – Port name on device_a (for example "G").

  • device_b – Second placed device or layout instance.

  • pin_b – Port name on device_b.

  • layer – Single routing layer for a same-layer connection.

  • width – Route width in database units (default 0.4 µm).

  • net – Optional net name; must agree with port nets when set.

  • obstacles – Extra obstacle rectangle(s), a list, or a mapping from layer name to obstacle rectangles.

  • clearance – Edge-to-edge clearance in database units.

  • escape – Port escape distance in database units.

  • bend_penalty – Extra cost per bend.

  • include_devices – Treat other device bounds as obstacles.

  • include_shapes – Treat other-net layout shapes as obstacles.

  • layers – Vertical layer stack, bottom to top.

  • via_layers – Mapping of adjacent layer pairs to via cut layer(s).

  • via_size – Via cut size in database units.

  • via_enclosure – Via enclosure in database units.

  • via_cost – Cost of changing layers.

Returns:

A Route describing the emitted connection.

Raises:
  • TypeError – If an argument is not a device or layout instance.

  • ValueError – If a port or layer is unknown, or the ports belong to different nets.

  • RuntimeError – If no legal path or via transition exists.

property constraints

Constraint metadata recorded by constraint() and helpers.

property generator_metadata

Metadata for generators instantiated by this builder.

property is_empty

Whether this builder or group contains no records.

property width

Bounding-box width of the builder or group.

property height

Bounding-box height of the builder or group.

move(dx, dy)

Translate every record in this builder and return self.

mirror(axis='y')

Mirror every record about its own bounds center.

add(item, x=0, y=0, mirror=None, prefix=None)

Place a composed fragment into this builder.

Shapes, devices, routes, groups, rows, columns, grids, stacks, and repeats are accepted. Placement copies the item’s records; the source handle remains valid and can be placed again.

group(name=None)

Create a local-coordinate layout fragment.

row(items=None, gap=0, align='bottom', distribute='fixed', width=None, name=None)

Create a horizontal composition, optionally adding items immediately.

column(items=None, gap=0, align='left', distribute='fixed', height=None, name=None)

Create a vertical composition, optionally adding items immediately.

stack(items=None, align='center', name=None)

Create an overlay composition.

repeat(unit=None, count=1, axis='x', pitch='abut', mirror=False, alternate=False, name=None)

Repeat a layout fragment along one axis.

spacer(distance=0, height=None)

Reserve a fixed gap inside a row or column.

stretch(weight=1)

Consume slack inside a row or column with an explicit size.

extents(*items)

Return the union bounds of handles, or None when empty.

clearance(first, second)

Return the edge-to-edge gap between two handles.

The result is negative when the bounding boxes overlap.

overlaps(first, second)

Whether two handle bounds overlap with positive area.

contains(outer, inner)

Whether outer fully contains inner.

distance(first, second, axis='x')

Return the center-to-center distance along axis.

measure(*items)

Return a dictionary describing the bounds of the given items.

report(gap_threshold=None, print_report=False)

Summarize layout area, device utilization, rows, and row gaps.

The report is intended as an agent-facing quality check. Devices are grouped into row bands by vertical center and similar height before gaps are measured, so a tall passive or routing blockage is not compared with every small device in the cell. A low device-area utilization or a large gap inside a row usually means fixed spacing was used where rows, columns, abutment, or constraints would pack the layout more tightly.

Parameters:
  • gap_threshold – Horizontal gap in database units that counts as large. Defaults to 10 micrometers.

  • print_report – Print the report as JSON so it appears in the procedural-run log.

Returns:

A JSON-compatible dictionary.

plan(devices=None, rows=None, columns=None, target_utilization=0.20, max_gap_um=10.0, require_composition=False, require_gate=True, notes=None)

Declare the placement plan that the compaction gate will verify.

Call this before placing devices. The plan is intentionally simple: expected devices, row/column grouping, a minimum device-area utilization, a maximum row gap, and whether composition helpers are required. finish_placement() (or compact()) must pass before route() or connect() is allowed when require_gate is true.

finish_placement()

Run the compaction gate and open routing.

The gate checks the declared plan against the current devices and quality report. A failed gate raises LayoutQualityError and leaves routing blocked.

compact()

Run the compaction gate and open routing.

The gate checks the declared plan against the current devices and quality report. A failed gate raises LayoutQualityError and leaves routing blocked.

review(min_utilization=None, max_gap_um=None, require_composition=None, require_plan=False)

Run the separate layout-review step and record its result.

Review is intentionally independent of the authoring flow: an agent can call it after routing, or a reviewer can call it on a generated layout. It returns a pass/fail record with actionable issues and the quality report used for the decision.

abut(first, second, edge='right', gap=0)

Move second against one edge of first.

distribute(items, axis='x', mode='equal')

Distribute item centers evenly between the first and last item.

constraint(kind, **options)

Apply a deterministic, local layout constraint.

Supported constraints are Align, AlignInOrder, Order, Symmetric, Group, Boundary, AspectRatio, Spread, Grid, PortLocation, and Generator.

align(*items, line='h_any')

Convenience wrapper for the Align constraint.

order(items, direction='left_to_right', abut=False, gap=0)

Convenience wrapper for the Order constraint.

symmetric(pairs, axis='vertical')

Convenience wrapper for the Symmetric constraint.

boundary(max_width=None, max_height=None, halo=0, items=None)

Validate that current geometry fits the requested boundary.

generator(**metadata)

Register a cell generator declared in the current script.

generate(generator, **options)

Instantiate a registered or built-in cell generator.

add_dummy_fill(layers=None, density=None, deviation=None, area=None, **options)

Queue a PDK-provided dummy metal fill pass.

OpenVLSI runs the implementation shipped by the active PDK package after the script finishes, so the fill sees the complete layout. layers may be a layer name or a list of layer names. density and deviation are percentages and may be scalars or per-layer mappings. area optionally limits fill to (x0, y0, x1, y1) database units or a polygon point list. Additional keyword options are forwarded to the PDK implementation.

iter_polygons(layer=None)

Yield (layer_name, [(x, y), ...]) for every shape in the layout.

bounds(layer=None)

Return (min_x, min_y, max_x, max_y) for the selected geometry.

With no layer filter the result includes ports and child instances, so a layout containing only an imported macro still reports its real extent. Passing a layer name limits the result to shapes on that layer.

layer_number(name)

Return the GDS layer number registered for name, if any.

db(value)

Return value rounded to the nearest integer database unit.

nm(value)

Convert nanometers to integer database units.

The conversion uses db_unit_nm, which is normally 1 for a 1 nm database unit.

um(value)

Convert micrometers to integer database units.

snap(value)

Snap a database-unit value to the project grid.

length(value)

Convert a length string or bare number to database units.

Parses SPICE-style suffixes such as 2.5u, 150n, 4k, and 1mm. A bare number is interpreted as database units.

to_dict()

Return the builder output as a JSON-compatible dictionary.

This is the document OpenVLSI validates and applies after the script finishes; scripts normally do not need to call it directly.

class procedural_runner.Layer(layout, name, number=None, datatype=None)

Handle returned by Layout.layer().

The handle binds a layer name (and optionally its stream number and datatype) so geometry calls do not need to repeat the layer argument. rect and poly are aliases for rectangle() and polygon().

Variables:
  • name – Layer name, including any purpose suffix such as .pin.

  • number – GDS layer number, or None when it is resolved later.

  • datatype – GDS datatype, or None when it is resolved later.

rectangle(x, y, width, height, name=None, net=None)

Draw a rectangle on this layer; see Layout.rectangle().

polygon(points, holes=None, name=None, net=None)

Draw a polygon on this layer; see Layout.polygon().

path(points, width, name=None, net=None)

Draw a path on this layer; see Layout.path().

text(x, y, text, height=1000, width=None, name=None, net=None)

Draw text on this layer; see Layout.text().

class procedural_runner.Shape(layout, record)

Handle for a shape added through the layout builder.

Shapes are returned by Layout.rectangle(), Layout.polygon(), Layout.path(), Layout.text(), and the boolean helpers. A shape is already part of the generated layout when it is returned; the handle exposes its editable name and net metadata.

Variables:
  • name – Optional shape name shown in the layout hierarchy.

  • net – Optional layout net name. Routers treat same-net shapes as connectable geometry and other-net shapes as obstacles.

property bounds

Axis-aligned (x0, y0, x1, y1) bounds, or None when empty.

property width

Shape width in database units.

property height

Shape height in database units.

property is_empty

Whether the shape has no geometry.

property ports

Shapes never expose named ports; provided for handle symmetry.

pin(name)

Shapes have no ports; raises KeyError.

port(name)

Shapes have no ports; raises KeyError.

anchor(name='center')

Return an anchor point on the shape bounds.

move(dx, dy)

Translate the shape in place and return self.

mirror(axis='y')

Mirror the shape about its own x or y axis center.

property name

Shape name, or an empty string when the shape is unnamed.

property net

Layout net name, or an empty string when the shape has no net.

class procedural_runner.DevicePlacement(name, device, model, parameters, shapes, ports, port_info, bounds, layout=None, device_record=None, port_records=None)

Handle returned by Layout.device().

The device geometry is flattened into the generated layout, but this object keeps the absolute port rectangles and the device metadata so a script can route to the device and LVS can recognize it.

Port rectangles are available both as attributes and through ports, for example m1.G and m1.ports["G"]. Each port rectangle is a (x, y, width, height) tuple in database units and can be passed directly to Layout.route().

Variables:
  • name – Instance name used to prefix emitted port and shape names.

  • device – Device-library cell name.

  • model – SPICE model name when the device library declares one.

  • parameters – Resolved device parameter values as strings.

  • shapes – Flattened Shape handles emitted for the device.

  • ports – Mapping of port name to absolute (x, y, width, height).

  • port_info – Per-port metadata with rectangle, layer, side, direction, and net keys.

  • bounds – Absolute device bounding box as x, y, width, and height keys.

Iterating a placement yields its flattened shapes, len(placement) is the shape count, and indexing with a port name returns that port rectangle.

property width

Device bounding-box width in database units.

property height

Device bounding-box height in database units.

property is_empty

Whether the device has no flattened shapes or ports.

pin(name)

Return the absolute port rectangle for name.

port(name)

Return the absolute port rectangle for name.

anchor(name='center')

Return an anchor point on the device bounds.

move(dx, dy)

Translate the device geometry, ports, and metadata in place.

mirror(axis='y')

Mirror the device geometry and port metadata in place.

refresh()

Refresh port/bounds caches after composition moved the records.

class procedural_runner.LayoutInstancePlacement(layout, record, cell_info=None)

Composable handle returned by Layout.instance().

The instance is already part of the builder. This handle exposes the referenced cell’s real bounds and ports, and can be moved, mirrored, added to rows/columns/grids, or used as a routing endpoint. Cell bounds and port metadata come from the project cell catalog supplied by OpenVLSI; when the catalog is unavailable, composition falls back to a one-unit bounding box.

Variables:
  • cell – Referenced layout cell name.

  • name – Instance name in the generated layout.

  • x – Instance origin x in database units.

  • y – Instance origin y in database units.

  • orientation – Placement orientation (r0, r90, r180, r270, mx, my, m45, or m135).

  • bounds – Absolute bounding box as x, y, width, and height keys.

  • ports – Mapping of port name to absolute (x, y, width, height) rectangles.

  • port_info – Per-port metadata with rectangle, layer, side, direction, and net keys.

property bounds

Absolute instance bounding box.

When the cell catalog has no geometry for the target, the fallback is a one-unit square at the instance origin.

property is_empty

Instances are references, so they are never treated as empty.

pin(name)

Return the absolute (x, y, width, height) port rectangle.

port(name)

Return the absolute (x, y, width, height) port rectangle.

anchor(name='center')

Return an anchor point on the instance bounds.

move(dx, dy)

Translate the instance origin in place.

mirror(axis='y')

Mirror the instance placement in place.

refresh()

Compatibility hook; the handle always reads the live record.

class procedural_runner.Route(net, layer, width, points, point_layers, segments, vias, shapes, length, bends, layer_stack)

Handle returned by Layout.route() and Layout.connect().

A route is already committed to the generated layout: its metal and via shapes are appended to the builder and carry the requested net. The handle reports the planned path and geometry so scripts can inspect or reuse the result.

Variables:
  • net – Net name carried by the emitted shapes.

  • layer – Layer of the first route point.

  • width – Route width in database units.

  • points – Ordered (x, y) route points, including port centers.

  • point_layers – Layer name for each entry in points.

  • segments – Straight segments with start, end, and layer.

  • vias – Via records with x, y, lower, upper, via_layers, pad_size, and cut_size.

  • shapes – Emitted Shape handles.

  • length – Total Manhattan length in database units.

  • bends – Number of direction changes within a layer.

  • layer_stack – Layer names available to the route.

  • via_count – Number of via transitions.

Iterating a route yields its emitted shapes and len(route) is the shape count.

property bounds

Axis-aligned (x0, y0, x1, y1) bounds of the route shapes.

property is_empty

Whether the route emitted no shapes.

property ports

Routes never expose named ports; provided for handle symmetry.

pin(name)

Routes have no ports; raises KeyError.

port(name)

Routes have no ports; raises KeyError.

anchor(name='center')

Return an anchor point on the route bounds.

move(dx, dy)

Translate all route shapes and the planned path in place.

mirror(axis='y')

Mirror all route shapes and planned coordinates in place.

class procedural_runner.Group(parent, name=None)

Local-coordinate layout fragment.

A group has the same geometry, device, routing, and generator API as the root builder. Adding the group to a layout or composition copies its records, so one group can be instanced more than once.

property bounds

Axis-aligned bounds of the group fragment.

class procedural_runner.Row(layout, gap=0, align='bottom', distribute='fixed', width=None, name=None)

Horizontal composition with optional abutment and slack distribution.

class procedural_runner.Column(layout, gap=0, align='left', distribute='fixed', height=None, name=None)

Vertical composition with optional abutment and slack distribution.

add(item)

Add an item and reflow the composition.

class procedural_runner.Grid(layout, columns=1, x_gap=0, y_gap=0, align='center', name=None)

Fixed-column grid of layout items.

class procedural_runner.Stack(layout, align='center', name=None)

Overlay items on a common origin without merging geometry.

class procedural_runner.Repeat(layout, unit=None, count=1, axis='x', pitch='abut', mirror=False, alternate=False, name=None)

Repeated, optionally mirrored copies of a layout fragment.

add(item)

Add an item and reflow the composition.

See also