API Reference

Quickplot

quickplot

phidl.quickplot(items)

Takes a list of devices/references/polygons or single one of those, and plots them. Use set_quickplot_options() to modify the viewer behavior (e.g. displaying ports, creating new windows, etc)

Parameters:items (PHIDL object or list of PHIDL objects) – The item(s) which are to be plotted

Examples

>>> R = pg.rectangle()
>>> quickplot(R)
>>> R = pg.rectangle()
>>> E = pg.ellipse()
>>> quickplot([R, E])

set_quickplot_options

phidl.set_quickplot_options(show_ports=None, show_subports=None, label_aliases=None, new_window=None, blocking=None, zoom_factor=None, interactive_zoom=None)

Sets plotting options for quickplot()

Parameters:
  • show_ports (bool) – Sets whether ports are drawn
  • show_subports (bool) – Sets whether subports (ports that belong to references) are drawn
  • label_aliases (bool) – Sets whether aliases are labeled with a text name
  • new_window (bool) – If True, each call to quickplot() will generate a separate window
  • blocking (bool) – If True, calling quickplot() will pause execution of (“block”) the remainder of the python code until the quickplot() window is closed. If False, the window will be opened and code will continue to run.
  • zoom_factor (float) – Sets the scaling factor when zooming the quickplot window with the mousewheel/trackpad
  • interactive_zoom (bool) – Enables/disables the ability to use mousewheel/trackpad to zoom

Geometry Library

arc

phidl.geometry.arc(radius=10, width=0.5, theta=45, start_angle=0, angle_resolution=2.5, layer=0)

Creates an arc of arclength theta starting at angle start_angle.

Parameters:
  • radius (int or float) – Radius of the arc centerline.
  • width (int or float) – Width of the arc.
  • theta (int or float) – Total angle coverage of the arc.
  • start_angle (int or float) – Starting angle.
  • angle_resolution (int or float) – Resolution of the curve of the arc.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an arc polygon and two ports (1 and 2) on either end.

Notes

Theta = 0 is located along the positive x-axis relative to the center of the arc.

Ports are added to each end of the arc to facilitate connecting those ends to other geometries.

basic_die

phidl.geometry.basic_die(size=(10000, 10000), street_width=100, street_length=1000, die_name='chip99', text_size=100, text_location='SW', layer=0, draw_bbox=True, bbox_layer=99)

Creates a basic chip/die template, with 4 right angle corners marking the boundary of the chip/die and a label with the name of the die.

Parameters:
  • size (array_like[2] of int or float) – x, y dimensions of the die.
  • street_width (int or float) – Width of the corner marks for die-sawing.
  • street_length (int or float) – Length of the corner marks for die-sawing.
  • die_name (str) – Label text.
  • text_size (int or float) – Label text size.
  • text_location ({'NW', 'N', 'NE', 'SW', 'S', 'SE'}) – Label text compass location.
  • layer (int) – Specific layer(s) to put polygon geometry on.
  • draw_bbox (bool) – If true, drawns a bbox around the chip die geometry.
  • bbox_layer (int) – Layer on which bbox is placed if draw_bbox is true.
Returns:

D (Device) – A Device containing a basic die geometry.

bbox

phidl.geometry.bbox(bbox=[(-1, -1), (3, 4)], layer=0)

Creates a bounding box rectangle from coordinates, to allow creation of a rectangle bounding box directly form another shape.

Parameters:
  • bbox (list of tuples of int or float) – Coordinates of the box [(x1, y1), (x2, y2)].
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a single rectangle polygon.

Examples

>>> D = pg.bbox(anothershape.bbox)

boolean

phidl.geometry.boolean(A, B, operation, precision=0.0001, num_divisions=[1, 1], max_points=4000, layer=0)

Performs boolean operations between 2 Device/DeviceReference objects or lists of Devices/DeviceReferences.

Parameters:
  • A (Device(/Reference) or list of Device(/Reference) or Polygon) – Input Devices.
  • B (Device(/Reference) or list of Device(/Reference) or Polygon) – Input Devices.
  • operation ({'not', 'and', 'or', 'xor', 'A-B', 'B-A', 'A+B'}) – Boolean operation to perform.
  • precision (float) – Desired precision for rounding vertex coordinates.
  • num_divisions (array-like[2] of int) – The number of divisions with which the geometry is divided into multiple rectangular regions. This allows for each region to be processed sequentially, which is more computationally efficient.
  • max_points (int) – The maximum number of vertices within the resulting polygon.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a polygon(s) with the boolean operations between the 2 input Devices performed.

Notes

‘A+B’ is equivalent to ‘or’. ‘A-B’ is equivalent to ‘not’. ‘B-A’ is equivalent to ‘not’ with the operands switched.

C

phidl.geometry.C(width=1, size=(10, 20), layer=0)

Generates a ‘C’ geometry with ports on both ends.

