photonics Module¶
This package is a library extension for KLayout to provide functionalities for photonic structures.
Warning
KLayout does not check if a loaded module has changed during runtime and thus does not reread/recompile it. This means you either must manually reload the library if you want to do it during runtime. Generally, it is easier and safer to close and reopen KLayout.
If this extension is modified (or any file in a /python
directory), don’t forget to either reload the module or
reopen KLayout.
Note
To reload a module during runtime use the following commands in the KLayout python console (not guaranteed to work in all cases):
>>> from importlib import reload
>>> import <module>
>>> reload(<module>)
Module contents¶
Photonic PCell-Extension Module
Warning
Before using this module for the first time, make sure the kppc.drc.slcleaner submodule is compiled and importable, as this module
relies on the drc package for DR-Cleaning. See drc
for further details.
A Module which provides extensions for standard KLyaout-PCells. This extension mainly provides functionalities for photonics. One main feature of photonics are so-called ports. These define a position and a direction on a Cell. They indicate where multiple Cells/Devices should interact with each other. For example, one can connect a waveguide with a linear taper. This module provides the classes and functions for this functionality. Additionally, this module provides a lot of convenience functions for interactions with the KLayout-API.
The main functionality for this module is in the class PhotDevice
.
Warning
When using this module to extend a PCell-Library any PCell class has to assign valid values to the
parameters layermap
, dataprep_config
, clean_rules
. These are accessed by PhotDevice
. If they
aren’t declared, a runtime error will occur.
-
class
kppc.photonics.
InstanceHolder
(cell_name, lib, pcell_decl, params=None, params_mod=None, id=0)[source]¶ Bases:
object
Class to keep track and hold the information of a pcell instance. The information will be processed to a PCell in
produce_impl()
-
move
(x=0, y=0, rot=0, mirrx=False, mag=1)[source]¶ Moves an instance. Units of microns relative to origin.
-
port
(port)[source]¶ Returns a reference to itself and the port number. No checks are made whether this port is valid or not! Available ports can be seen if such an object is instantiated.
- Parameters
port (
int
) – index of the port- Returns
self, port
-
-
class
kppc.photonics.
PhotDevice
[source]¶ Bases:
pya.PCellDeclarationHelper
Wrapper for calls to the Klayout API.
- Variables
layermap (dict) – The layermap dictionary. This value has to be written by a child class. If undefined this class won’t work and crash.
dataprep_config (str) – String with the path to the file containing the dataprep instructions. If left empty, dataprep will do nothing.
clean_rules (list) – String with the path to the file containing the DR-Cleaning rules. If left empty, DR-Cleaning will do nothing. If the cells are built similar to the FreePDK45-SampleCells example, DR-Cleaning will not work without dataprep, or will be without any effect.
keep (bool) – Parameter created during
__init__()
via pya.DeclarationHelper. If set to True in the PCell, all child-cells will be preserved at the end. If set to False only the Dataprep Sub-Cell will be preserved.dataprep (bool) – If this flag is set,
kppc.photonics.dataprep.dataprep()
will be performed on the cell. The variabledataprep_config
holds the path to the instructions for dataprep.clean (bool) – If this flag is set,
kppc.drc.clean()
will be performed on the cell. Rules for the DR-Cleaning are pulled fromclean_rules
.top (bool) – Hidden parameter that indicates whether this cell is a top_cell. Default is yes. When an instance is added through
add_pcell_variant()
these cells will not be set to top_cells as they are instantiated from another cell.only_top_ports – GUI parameter. If set to true, only ports of the top most hierarchy level (top_cell) will be annotated by text.
-
add_layer
(var_name, name='', layer=0, datatype=0, ld=(), field_name='', hidden=False)[source]¶ Add a layer to the layer list of the pcell by name.
-
add_params
(params)[source]¶ Create the PCell conform dictionary from a parameter list
- Parameters
params (
dict
) – Dictionary of parameters
-
add_pcell_variant
(params, number=1)[source]¶ Add variants of PCells. Creates a list of InstanceHolders and modifies their parameters accordingly.
- Parameters
- Returns
list of
kppc.photonics.InstanceHolder
-
add_pcells
(instance_list)[source]¶ Creates list of instances of PCells. These are the effective Klayout cell instances.
- Parameters
instance_list (
list
) – list ofkppc.photonics.InstanceHolder
- Returns
list of instantiated pya.CellInstArray
-
calculate_ports
(instances)[source]¶ Calculates port locations in the cell layout. This is to propagate the port locations upwards
- Parameters
instances (
list
) – list containingkppc.photonics.InstanceHolder
-
clear_ports
()[source]¶ Clears self.portlist and by that delete all ports. This is used when updating the Ports
-
coerce_parameters_impl
()[source]¶ Method called by Klayout to update a PCell. For photonic PCells the ports are updated/calculated in the parameter of the PCell. And desired movement transformations are performed.
Because the calculated ports of our own PCell are used by parent cells and are needed before ~produce_impl, we must calculate them twice. First to calculate where our own ports are and then again to instantiate the child cells. This is unfortunate but not a big problem, since dataprep and DR-cleaning take the majority of computation time.
- Returns
-
connect_port
(pos1, portlist1, port1, pos2, portlist2, port2)[source]¶ Connect ports of two instances. The second instance will be transformed to attach to the first instance.
-
connect_port_to_port
(port1, port2)[source]¶ Connect Ports from two InstanceHolder instances.
Connect two InstanceHolders together. Attach <InstanceHolder instance1>.port(<port1>) to <InstanceHolder instance2>.port(<port2>). This will apply a transformation to Instance2. There can only be either a transformation through connect_port_to_port or through InstanceHolder.move
-
create_param_inst
()[source]¶ To be overwritten by the effective PCell
- Returns
Iterable with the declarations of the child PCells.
-
create_path
(points, width, layer)[source]¶ Creates a pya.Path object and inserts it into the Library-PCell.
-
create_polygon
(points, layer)[source]¶ Creates a Polygon and adjusts from microns to database units. Format: [[x1,y1],[x2,y2],…] in microns
-
create_port
(x, y, rot=0, length=0, name=None)[source]¶ Creates a Port at the specified coordinates.
This function will be used when a port is created through the PortCreation tuple.
-
flip_shape_xaxis
(shape)[source]¶ Flip a polygon (or any shape) at the x-axis
- Parameters
shape (
Shape
) – pya.Shape object (e.g. through photonicpcell.create_polygon obtained)
-
flip_shape_yaxis
(shape)[source]¶ Flip a polygon (or any shape) at the y-axis
- Parameters
shape (
Shape
) – pya.Shape object (e.g. through photonicpcell.create_polygon obtained)
-
get_layer
(name, purpose='')[source]¶ Creates LayerInfo object
Creates a pya.LayerInfo object to find layer indexes in the current layout.
-
get_transformations
()[source]¶ Convert transformation strings back to pya.ICplxTrans objects
- Returns
list of pya.ICplxTrans objects
-
insert_shape
(shape, layer)[source]¶ Any other Klayout shape can be added to the PCell through this function.
- Parameters
shape (
Shape
) – pya.Shape objectlayer (
LayerInfo
) – layer where to write to
- Returns
reference to shape
-
produce_impl
()[source]¶ Create the effective Klayout shapes. For this all the InstanceHolders are cycled through and all the child instances are created. Furthermore, if desired, dataprep is performed, which copies and sizes the shapes as desired. Dataprep will only create shapes on the topmost cell. Finally, if desired DR-cleaning is performed and in the process the shapes will be manhattanized.
-
set_transformation
(ind, trans)[source]¶ Transforms child cells to the intended position, defined either by connected ports or by manual positioning.
- Parameters
ind (
int
) – index of the child celltrans (
ICplxTrans
) – Transformation object with which to transform the child cell
Submodules¶
photonics.dataprep module¶
-
kppc.photonics.dataprep.
add
(layout, cell, slayers, dlayers, ex_amount, layers, out_cell=None)[source]¶ Combines all slayers’ shapes into a region and merges this region with each of dlayers’ regions.
- Parameters
layout – the layout on which the cells are located
cell – the cell from which to copy the layers (source shapes)
slayers – the layers to copy
dlayers – the layers where to copy to
ex_amount – the amount added around the source shapes
layers – the layermapping
out_cell – the cell where to put the shapes. If not specified, the input cell will be used.
-
kppc.photonics.dataprep.
dataprep
(in_cell, layout, out_cell=None, config=None, layers_org=None)[source]¶ Dataprep that creates excludes layers etc. with boolean operation on input layers that will be added/substracted to outputlayers.
- Parameters
in_cell – the cell from which to take shapes
layout – the layout on which we perform the operations (most likely self.layout)
out_cell – the output cell. if not specified take the input cell
config – the config file. This file specifies the boolean operations (self.dataprepconfig)
layers_org – the original layermap we use (most likely self.layermap)
photonics.layermaps module¶
-
kppc.photonics.layermaps.
load
(filename)[source]¶ Simple routine to read a .layermap file into a dictionary
- Parameters
filename (str) – Filename with path
- Returns
Dictionary of dictionaries in the form of {layer: {purpose1:(layer_number,purpose_number), purpose2:(layer_number1,purpose_number2)},layer2: {…} }
- Return type
- Examples
>>> import kppc.photonics.layermaps as lm >>> lm.load(os.path.expanduser('~/.klayout/salt/zccmos/FreePDK45_tech/tech/FreePDK45.layermap')) {'pwell': {'blockage': ('109', '1'), 'drawing': ('109', '0')}, ... }