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='insert_cell+chip', include_imports=True, use_create_with_refpoints=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 and if some extra code is printed. Has the following options:

    • ”insert_cell”: only insert_cell() calls which can be copied to existing chip’s/element’s build method

    • ”insert_cell+chip”: same as previous, but prints also the chip code, can copy to empty file to create new chip

    • ”create”: only create() and cell.insert() calls which can be copied to an existing macro with layout and top_cell

    • ”create+macro”: same as previous, but includes initial lines for macro, can copy to empty file to create new macro

  • include_imports – If true, then import statements for all used elements are included in the generated code

  • use_create_with_refpoints – If true, then create_with_refpoints() is used instead of create(). Only used when output_format is “create” or “create+macro”. Required if you want to use refpoints as waveguide points.

  • 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: kqcircuits.elements.waveguide_composite.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]

Remove all PCells and return their data.

Returns: 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.

kqcircuits.util.layout_to_code.restore_pcells_to_views(views)[source]

Re-populate each view’s Top Cell with PCells as extracted by extract_pcell_data_from_views.

Parameters

views – List of list of (type, location, parameters) tuples.

../_images/kqcircuits.util.layout_to_code.png