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_couplerFor library development, import from rosette.components:
from rosette.components import mmi, ring, grating_couplerThe 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:
| Function | Metric |
|---|---|
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) -> LibraryRead 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 | PathPath to the GDS file.
Returns
LibraryA Library containing all cells from the GDS file.
funcwrite_gds(path, design, cells=None, *, quiet=False, verbose=False) -> NoneWrite 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 | PathOutput file path.
paramdesignCell | LibraryCell or Library to write.
paramcellslist[Cell] | None= NoneOptional list of child cells. If None and design is a Cell,
child cells are auto-collected from Instance references.
paramquietbool= FalseIf True, suppress the build summary.
paramverbosebool= FalseIf True, print detailed build info including port positions.
Returns
NonePlacement
Import connect_transform from rosette.
funcconnect_transform(component_port, target_port) -> TransformCalculate 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_portPortPort on the component being placed.
paramtarget_portPortPort to connect to.
Returns
TransformTransform that aligns the two ports.
Configuration
Import load_layer_map from rosette.project.
funcload_layer_map(config_path=None) -> LayerMapLoad 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= NoneOptional explicit path to rosette.toml. If None, searches
from current directory upward.
Returns
LayerMapLayerMap with named layer access.
DRC
Import DrcPolicy, load_drc_rules, and run_drc from rosette.drc.
funcload_drc_rules(config_path=None) -> DrcRulesLoad 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= NoneOptional explicit path to rosette.toml. If None, searches
from current directory upward.
Returns
DrcRulesDrcRules built from the configuration.
funcrun_drc(cell, rules, library=None, *, policy=None) -> DrcResultRun 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}")paramcellCellThe cell to check.
paramrulesDrcRulesDRC rules to apply.
paramlibraryLibrary | None= NoneLibrary containing referenced cells (required if cell has refs).
parampolicyDrcPolicy | None= NoneOptional explicit per-run cell skips and local waiver regions. DRC policy is
separate from Cell geometry; see DrcPolicy.
Returns
DrcResultDrcResult with violations and statistics.
Design Checks
Import load_checks_config and run_checks from rosette.checks.
funcload_checks_config(config_path=None) -> ChecksConfigLoad 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= NoneOptional explicit path to rosette.toml. If None, searches
from current directory upward.
Returns
ChecksConfigChecksConfig built from the configuration.
funcrun_checks(cell, config=None, library=None) -> ChecksResultRun 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}")paramcellCellThe cell to check.
paramconfigChecksConfig | None= NoneChecks configuration. Defaults to ChecksConfig().
paramlibraryLibrary | None= NoneLibrary containing referenced cells. If None and cell has Instance
tracking, a Library is auto-built.
Returns
ChecksResultChecksResult 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]] | NoneLoad 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= NoneOptional explicit path to rosette.toml. If None, searches
from current directory upward.
Returns
tuple[DfmConfig, GaussianModel, list[Layer]] | NoneTuple 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) -> DfmResultRun 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}")paramcellCellThe cell to predict.
paramlayerslist[Layer]Layers to process.
parammodelGaussianModel | None= NoneThe prediction model. Defaults to GaussianModel(sigma=0.08).
paramconfigDfmConfig | None= NoneDFM configuration. Defaults to DfmConfig().
paramlibraryLibrary | None= NoneLibrary containing referenced cells (required if cell has refs).
Returns
DfmResultDfmResult 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.
paramcenterPointCenter point of the arc.
paramradiusfloatRadius of the arc.
paramstart_anglefloatStarting angle in degrees (0 = +X direction).
paramend_anglefloatEnding angle in degrees.
paramnum_pointsint= 64Number 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) -> RenderResultRender a Cell or Library to a PNG image, returning a
RenderResult with the image bytes and world↔pixel transform
metadata.
paramdesignCell | LibraryThe Cell or Library to render.
parambboxBBox | None= NoneOptional explicit world-space region (microns). If omitted, derived from cell
or the full library extent.
paramcellstr | None= NoneRender only the named cell instead of the selected/unique top or the full multi-root library.
paramlayerslist[tuple[int, int]] | None= NoneRestrict rendering to these (layer, datatype) pairs.
paramwidthint= 1024Output width in pixels.
paramheightint | None= NoneOutput height in pixels. If None, derived from aspect ratio.
parampadfloat= 0.1Fractional padding around the target bbox (0.1 = 10%).
parambgstr= '#1a1a1a'Background color as #RRGGBB or #RRGGBBAA.
paramfill_alphaint= 178Alpha applied to layer fill colors (0-255). Default 178 (~70%).
parampalettedict[int, str] | None= NoneOptional {layer_number: hex_color} overrides.
Returns
RenderResultA RenderResult with png (bytes), view (dict), and
layers_rendered.