Instance

A cell placed at a specific location with optional transformations.

Instance solves the ergonomic problem of needing to pass the Cell twice: once to create a CellRef, and again to query ports. With Instance, the Cell reference is preserved, allowing direct port queries.

# Old pattern (redundant):
gc_ref = CellRef(gc_cell).at(0, 0)
port = gc_ref.port("opt", gc_cell)  # Must pass gc_cell again

# New pattern (ergonomic):
gc_in = gc_cell.at(0, 0)            # Returns Instance
port = gc_in.port("opt")            # No redundancy!

Instances can be added directly to cells and support transform chaining:

gc = gc_cell.at(100, 50)
top.add_ref(gc)

Transform chaining order

Each chained call wraps the outside of the accumulated transform. The first call in the chain is applied first to the geometry.

# .at(10, 0).rotate(90) -> translate first, THEN rotate around origin
# Point (0,0) becomes (10,0) then rotates to (0,10) -- NOT at (10,0)!

# To rotate a component then place it at a specific position,
# rotate first, then translate:
inst = cell.at(0, 0).rotate(90).at(25, 50)  # rotate, then move to (25,50)

Attributes

attributecellCell

The underlying cell definition.

attributetransformTransform

The current transform applied to this instance.

attributecell_namestr

Name of the referenced cell (for compatibility with CellRef).

Methods

func__init__(cell, transform=None) -> None

Create an Instance from a Cell and optional transform.

Typically you don't call this directly — use cell.at(x, y) instead.

paramcellCell

The cell definition.

paramtransformTransform | None
= None

Optional transform. Defaults to identity.

Returns

None
funcat(x, y) -> Instance

Set the position (translation).

Returns a new Instance — instances are immutable.

paramxfloat

X coordinate.

paramyfloat

Y coordinate.

Returns

Instance

A new Instance with updated transform.

funcrotate(angle_deg) -> Instance

Rotate by angle (in degrees, counter-clockwise).

paramangle_degfloat

Rotation angle in degrees.

Returns

Instance

A new Instance with updated transform.

funcmirror_x() -> Instance

Mirror across X axis (flips Y coordinates).

Returns

Instance

A new Instance with updated transform.

funcmirror_y() -> Instance

Mirror across Y axis (flips X coordinates).

Returns

Instance

A new Instance with updated transform.

funcscale(s) -> Instance

Scale uniformly.

paramsfloat

Scale factor.

Returns

Instance

A new Instance with updated transform.

funcport(name) -> Port

Get a transformed port from this instance.

Unlike CellRef.port(), this doesn't require passing the Cell again since the Instance already knows its cell definition. Both position and direction are fully transformed (translation, rotation, mirroring).

Example

gc = gc_cell.at(100, 50)
opt_port = gc.port("opt")  # Transformed port position & direction

# 180-degree rotation flips both position and direction:
flipped = gc_cell.at(0, 0).rotate(180).at(50, 0)
p = flipped.port("opt")   # direction is now (-1, 0)
paramnamestr

Name of the port to retrieve.

Returns

Port

The port with position and direction transformed.

functo_ref() -> CellRef

Convert to a CellRef for use with low-level APIs.

The transform is decomposed into GDS-compatible components (mirror, rotation, translation) following the GDS convention.

Returns

CellRef

A CellRef with the same cell name and transform.

On this page