Skip to content

Decks and rules

Types at a glance

Type Carries / typical source What it does and why
Deck Layer declarations, calculations, rules, and settings The object that holds a complete rule deck. Start here to declare layers, calculations, and named rules before validation or export.
Region Polygons; deck.layer(...), geometry Booleans, marker construction A collection of polygons. Use it to describe material, select whole shapes, combine covered areas, or build polygon markers.
Edges Directed segments; region.edges() A collection of directed line segments. Use it when a rule needs individual sides, edge angles, or checks along a boundary.
EdgePairs Ordered pairs of directed segments; distance checks, corner pairs A collection of ordered edge pairs. Use it to keep both sides of a width, spacing, overlap, or margin finding together.
Corners, Corner Contour vertices / a bound vertex; region.corners() Corners holds polygon vertices; Corner is one vertex inside a builder. Use its angle and adjoining edges to write corner rules.
Layout Input layout context The layout input used by the deck. Use it to read geometry and text or inspect layout-wide information such as the input grid.
Number, String, Predicate Typed runtime value, text value, or Boolean expression Number, String, and Predicate describe a value, text, and true/false result calculated at execution. Use them for layout-dependent measurements, messages, and conditions.
Check Findings with marker geometry and messages A stream of findings with their marker shapes and optional messages. Use it to remove exempt findings or add messages before rule registration.
Connectivity Immutable connection description A saved description of how conductor shapes connect. Use it to tell same-net and different-net geometry apart during execution.
Texts, Text, Ports Label collections, bound labels, and KFactory port collections Texts is a label collection and Text is one label; Ports is a connection-point collection. Use them for label-based regions and port-face checks.
BoundingBoxView Per-polygon selection view, region.bbox; returns original polygons A view of each polygon's smallest axis-aligned box. Use it to select the original polygons by box width or height without replacing them with boxes.
ReferenceLayout Declared reference input; .name and .layout A named extra layout file declared for the deck. Use its layout or layers when a rule needs reference geometry as well as the primary layout.
CompiledDeck, ValidationReport Validated snapshot / diagnostics and backend support CompiledDeck is a checked snapshot ready for export; ValidationReport holds errors and backend-support results. Use the report to fix a deck before taking the snapshot.

Deck and rules

Call / property Result and key options What it does and why
Deck(name, units=..., grid_rounding="error", top_cell=None, geometry=None) Deck; units are required: "nm", "um", "mm" Creates the deck and sets its physical units and grid policy. Use one Deck to hold rules that share the same layout inputs and settings.
GeometryPolicy(point_touch="separate") Default topology; "join" allows point-connected contours Sets how supported operations handle polygons that meet at just one point. Use it to make the chosen joining or separation rule consistent.
deck.layer(10, 0, name="METAL") Region; datatype defaults to 0, name is optional Declares a read of GDS layer 10, datatype 0. Use the returned Region in calculations; declaration alone does not open a layout file.
deck.layer(10, shapes="raw", hierarchical=True, point_touch="join", input=reference) Source objects, hierarchy, topology, and reference input Chooses source-object handling, hierarchical reads, point touches, and a reference input. Use these options when object copies or placements affect the rule.
deck.layout Primary Layout Returns the primary layout context. Use it as the starting point for layout-wide reads and checks.
deck.rule("ID", "Explanation", violations=..., group=None, tags=()) Register findings; a tuple/list keeps separate marker streams Attaches findings to a visible rule ID and explanation. Use group and tags to organize rules; a tuple or list keeps separate finding streams.
deck.rule("ID", "Explanation", violations=..., when=predicate) Run only when the predicate is true Runs the rule only if its runtime condition is true. Use it for layout-dependent rules without using Python if on a symbolic value.
deck.rule("ID", "Explanation", violations=..., runtime_message=text, category_description="...") Runtime message and category text Adds runtime message text or a category-text override. Use it when the report description must depend on the layout or differ from marker comments.
deck.empty(kind="region") Empty Region; also "edges", "edge_pairs" Creates an empty geometry collection of the chosen kind in the primary context. Use it as an empty branch or starting result without inventing shapes.
deck.name, deck.units, deck.grid_rounding, deck.geometry Deck configuration Reads the name, units, rounding policy, and point-touch settings already chosen for the deck. Use these values in helpers without repeating configuration.
deck.reference_layout(name, path=..., top_cell=None) ReferenceLayout; file is read during export Declares an extra layout by name and path. Use it for a reference file that will be embedded when the deck is exported.
deck.box((xmin, ymin, xmax, ymax)) Literal rectangle Region Creates a rectangle from fixed coordinates. Use it for a known reporting area, search area, or marker region.

Use literal rule IDs and messages. Pass multiple findings as a tuple/list to keep Region, Edges, EdgePairs, and Check streams separate. See authoring conventions.

Names, metadata, and conditions

Datatype defaults to zero. Names are optional: unnamed layers use layout:10/0 (or reference_name:10/0), with #2, #3, etc. for repeated reads. Explicit duplicate names are errors; variable names are not inferred. Do not mix numeric positional layer arguments with legacy gds= arguments.

when=predicate skips a rule's findings, message, and category when false. A rule that runs with no violations still has an empty category. Conditions must belong to the same deck and cannot use a bound collection item outside its builder.

