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 again

Attributes

attributecell_namestr

Name of the referenced cell.

Methods

func__init__(cell_or_name) -> None

Create a new cell reference.

Example

ref1 = CellRef("my_cell")      # From string
ref2 = CellRef(waveguide_cell) # From Cell object
paramcell_or_nameCell | str

Either a Cell object or a cell name string.

Returns

None
funcat(x, y) -> CellRef

Set the position.

paramxfloat

X coordinate.

paramyfloat

Y coordinate.

Returns

CellRef
funcrotate(angle_deg) -> CellRef

Rotate by angle (in degrees).

paramangle_degfloat

Rotation angle in degrees.

Returns

CellRef
funcmirror_x() -> CellRef

Mirror across X axis (flips Y coordinates).

Returns

CellRef
funcmirror_y() -> CellRef

Mirror across Y axis (flips X coordinates).

Returns

CellRef
funcscale(s) -> CellRef

Scale uniformly.

paramsfloat

Scale factor.

Returns

CellRef
funcarray(columns, rows, col_spacing, row_spacing) -> CellRef

Set 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)
paramcolumnsint

Number of columns (>= 1).

paramrowsint

Number of rows (>= 1).

paramcol_spacingfloat

Column pitch: center-to-center distance between adjacent copies along local +X, in µm. Negative values place copies along local −X.

paramrow_spacingfloat

Row pitch: center-to-center distance between adjacent copies along local +Y, in µm. Negative values place copies along local −Y.

Returns

CellRef

A new CellRef with array repetition set.

funcarray_vectors(columns, rows, col_vector, row_vector) -> CellRef

Set 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),
)
paramcolumnsint

Number of columns (1 to 32767).

paramrowsint

Number of rows (1 to 32767).

paramcol_vectorVector2

Column displacement: the offset between copy (c, r) and (c+1, r), in µm.

paramrow_vectorVector2

Row displacement: the offset between copy (c, r) and (c, r+1), in µm.

Returns

CellRef

A new CellRef with array repetition set.

funcport(name, cell) -> Port

Get a transformed port from this cell reference.

Unlike Instance.port(), this requires passing the source Cell because CellRef only stores the cell name.

paramnamestr

Name of the port to retrieve.

paramcellCell

The source Cell object containing the port definition.

Returns

Port

The port with position and direction transformed.

On this page