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.

from rosette import *

# 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 waveguide, bend, mmi_1x2

For library development, import from rosette.components:

from rosette.components import waveguide, bend, mmi_1x2
attributeDEFAULT_LAYERSlist[dict]
= [{'name': 'silicon', ...}, {'name': 'metal', ...}, {'name': 'text', ...}]

Default layer definitions used as fallback when rosette.toml has no [layers] section. Contains three layers: silicon (1/0), metal (10/0), text (100/0).

I/O

funcread_gds(path) -> Library

Read a GDS file and return a Library.

Example

lib = read_gds("input.gds")
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.

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

Configuration

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

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, and no_self_intersection), and inter-layer rules in the [[drc.rules]] array.

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) -> DrcResult

Run DRC on a cell.

Example

rules = load_drc_rules()
result = run_drc(cell, rules)
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).

Returns

DrcResult

DrcResult with violations and statistics.

Design 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.

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

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

Load DFM configuration from rosette.toml.

Reads the [dfm] section which configures the virtual nanofabrication prediction tool.

Example

config, model, layers = load_dfm_config()
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]]

Tuple of (config, model, layers) where layers is the list of layers to predict (empty list means all layers).

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.

funcadd_dfm_predictions(cell, result, datatype_offset=100) -> None

Add DFM predicted polygons to a cell on offset layers.

For each layer in the DFM result, adds the predicted polygons to the cell on a new layer with the same number but datatype offset by datatype_offset. This makes it easy to visualize designed vs predicted geometry side-by-side.

Example

result = run_dfm(cell, layers=[Layer(1, 0)])
add_dfm_predictions(cell, result)
write_gds("output.gds", cell)
# Layer 1/0 = designed, Layer 1/100 = predicted
paramcellCell

The cell to add predicted polygons to (modified in-place).

paramresultDfmResult

DFM prediction result from run_dfm.

paramdatatype_offsetint
= 100

Offset added to the original datatype.

Returns

None

Geometry Utilities

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.

funcoffset_polygon(centerline, width) -> Polygon

Create a polygon from a centerline and uniform width.

The polygon is created by offsetting the centerline perpendicular to the path direction at each point, forming a "ribbon" shape.

paramcenterlinelist[Point]

List of points defining the centerline path (minimum 2 points).

paramwidthfloat

Width of the polygon.

Returns

Polygon

A closed polygon.

funcoffset_polygon_varying(centerline, widths) -> Polygon

Create a polygon from a centerline with varying width.

Similar to offset_polygon, but allows specifying a different width at each centerline point for tapered or variable-width shapes.

paramcenterlinelist[Point]

List of points defining the centerline path.

paramwidthslist[float]

Width at each centerline point (must have same length as centerline).

Returns

Polygon

A closed polygon.

funcpath_length(points) -> float

Calculate the total length of a polyline path.

parampointslist[Point]

List of points defining the path.

Returns

float

Sum of distances between consecutive points.

funcfresnel_c(t) -> float

Fresnel cosine integral C(t).

Used for generating Euler (clothoid) spiral bends. C(t) = integral from 0 to t of cos(pi/2 * u^2) du.

paramtfloat

Upper limit of integration.

Returns

float
funcfresnel_s(t) -> float

Fresnel sine integral S(t).

Used for generating Euler (clothoid) spiral bends. S(t) = integral from 0 to t of sin(pi/2 * u^2) du.

paramtfloat

Upper limit of integration.

Returns

float

On this page