API Reference

Complete reference for every class and function in the Rosette Python API.

Unstable API

Rosette is pre-1.0. Function signatures, class interfaces, and behavior may change between releases without notice.

For machine-readable contracts, use the complete Python API stub and CLI manifest. In an initialized project, prefer the generated .rosette/api.pyi and .rosette/cli.json when .rosette/manifest.json matches the installed package. If Rosette reports stale references, run uv run rosette update. This website tracks current development.

from rosette import Cell, Layer, Point, Polygon
from rosette.io import write_gds
from rosette.routing import BendInfo, Route

# Create a simple cell
cell = Cell("my_design")
cell.add_polygon(Polygon.rect(Point.origin(), 10, 5), Layer(1, 0))
write_gds("output.gds", cell)

# Route between ports
route = Route(Layer(1, 0), width=0.5, bend_radius=5.0)
route.start_at_port(port_a)
route.to(50, 0)
route.end_at_port(port_b)
cell = route.to_cell("my_route")

In user projects (after rosette init), components are local:

from components import mmi, ring, grating_coupler

For library development, import from rosette.components:

from rosette.components import mmi, ring, grating_coupler

The component surface is documented by project template rather than as a stable core API. See the generic component catalog or the blank component scaffold. The shared component-authoring guide applies to both. After initialization, the project-local components/ source is authoritative.

Classes

Geometry

Layout

Component metrics

Component functions return geometry-only Cells. When a component has a meaningful optical metric, import its semantically named companion from components in a generated project or from rosette.components during library development:

FunctionMetric
sbend_path_length(...)S-bend centerline length.
mmi_through_length(...)Straight through length across the MMI and tapers.
ring_round_trip_length(...)Ring or racetrack resonator round-trip length.
crossing_through_length(...)Through length across either crossing axis.
directional_coupler_arm_length(...)Centerline length of either symmetric coupler arm.
bragg_grating_length(...)Total grating length, including terminator and phase stub.

These names identify the measured path. Do not assume every component has one generic path or a Cell.path_length value.

Configuration

DRC

Design Checks

DFM

Rendering

Functions

I/O

Import read_gds and write_gds from rosette.io.

funcread_gds(path) -> Library

Read a GDS file and return a Library.

Rosette emits a UserWarning when the source contains records that its format-neutral model cannot preserve, such as element properties, BOX, or NODE. Re-exporting such a library omits those records.

Example

lib = read_gds("input.gds")
print("roots:", [cell.name for cell in lib.roots()])
for cell in lib.cells():
    print(cell.name)
parampathstr | Path

Path to the GDS file.

Returns

Library

A Library containing all cells from the GDS file.

funcwrite_gds(path, design, cells=None, *, quiet=False, verbose=False) -> None

Write a Cell or Library to a GDS file.

When writing a Cell built using Instance references (via cell.at()), child cells are automatically collected. A build summary is printed to stderr by default.

Output uses a 1 nm database grid. Export raises ValueError instead of silently collapsing geometry that is not representable on that grid. Library names and text must be ASCII without embedded NUL characters; structure names use the GDS Release 6 alphabet and maximum length of 32 characters.

Example

# Auto-collection (recommended):
top = Cell("top")
top.add_ref(gc_cell.at(0, 0))
write_gds("output.gds", top)

# Suppress output for batch processing:
write_gds("output.gds", top, quiet=True)
parampathstr | Path

Output file path.

paramdesignCell | Library

Cell or Library to write.

paramcellslist[Cell] | None
= None

Optional list of child cells. If None and design is a Cell, child cells are auto-collected from Instance references.

paramquietbool
= False

If True, suppress the build summary.

paramverbosebool
= False

If True, print detailed build info including port positions.

Returns

None

Placement

Import connect_transform from rosette.

funcconnect_transform(component_port, target_port) -> Transform

Calculate the transform that aligns a component port with a target port, with their directions facing each other.

Example

child = Cell("child")
child_port = Port("in", Point(0, 0), Vector2(-1, 0), width=0.5)
target_port = Port("out", Point(10, 0), Vector2(1, 0), width=0.5)
transform = connect_transform(child_port, target_port)
instance = Instance(child, transform)
paramcomponent_portPort