category_description overrides category text, including an empty string; marker comments keep the rule message. runtime_message supplies a runtime String while the registration keeps a literal explanation. These features need matching backend capabilities.

Use tags=("width", "recommended") for application labels. Lists also work. Tags do not change calculations, messages, severity, or pass/fail behavior. They preserve case and internal spaces, with no reserved names. Each tag must be nonempty, at most 256 characters, and have no outer whitespace or control characters. Duplicates are removed in order; the compiled tuple is immutable.

Validation and export

Call / property Result / behavior What it does and why
load("rules.py", import_root=None) Deck; executes trusted Python exporting module-level deck Runs the trusted Python file and returns its module-level deck. Use it to load a deck with its normal Python helpers and imports.
deck.validate(capabilities=None) ValidationReport; no geometry execution or reference-file reading Checks deck structure and returns a report instead of immediately raising for validation errors. Supply capabilities to check backend support at the same time.
report.is_valid, report.diagnostics, report.backend_compatibility Validity, diagnostics, compatibility state Gives the pass/fail result, the list of diagnostics, and backend compatibility. Use them to decide whether to show errors or continue with export.
report.require_valid() CompiledDeck, or raise DeckValidationError Returns the checked snapshot or raises if the report has errors. Use it to stop a workflow before an invalid deck is exported.
deck.compile(capabilities=None), deck.require_valid(capabilities=None) Validated CompiledDeck snapshot Checks the deck and returns a snapshot in one call. Use either convenience method when a separate report is not needed.
validate_model(model, capabilities=None) Validate a model; see integration options Checks a graph model directly without first building a Deck. Use it when an application already has serialized or constructed model data.
compiled.graph, compiled.requirements, compiled.local_inputs Graph, operation/version/options requirements, local reference bindings Gives the rule graph, required operations/options, and local reference-file bindings. Use them when preparing an export or connecting an application to a backend.
deck.write("rules.fcd", capabilities=None) Export .fcd; embed references; refuse existing files; return Path Writes the deck and embedded references to a new .fcd file. Use this as the usual file-export method after rule declarations.
write_deck_file(compiled, destination) Lower-level artifact writer Writes an existing compiled snapshot to a new artifact file. Use it when an application has already compiled the deck and should not rebuild it.
open_deck_file(path) CompiledDeckFile; inspect .path / .manifest Opens and checks an .fcd artifact without extracting its reference files. Use its manifest to inspect deck names, rules, and stored references.
artifact.extract_references(directory) Extract embedded references; returns name-to-Path mapping Writes checked copies of embedded reference files into a new directory. Use it when the execution step needs those files on disk.
Diagnostic, SourceLocation Diagnostic code, message, severity, path, rule_id, source location; diagnostic.format() formats a diagnostic Diagnostic explains a reported problem; SourceLocation points to a Python file and line when known. Use them to show useful errors next to the author's code.
Capabilities, OperationSupport, OptionSupport, OperationRequirement Capability manifests / required operations; see integration contract Capabilities lists supported versions; OperationSupport and OptionSupport name supported calls and choices. OperationRequirement records what a deck needs, so it can be checked before execution.
DeckLoadError, DeckValidationError Loading / validation exceptions DeckLoadError means loading failed; DeckValidationError means the deck failed validation. Catch them separately to explain which step the author must fix.

See validation for diagnostics and backend support, and exporting for output paths and reference files.

Testing helpers come from fabcheck.testing:

Helper Assertion What it does and why
assert_valid(deck, capabilities=None) Returns compiled snapshot or raises with diagnostics Asserts that the deck validates, then returns its snapshot. Use it in tests so invalid rules fail with readable diagnostics.
assert_rule_ids(compiled, expected) Exact IDs in declaration order Checks exact rule IDs in order, including missing or extra rules. Use it to catch accidental changes to the set of registered rules.
assert_diagnostics(report, expected) Exact diagnostic codes and multiplicity, ignoring order Checks diagnostic codes and their counts while ignoring order. Use it to test expected validation failures without depending on message wording.
assert_requirements(compiled, expected) Exact operation versions and options Checks required operation versions and option values. Use it to detect a deck gaining or losing a backend requirement.

Compatibility spellings

Existing spelling Preferred spelling / equivalent What it does and why
e.with_length(...), e.with_angle(...) length_between(...), angle_between(...) These older names select whole edges by length or angle. Use the newer names to make range selection easier to recognize.
deck.layer("METAL", gds=(10, 0)) deck.layer(10, 0, name="METAL") The older layer declaration names the same GDS layer and datatype. Use the numeric-first form in new decks while keeping explicit names when helpful.
deck.rule("ID", message="Explanation", violations=...) deck.rule("ID", "Explanation", violations=...) The keyword message form still registers the same explanation. Put the message second in new decks so it is easy to read beside the rule ID.
a.with_area(...), p.with_area(...) area_between(...) These older names select objects by area just like area_between(). Use the preferred name in new code; existing decks keep the same behavior.
findings.discard_interacting(mask), findings.exclude(mask) findings.ignore(mask) These names remove whole interacting findings, including touches, just like ignore(). Use ignore() in new code to make the exemption step clear.
Distance(threshold=..., relation=..., ...) DistanceOptions(...) plus explicit check threshold Distance includes a threshold and relation; DistanceOptions holds reusable settings alone. Use DistanceOptions when sharing settings across checks with different thresholds.