Parameters:
  • width (int or float) – Thickness of the line forming the C.
  • size (tuple of int or float) – Lengths of the base + top edges and the height of the C, respectively.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a [-bracket-shaped polygon and two ports (1 and 2) on either end of the [ shape.

circle

phidl.geometry.circle(radius=10, angle_resolution=2.5, layer=0)

Generates a circle geometry.

Parameters:
  • radius (int or float) – Radius of the circle.
  • angle_resolution (int or float) – Resolution of the curve of the ring (# of degrees per point).
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a circle polygon.

compass

phidl.geometry.compass(size=(4, 2), layer=0)

Creates a rectangular contact pad with centered ports on edges of the rectangle (north, south, east, and west).

Parameters:
  • size (array_like[2]) – Dimensions of the rectangular contact pad.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a rectangular contact pad with centered ports.

compass_multi

phidl.geometry.compass_multi(size=(4, 2), ports={'N': 3, 'S': 4}, layer=0)

Creates a rectangular contact pad with multiple ports along the edges rectangle (north, south, east, and west).

Parameters:
  • size (array_like) – Dimensions of the rectangular contact pad.
  • ports (dict) – Number of ports on each edge of the rectangle.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a rectangular contact pad with multiple ports.

connector

phidl.geometry.connector(midpoint=(0, 0), width=1, orientation=0)

Creates a Device which has back-to-back ports.

Parameters:
  • midpoint (array-like) – Coordinates of Device midpoint.
  • width (int or float) – Width of connector on non-port axis.
  • orientation (int or float) – Orientation of the ports.
Returns:

D (Device) – A Device containing a back-to-back port geometry.

copy

phidl.geometry.copy(D)

Copies a Device.

Parameters:D (Device) – Device to be copied.
Returns:Device – Copied Device.

copy_layer

phidl.geometry.copy_layer(D, layer=1, new_layer=2)

Copies a layer within a Device to another layer in the same Device.

Parameters:
  • D (Device) – Device containing layer to be copied.
  • layer (int, array-like[2], or set) – Specific layer(s) to copy.
  • new_layer (int, array-like[2], or set) – Specific layer(s) to put copied layer on.
Returns:

Device – A Device containing the original and copied layers.

cross

phidl.geometry.cross(length=10, width=3, layer=0)

Generates a right-angle cross (+ shape, symmetric) from two rectangles of specified length and width.

Parameters:
  • length (int or float) – Length of the cross from one end to the other.
  • width (int or float) – Width of the arms of the cross.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a cross polygon.

deepcopy

phidl.geometry.deepcopy(D)

Deep copies a Device.

Parameters:D (Device) – Device to be deep copied.
Returns:Device – Deep copied Device.

ellipse

phidl.geometry.ellipse(radii=(10, 5), angle_resolution=2.5, layer=0)

Generates an ellipse geometry.

Parameters:
  • radii (tuple of int or float) – Semimajor (x) and semiminor (y) axis lengths of the ellipse.
  • angle_resolution (int or float) – Resolution of the curve of the ring (# of degrees per point).
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an ellipse polygon.

extract

phidl.geometry.extract(D, layers=[0, 1])

Extracts polygons from a given Device.

Parameters:
  • D (Device) – Device to extract polygons from.
  • layers (array-like[2] or set) – Specific layer(s) to extract polygon geometry from.
Returns:

Device – A Device containing the extracted polygons.

fill_rectangle

phidl.geometry.fill_rectangle(D, fill_size=(40, 10), avoid_layers='all', include_layers=None, margin=100, fill_layers=(0, 1, 3), fill_densities=(0.5, 0.25, 0.7), fill_inverted=None, bbox=None)

Creates a rectangular fill pattern and fills all empty areas in the input device D

Parameters:
  • D (Device) – Device to be filled
  • fill_size (array-like[2]) – Rectangular size of the fill element
  • avoid_layers ('all' or list of layers) – Layers to be avoided (not filled) in D
  • include_layers – Layers to be included (filled) in D, supercedes avoid_layers
  • margin (int or float) – Margin spacing around avoided areas – fill will not come within margin of the geometry in D
  • fill_layers (list of layers) – Defines the fill pattern layers
  • fill_densities (float between 0 and 1) – Defines the fill pattern density (1.0 == fully filled)
  • fill_inverted (bool) – Inverts the fill pattern
  • bbox (array-like[2][2]) – Limit the fill pattern to the area defined by this bounding box
Returns:

F (Device)

flagpole

phidl.geometry.flagpole(size=(4, 2), stub_size=(2, 1), shape='p', taper_type='straight', layer=0)

Creates a flagpole geometry of one of four configurations, all involving a vertical central column and a outward-pointing flag.

Parameters:
  • size (array-like) – (width, height) of the flag.
  • stub_size (array-like) – (width, height) of the pole stub.
  • shape ({'p', 'q', 'b', 'd'}) – Configuration of the flagpole, where the curved portion of the letters represents the flag and the straight portion the pole.
  • taper_type ({'straight', 'fillet', None}) – Type of taper between the bottom corner of the stub on the side of the flag and the corner of the flag closest to the stub.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a flagpole geometry.

geometry_to_ports

phidl.geometry.geometry_to_ports(device, layer=0)

Converts geometry representing ports over the whole Device hierarchy into Port objects.

Parameters:
  • device (Device) – Device containing geometry representing ports to convert.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on (the special port record layer)
Returns:

temp_device (Device) – A Device with all geometry representing ports converted to Ports and removed.

Notes

Does not mutate the device in the argument. Returns a new one lacking all port geometry (incl. labels)

grating

phidl.geometry.grating(*args, **kwargs)

Simple grating structure for photonics

Parameters:
  • num_periods (int) – Number of gratings.
  • period (int or float) – Distance between gratings.
  • fill_factor (int or float) – Thickness of the gratings.
  • width_grating (int or float) – Width of the gratings.
  • length_taper (int or float) – Length of the taper section.
  • width (int or float) – Width of the end of the taper section.
  • partial_etch (bool) – If True, makes an untapered, partially-etched grating.
Returns:

G (Device) – A Device containing a fiber grating geometry.

grid

phidl.geometry.grid(device_list, spacing=(5, 10), separation=True, shape=None, align_x='x', align_y='y', edge_x='x', edge_y='ymax')

Places the devices in the device_list (1D or 2D) on a grid.

Parameters:
  • device_list (array-like[N] of Device) – Devices to be placed onto a grid.
  • spacing (int, float, or array-like[2] of int or float) – Spacing between adjacent elements on the grid, can be a tuple for different distances in width and height (x,y).
  • separation (bool) – If True, guarantees elements are speparated with a fixed spacing between; if False, elements are spaced evenly along a grid.
  • shape (array-like[2]) – x, y shape of the grid (as if np.reshape() were run with shape[::-1]). If no shape is given and the list is 1D, the output is as if np.reshape were run with (-1, size of list).
  • align_x ({'x', 'xmin', 'xmax'}) – Which edge to perform the x (column) alignment along
  • align_y ({'y', 'ymin', 'ymax'}) – Which edge to perform the y (row) alignment along
  • edge_x ({'x', 'xmin', 'xmax'}) – Which edge to perform the x (column) distribution along (unused if separation == True)
  • edge_y ({'y', 'ymin', 'ymax'}) – Which edge to perform the y (row) distribution along (unused if separation == True)
Returns:

device_matrix (Device) – A Device containing all the Devices in device_list in a grid.

gridsweep

phidl.geometry.gridsweep(function, param_x={'width': [1, 5, 6, 7]}, param_y={'length': [1.1, 2, 70]}, param_defaults={}, param_override={}, spacing=(50, 100), separation=True, align_x='x', align_y='y', edge_x='x', edge_y='ymin', label_layer=255)

Creates a parameter sweep of devices and places them on a grid with labels for each device. For instance, given a function defined like myshape(width, height, offset, layer) and the following parameters:

param_x = {‘width’ : [4, 5, 6] }, param_y = {‘height’ : [7, 9],

‘layer’ : [1, 2, 3] },

param_defaults = {‘scale’ : 1}

gridsweep() produce a grid of devices with the following layout/parameters:
(w=4, h=7, s=1, l=1) (w=5, h=7, s=1, l=1) (w=6, h=7, s=1, l=1) (w=4, h=7, s=1, l=2) (w=5, h=7, s=1, l=2) (w=6, h=7, s=1, l=2) (w=4, h=7, s=1, l=3) (w=5, h=7, s=1, l=3) (w=6, h=7, s=1, l=3) (w=4, h=9, s=1, l=1) (w=5, h=9, s=1, l=1) (w=6, h=9, s=1, l=1) (w=4, h=9, s=1, l=2) (w=5, h=9, s=1, l=2) (w=6, h=9, s=1, l=2) (w=4, h=9, s=1, l=3) (w=5, h=9, s=1, l=3) (w=6, h=9, s=1, l=3)
Parameters:
  • function (function that produces a Device) – The function which will be used to create the individual devices in the grid. Must only return a single Device (e.g. any of the functions in pg.geometry)
  • param_x (dict) – A dictionary of one or more parameters to sweep in the x-direction
  • param_y (dict) – A dictionary of one or more parameters to sweep in the y-direction
  • param_defaults (dict) – Default parameters to pass to every device in the grid
  • param_override (dict) – Parameters that will override param_defaults, equivalent to changing param_defaults (useful )
  • spacing (int, float, or array-like[2] of int or float) – Spacing between adjacent elements on the grid, can be a tuple for different distances in width and height (x,y).
  • separation (bool) – If True, guarantees elements are separated with a fixed spacing between; if False, elements are spaced evenly along a grid.
  • shape (array-like[2]) – x, y shape of the grid (see np.reshape). If no shape is given and the list is 1D, the output is as if np.reshape were run with (1, -1).
  • align_x ({'x', 'xmin', 'xmax'}) – Which edge to perform the x (column) alignment along
  • align_y ({'y', 'ymin', 'ymax'}) – Which edge to perform the y (row) alignment along
  • edge_x ({'x', 'xmin', 'xmax'}) – Which edge to perform the x (column) distribution along (unused if separation == True)
  • edge_y ({'y', 'ymin', 'ymax'}) – Which edge to perform the y (row) distribution along (unused if separation == True)
  • label_layer (None or layer) – If not None, will place a label that describes the parameters on the device
Returns:

device_matrix (Device) – A Device containing all the Devices in device_list in a grid.

hecken_taper

phidl.geometry.hecken_taper(*args, **kwargs)

Creates a Hecken-tapered microstrip.

Parameters:
  • length (int or float) – Length of the microstrip.
  • B (int or float) – Controls the intensity of the taper.
  • dielectric_thickness (int or float) – Thickness of the substrate.
  • eps_r (int or float) – Dielectric constant of the substrate.
  • Lk_per_sq (float) – Kinetic inductance per square of the microstrip.
  • Z1 (int, float, or None) – Impedance of the left side region of the microstrip.
  • Z2 (int, float, or None) – Impedance of the right side region of the microstrip.
  • width1 (int, float, or None) – Width of the left side of the microstrip.
  • width2 (int, float, or None) – Width of the right side of the microstrip.
  • num_pts (int) – Number of points comprising the curve of the entire microstrip.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a Hecken-tapered microstrip.

import_gds

phidl.geometry.import_gds(filename, cellname=None, flatten=False)

Imports a GDS file and returns a Device with all the corresponding geometry

Parameters:
  • filename (str) – Path or name of file to be imported
  • cellname (str or None) – Name of the cell that will be returned as a Device. If None, will automatically select the topmost cell
  • flatten (bool) – Whether to flatten the imported geometry, removing all cell heirarchy
Returns:

Device – A PHIDL Device with all the geometry/labels/etc imported from the GDS file

inset

invert

phidl.geometry.invert(elements, border=10, precision=0.0001, num_divisions=[1, 1], max_points=4000, layer=0)

Creates an inverted version of the input shapes with an additional border around the edges.

Parameters:
  • elements (Device(/Reference), list of Device(/Reference), or Polygon) – A Device containing the polygons to invert.
  • border (int or float) – Size of the border around the inverted shape (border value is the distance from the edges of the boundary box defining the inverted shape to the border, and is applied to all 4 sides of the shape).
  • precision (float) – Desired precision for rounding vertex coordinates.
  • num_divisions (array-like[2] of int) – The number of divisions with which the geometry is divided into multiple rectangular regions. This allows for each region to be processed sequentially, which is more computationally efficient.
  • max_points (int) – The maximum number of vertices within the resulting polygon.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing the inverted version of the input shape(s) and the corresponding border(s).

L

phidl.geometry.L(width=1, size=(10, 20), layer=0)

Generates an ‘L’ geometry with ports on both ends.

Parameters:
  • width (int or float) – Thickness of the line forming the L.
  • size (tuple of int or float) – Lengths of the base and height of the L, respectively.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an L-shaped polygon and two ports (1 and 2) on either end of the L.

litho_calipers

phidl.geometry.litho_calipers(notch_size=[2, 5], notch_spacing=2, num_notches=11, offset_per_notch=0.1, row_spacing=0, layer1=1, layer2=2)

Creates a vernier caliper structure for lithography alignment tests. Vernier structure is made horizontally.

Parameters:
  • notch_size (array-like[2] of int or flaot) – x, y size of the notches.
  • notch_spacing (int or float) – Spacing between notches on the control structure.
  • num_notches (int) – Number of notches on one side of the structure (total number of notches is 2*num_notches + 1).
  • offset_per_notch (int or float) – The amount of horizontal offset to apply to the notch spacing per notch on the non-control structure.
  • row_spacing (int or float) – The amount of vertical space between the control and non-control structures.
  • layer1 (int, array-like[2], or set) – Specific layer(s) to put the control geometry on.
  • layer2 (int, array-like[2], or set) – Specific layer(s) to put the non-control geometry on.
Returns:

Device – A Device containing the caliper structures.

litho_star

phidl.geometry.litho_star(num_lines=20, line_width=2, diameter=200, layer=0)

Creates a circular-star shape from lines, used as a lithographic resolution test pattern.

Parameters:
  • num_lines (int) – Number of lines in the circular-star shape.
  • line_width (int or float) – Thickness of star spike lines.
  • diameter (int or float) – Diameter of the circular-star shape (total length of each star spike).
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a line-based circular-star shape.

litho_steps

phidl.geometry.litho_steps(line_widths=[1, 2, 4, 8, 16], line_spacing=10, height=100, layer=0)

Produces a positive + negative tone linewidth test, used for lithography resolution test patterning.

Parameters:
  • line_widths (array-like[N] of int or float) – Widths of the steps (positive side).
  • line_spacing (int or float) – Space between each step (negative side).
  • height (int or float) – Height of the steps.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing the lithographic linewidth resolution test geometry.

litho_ruler

phidl.geometry.litho_ruler(height=2, width=0.5, spacing=1.2, scale=[3, 1, 1, 1, 1, 2, 1, 1, 1, 1], num_marks=21, layer=0)

Creates a ruler structure for lithographic measurement with marks of varying scales to allow for easy reading by eye.

Parameters:
  • height (float) – Height of the ruling marks.
  • width (float) – Width of the ruling marks.
  • spacing (float) – Center-to-center spacing of the ruling marks
  • scale (array-like) – Height scale pattern of marks
  • num_marks (int) – Total number of marks to generate
  • num_marks – Total number of marks to generate
  • layer (int, array-like[2], or set) – Specific layer(s) to put the ruler geometry on.
Returns:

Device – A Device containing the ruler structure

meander_taper

phidl.geometry.meander_taper(*args, **kwargs)

Takes in an array of x-positions and a array of widths (corresponding to each x-position) and creates a meander. Typically used for creating meandered tapers

Parameters:
  • x_taper (array-like[N]) – The x-coordinates of the data points, must be increasing.
  • w_taper (array-like[N]) – The y-coordinates of the data points, same length as x_taper.
  • meander_length (int or float) – Length of each section of the meander
  • spacing_factor (int or float) – Multiplicative spacing factor between adjacent meanders
  • min_spacing (int or float) – Minimum spacing between adjacent meanders
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device)

offset

phidl.geometry.offset(elements, distance=0.1, join_first=True, precision=0.0001, num_divisions=[1, 1], join='miter', tolerance=2, max_points=4000, layer=0)

Shrinks or expands a polygon or set of polygons.

Parameters:
  • elements (Device(/Reference), list of Device(/Reference), or Polygon) – Polygons to offset or Device containing polygons to offset.
  • distance (int or float) – Distance to offset polygons. Positive values expand, negative shrink.
  • precision (float) – Desired precision for rounding vertex coordinates.
  • num_divisions (array-like[2] of int) – The number of divisions with which the geometry is divided into multiple rectangular regions. This allows for each region to be processed sequentially, which is more computationally efficient.
  • join ({'miter', 'bevel', 'round'}) – Type of join used to create the offset polygon.
  • tolerance (int or float) – For miter joints, this number must be at least 2 and it represents the maximal distance in multiples of offset between new vertices and their original position before beveling to avoid spikes at acute joints. For round joints, it indicates the curvature resolution in number of points per full circle.
  • max_points (int) – The maximum number of vertices within the resulting polygon.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a polygon(s) with the specified offset applied.

optimal_90deg

phidl.geometry.optimal_90deg(width=100.0, num_pts=15, length_adjust=1, layer=0)

Creates an optimally-rounded 90 degree bend that is sharp on the outer corner.

Parameters:
  • width (int or float) – Width of the ports on either side of the bend.
  • num_pts (int) – The number of points comprising the curved section of the bend.
  • length_adjust (int or float) – Adjusts the length of the non-curved portion of the bend.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded 90 degree bend.

Notes

Optimal structure from https://doi.org/10.1103/PhysRevB.84.174510 Clem, J., & Berggren, K. (2011). Geometry-dependent critical currents in superconducting nanocircuits. Physical Review B, 84(17), 1–27.

optimal_hairpin

phidl.geometry.optimal_hairpin(*args, **kwargs)

Creates an optimally-rounded hairpin geometry, with a 180 degree turn on the right end of the polygon connected to two prongs extending towards ports on the left end.

Parameters:
  • width (int or float) – Width of the hairpin leads.
  • pitch (int or float) – Distance between the two hairpin leads. Must be greater than width.
  • length (int or float) – Length of the hairpin from the connectors to the opposite end of the curve.
  • turn_ratio (int or float) – Specifies how much of the hairpin is dedicated to the 180 degree turn. A turn_ratio of 10 will result in 20% of the hairpin being comprised of the turn.
  • num_pts (int) – Number of points constituting the 180 degree turn.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded hairpin geometry.

Notes

Hairpin pitch must be greater than width.

Optimal structure from https://doi.org/10.1103/PhysRevB.84.174510 Clem, J., & Berggren, K. (2011). Geometry-dependent critical currents in superconducting nanocircuits. Physical Review B, 84(17), 1–27.

optimal_step

phidl.geometry.optimal_step(*args, **kwargs)

Creates an optimally-rounded step geometry.

Parameters:
  • start_width (int or float) – Width of the connector on the left end of the step.
  • end_width (int or float) – Width of the connector on the right end of the step.
  • num_pts (int) – The number of points comprising the entire step geometry.
  • width_tol (float) – Point at which to terminate the calculation of the optimal step
  • anticrowding_factor (int or float) – Factor to reduce current crowding by elongating the structure and reducing the curvature
  • symmetric (bool) – If True, adds a mirrored copy of the step across the x-axis to the geometry and adjusts the width of the ports.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded step.

Notes

Optimal structure from https://doi.org/10.1103/PhysRevB.84.174510 Clem, J., & Berggren, K. (2011). Geometry-dependent critical currents in superconducting nanocircuits. Physical Review B, 84(17), 1–27.

outline

phidl.geometry.outline(elements, distance=1, precision=0.0001, num_divisions=[1, 1], join='miter', tolerance=2, join_first=True, max_points=4000, open_ports=False, layer=0)

Creates an outline around all the polygons passed in the elements argument. elements may be a Device, Polygon, or list of Devices.

Parameters:
  • elements (Device(/Reference), list of Device(/Reference), or Polygon) – Polygons to outline or Device containing polygons to outline.
  • distance (int or float) – Distance to offset polygons. Positive values expand, negative shrink.
  • precision (float) – Desired precision for rounding vertex coordinates.
  • num_divisions (array-like[2] of int) – The number of divisions with which the geometry is divided into multiple rectangular regions. This allows for each region to be processed sequentially, which is more computationally efficient.
  • join ({'miter', 'bevel', 'round'}) – Type of join used to create the offset polygon.
  • tolerance (int or float) – For miter joints, this number must be at least 2 and it represents the maximal distance in multiples of offset between new vertices and their original position before beveling to avoid spikes at acute joints. For round joints, it indicates the curvature resolution in number of points per full circle.
  • join_first (bool) – Join all paths before offsetting to avoid unnecessary joins in adjacent polygon sides.
  • max_points (int) – The maximum number of vertices within the resulting polygon.
  • open_ports (bool or float) – If not False, holes will be cut in the outline such that the Ports are not covered. If True, the holes will have the same width as the Ports. If a float, the holes will be be widened by that value (useful for fully clearing the outline around the Ports for positive-tone processes
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.)
Returns:

D (Device) – A Device containing the outlined polygon(s).

packer

phidl.geometry.packer(D_list, spacing=10, aspect_ratio=(1, 1), max_size=(None, None), sort_by_area=True, density=1.1, precision=0.01, verbose=False)

Packs geometries together into rectangular bins.

Parameters:
  • D_list (array-like of Devices) – Input Devices to be packed.
  • spacing (int or float) – The minimum distance between adjacent shapes.
  • aspect_ratio (array-like) – The (width, height) ratio of the rectangular bin.
  • max_size (array-like) – Limits the size into which the shapes will be packed.
  • sort_by_area (bool) – If true, pre-sorts the shapes by area.
  • density (int or float) – Density of packing. Values closer to 1 pack tighter but require more computation.
  • precision (float) – Desired precision for rounding vertex coordinates.
  • verbose (bool) – Whether to display results of packing attempts
Returns:

D_packed_list (Device or list of Devices) – A Device or list of Devices containing all the packed rectangular bins generated.

Notes

If a max-size is specified, the function will create as many bins as necessary to pack all the geometries and then return a list of the filled-bin Devices.

polygon_ports

phidl.geometry.polygon_ports(xpts=[-1, -1, 0, 0], ypts=[0, 1, 1, 0], layer=0)

Creates a polygon with ports on all edges.

Parameters:
  • xpts (array-like) – x-coordinate values of the polygon vertices.
  • ypts (array-like) – y-coordinate values of the polygon vertices.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

P (Device) – A Device containing a polygon with ports on all edges.

ports_to_geometry

phidl.geometry.ports_to_geometry(device, layer=0)

Converts Port objects over the whole Device hierarchy to geometry and labels.

Parameters:
  • device (Device) – Device containing Port objects to convert.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on (the special port record layer).
Returns:

temp_device (Device) – A Device with all Ports converted to geometry/labels and removed.

preview_layerset

phidl.geometry.preview_layerset(ls, size=100, spacing=100)

Generates a preview Device with representations of all the layers, used for previewing LayerSet color schemes in quickplot or saved .gds files.

Parameters:
  • ls (LayerSet) – Set of layers to preview color schemes.
  • size (int or float) – Resizing factor for the preview Device.
  • spacing (int or float) – The space between each layer representation.
Returns:

D (Device) – A Device containing a representation of all the layers in the input LayerSet.

racetrack_gradual

phidl.geometry.racetrack_gradual(width=0.3, R=5, N=3, layer=0)

Creates a gradual racetrack bent geometry.

Parameters:
  • width (int or float) – Width of the track.
  • R (int or float) – Radius of the track at its most curved point.
  • N (int or float) – Radius of the track at its least curved point.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a gradual racetrack bent geometry.

ramp

phidl.geometry.ramp(length=10, width1=5, width2=8, layer=0)

Creates a ramp geometry.

Parameters:
  • length (int or float) – Length of the ramp section.
  • width1 (int or float) – Width of the start of the ramp section.
  • width2 (int, float, or None) – Width of the end of the ramp section (if width2 is None, width2 becomes the same as width1).
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a ramp geometry.

rectangle

phidl.geometry.rectangle(size=(4, 2), layer=0)

Generates a rectangle geometry.

Parameters:
  • size (tuple of int or float) – Width and height of rectangle.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a single rectangle polygon.

ring

phidl.geometry.ring(radius=10, width=0.5, angle_resolution=2.5, layer=0)

Generates a ring geometry.

Parameters:
  • radius (int or float) – Radius of the ring centerline
  • width (int or float) – Width of the ring.
  • angle_resolution (int or float) – Resolution of the curve of the ring (# of degrees per point).
  • layer – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a ring polygon.

Notes

The ring is formed by taking the radius out to the specified value, and then constructing the thickness by dividing the width in half and adding that value to either side of the radius.

The angle_resolution alters the precision of the curve of the ring. Larger values yield lower resolution.

snspd

phidl.geometry.snspd(*args, **kwargs)

Creates an optimally-rounded SNSPD.

Parameters:
  • width (int or float) – Width of the wire.
  • pitch (int or float) – Distance between two adjacent wires. Must be greater than width.
  • size (None or array-like[2] of int or float) – (width, height) of the rectangle formed by the outer boundary of the SNSPD. Must be none if num_squares is specified.
  • num_squares (int or None) – Total number of squares inside the SNSPD length. Must be none if size is specified.
  • turn_ratio (int or float) – Specifies how much of the SNSPD width is dedicated to the 180 degree turn. A turn_ratio of 10 will result in 20% of the width being comprised of the turn.
  • terminals_same_side (bool) – If True, both ports will be located on the same side of the SNSPD.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded SNSPD.

snspd_expanded

phidl.geometry.snspd_expanded(wire_width=0.2, wire_pitch=0.6, size=(10, 8), num_squares=None, connector_width=1, connector_symmetric=False, turn_ratio=4, terminals_same_side=False, layer=0)

Creates an optimally-rounded SNSPD with wires coming out of it that expand.

Parameters:
  • width (int or float) – Width of the wire.
  • pitch (int or float) – Distance between two adjacent wires. Must be greater than width.
  • size (None or array-like[2] of int or float) – (width, height) of the rectangle formed by the outer boundary of the SNSPD. Must be none if num_squares is specified.
  • num_squares (int or None) – Total number of squares inside the SNSPD length. Must be none if size is specified.
  • connector_width (int or float) – Width of the connectors.
  • connector_symmetric (bool) – If True, mirrors the connectors across their flat edge and adds them to the connector geometry.
  • turn_ratio (int or float) – Specifies how much of the SNSPD width is dedicated to the 180 degree turn. A turn_ratio of 10 will result in 20% of the width being comprised of the turn.
  • terminals_same_side (bool) – If True, both ports will be located on the same side of the SNSPD.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded SNSPD with expanding input/ output wires.

snspd_candelabra

phidl.geometry.snspd_candelabra(wire_width=0.52, wire_pitch=0.56, haxis=90, vaxis=50, equalize_path_lengths=False, xwing=False, layer=0)

Creates an optimally-rounded SNSPD with low current crowding and arbtitrarily-high fill factor as described by Reddy et. al., APL Photonics 7, 051302 (2022) https://doi.org/10.1063/5.0088007

Parameters:
  • wire_width (int or float) – Width of the wire.
  • wire_pitch (int or float) – Distance between two adjacent wires. Must be greater than width.
  • haxis (int or float) – Length of horizontal diagonal of the rhomboidal active area. The parameter haxis is prioritized over vaxis.
  • vaxis (int or float) – Length of vertical diagonal of the rhomboidal active area.
  • equalize_path_lengths (bool) – If True, adds wire segments to hairpin bends to equalize path lengths from center to center for all parallel wires in active area.
  • xwing (bool) – If True, replaces 90-degree bends with 135-degree bends.
  • layer (int) – Specific layer to put polygon geometry on.
Returns:

D (Device) – A Device containing an optimally-rounded SNSPD with minimized current crowding for any fill factor.

straight

phidl.geometry.straight(size=(4, 2), layer=0)

Generates a rectangular wire geometry with ports on the length edges.

Parameters:
  • size (tuple of int or float) – The length and width of the rectangle.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a rectangle polygon and two ports (1 and 2) on either end.

Notes

Ports are included on both sides of the length edge (i.e. size[0]) of the geometry.

taper

phidl.geometry.taper(length=10, width1=5, width2=None, port=None, layer=0)

Creates a tapered trapezoid/rectangle geometry.

Parameters:
  • length (int or float) – Length of the shape.
  • width1 (int, float, or None) – Width of end 1 of the taper section (width is equal to the port width if Port is not None and width1 is None).
  • width2 (int, float, or None) – Width of end 2 of the taper section (width is equal to the port width if Port is not None and width2 is None).
  • port (Port or None) – Port with which to match the width of the taper ends.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a taper geometry.

tee

phidl.geometry.tee(size=(4, 2), stub_size=(2, 1), taper_type=None, layer=0)

Creates a T-shaped geometry.

Parameters:
  • size (array-like) – (width, height) of the horizontal top part of the T shape.
  • stub_size (array-like) – (width, height) of the vertical stub part of the T shape.
  • taper_type ({'straight', 'fillet', None}) – If specified, the type of taper between the bottom corners of the stub and the bottom corners of the T shape.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a T-shaped geometry.

test_comb

phidl.geometry.test_comb(pad_size=(200, 200), wire_width=1, wire_gap=3, comb_layer=0, overlap_zigzag_layer=1, comb_pad_layer=2, comb_gnd_layer=3, overlap_pad_layer=4)

Overlap comb test structure for checking whether two layers are electrically isolated

Parameters:
  • pad_size (array-like) – x and y dimensions of the comb pads.
  • wire_width (int or float) – Width of the test comb teeth.
  • wire_gap (int or float) – Size of the gap between comb teeth.
  • comb_layer (int, array-like[2], or set) – Specific layer(s) to put comb geometry on.
  • overlap_zigzag_layer (int, array-like[2], or set) – Specific layer(s) to put overlap zigzag geometry on.
  • comb_pad_layer (int, array-like[2], or set) – Specific layer(s) to put comb pads on.
  • comb_gnd_layer (int, array-like[2], or set) – Specific layer(s) to put the comb ground on.
  • overlap_pad_layer (int, array-like[2], or set) – Specific layer(s) to put overlap pads on.
Returns:

CI (Device) – A Device containing a test comb geometry.

Notes

Call comb_insulation_test_structure() with any of the parameters shown below which you’d like to change. You only need to supply the parameters which you intend on changing You can alternatively call it with no parameters and it will take all the default values shown below.

Ex::
comb_insulation_test_structure(pad_size=(175,175), wire_width=2, wire_gap=5)
  • or -::
    comb_insulation_test_structure()

test_ic

phidl.geometry.test_ic(wire_widths=[0.25, 0.5, 1, 2, 4], wire_widths_wide=[0.75, 1.5, 3, 4, 6], pad_size=(200, 200), pad_gap=75, wire_layer=0, pad_layer=1, gnd_layer=1)

Critical current test structure for superconducting wires.

Parameters:
  • wire_widths (array-like[N]) – The widths of the thinnest parts of the test wires.
  • wire_widths_wide (array-like[N]) – The widths of the thickest parts of the test wires.
  • pad_size (array-like[2] of int or float) – (width, height) of the pads.
  • pad_gap (int or float) – Distance between the pads and the ground plane.
  • wire_layer (int) – Specific layer(s) to put the wires on.
  • pad_layer (int) – Specific layer(s) to put the pads on.
  • gnd_layer (int or None) – Specific layer(s) to put the ground plane on.
Returns:

Device – A Device containing the critical-current test structure.

test_res

phidl.geometry.test_res(pad_size=[50, 50], num_squares=1000, width=1, res_layer=0, pad_layer=1, gnd_layer=2)

Creates an efficient resonator structure for a wafer layout.

Parameters:
  • pad_size (array-like[2] of int or float) – (width, height) of the two matched impedance pads in microns.
  • num_squares (int or float) – Number of squares comprising the resonator wire.
  • width (int or float) – The width of the squares in microns.
  • res_layer (int) – Specific layer(s) to put the resonator structure on.
  • pad_layer (int or None) – Specific layer(s) to put the pads on.
  • gnd_layer (int or None) – Specific layer(s) to put the ground plane on.
Returns:

P (Device) – A Device containing an efficient resonator structure.

test_via

phidl.geometry.test_via(num_vias=100, wire_width=10, via_width=15, via_spacing=40, pad_size=(300, 300), min_pad_spacing=0, pad_layer=0, wiring1_layer=1, wiring2_layer=2, via_layer=3)

Via chain test structure

Parameters:
  • num_vias (int) – The total number of requested vias (must be an even number).
  • wire_width (int or float) – The width of the wires.
  • via_width (int or float) – Diameter of the vias.
  • via_spacing (int or float) – Distance between vias.
  • pad_size (array-like[2]) – (width, height) of the pads.
  • min_pad_spacing (int or float) – Defines the minimum distance between the two pads.
  • pad_layer (int) – Specific layer to put the pads on.
  • wiring1_layer (int) – Specific layer to put the top wiring on.
  • wiring2_layer (int) – Specific layer to put the bottom wiring on.
  • via_layer (int) – Specific layer to put the vias on.
Returns:

  • VR (Device) – A Device containing the test via structures.
  • Usage
  • —–
  • Call via_route_test_structure() by indicating the number of vias you want
  • drawn. You can also change the other parameters however if you do not
  • specifiy a value for a parameter it will just use the default value
  • Ex:: – via_route_test_structure(num_vias=54)
  • - or -:: – via_route_test_structure(num_vias=12, pad_size=(100,100),wire_width=8)
  • ex (via_route(54, min_pad_spacing=300))

text

phidl.geometry.text(text='abcd', size=10, justify='left', layer=0, font='DEPLOF')

Creates geometries of text

Parameters:
  • text (str) – Text string to be written.
  • size (int or float) – Size of the text
  • justify ({'left', 'right', 'center'}) – Justification of the text.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
  • font (str) – Font face to use. Default DEPLOF does not require additional libraries, otherwise freetype will be used to load fonts. Font can be given either by name (e.g. “Times New Roman”), or by file path. OTF or TTF fonts are supported.
Returns:

t (Device) – A Device containing the text geometry.

turn

phidl.geometry.turn(port, radius=10, angle=270, angle_resolution=2.5, layer=0)

Starting from a port, creates an arc which connects to the specified port on one end.

Parameters:
  • port (Port) – Port to anchor arc to.
  • radius (int or float) – Radius of the arc centerline.
  • angle (int or float) – Total angle coverage of the arc.
  • angle_resolution (int or float) – Resolution of the curve of the arc.
  • layer (int, array-like[2], or set) – Specific layer(s) to put the polygon geometry on.
Returns:

D (Device) – A Device containing an arc polygon and two ports (1 and 2) on either end.

Notes

Angle = 0 is located along the positive x-axis relative to the center of the arc. Ports are added to each end of the arc to facilitate connecting those ends to other geometries. Port 2 is aligned to connect to the specified port.

union

phidl.geometry.union(D, by_layer=False, precision=0.0001, join_first=True, max_points=4000, layer=0)

Performs the union of all polygons within a Device.

Parameters:
  • D (Device(/Reference)) – A Device containing polygons to perform a union on.
  • by_Layer (bool) – If true, performs the union operation layer-wise so each layer can be individually combined.
  • precision (float) – Desired precision for rounding vertex coordinates.
  • join_first (bool) – Join all paths before offsetting to avoid unnecessary joins in adjacent polygon sides.
  • max_points (int) – The maximum number of vertices within the resulting polygon.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

U (Device) – A Device containing the union of the polygons within the input Device.

xor_diff

phidl.geometry.xor_diff(A, B, precision=0.0001)

Given two Devices A and B, performs the layer-by-layer XOR difference between A and B and returns polygons representing the differences between A and B.

Parameters:
  • A (Device(/Reference) or list of Device(/Reference)) – A Device containing a polygon(s).
  • B (Device(/Reference) or list of Device(/Reference)) – A Device containing a polygon(s).
  • precision (float) – Desired precision for rounding vertex coordinates.
Returns:

D (Device) – A Device containing a polygon(s) defined by the XOR difference result between A and B.

ytron_round

phidl.geometry.ytron_round(rho=1, arm_lengths=(500, 300), source_length=500, arm_widths=(200, 200), theta=2.5, theta_resolution=10, layer=0)

Ytron structure for superconducting nanowires

McCaughan, A. N., Abebe, N. S., Zhao, Q.-Y. & Berggren, K. K. Using Geometry To Sense Current. Nano Lett. 16, 7626–7631 (2016). http://dx.doi.org/10.1021/acs.nanolett.6b03593

Parameters:
  • rho (int or float) – Radius of curvature of ytron intersection point
  • arm_lengths (array-like[2] of int or float) – Lengths of the left and right arms of the yTron, respectively.
  • source_length (int or float) – Length of the source of the yTron.
  • arm_widths (array-like[2] of int or float) – Widths of the left and right arms of the yTron, respectively.
  • theta (int or float) – Angle between the two yTron arms.
  • theta_resolution (int or float) – Angle resolution for curvature of ytron intersection point
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
Returns:

D (Device) – A Device containing a yTron geometry.

device_lru_cache

class phidl.geometry.device_lru_cache(fn)

Bases: object

Least-recently-used (LRU) cache for Devices

Path Library

arc

phidl.path.arc(radius=10, angle=90, num_pts=720)

Create a circular arc Path

Parameters:
  • radius (int or float) – Radius of arc
  • angle (int or float) – Total angle of arc
  • num_pts (int) – Number of points used per 360 degrees
Returns:

Path – A Path object with the specified arc

euler

phidl.path.euler(radius=3, angle=90, p=1.0, use_eff=False, num_pts=720)

Create an Euler bend (also known as “racetrack” or “clothoid” curves) that adiabatically transitions from straight to curved. By default, radius corresponds to the minimum radius of curvature of the bend. However, if use_eff is set to True, radius corresponds to the effective radius of curvature (making the curve a drop-in replacement for an arc). If p < 1.0, will create a “partial euler” curve as described in Vogelbacher et. al. https://dx.doi.org/10.1364/oe.27.031394

Parameters:
  • radius (int or float) – Minimum radius of curvature
  • angle (int or float) – Total angle of curve
  • p (float) – Proportion of curve that is an Euler curve
  • use_eff (bool) – If False: radius corresponds to minimum radius of curvature of the bend If True: The curve will be scaled such that the endpoints match an arc with parameters radius and angle
  • num_pts (int) – Number of points used per 360 degrees
Returns:

Path – A Path object with the specified Euler curve

smooth

phidl.path.smooth(points=[(20, 0), (40, 0), (80, 40), (80, 10), (100, 10)], radius=4, corner_fun=<function euler>, **kwargs)

Create a smooth path from a series of waypoints. Corners will be rounded using corner_fun and any additional key word arguments (for example, use_eff = True when corner_fun = pp.euler)

Parameters:
  • points (array-like[N][2] or Path) – List of waypoints for the path to follow
  • radius (int or float) – Radius of curvature, this argument will be passed to corner_fun
  • corner_fun (function) – The function that controls how the corners are rounded. Typically either arc() or euler()
  • **kwargs (dict) – Extra keyword arguments that will be passed to corner_fun
Returns:

Path – A Path object with the specified smoothed path.

straight

phidl.path.straight(length=5, num_pts=100)

Creates a straight Path

Parameters:
  • length (int or float) – Total length of straight path
  • num_pts (int) – Number of points along Path
Returns:

Path – A Path object with the specified straight section

spiral

phidl.path.spiral(num_turns=5, gap=1, inner_gap=2, num_pts=10000)

Creates a spiral geometry consisting of two oddly-symmetric semi-circular arcs in the centre and two Archimedean (involute) spiral arms extending outward from the ends of both arcs.

Parameters:
  • num_turns (int or float) – The number of turns in the spiral. Must be greater than 1. A full spiral rotation counts as 1 turn, and the center arcs will together always be 0.5 turn.
  • gap (int or float) – The distance between any point on one arm of the spiral and a point with the same angular coordinate on an adjacent arm.
  • inner_gap (int or float) – The inner size of the spiral, equal to twice the chord length of the centre arcs.
  • num_pts (int) – The number of points in the entire spiral. The actual number of points will be slightly different than the specified value, as they are dynamically allocated using the path lengths of the spiral.
Returns:

Path – A Path object forming a spiral

Notes

num_turns usage (x is any whole number):
  • num_turns = x.0: Output arm will be extended 0.5 turn to be on

the same side as the input. - num_turns < x.5: Input arm will be extended by the fractional amount. - num_turns = x.5: Both arms will be the same length and the input and output will be on opposite sides. - num_turns > x.5: Output arm will be extended by the fractional amount.

Routing Library

route_sharp

phidl.routing.route_sharp(port1, port2, width=None, path_type='manhattan', manual_path=None, layer=nan, **kwargs)

Convenience function that routes a path between ports and immediately extrudes the path to create polygons. Has several waypoint path type options. Equivalent to e.g.

>>> P = pr.path_manhattan(port1, port2, radius)
>>> D = P.extrude(width)
Parameters:
  • port2 (port1,) – Ports to route between.
  • width (None, int, float, array-like[2], or CrossSection) –

    If None, the route linearly tapers between the widths the ports If set to a single number (e.g. width=1.7): makes a fixed-width route If set to a 2-element array (e.g. width=[1.8,2.5]): makes a route

    whose width varies linearly from width[0] to width[1]

    If set to a CrossSection: uses the CrossSection parameters for the route

  • path_type ({'manhattan', 'L', 'U', 'J', 'C', 'V', 'Z', 'straight', 'manual'}) –
    Method of waypoint path creation. Should be one of
    • ’manhattan’ - automatic manhattan routing
      (see path_manhattan() ).
    • ’L’ - L-shaped path for orthogonal ports that can be directly
      connected (see path_L() ).
    • ’U’ - U-shaped path for parrallel or facing ports
      (see path_U() ).
    • ’J’ - J-shaped path for orthogonal ports that cannot be
      directly connected (see path_J() ).
    • ’C’ - C-shaped path for ports that face away from each
      other (see path_C() ).
    • ’Z’ - Z-shaped path with three segments for ports at any
      angles (see path_Z() ).
    • ’V’ - V-shaped path with two segments for ports at any
      angles (see path_V() ).
    • ’straight’ - straight path for ports that face each other
      see path_straight() ).
    • ’manual’ - use an explicit waypoint path provided
      in manual_path.
  • manual_path (array-like[N][2] or Path) – Waypoint path for creating a manual route
  • layer (int or array-like[2]) – Layer to put route on. layer=0 is used by default.
  • **kwargs – Keyword arguments passed to the waypoint path function.
Returns:

D (Device) – A Device containing the route and two ports (1 and 2) on either end.

route_smooth

phidl.routing.route_smooth(port1, port2, radius=5, width=None, path_type='manhattan', manual_path=None, smooth_options={'corner_fun': <function euler>, 'use_eff': True}, layer=nan, **kwargs)

Convenience function that routes a path between ports using pp.smooth(), then immediately extrudes the path to create polygons. Has several waypoint path type options. Equivalent to e.g.

>>> pts = pr.path_manhattan(port1, port2, radius)
>>> P = pp.smooth(pts, radius)
>>> D = P.extrude(width)
Parameters:
  • port2 (port1,) – Ports to route between.
  • radius (int or float) – Bend radius passed to pp.smooth
  • width (None, int, float, array-like[2], or CrossSection) –

    If None, the route linearly tapers between the widths the ports If set to a single number (e.g. width=1.7): makes a fixed-width route If set to a 2-element array (e.g. width=[1.8,2.5]): makes a route

    whose width varies linearly from width[0] to width[1]

    If set to a CrossSection: uses the CrossSection parameters for the route

  • path_type ({'manhattan', 'L', 'U', 'J', 'C', 'V', 'Z', 'straight', 'manual'}) –
    Method of waypoint path creation. Should be one of
    • ’manhattan’ - automatic manhattan routing
      (see path_manhattan() ).
    • ’L’ - L-shaped path for orthogonal ports that can be directly
      connected (see path_L() ).
    • ’U’ - U-shaped path for parrallel or facing ports
      (see path_U() ).
    • ’J’ - J-shaped path for orthogonal ports that cannot be
      directly connected (see path_J() ).
    • ’C’ - C-shaped path for ports that face away from each
      other (see path_C() ).
    • ’Z’ - Z-shaped path with three segments for ports at any
      angles (see path_Z() ).
    • ’V’ - V-shaped path with two segments for ports at any
      angles (see path_V() ).
    • ’straight’ - straight path for ports that face each other
      see path_straight() ).
    • ’manual’ - use an explicit waypoint path provided
      in manual_path.
  • manual_path (array-like[N][2] or Path) – Waypoint path for creating a manual route
  • smooth_options (dict) – Keyword arguments passed to pp.smooth
  • layer (int or array-like[2]) – Layer to put route on. layer=0 is used by default.
  • **kwargs – Keyword arguments passed to the waypoint path function.
Returns:

D (Device) – A Device containing the route and two ports (1 and 2) on either end.

route_quad

phidl.routing.route_quad(port1, port2, width1=None, width2=None, layer=0)

Routes a basic quadrilateral polygon directly between two ports.

Parameters:
  • port2 (port1,) – Ports to route between.
  • width2 (width1,) – Width of quadrilateral at ports. If None, uses port widths.
  • layer (int or array-like[2]) – Layer to put the route on.
Returns:

D (Device) – A Device containing the route and two ports (1 and 2) on either end.

route_xy

phidl.routing.route_xy(port1, port2, directions='xxyx', width=None, layer=nan)

Routes a path in x and y directions (manhattan) from one point (or Port) to another. The directions string determines the order of the x/y steps. Example: directions = ‘xyx’ will travel

1/2 the distance in x from p1 to p2 The whole distance in y from p1 to p2 1/2 of the distance in x from p1 to p2
Parameters:
  • port2 (port1,) – Points to route between.
  • directions (string of {'x','y'} characters) – Directions the Path will be routed along
Returns:

D (Device) – A Device containing the route and two ports (1 and 2) on either end.

path_manhattan

phidl.routing.path_manhattan(port1, port2, radius)

Return waypoint path between port1 and port2 using manhattan routing. Routing is performed using straight, L, U, J, or C waypoint path as needed. Ports must face orthogonal or parallel directions.

Parameters:
  • port2 (port1,) – Ports to route between.
  • radius (float or int) – Bend radius for 90 degree bend.
Returns:

points (Path) – Waypoints for the route path to follow.

path_straight

phidl.routing.path_straight(port1, port2)

Return waypoint path between port1 and port2 in a straight line. Useful when ports point directly at each other.

Parameters:port2 (port1,) – Ports to route between.
Returns:points (array[2][2]) – Waypoints for the route path to follow.

path_L

phidl.routing.path_L(port1, port2)

Return waypoint path between port1 and port2 in an L shape. Useful when orthogonal ports can be directly connected with one turn.

Parameters:port2 (port1,) – Ports to route between.
Returns:points (Path) – Waypoints for the route path to follow.

path_U

phidl.routing.path_U(port1, port2, length1=200)

Return waypoint path between port1 and port2 in a U shape. Useful when ports face the same direction or toward each other.

Parameters:
  • port2 (port1,) – Ports to route between.
  • length1 (int or float) – Length of segment exiting port1. Should be larger than bend radius.
Returns:

points (Path) – Waypoints for the route path to follow.

path_J

phidl.routing.path_J(port1, port2, length1=200, length2=200)

Return waypoint path between port1 and port2 in a J shape. Useful when orthogonal ports cannot be connected directly with an L shape.

Parameters:
  • port2 (port1,) – Ports to route between.
  • length1 (int or float) – Length of segment exiting port1. Should be larger than bend radius.
  • length2 (int or float) – Length of segment exiting port2. Should be larger than bend radius.
Returns:

points (Path) – Waypoints for the route path to follow.

path_C

phidl.routing.path_C(port1, port2, length1=100, left1=100, length2=100)

Return waypoint path between port1 and port2 in a C shape. Useful when ports are parrallel and face away from each other.

Parameters:
  • port2 (port1,) – Ports to route between.
  • length1 (int or float) – Length of route segment coming out of port1. Should be at larger than bend radius.
  • left1 (int or float) – Length of route segment that turns left (or right if negative) from port1. Should be larger than twice the bend radius.
  • length2 (int or float) – Length of route segment coming out of port2. Should be larger than bend radius.
Returns:

points (Path) – Waypoints for the route path to follow.

path_V

phidl.routing.path_V(port1, port2)

Return waypoint path between port1 and port2 in a V shape. Useful when ports point to a single connecting point

Parameters:port2 (port1,) – Ports to route between.
Returns:points (Path) – Waypoints for the route path to follow.

path_Z

phidl.routing.path_Z(port1, port2, length1=100, length2=100)

Return waypoint path between port1 and port2 in a Z shape. Ports can have any relative orientation.

Parameters:
  • port2 (port1,) – Ports to route between.
  • length1 (int or float) – Length of route segment coming out of port1.
  • length2 (int or float) – Length of route segment coming out of port2.
Returns:

points (Path) – Waypoints for the route path to follow.

Layout Classes

CellArray

class phidl.device_layout.CellArray(device, columns, rows, spacing, origin=(0, 0), rotation=0, magnification=None, x_reflection=False)

Bases: gdspy.library.CellArray, phidl.device_layout._GeometryHelper

Multiple references to an existing cell in an array format.

Parameters:
  • device (Device) – The referenced Device.
  • columns (int) – Number of columns in the array.
  • rows (int) – Number of rows in the array.
  • spacing (array-like[2] of int or float) – Distances between adjacent columns and adjacent rows.
  • origin (array-like[2] of int or float) – Position where the cell is inserted.
  • rotation (int or float) – Angle of rotation of the reference (in degrees).
  • magnification (int or float) – Magnification factor for the reference.
  • x_reflection (bool) – If True, the reference is reflected parallel to the x direction before being rotated.
area(by_spec=False)

Calculate the total area of the cell array with the magnification factor included.

Parameters:by_spec (bool) – If True, the return value is a dictionary with the areas of each individual pair (layer, datatype).
Returns:out (number, dictionary) – Area of this cell.
get_bounding_box()

Calculate the bounding box for this reference.

Returns:out (Numpy array[2, 2] or None) – Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_labels(depth=None, set_transform=False)

Return the list of labels created by this reference.

Parameters:
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve labels from.
  • set_transform (bool) – If True, labels will include the transformations from the reference.
Returns:

out (list of Label) – List containing the labels in this cell and its references.

get_paths(depth=None)

Return the list of paths created by this reference.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve paths from.
Returns:out (list of FlexPath or RobustPath) – List containing the paths in this cell and its references.
get_polygons(by_spec=False, depth=None)

Return the list of polygons created by this reference.

Parameters:
  • by_spec (bool or tuple) – If True, the return value is a dictionary with the polygons of each individual pair (layer, datatype). If set to a tuple of (layer, datatype), only polygons with that specification are returned.
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If by_spec is True the key will be name of the referenced cell.
Returns:

out (list of array-like[N][2] or dictionary) – List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons (if by_spec is True).

Note

Instances of FlexPath and RobustPath are also included in the result by computing their polygonal boundary.

get_polygonsets(depth=None)

Return the list of polygons created by this reference.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons from.
Returns:out (list of PolygonSet) – List containing the polygons in this cell and its references.
mirror(p1=(0, 1), p2=(0, 0))

Mirrors a CellArray across the line formed between the two specified points.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves the CellArray from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this CellArray.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of the move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
rotate(angle=45, center=(0, 0))

Rotates all elements in the CellArray around the specified centerpoint.

Parameters:
  • angle (int or float) – Angle to rotate the CellArray in degrees.
  • center (array-like[2], Port, or None) – Midpoint of the CellArray.
to_gds(outfile, multiplier)

Convert this object to a GDSII element.

Parameters:
  • outfile (open file) – Output to write the GDSII.
  • multiplier (number) – A number that multiplies all dimensions written in the GDSII element.
to_svg(outfile, scaling, precision)

Write an SVG fragment representation of this object.

Parameters:
  • outfile (open file) – Output to write the SVG representation.
  • scaling (number) – Scaling factor for the geometry.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.
translate(dx, dy)

Translate this reference.

Parameters:
  • dx (number) – Distance to move in the x-direction.
  • dy (number) – Distance to move in the y-direction.
Returns:

out (CellArray) – This object.

bbox

Returns the bounding box of the CellArray.

center

Returns the center of the bounding box.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

CrossSection

class phidl.device_layout.CrossSection

Bases: object

The CrossSection object for extruding a Path. To be used in combination with a Path to create a Device.

Parameters:path (array-like[N][2], Path, or list of Paths) – Points or Paths to append() initially
add(width=1, offset=0, layer=0, ports=(None, None), name=None)

Adds a cross-sectional element to the CrossSection. If ports are specified, when creating a Device with the extrude() command there be have Ports at the ends.

Parameters:
  • width (float) – Width of the segment
  • offset (float) – Offset of the segment (positive values = right hand side)
  • layer (int, tuple of int, or set of int) – The polygon layer to put the segment on
  • ports (array-like[2] of str, int, or None) – If not None, specifies the names for the ports at the ends of the cross-sectional element
  • name (str, int, or None) – Name of the cross-sectional element for later access
copy()

Creates a copy of the CrosSection.

Returns:CrossSection – A copy of the CrossSection
extrude(path, simplify=None)

Combines the 1D CrossSection with a 1D Path to form 2D polygons.

Parameters:
Returns:

Device – A Device with polygons added that correspond to the extrusion of the Path with the CrossSection

Device

class phidl.device_layout.Device(*args, **kwargs)

Bases: gdspy.library.Cell, phidl.device_layout._GeometryHelper

The basic object that holds polygons, labels, and ports in PHIDL

absorb(reference)

Flattens and absorbs polygons from an underlying DeviceReference into the Device, destroying the reference in the process but keeping the polygon geometry.

Parameters:reference (DeviceReference) – DeviceReference to be absorbed into the Device.
add(element)

Add a new element or list of elements to this cell.

Parameters:element (PolygonSet, CellReference, CellArray or iterable) – The element or iterable of elements to be inserted in this cell.
Returns:out (Cell) – This cell.
add_array(device, columns=2, rows=2, spacing=(100, 100), alias=None)

Creates a CellArray reference to a Device.

Parameters:
  • device (Device) – The referenced Device.
  • columns (int) – Number of columns in the array.
  • rows (int) – Number of rows in the array.
  • spacing (array-like[2] of int or float) – Distances between adjacent columns and adjacent rows.
  • alias (str or None) – Alias of the referenced Device.
Returns:

a (CellArray) – A CellArray containing references to the input Device.

add_label(text='hello', position=(0, 0), magnification=None, rotation=None, anchor='o', layer=255)

Adds a Label to the Device.

Parameters:
  • text (str) – Label text.
  • position (array-like[2]) – x-, y-coordinates of the Label location.
  • magnification (int, float, or None) – Magnification factor for the Label text.
  • rotation (int, float, or None) – Angle rotation of the Label text.
  • anchor ({'n', 'e', 's', 'w', 'o', 'ne', 'nw', ..}) – Position of the anchor relative to the text.
  • layer (int, array-like[2], or set) – Specific layer(s) to put Label on.
add_polygon(points, layer=nan)

Adds a Polygon to the Device.

Parameters:
  • points (array-like[N][2]) – Coordinates of the vertices of the Polygon.
  • layer (int, array-like[2], or set) – Specific layer(s) to put polygon geometry on.
add_port(name=None, midpoint=(0, 0), width=1, orientation=45, port=None)

Adds a Port to the Device.

Parameters:
  • name (str) – Name of the Port object.
  • midpoint (array-like[2] of int or float) – Midpoint of the Port location.
  • width (int or float) – Width of the Port.
  • orientation (int or float) – Orientation (rotation) of the Port.
  • port (Port or None) – A Port if the added Port is a copy of an existing Port.

Notes

Can be called to copy an existing port like add_port(port = existing_port) or to create a new port add_port(myname, mymidpoint, mywidth, myorientation). Can also be called to copy an existing port with a new name like add_port(port = existing_port, name = new_name)

add_ref(device, alias=None)

Takes a Device and adds it as a DeviceReference to the current Device.

Parameters:
  • device (Device) – Device to be added as a DeviceReference.
  • alias (str) – Alias of the Device.
Returns:

d (DeviceReference) – A DeviceReference that is added to the current Device.

align(elements='all', alignment='ymax')

Align elements in the Device

Parameters:
  • elements (array-like of PHIDL objects, or 'all') – Elements in the Device to align.
  • alignment ({'x', 'y', 'xmin', 'xmax', 'ymin', 'ymax'}) – Which edge to align along (e.g. ‘ymax’ will move the elements such that all of their topmost points are aligned)
area(by_spec=False)

Calculate the total area of the elements on this cell, including cell references and arrays.

Parameters:by_spec (bool) – If True, the return value is a dictionary with the areas of each individual pair (layer, datatype).
Returns:out (number, dictionary) – Area of this cell.
copy(name, deep_copy=False, translation=None, rotation=None, scale=None, x_reflection=False)

Create a copy of this cell.

Parameters:
  • name (string) – The name of the cell.
  • deep_copy (bool) – If False, the new cell will contain only references to the existing elements. If True, copies of all elements are also created. If any transformation is performed, this argument is automatically set to True.
  • translation (Numpy array[2]) – Amount to translate the cell contents.
  • rotation (number) – Rotation angle (in radians).
  • scale (number) – Scaling factor.
  • x_reflection (bool) – Reflect the geometry accros the x axis.
Returns:

out (Cell) – The new copy of this cell.

distribute(elements='all', direction='x', spacing=100, separation=True, edge='center')

Distributes the specified elements in the Device.

Parameters:
  • elements (array-like of PHIDL objects or 'all') – Elements to distribute.
  • direction ({'x', 'y'}) – Direction of distribution; either a line in the x-direction or y-direction.
  • spacing (int or float) – Distance between elements.
  • separation (bool) – If True, guarantees elements are speparated with a fixed spacing between; if False, elements are spaced evenly along a grid.
  • edge ({'x', 'xmin', 'xmax', 'y', 'ymin', 'ymax'}) – Which edge to perform the distribution along (unused if separation == True)
flatten(single_layer=None)

Flattens the heirarchy of the Device such that there are no longer any references to other Devices. All polygons and labels from underlying references are copied and placed in the top-level Device. If single_layer is specified, all polygons are moved to that layer.

Parameters:single_layer (None, int, tuple of int, or set of int) – If not None, all polygons are moved to the specified
get_bounding_box()

Calculate the bounding box for this cell.

Returns:out (Numpy array[2, 2] or None) – Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_datatypes()

Return the set of datatypes in this cell.

Returns:out (set) – Set of the datatypes used in this cell.
get_dependencies(recursive=False)

Return a set of the cells included in this cell as references.

Parameters:recursive (bool) – If True returns cascading dependencies.
Returns:out (set of Cell) – Set of the cells referenced by this cell.
get_info()

Gathers the .info dictionaries from every sub-Device and returns them in a list.

Parameters:depth (int or None) – If not None, defines from how many reference levels to retrieve Ports from.
Returns:list of dictionaries – List of the “.info” property dictionaries from all sub-Devices
get_labels(depth=None, set_transform=False)

Return a list with a copy of the labels in this cell.

Parameters:
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve labels from.
  • set_transform (bool) – If True, labels will include the transformations from the references they are from.
Returns:

out (list of Label) – List containing the labels in this cell and its references.

get_layers()

Return the set of layers in this cell.

Returns:out (set) – Set of the layers used in this cell.
get_paths(depth=None)

Return a list with a copy of the paths in this cell.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve paths from.
Returns:out (list of FlexPath or RobustPath) – List containing the paths in this cell and its references.
get_polygons(by_spec=False, depth=None)

Return a list of polygons in this cell.

Parameters:
  • by_spec (bool or tuple) – If True, the return value is a dictionary with the polygons of each individual pair (layer, datatype), which are used as keys. If set to a tuple of (layer, datatype), only polygons with that specification are returned.
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If by_spec is True the key will be the name of this cell.
Returns:

out (list of array-like[N][2] or dictionary) – List containing the coordinates of the vertices of each polygon, or dictionary with with the list of polygons (if by_spec is True).

Note

Instances of FlexPath and RobustPath are also included in the result by computing their polygonal boundary.

get_polygonsets(depth=None)

Return a list with a copy of the polygons in this cell.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons from.
Returns:out (list of PolygonSet) – List containing the polygons in this cell and its references.
get_ports(depth=None)

Returns copies of all the ports of the Device, rotated and translated so that they’re in their top-level position. The Ports returned are copies of the originals, but each copy has the same uid as the original so that they can be traced back to the original if needed.

Parameters:depth (int or None) – If not None, defines from how many reference levels to retrieve Ports from.
Returns:port_list (list of Port) – List of all Ports in the Device.
get_svg_classes()

Return the set of classes for the SVG representation of this cell.

Returns:out0, out1 (sets of 2-tuples) – Sets of (layer, datatype) and (layer, texttype) used in this cell.
get_texttypes()

Return the set of texttypes in this cell.

Returns:out (set) – Set of the texttypes used in this cell.
hash_geometry(precision=0.0001)

Computes an SHA1 hash of the geometry in the Device. For each layer, each polygon is individually hashed and then the polygon hashes are sorted, to ensure the hash stays constant regardless of the ordering the polygons. Similarly, the layers are sorted by (layer, datatype)

Parameters:precision (float) – Roudning precision for the the objects in the Device. For instance, a precision of 1e-2 will round a point at (0.124, 1.748) to (0.12, 1.75)
Returns:str – Hash result in the form of an SHA1 hex digest string

Notes

Algorithm:

hash(
    hash(First layer information: [layer1, datatype1]),
    hash(Polygon 1 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3)] ),
    hash(Polygon 2 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] ),
    hash(Polygon 3 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3)] ),
    hash(Second layer information: [layer2, datatype2]),
    hash(Polygon 1 on layer 2 points: [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] ),
    hash(Polygon 2 on layer 2 points: [(x1,y1),(x2,y2),(x3,y3)] ),
)
mirror(p1=(0, 1), p2=(0, 0))

