CellRef
A reference to another cell with transformation.
CellRef stores the name of a referenced cell along with a GDS-compatible
transform (translation, rotation, mirroring, scale). For most use cases,
prefer the higher-level Instance API via cell.at(x, y) which
preserves the cell reference for ergonomic port queries.
# Preferred: use Instance via cell.at()
gc_in = gc_cell.at(0, 0)
port = gc_in.port("opt") # No need to pass cell again
# Low-level: CellRef requires passing the cell for port queries
ref = CellRef(gc_cell).at(0, 0)
port = ref.port("opt", gc_cell) # Must pass gc_cell againAttributes
attributecell_namestrName of the referenced cell.
Methods
func__init__(cell_or_name) -> NoneCreate a new cell reference.
Example
ref1 = CellRef("my_cell") # From string
ref2 = CellRef(waveguide_cell) # From Cell objectparamcell_or_nameCell | strEither a Cell object or a cell name string.
Returns
Nonefuncat(x, y) -> CellRefSet the position.
paramxfloatX coordinate.
paramyfloatY coordinate.
Returns
CellReffuncrotate(angle_deg) -> CellRefRotate by angle (in degrees).
paramangle_degfloatRotation angle in degrees.
Returns
CellReffuncmirror_x() -> CellRefMirror across X axis (flips Y coordinates).
Returns
CellReffuncmirror_y() -> CellRefMirror across Y axis (flips X coordinates).
Returns
CellReffuncscale(s) -> CellRefScale uniformly.
paramsfloatScale factor.
Returns
CellReffuncarray(columns, rows, col_spacing, row_spacing) -> CellRefSet array repetition (columns × rows rectangular grid with given pitch).
Creates a GDS AREF: a single compact array reference instead of many individual references. In the viewer, the entire array is selected and moved as one object.
For hex packings or any skewed / non-orthogonal grid, use
array_vectors instead.
Example
# 10×5 array with 20 µm column pitch and 15 µm row pitch
ref = CellRef("unit").at(0, 0).array(10, 5, 20.0, 15.0)
top.add_ref(ref)paramcolumnsintNumber of columns (>= 1).
paramrowsintNumber of rows (>= 1).
paramcol_spacingfloatColumn pitch: center-to-center distance between adjacent copies along local +X, in µm. Negative values place copies along local −X.
paramrow_spacingfloatRow pitch: center-to-center distance between adjacent copies along local +Y, in µm. Negative values place copies along local −Y.
Returns
CellRefA new CellRef with array repetition set.
funcarray_vectors(columns, rows, col_vector, row_vector) -> CellRefSet array repetition from arbitrary column and row displacement vectors.
Lower-level constructor supporting non-orthogonal lattices: hex packings, skewed test arrays, etc. Vectors are defined in the CellRef's local (pre-transform) coordinate space, in µm.
Example
import math
from rosette import Vector2
# Hex packing (flat-top): adjacent rows staggered by pitch/2.
pitch = 10.0
ref = CellRef("unit").array_vectors(
6, 4,
Vector2(pitch, 0.0),
Vector2(pitch / 2.0, pitch * math.sqrt(3.0) / 2.0),
)paramcolumnsintNumber of columns (1 to 32767).
paramrowsintNumber of rows (1 to 32767).
paramcol_vectorVector2Column displacement: the offset between copy (c, r) and
(c+1, r), in µm.
paramrow_vectorVector2Row displacement: the offset between copy (c, r) and
(c, r+1), in µm.
Returns
CellRefA new CellRef with array repetition set.
funcport(name, cell) -> PortGet a transformed port from this cell reference.
Unlike Instance.port(), this requires passing the source Cell
because CellRef only stores the cell name.
paramnamestrName of the port to retrieve.
paramcellCellThe source Cell object containing the port definition.
Returns
PortThe port with position and direction transformed.