Port
A named port with position, direction, and optional width.
Ports are the primary mechanism for connecting components and routing
waveguides. Each port has a position in layout space, a unit vector
direction pointing outward from the component, and an optional
width used for waveguide width matching.
Port names must be nonempty. Positions must be finite, directions must be
finite and nonzero, and optional widths must be positive and finite. Rosette
normalizes the direction during construction, so callers may pass any valid
nonzero vector. A cell cannot contain two ports with the same name. Invalid
Python inputs raise ValueError before changing model state.
# Port facing +X at the origin, 0.5 um wide
p = Port("opt", Point(0, 0), Vector2(1, 0), width=0.5)
# Check the angle (degrees)
p.angle() # 0.0
# Two ports can connect if they are co-located with opposite directions
other = Port("in", Point(0, 0), Vector2(-1, 0), width=0.5)
p.can_connect_to(other) # TrueAttributes
attributenamestrNonempty name of the port (e.g. "opt", "in", "out_1"). Names are
unique within a cell.
attributepositionPointFinite position of the port in layout coordinates.
attributedirectionVector2Normalized unit vector pointing outward from the component. For example,
a port on the right edge of a component has direction (1, 0).
attributewidthfloat | NonePositive finite waveguide width at this port, or None if unspecified.
Methods
func__init__(name, position, direction, width=None) -> NoneCreate a new Port.
Example
Port("opt", Point(0, 0), Vector2(1, 0), width=0.5)
Port("elec", Point(10, 5), Vector2(0, 1)) # No widthparamnamestrNonempty name of the port.
parampositionPointFinite position in layout coordinates.
paramdirectionVector2Finite, nonzero outward-facing vector. It is normalized during construction.
paramwidthfloat | None= NonePositive finite waveguide width at the port, or None.
Returns
NoneRaises ValueError if any invariant is violated.
funcangle() -> floatReturn the port direction as an angle in degrees.
The angle is measured counter-clockwise from the +X axis. For example,
a direction of (1, 0) returns 0.0, and (0, 1) returns 90.0.
Returns
floatDirection angle in degrees.
funccan_connect_to(other, tolerance=0.001) -> boolCheck if this port can connect to another port.
Two ports can connect when they are at the same position (within
tolerance) and have opposite directions. This is the geometric
condition for a flush waveguide junction.
Example
a = Port("out", Point(100, 0), Vector2(1, 0), width=0.5)
b = Port("in", Point(100, 0), Vector2(-1, 0), width=0.5)
a.can_connect_to(b) # True: same position, opposite directions
c = Port("in", Point(100, 1), Vector2(-1, 0), width=0.5)
a.can_connect_to(c) # False: positions differparamotherPortThe other port to check against.
paramtolerancefloat= 0.001Maximum position distance for ports to be considered co-located.
Returns
boolTrue if the ports can connect, False otherwise.