Mirrors a Device across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves elements of the Device from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this Device.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of the move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
remap_layers(layermap={}, include_labels=True)

Moves all polygons in the Device from one layer to another according to the layermap argument.

Parameters:
  • layermap (dict) – Dictionary of values in format {layer_from : layer_to}
  • include_labels (bool) – Selects whether to move Labels along with polygons
remove(items)

Removes items from a Device, which can include Ports, PolygonSets, CellReferences, and Labels.

Parameters:items (array-like[N]) – Items to be removed from the Device.
remove_labels(test)

Remove labels from this cell.

The function or callable test is called for each label in the cell. If its return value evaluates to True, the corresponding label is removed from the cell.

Parameters:test (callable) – Test function to query whether a label should be removed. The function is called with the label as the only argument.
Returns:out (Cell) – This cell.

Examples

Remove labels in layer 1:

>>> cell.remove_labels(lambda lbl: lbl.layer == 1)
remove_layers(layers=(), include_labels=True, invert_selection=False)

Removes layers from a Device.

Parameters:
  • layers (int, array-like[2], or set) – Specific layer(s) to remove.
  • include_labels (bool) – If True, keeps the labels corresponding to the input layers.
  • invert_selection (bool) – If True, removes all layers except those specified.
remove_paths(test)

