kqcircuits.util.layout_to_code
- kqcircuits.util.layout_to_code.convert_cells_to_code(top_cell, print_waveguides_as_composite=False, add_instance_names=True, refpoint_snap=50.0, grid_snap=1.0, output_format='chip', include_imports=True, create_code=True)[source]
Prints out the Python code required to create the cells in top_cell.
For each instance that is selected in GUI, prints out an insert_cell() command that can be copy pasted to a chip’s build(). If no instances are selected, then it will do the same for all instances that are one level below the chip cell in the cell hierarchy. PCell parameters are taken into account. Waveguide points can automatically be snapped to closest refpoints in the generated code.
- Parameters:
top_cell – cell whose child cells will be printed as code
print_waveguides_as_composite – If true, then WaveguideCoplanar elements are printed as WaveguideComposite.
add_instance_names – If true, then unique instance names will be added for each printed element. This is required if you want to have waveguides connect to refpoints of elements that were placed in GUI.
refpoint_snap – If a waveguide point is closer than refpoint_snap to a refpoint, the waveguide point will be at that refpoint.
grid_snap – If a waveguide point was not close enough to a refpoint, it will be snapped to a square grid with square side length equal to grid_snap
output_format –
Determines the format of the code for placing cells. Has the following options:
”build”: Creates code that can be used inside the
build
method of aChip
orElement
”chip”: Same as the above, but also outputs a full
Chip
class definition”macro”: Creates code that can be used in a stand-alone KLayout macro or python script
include_imports – If true, then import statements for all used elements are included in the generated code
create_code – if False then does not export code but snap cells to refpoints in place
- Returns:
The generated Python code. This is also printed.
- Return type:
str
- kqcircuits.util.layout_to_code.get_node_params(node: Node)[source]
Generate a list of parameters for Node in string form
- Parameters:
node – a Node to convert
- Returns: a tuple (node_params, element) where
node_params: string of comma-separated key-value pairs that can be passed to the initializer of Node, starting with
", "
element: class that implements the node’s element, or None if the node has no element
- kqcircuits.util.layout_to_code.extract_pcell_data_from_views()[source]
Iterate over all KQCircuits PCells and return their data and instances.
- Returns: a tuple (views, instances) where
views: a list of lists. Each element corresponds to a view in KLayout and it is a list of
(type, location, parameters)
tuples. These tuples completely describe the type, position and parameters of a single PCell in the “Top Cell” of this view. instances: flattened list of all instances of KQCircuits PCells found.