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
attributecellCellThe underlying cell definition.
attributetransformTransformThe current transform applied to this instance.
attributecell_namestrName of the referenced cell (for compatibility with CellRef).
Methods
func__init__(cell, transform=None) -> NoneCreate an Instance from a Cell and optional transform.
Typically you don't call this directly — use cell.at(x, y) instead.
paramcellCellThe cell definition.
paramtransformTransform | None= NoneOptional transform. Defaults to identity.
Returns
Nonefuncat(x, y) -> InstanceSet the position (translation).
Returns a new Instance — instances are immutable.
paramxfloatX coordinate.
paramyfloatY coordinate.
Returns
InstanceA new Instance with updated transform.
funcrotate(angle_deg) -> InstanceRotate by angle (in degrees, counter-clockwise).
paramangle_degfloatRotation angle in degrees.
Returns
InstanceA new Instance with updated transform.
funcmirror_x() -> InstanceMirror across X axis (flips Y coordinates).
Returns
InstanceA new Instance with updated transform.
funcmirror_y() -> InstanceMirror across Y axis (flips X coordinates).
Returns
InstanceA new Instance with updated transform.
funcscale(s) -> InstanceScale uniformly.
paramsfloatScale factor.
Returns
InstanceA new Instance with updated transform.
funcport(name) -> PortGet 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)paramnamestrName of the port to retrieve.
Returns
PortThe port with position and direction transformed.
functo_ref() -> CellRefConvert 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
CellRefA CellRef with the same cell name and transform.