Remove paths from this cell.

The function or callable test is called for each FlexPath or RobustPath in the cell. If its return value evaluates to True, the corresponding label is removed from the cell.

Parameters:test (callable) – Test function to query whether a path should be removed. The function is called with the path as the only argument.
Returns:out (Cell) – This cell.
remove_polygons(test)

Remove polygons from this cell.

The function or callable test is called for each polygon in the cell. If its return value evaluates to True, the corresponding polygon is removed from the cell.

Parameters:test (callable) – Test function to query whether a polygon should be removed. The function is called with arguments: (points, layer, datatype)
Returns:out (Cell) – This cell.

Examples

Remove polygons in layer 1:

>>> cell.remove_polygons(lambda pts, layer, datatype:
...                      layer == 1)

Remove polygons with negative x coordinates:

>>> cell.remove_polygons(lambda pts, layer, datatype:
...                      any(pts[:, 0] < 0))
rotate(angle=45, center=(0, 0))

Rotates all Polygons in the Device around the specified center point.

Parameters:
  • angle (int or float) – Angle to rotate the Device in degrees.
  • center (array-like[2] or None) – Midpoint of the Device.
to_gds(outfile, multiplier, timestamp=None)

Convert this cell to a GDSII structure.

Parameters:
  • outfile (open file) – Output to write the GDSII.
  • multiplier (number) – A number that multiplies all dimensions written in the GDSII structure.
  • timestamp (datetime object) – Sets the GDSII timestamp. If None, the current time is used.