Port on the component being placed.

paramtarget_portPort

Port to connect to.

Returns

Transform

Transform that aligns the two ports.

Configuration

Import load_layer_map from rosette.project.

funcload_layer_map(config_path=None) -> LayerMap

Load layer definitions from rosette.toml.

Reads the [layers] section which maps semantic names to GDS layer numbers with optional display properties (color, fill, opacity).

Example

layers = load_layer_map()
layers.silicon.layer   # Layer(1, 0)
layers.silicon.color   # "#ff69b4"
paramconfig_pathstr | Path | None
= None

Optional explicit path to rosette.toml. If None, searches from current directory upward.

Returns

LayerMap

LayerMap with named layer access.

DRC

Import DrcPolicy, load_drc_rules, and run_drc from rosette.drc.

funcload_drc_rules(config_path=None) -> DrcRules

Load DRC rules from rosette.toml.

Searches for rosette.toml in the current directory and parent directories. Rules are defined per-layer in the [drc.layers] section (supporting min_width, min_spacing, min_area, angles, min_edge_length, max_width, acute_angle, snap_to_grid, density, no_self_intersection, and no_overlap), and inter-layer rules in the [[drc.rules]] array. See the project configuration reference for the complete schema.

An optional top-level [drc].warning_margin knob downgrades near-threshold numeric violations to warnings (see DrcRules.warning_margin).

Layer keys can use semantic names from the [layers] section (e.g. [drc.layers.silicon]) or the traditional "number/datatype" format (e.g. [drc.layers."1/0"]). Inter-layer rules also accept semantic names for layer1, layer2, inner, and outer fields.

Example

rules = load_drc_rules()
result = run_drc(cell, rules)
paramconfig_pathstr | Path | None
= None

Optional explicit path to rosette.toml. If None, searches from current directory upward.

Returns

DrcRules

DrcRules built from the configuration.

funcrun_drc(cell, rules, library=None, *, policy=None) -> DrcResult

Run DRC on a cell.

Example

from rosette import BBox, Point
from rosette.drc import DrcPolicy, load_drc_rules, run_drc

rules = load_drc_rules()
policy = DrcPolicy()
policy.skip_cell("trusted_pdk_cell")
policy.waive_region("taper", BBox(Point(9, -1), Point(11, 1)))

result = run_drc(cell, rules, policy=policy)
if result.passed:
    print("DRC passed!")
else:
    for v in result.violations:
        print(f"  {v.message}")
paramcellCell

The cell to check.

paramrulesDrcRules

DRC rules to apply.

paramlibraryLibrary | None
= None

Library containing referenced cells (required if cell has refs).

parampolicyDrcPolicy | None
= None

Optional explicit per-run cell skips and local waiver regions. DRC policy is separate from Cell geometry; see DrcPolicy.

Returns

DrcResult

DrcResult with violations and statistics.

Design Checks

Import load_checks_config and run_checks from rosette.checks.

funcload_checks_config(config_path=None) -> ChecksConfig

Load design checks config from rosette.toml.

Reads the [checks] section. If absent, returns a ChecksConfig with sensible defaults.

Example

config = load_checks_config()
result = run_checks(cell, config)
paramconfig_pathstr | Path | None
= None

Optional explicit path to rosette.toml. If None, searches from current directory upward.

Returns

ChecksConfig

ChecksConfig built from the configuration.

funcrun_checks(cell, config=None, library=None) -> ChecksResult

Run design checks on a cell.

Runs all design checks: connectivity (unconnected ports, width/angle mismatch) and bend radius (below minimum, auto-reduced). Ports on the top-level cell are treated as external I/O and are not flagged as unconnected.

When called with a Cell built using Instance references, child cells are automatically collected into a Library for hierarchy resolution. Bend-radius checks read route diagnostics retained privately alongside Cells created by Route.to_cell(); they do not inspect generic Cell metadata.

Example

config = ChecksConfig(min_bend_radius=5.0)
result = run_checks(cell, config)
if not result.passed:
    for v in result.violations:
        print(f"  {v.message}")
paramcellCell

The cell to check.

paramconfigChecksConfig | None
= None

Checks configuration. Defaults to ChecksConfig().

paramlibraryLibrary | None
= None