to_svg(outfile, scaling, precision, attributes)

Write an SVG fragment representation of this object.

Parameters:
  • outfile (open file) – Output to write the SVG representation.
  • scaling (number) – Scaling factor for the geometry.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.
  • attributes (string) – Additional attributes to set for the cell group.
write_gds(filename, unit=1e-06, precision=1e-09, auto_rename=True, max_cellname_length=28, cellname='toplevel')

Writes a Device to a GDS file.

Parameters:
  • filename (str or file) – The GDS file to write to.
  • unit (int or float) – Unit size for the objects in the library (in meters).
  • precision (float) – Precision for the dimensions of the objects in the library (in meters).
  • auto_rename (bool) – If True, fixes any duplicate cell names.
  • max_cellname_length (int or None) – If given, and if auto_rename is True, enforces a limit on the length of the fixed duplicate cellnames.
  • cellname (str) – Name of the top-level cell in the saved GDS
write_svg(outfile, scaling=10, style=None, fontstyle=None, background='#222', pad='5%', precision=None)

Export this cell to an SVG file.

The dimensions actually written on the GDSII file will be the dimensions of the objects created times the ratio unit/precision. For example, if a circle with radius 1.5 is created and we set GdsLibrary.unit to 1.0e-6 (1 um) and GdsLibrary.precision to 1.0e-9` (1 nm), the radius of the circle will be 1.5 um and the GDSII file will contain the dimension 1500 nm.

Parameters:
  • outfile (file, string or Path) – The file (or path) where the GDSII stream will be written. It must be opened for writing operations in binary format.
  • scaling (number) – Scaling factor for the geometry.
  • style (dict or None) – Dictionary indexed by (layer, datatype) tuples. Entries must be dictionaries with CSS key-value pairs for the presentation attributes of the geometry in that layer and datatype.
  • fontstyle (dict or None) – Dictionary indexed by (layer, texttype) tuples. Entries must be dictionaries with CSS key-value pairs for the presentation attributes of the labels in that layer and texttype.
  • background (string or None) – String specifying the background color. If None, no background is inserted.
  • pad (number or string) – Background margin around the cell bounding box. It can be specified as a percentage of the width or height, whichever is the largest.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.

Examples

>>> cell = gdspy.Cell('MAIN')
>>> cell.add(gdspy.Rectangle((0, 0), (10, 10), layer=1))
>>> # Define fill and stroke for layer 1 and datatype 0
>>> mystyle = {(1, 0): {'fill': '#CC00FF',
                        'stroke': 'black'}}
>>> cell.write_svg('main.svg', style=mystyle)
bbox

Returns the bounding box of the Device.

center

Returns the center of the bounding box.

layers

Returns a set of the Layers in the Device.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

DeviceReference

class phidl.device_layout.DeviceReference(device, origin=(0, 0), rotation=0, magnification=None, x_reflection=False)

Bases: gdspy.library.CellReference, phidl.device_layout._GeometryHelper

Simple reference to an existing Device.

Parameters:
  • device (Device) – The referenced Device.
  • origin (array-like[2] of int or float) – Position where the Device is inserted.
  • rotation (int or float) – Angle of rotation of the reference (in degrees)
  • magnification (int or float) – Magnification factor for the reference.
  • x_reflection (bool) – If True, the reference is reflected parallel to the x-direction before being rotated.
area(by_spec=False)

Calculate the total area of the referenced cell with the magnification factor included.

Parameters:by_spec (bool) – If True, the return value is a dictionary with the areas of each individual pair (layer, datatype).
Returns:out (number, dictionary) – Area of this cell.
connect(port, destination, overlap=0)

Moves and rotates this object such that the the Port specified by port is connected (aligned and adjacent) with the Port specified by destination

Parameters:
  • port (str or Port) –
  • destination (array-like[2]) –
  • overlap (int or float) –
get_bounding_box()

Calculate the bounding box for this reference.

Returns:out (Numpy array[2, 2] or None) – Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or None if the cell is empty.
get_labels(depth=None, set_transform=False)

Return the list of labels created by this reference.

Parameters:
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve labels from.
  • set_transform (bool) – If True, labels will include the transformations from the reference.
Returns:

out (list of Label) – List containing the labels in this cell and its references.

get_paths(depth=None)

Return the list of paths created by this reference.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve paths from.
Returns:out (list of FlexPath or RobustPath) – List containing the paths in this cell and its references.
get_polygons(by_spec=False, depth=None)

Return the list of polygons created by this reference.

Parameters:
  • by_spec (bool or tuple) – If True, the return value is a dictionary with the polygons of each individual pair (layer, datatype). If set to a tuple of (layer, datatype), only polygons with that specification are returned.
  • depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If by_spec is True the key will be the name of the referenced cell.
Returns:

out (list of array-like[N][2] or dictionary) – List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons (if by_spec is True).

Note

Instances of FlexPath and RobustPath are also included in the result by computing their polygonal boundary.

get_polygonsets(depth=None)

Return the list of polygons created by this reference.

Parameters:depth (integer or None) – If not None, defines from how many reference levels to retrieve polygons from.
Returns:out (list of PolygonSet) – List containing the polygons in this cell and its references.
mirror(p1=(0, 1), p2=(0, 0))

Mirrors a DeviceReference across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves the DeviceReference from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this DeviceReference.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
rotate(angle=45, center=(0, 0))

Rotates all Polygons in the DeviceReference around the specified centerpoint.

Parameters:
  • angle (int or float) – Angle to rotate the DeviceReference in degrees.
  • center (array-like[2] or None) – Midpoint of the DeviceReference.
to_gds(outfile, multiplier)

Convert this object to a GDSII element.

Parameters:
  • outfile (open file) – Output to write the GDSII.
  • multiplier (number) – A number that multiplies all dimensions written in the GDSII element.
to_svg(outfile, scaling, precision)

Write an SVG fragment representation of this object.

Parameters:
  • outfile (open file) – Output to write the SVG representation.
  • scaling (number) – Scaling factor for the geometry.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.
translate(dx, dy)

Translate this reference.

Parameters:
  • dx (number) – Distance to move in the x-direction.
  • dy (number) – Distance to move in the y-direction.
Returns:

out (CellReference) – This object.

bbox

Returns the bounding box of the DeviceReference.

center

Returns the center of the bounding box.

info

Returns information about the properties of the reference’s parent.

ports

This property allows you to access myref.ports, and receive a copy of the ports dict which is correctly rotated and translated.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

Group

class phidl.device_layout.Group(*args)

Bases: phidl.device_layout._GeometryHelper

Groups objects together so they can be manipulated as though they were a single object (move/rotate/mirror).

add(element)

Adds an element to the Group.

Parameters:element (Device, DeviceReference, Port, Polygon, CellArray, Label, or Group) – Element to add.
align(alignment='ymax')

Aligns the elements in the Group.

Parameters:alignment ({'x', 'y', 'xmin', 'xmax', 'ymin', 'ymax'}) – Which edge to align along (e.g. ‘ymax’ will align move the elements such that all of their topmost points are aligned)
distribute(direction='x', spacing=100, separation=True, edge='center')

Distributes the elements in the Group.

Parameters:
  • direction ({'x', 'y'}) – Direction of distribution; either a line in the x-direction or y-direction.
  • spacing (int or float) – Distance between elements.
  • separation (bool) – If True, guarantees elements are speparated with a fixed spacing between; if False, elements are spaced evenly along a grid.
  • edge ({'x', 'xmin', 'xmax', 'y', 'ymin', 'ymax'}) – Which edge to perform the distribution along (unused if separation == True)
mirror(p1=(0, 1), p2=(0, 0))

Mirrors a Group across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves the Group from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this Group.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of the move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
rotate(angle=45, center=(0, 0))

Rotates all elements in a Group around the specified centerpoint.

Parameters:
  • angle (int or float) – Angle to rotate the Group in degrees.
  • center (array-like[2] or None) – Midpoint of the Group.
bbox

Returns the bounding boxes of the Group.

center

Returns the center of the bounding box.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

Label

class phidl.device_layout.Label(*args, **kwargs)

Bases: gdspy.label.Label, phidl.device_layout._GeometryHelper

Text that can be used to label parts of the geometry or display messages. The text does not create additional geometry, it’s meant for display and labeling purposes only.

mirror(p1=(0, 1), p2=(0, 0))

Mirrors a Label across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves the Label from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this Label.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of the move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
rotate(angle=45, center=(0, 0))

Rotates Label around the specified centerpoint.

Parameters:
  • angle (int or float) – Angle to rotate the Label in degrees.
  • center (array-like[2] or None) – Midpoint of the Label.
to_gds(outfile, multiplier)

Convert this label to a GDSII structure.

Parameters:
  • outfile (open file) – Output to write the GDSII.
  • multiplier (number) – A number that multiplies all dimensions written in the GDSII structure.
to_svg(outfile, scaling, precision)

Write an SVG fragment representation of this object.

Parameters:
  • outfile (open file) – Output to write the SVG representation.
  • scaling (number) – Scaling factor for the geometry.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.
translate(dx, dy)

Translate this label.

Parameters:
  • dx (number) – Distance to move in the x-direction
  • dy (number) – Distance to move in the y-direction
Returns:

out (Label) – This object.

Examples

>>> text = gdspy.Label((0, 0), (10, 20))
>>> text = text.translate(2, 0)
>>> myCell.add(text)
bbox

Returns the bounding box of the Label.

center

Returns the center of the bounding box.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

Layer

class phidl.device_layout.Layer(gds_layer=0, gds_datatype=0, name='unnamed', description=None, inverted=False, color=None, alpha=0.6, dither=None)

Bases: object

Layer object.

Parameters:
  • gds_layer (int) – GDSII Layer number.
  • gds_datatype (int) – GDSII datatype.
  • name (str) – Name of the Layer.
  • color (str) – Hex code of color for the Layer.
  • alpha (int or float) – Alpha parameter (opacity) for the Layer.
  • dither (str) – KLayout dither parameter (texture) for the Layer (only used in phidl.utilities.write_lyp)

LayerSet

class phidl.device_layout.LayerSet

Bases: object

Set of layer objects.

add_layer(name='unnamed', gds_layer=0, gds_datatype=0, description=None, color=None, inverted=False, alpha=0.6, dither=None)

Adds a layer to an existing LayerSet object.

Parameters:
  • name (str) – Name of the Layer.
  • gds_layer (int) – GDSII Layer number.
  • gds_datatype (int) – GDSII datatype.
  • description (str) – Layer description.
  • color (str) – Hex code of color for the Layer.
  • inverted (bool) – If true, inverts the Layer.
  • alpha (int or float) – Alpha parameter (opacity) for the Layer, value must be between 0.0 and 1.0.
  • dither (str) – KLayout dither style (only used in phidl.utilities.write_lyp() )

Path

class phidl.device_layout.Path(path=None)

Bases: phidl.device_layout._GeometryHelper

The Path object for making smooth Paths. To be used in combination with a CrossSection to create a Device.

Parameters:path (array-like[N][2], Path, or list of Paths) – Points or Paths to append() initially
append(path)

Attaches the input path to the end of this object. The input path will be automatically rotated and translated such that it continues smoothly from the previous segment.

Parameters:path (Path, array-like[N][2], or list of Paths) – The input path that will be appended
copy()

Creates a copy of the Path.

Returns:Path – A copy of the Path
curvature()

Calculates the curvature of the Path. Note this curvature is numerically computed so areas where the curvature jumps instantaneously (such as between an arc and a straight segment) will be slightly interpolated, and sudden changes in point density along the curve can cause discontinuities.

Returns:
  • s (array-like[N]) – The arc-length of the Path
  • K (array-like[N]) – The curvature of the Path
extrude(width, layer=nan, simplify=None)

Combines the 1D Path with a 1D cross-section to form 2D polygons.

Parameters:
  • width (int, float, array-like[2], or CrossSection) –

    If set to a single number (e.g. width=1.7): makes a constant-width extrusion If set to a 2-element array (e.g. width=[1.8,2.5]): makes an extrusion

    whose width varies linearly from width[0] to width[1]

    If set to a CrossSection: uses the CrossSection parameters for extrusion

  • layer (int, tuple of int, or set of int) – The layer to put the extruded polygons on. layer=0 is used by default.
  • simplify (float) – Tolerance value for the simplification algorithm. All points that can be removed without changing the resulting polygon by more than the value listed here will be removed. Also known as epsilon here https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
Returns:

Device – A Device with polygons added that correspond to the extrusion of the Path

hash_geometry(precision=0.0001)

Computes an SHA1 hash of the points in the Path and the start_angle and end_angle

Parameters:precision (float) – Roudning precision for the the objects in the Device. For instance, a precision of 1e-2 will round a point at (0.124, 1.748) to (0.12, 1.75)
Returns:str – Hash result in the form of an SHA1 hex digest string

Notes

Algorithm:

hash(
    hash(First layer information: [layer1, datatype1]),
    hash(Polygon 1 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3)] ),
    hash(Polygon 2 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] ),
    hash(Polygon 3 on layer 1 points: [(x1,y1),(x2,y2),(x3,y3)] ),
    hash(Second layer information: [layer2, datatype2]),
    hash(Polygon 1 on layer 2 points: [(x1,y1),(x2,y2),(x3,y3),(x4,y4)] ),
    hash(Polygon 2 on layer 2 points: [(x1,y1),(x2,y2),(x3,y3)] ),
)
length()

Computes the cumulative length (arc length) of the path.

Returns:float – The length of the Path
mirror(p1=(0, 1), p2=(0, 0))

Mirrors the Path across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves the Path from the origin point to the destination. Both origin and destination can be 1x2 array-like or a Port.

Parameters:
  • origin (array-like[2], Port) – Origin point of the move.
  • destination (array-like[2], Port) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
offset(offset=0)

Offsets the Path so that it follows the Path centerline plus an offset. The offset can either be a fixed value, or a function of the form my_offset(t) where t goes from 0->1

Parameters:offset (int or float, callable) – Magnitude of the offset
rotate(angle=45, center=(0, 0))

Rotates all Polygons in the Device around the specified center point. If no center point specified will rotate around (0,0).

Parameters:
  • angle (int or float) – Angle to rotate the Device in degrees.
  • center (array-like[2] or None) – Midpoint of the Device.
bbox

Returns the bounding box of the Path.

center

Returns the center of the bounding box.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

Polygon

class phidl.device_layout.Polygon(points, gds_layer, gds_datatype, parent)

Bases: gdspy.polygon.Polygon, phidl.device_layout._GeometryHelper

Polygonal geometric object.

Parameters:
  • points (array-like[N][2]) – Coordinates of the vertices of the Polygon.
  • gds_layer (int) – GDSII layer of the Polygon.
  • gds_datatype (int) – GDSII datatype of the Polygon.
  • parent
area(by_spec=False)

Calculate the total area of this polygon set.

Parameters:by_spec (bool) – If True, the return value is a dictionary with {(layer, datatype): area}.
Returns:out (number, dictionary) – Area of this object.
fillet(radius, points_per_2pi=128, max_points=199, precision=0.001)

Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

Parameters:
  • radius (number, array-like) – Radius of the corners. If number: all corners filleted by that amount. If array: specify fillet radii on a per-polygon basis (length must be equal to the number of polygons in this PolygonSet). Each element in the array can be a number (all corners filleted by the same amount) or another array of numbers, one per polygon vertex. Alternatively, the array can be flattened to have one radius per PolygonSet vertex.
  • points_per_2pi (integer) – Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi.
  • max_points (integer) – Maximal number of points in each resulting polygon (at least 5, otherwise the resulting polygon is not fractured).
  • precision (float) – Desired precision for rounding vertice coordinates in case of fracturing.
Returns:

out (PolygonSet) – This object.

fracture(max_points=199, precision=0.001)

Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most max_points. This operation occurs in place.

Parameters:
  • max_points (integer) – Maximal number of points in each resulting polygon (at least 5 for the fracture to occur).
  • precision (float) – Desired precision for rounding vertice coordinates.
Returns:

out (PolygonSet) – This object.

get_bounding_box()

Calculate the bounding box of the polygons.

Returns:out (Numpy array[2, 2] or None) – Bounding box of this polygon in the form [[x_min, y_min], [x_max, y_max]], or None if the polygon is empty.
mirror(p1=(0, 1), p2=(0, 0))

Mirrors a Polygon across the line formed between the two specified points. points may be input as either single points [1,2] or array-like[N][2], and will return in kind.

Parameters:
  • p1 (array-like[N][2]) – First point of the line.
  • p2 (array-like[N][2]) – Second point of the line.
move(origin=(0, 0), destination=None, axis=None)

Moves elements of the Device from the origin point to the destination. Both origin and destination can be 1x2 array-like, Port, or a key corresponding to one of the Ports in this device.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
  • axis ({'x', 'y'}) – Direction of move.
movex(origin=0, destination=None)

Moves an object by a specified x-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, key, or None) – Destination point of the move.
movey(origin=0, destination=None)

Moves an object by a specified y-distance.

Parameters:
  • origin (array-like[2], Port, or key) – Origin point of the move.
  • destination (array-like[2], Port, or key) – Destination point of the move.
rotate(angle=45, center=(0, 0))

Rotates a Polygon by the specified angle.

Parameters:
  • angle (int or float) – Angle to rotate the Polygon in degrees.
  • center (array-like[2] or None) – Midpoint of the Polygon.
scale(scalex, scaley=None, center=(0, 0))

Scale this object.

Parameters:
  • scalex (number) – Scaling factor along the first axis.
  • scaley (number or None) – Scaling factor along the second axis. If None, same as scalex.
  • center (array-like[2]) – Center point for the scaling operation.
Returns:

out (PolygonSet) – This object.

simplify(tolerance=0.001)

Removes points from the polygon but does not change the polygon shape by more than tolerance from the original. Uses the Ramer-Douglas-Peucker algorithm.

Parameters:tolerance (float) – Tolerance value for the simplification algorithm. All points that can be removed without changing the resulting polygon by more than the value listed here will be removed. Also known as epsilon here https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
to_gds(outfile, multiplier)

Convert this object to a series of GDSII elements.

Parameters:
  • outfile (open file) – Output to write the GDSII.
  • multiplier (number) – A number that multiplies all dimensions written in the GDSII elements.
to_svg(outfile, scaling, precision)

Write an SVG fragment representation of this object.

Parameters:
  • outfile (open file) – Output to write the SVG representation.
  • scaling (number) – Scaling factor for the geometry.
  • precision (positive integer or None) – Maximal number of digits for coordinates after scaling.
translate(dx, dy)

Translate this polygon.

Parameters:
  • dx (number) – Distance to move in the x-direction.
  • dy (number) – Distance to move in the y-direction.
Returns:

out (PolygonSet) – This object.

bbox

Returns the bounding box of the Polygon.

center

Returns the center of the bounding box.

size

Returns the (x, y) size of the bounding box.

x

Returns the x-coordinate of the center of the bounding box.

xmax

Returns the maximum x-value of the bounding box.

xmin

Returns the minimum x-value of the bounding box.

xsize

Returns the horizontal size of the bounding box.

y

Returns the y-coordinate of the center of the bounding box.

ymax

Returns the maximum y-value of the bounding box.

ymin

Returns the minimum y-value of the bounding box.

ysize

Returns the vertical size of the bounding box.

Port

class phidl.device_layout.Port(name=None, midpoint=(0, 0), width=1, orientation=0, parent=None)

Bases: object

Port object that can be used to easily snap together other geometric objects

Parameters:
  • name (str) – Name of the Port object.
  • midpoint (array-like[2] of int or float) – Midpoint of the Port location.
  • width (int or float) – Width of the Port.
  • orientation (int or float) – Orientation (rotation) of the Port.
  • parent
rotate(angle=45, center=None)

Rotates a Port around the specified center point, if no centerpoint specified will rotate around (0,0).

Parameters:angle (int or float) – Angle to rotate the Port in degrees. center : array-like[2] or None Midpoint of the Port.
center

Returns the midpoint of the Port.

endpoints

Returns the endpoints of the Port.

normal

Returns a vector normal to the Port

Returns:array-like[2] – Vector normal to the Port
x

Returns the x-coordinate of the Port midpoint.

y

Returns the y-coordinate of the Port midpoint.

make_device

phidl.device_layout.make_device(fun, config=None, **kwargs)

Makes a Device from a function.

Parameters:
  • fun (str) – Name of the function to make the Device with.
  • config (dict or None) – A dictionary containing arguments for the given function.
Returns:

D (Device) – A Device constructed from the specified function.

reset

phidl.device_layout.reset()

Resets the built-in Layer dictionary (controls the coloring in quickplot() ), and sets the Device universal ID (uid) to zero.