Library containing referenced cells. If None and cell has Instance tracking, a Library is auto-built.

Returns

ChecksResult

ChecksResult with violations and statistics.

DFM

Import load_dfm_config and run_dfm from rosette.dfm.

funcload_dfm_config(config_path=None) -> tuple[DfmConfig, GaussianModel, list[Layer]] | None

Load DFM configuration from rosette.toml.

Reads the [dfm] section which configures the virtual nanofabrication prediction tool. Layer references in the layers list and [dfm.layer.*] overrides accept semantic names from the [layers] section (e.g. "silicon") or the traditional "number/datatype" format (e.g. "1/0").

Returns None when rosette.toml has no [dfm] section, so callers can treat "DFM not configured" as a graceful skip (matching how [drc] and [checks] degrade) rather than an error. Only genuinely invalid DFM settings raise.

Example

loaded = load_dfm_config()
if loaded is not None:
    config, model, layers = loaded
    result = run_dfm(cell, layers=layers, model=model, config=config)
paramconfig_pathstr | Path | None
= None

Optional explicit path to rosette.toml. If None, searches from current directory upward.

Returns

tuple[DfmConfig, GaussianModel, list[Layer]] | None

Tuple of (config, model, layers) where layers is the configured non-empty list of layers to predict, or None when rosette.toml has no [dfm] section.

funcrun_dfm(cell, layers, model=None, config=None, library=None) -> DfmResult

Run DFM prediction on a cell.

Rasterizes each specified layer, applies the fabrication prediction model, and extracts contour polygons representing the predicted fabricated geometry.

Example

result = run_dfm(cell, layers=[Layer(1, 0)])
for lp in result.layers:
    print(f"  Layer {lp.layer}: {lp.input_polygon_count} -> {lp.predicted_polygon_count}")
paramcellCell

The cell to predict.

paramlayerslist[Layer]

Layers to process.

parammodelGaussianModel | None
= None

The prediction model. Defaults to GaussianModel(sigma=0.08).

paramconfigDfmConfig | None
= None

DFM configuration. Defaults to DfmConfig().

paramlibraryLibrary | None
= None

Library containing referenced cells (required if cell has refs).

Returns

DfmResult

DfmResult with per-layer predictions and statistics.

Geometry Utilities

Import arc_points from rosette.geometry.

funcarc_points(center, radius, start_angle, end_angle, num_points=64) -> list[Point]

Generate points along a circular arc.

paramcenterPoint

Center point of the arc.

paramradiusfloat

Radius of the arc.

paramstart_anglefloat

Starting angle in degrees (0 = +X direction).

paramend_anglefloat

Ending angle in degrees.

paramnum_pointsint
= 64

Number of points to generate.

Returns

list[Point]

List of points along the arc.

Rendering

Import render_png from rosette.render.

Experimental

The rendering API is evolving; the signature and RenderResult shape may change without notice.

funcrender_png(design, *, bbox=None, cell=None, layers=None, width=1024, height=None, pad=0.1, bg='#1a1a1a', fill_alpha=178, palette=None) -> RenderResult

Render a Cell or Library to a PNG image, returning a RenderResult with the image bytes and world↔pixel transform metadata.

paramdesignCell | Library

The Cell or Library to render.

parambboxBBox | None
= None

Optional explicit world-space region (microns). If omitted, derived from cell or the full library extent.

paramcellstr | None
= None

Render only the named cell instead of the selected/unique top or the full multi-root library.

paramlayerslist[tuple[int, int]] | None
= None

Restrict rendering to these (layer, datatype) pairs.

paramwidthint
= 1024

Output width in pixels.

paramheightint | None
= None

Output height in pixels. If None, derived from aspect ratio.

parampadfloat
= 0.1

Fractional padding around the target bbox (0.1 = 10%).

parambgstr
= '#1a1a1a'

Background color as #RRGGBB or #RRGGBBAA.

paramfill_alphaint
= 178

Alpha applied to layer fill colors (0-255). Default 178 (~70%).

parampalettedict[int, str] | None
= None

Optional {layer_number: hex_color} overrides.

Returns

RenderResult

A RenderResult with png (bytes), view (dict), and layers_rendered.

On this page