Types¶
Bases: TypedDict
Internal step shape with values already in dbu.
Public APIs accept :class:Step (microns); routing-internal code
converts to StepDbu once at the boundary.
Bases: ProtoTInstance[float], UMGeometricObject
An Instance of a KCell.
An Instance is a reference to a KCell with a transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
_instance |
The internal |
|
ports |
DInstancePorts
|
Transformed ports of the KCell |
kcl |
Pointer to the layout object holding the instance |
|
d |
Helper that allows retrieval of instance information in um |
cell
property
writable
¶
Parent KCell of the Instance.
parent_cell
property
writable
¶
Gets the cell this instance is contained in.
pins
cached
property
¶
Gets the transformed ports of the KCell.
ports
cached
property
¶
Gets the transformed ports of the KCell.
__getitem__(key)
¶
Returns port from instance.
The key can either be an integer, in which case the nth port is returned, or a string in which case the first port with a matching name is returned.
If the instance is an array, the key can also be a tuple in the
form of c.ports[key_name, i_a, i_b], where i_a is the index in
the instance.a direction and i_b the instance.b direction.
E.g. c.ports["a", 3, 5], accesses the ports of the instance which is
3 times in a direction (4th index in the array), and 5 times in b direction
(5th index in the array).
__init__(kcl, instance)
¶
Create an instance from a KLayout Instance.
Bases: ProtoTInstance[int], DBUGeometricObject
An Instance of a KCell.
An Instance is a reference to a KCell with a transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
_instance |
The internal |
|
ports |
InstancePorts
|
Transformed ports of the KCell |
kcl |
Pointer to the layout object holding the instance |
|
d |
Helper that allows retrieval of instance information in um |
cell
property
writable
¶
Parent KCell of the Instance.
parent_cell
property
writable
¶
Gets the cell this instance is contained in.
pins
cached
property
¶
Gets the transformed pins of the KCell.
ports
cached
property
¶
Gets the transformed ports of the KCell.
__getitem__(key)
¶
Returns port from instance.
The key can either be an integer, in which case the nth port is returned, or a string in which case the first port with a matching name is returned.
If the instance is an array, the key can also be a tuple in the
form of c.ports[key_name, i_a, i_b], where i_a is the index in
the instance.a direction and i_b the instance.b direction.
E.g. c.ports["a", 3, 5], accesses the ports of the instance which is
3 times in a direction (4th index in the array), and 5 times in b direction
(5th index in the array).
__init__(kcl, instance)
¶
Create an instance from a KLayout Instance.
to_yaml(representer, node)
classmethod
¶
Convert the instance to a yaml representation.
Bases: ProtoTKCell[float], UMGeometricObject, DCreatePort
Cell with floating point units.
insts
property
¶
Instances associated with the cell.
pins
property
writable
¶
Pins associated with the cell.
ports
property
writable
¶
Ports associated with the cell.
__getitem__(key)
¶
Returns port from instance.
__init__(name=None, kcl=None, kdb_cell=None, ports=None, info=None, settings=None, pins=None, *, base=None)
¶
Constructor of KCell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
TKCell | None
|
If not |
None
|
name
|
str | None
|
Name of the cell, if None will autogenerate name to
"Unnamed_ |
None
|
kcl
|
KCLayout | None
|
KCLayout the cell should be attached to. |
None
|
kdb_cell
|
Cell | None
|
If not |
None
|
ports
|
Iterable[ProtoPort[Any]] | None
|
Attach an existing [Ports][kfactory.kcell.Ports] object to the KCell,
if |
None
|
info
|
dict[str, Any] | None
|
Info object to attach to the KCell. |
None
|
settings
|
dict[str, Any] | None
|
KCellSettings object to attach to the KCell. |
None
|
__lshift__(cell)
¶
Convenience function for DKCell.create_inst.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
AnyTKCell
|
The cell to be added as an instance |
required |
add_port(*, port, name=None, keep_mirror=False)
¶
Create a port in the cell.
create_pin(*, ports, name=None, pin_type='DC', info=None)
¶
Create a pin in the cell.
Bases: ProtoTKCell[int], DBUGeometricObject, ICreatePort
Cell with integer units.
insts
property
¶
Instances associated with the cell.
pins
property
writable
¶
Pins associated with the cell.
ports
property
writable
¶
Ports associated with the cell.
__getitem__(key)
¶
Returns port from instance.
__init__(name=None, kcl=None, kdb_cell=None, ports=None, info=None, settings=None, pins=None, *, base=None)
¶
Constructor of KCell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
TKCell | None
|
If not |
None
|
name
|
str | None
|
Name of the cell, if None will autogenerate name to
"Unnamed_ |
None
|
kcl
|
KCLayout | None
|
KCLayout the cell should be attached to. |
None
|
kdb_cell
|
Cell | None
|
If not |
None
|
ports
|
Iterable[ProtoPort[Any]] | None
|
Attach an existing [Ports][kfactory.kcell.Ports] object to the KCell,
if |
None
|
info
|
dict[str, Any] | None
|
Info object to attach to the KCell. |
None
|
settings
|
dict[str, Any] | None
|
KCellSettings object to attach to the KCell. |
None
|
__lshift__(cell)
¶
Convenience function for KCell.create_inst.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
AnyTKCell
|
The cell to be added as an instance |
required |
add_port(*, port, name=None, keep_mirror=False)
¶
Create a port in the cell.
create_pin(*, ports, name=None, pin_type='DC', info=None)
¶
Create a pin in the cell.
from_yaml(constructor, node, verbose=False)
classmethod
¶
Internal function used by the placer to convert yaml to a KCell.
to_yaml(representer, node)
classmethod
¶
Internal function to convert the cell to yaml.
Bases: ProtoKCell[TUnit, TKCell], Generic[TUnit], ABC
ghost_cell
property
writable
¶
Returns a value indicating whether the cell is a "ghost cell".
prop_id
property
writable
¶
Gets the properties ID associated with the cell.
__copy__()
¶
Enables use of copy.copy and copy.deep_copy.
__getattr__(name)
¶
If KCell doesn't have an attribute, look in the KLayout Cell.
__getitem__(key)
abstractmethod
¶
Returns port from instance.
__hash__()
¶
Hash the KCell.
auto_rename_ports(rename_func=None)
¶
Rename the ports with the schema angle -> "NSWE" and sort by x and y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rename_func
|
Callable[..., None] | None
|
Function that takes Iterable[Port] and renames them. This can of course contain a filter and only rename some of the ports |
None
|
cell_index()
¶
Gets the cell index.
circuit(l2n, port_types=('optical',), ignore_unnamed=False, exclude_purposes=None, allow_width_mismatch=False)
¶
Create the circuit of the KCell in the given netlist.
connectivity_check(port_types=None, layers=None, db=None, recursive=True, add_cell_ports=False, check_layer_connectivity=True)
¶
Create a ReportDatabase for port problems.
Problems are overlapping ports that aren't aligned, more than two ports overlapping, width mismatch, port_type mismatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_types
|
list[str] | None
|
Filter for certain port typers |
None
|
layers
|
list[int] | None
|
Only create the report for certain layers |
None
|
db
|
ReportDatabase | None
|
Use an existing ReportDatabase instead of creating a new one |
None
|
recursive
|
bool
|
Create the report not only for this cell, but all child cells as well. |
True
|
add_cell_ports
|
bool
|
Also add a category "CellPorts" which contains all the cells selected ports. |
False
|
check_layer_connectivity
|
bool
|
Check whether the layer overlaps with instances. |
True
|
convert_to_static(recursive=True)
¶
Convert the KCell to a static cell if it is pdk KCell.
dcreate_inst(cell, trans=None, *, a=None, b=None, na=1, nb=1, libcell_as_static=False, static_name_separator='__')
¶
Add an instance of another KCell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
ProtoTKCell[Any] | int
|
The cell to be added |
required |
trans
|
DTrans | DVector | DCplxTrans | None
|
The integer transformation applied to the reference |
None
|
a
|
DVector | None
|
Vector for the array. Needs to be in positive X-direction. Usually this is only a Vector in x-direction. Some foundries won't allow other Vectors. |
None
|
b
|
DVector | None
|
Vector for the array. Needs to be in positive Y-direction. Usually this is only a Vector in x-direction. Some foundries won't allow other Vectors. |
None
|
na
|
int
|
Number of elements in direction of |
1
|
nb
|
int
|
Number of elements in direction of |
1
|
libcell_as_static
|
bool
|
If the cell is a Library cell (different KCLayout object), convert it to a static cell. This can cause name collisions that are automatically resolved by appending $1[..n] on the newly created cell. |
False
|
static_name_separator
|
str
|
Stringt to separate the KCLayout name from the cell name when converting library cells (other KCLayout object than the one of this KCell) to static cells (copy them into this KCell's KCLayout). |
'__'
|
Returns:
| Type | Description |
|---|---|
DInstance
|
The created instance |
delete()
¶
Delete the cell.
draw_ports()
¶
Draw all the ports on their respective layer.
dup(new_name=None)
¶
Copy the full cell.
Sets _locked to False
Returns:
| Name | Type | Description |
|---|---|---|
cell |
Self
|
Exact copy of the current cell.
The name will have |
each_inst()
¶
Iterates over all child instances (which may actually be instance arrays).
each_overlapping_inst(b)
¶
Gets the instances overlapping the given rectangle.
each_touching_inst(b)
¶
Gets the instances overlapping the given rectangle.
flatten(merge=True)
¶
Flatten the cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
merge
|
bool
|
Merge the shapes on all layers. |
True
|
get_meta_data(meta_format=None)
¶
Read metadata from the KLayout Layout object.
icreate_inst(cell, trans=None, *, a=None, b=None, na=1, nb=1, libcell_as_static=False, static_name_separator='__')
¶
Add an instance of another KCell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
ProtoTKCell[Any] | int
|
The cell to be added |
required |
trans
|
Trans | Vector | ICplxTrans | None
|
The integer transformation applied to the reference |
None
|
a
|
Vector | None
|
Vector for the array. Needs to be in positive X-direction. Usually this is only a Vector in x-direction. Some foundries won't allow other Vectors. |
None
|
b
|
Vector | None
|
Vector for the array. Needs to be in positive Y-direction. Usually this is only a Vector in x-direction. Some foundries won't allow other Vectors. |
None
|
na
|
int
|
Number of elements in direction of |
1
|
nb
|
int
|
Number of elements in direction of |
1
|
libcell_as_static
|
bool
|
If the cell is a Library cell (different KCLayout object), convert it to a static cell. This can cause name collisions that are automatically resolved by appending $1[..n] on the newly created cell. |
False
|
static_name_separator
|
str
|
Stringt to separate the KCLayout name from the cell name when converting library cells (other KCLayout object than the one of this KCell) to static cells (copy them into this KCell's KCLayout). |
'__'
|
Returns:
| Type | Description |
|---|---|
Instance
|
The created instance |
insert_vinsts(recursive=True)
¶
Insert all virtual instances and create Instances of real KCells.
l2n(port_types=('optical',))
¶
Generate a LayoutToNetlist object from the port types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_types
|
Iterable[str]
|
The port types to consider for the netlist extraction. |
('optical',)
|
Returns: LayoutToNetlist extracted from instance and cell port positions.
l2n_elec(mark_port_types=('electrical', 'RF', 'DC'), connectivity=None, port_mapping=None)
¶
Generate a LayoutToNetlist object from the port types.
Uses electrical connectivity for extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mark_port_types
|
Iterable[str]
|
The port types to consider for the netlist extraction. |
('electrical', 'RF', 'DC')
|
connectivity
|
Sequence[tuple[LayerInfo] | tuple[LayerInfo, LayerInfo] | tuple[LayerInfo, LayerInfo, LayerInfo],] | None
|
Define connectivity between layers. These can be single layers (just consider this layer as metal), two layers (two metals which touch each other), or three layers (two metals with a via) |
None
|
port_mapping
|
dict[str, dict[str | None, str]] | None
|
Remap ports of cells to others. This allows to define
equivalent ports in the lvs. E.g. |
None
|
Returns: LayoutToNetlist extracted from electrical connectivity.
l2n_ports(port_types=('optical',), exclude_purposes=None, ignore_unnamed=False, allow_width_mismatch=False)
¶
Generate a LayoutToNetlist object from the port types.
Uses kfactory ports as a basis for extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port_types
|
Iterable[str]
|
The port types to consider for the netlist extraction. |
('optical',)
|
exclude_purposes
|
list[str] | None
|
List of purposes, if an instance has that purpose, it will be ignored. |
None
|
ignore_unnamed
|
bool
|
Ignore any instance without |
False
|
Returns: LayoutToNetlist extracted from instance and cell port positions.
plot(lyrdb=None, display_type=None)
¶
Display cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lyrdb
|
Path | str | None
|
Path to the lyrdb file. |
None
|
display_type
|
Literal['image', 'widget'] | None
|
Type of display. Options are "widget" or "image". |
None
|
read(filename, options=None, register_cells=False, test_merge=True, update_kcl_meta_data='drop', meta_format=None)
¶
Read a GDS file into the existing KCell.
Any existing meta info (KCell.info and KCell.settings) will be overwritten if a KCell already exists. Instead of overwriting the cells, they can also be loaded into new cells by using the corresponding cell_conflict_resolution.
Layout meta infos are ignored from the loaded layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Path of the GDS file. |
required |
options
|
LoadLayoutOptions | None
|
KLayout options to load from the GDS. Can determine how merge conflicts are handled for example. See https://www.klayout.de/doc-qt5/code/class_LoadLayoutOptions.html |
None
|
register_cells
|
bool
|
If |
False
|
test_merge
|
bool
|
Check the layouts first whether they are compatible (no differences). |
True
|
update_kcl_meta_data
|
Literal['overwrite', 'skip', 'drop']
|
How to treat loaded KCLayout info. overwrite: overwrite existing info entries skip: keep existing info values drop: don't add any new info |
'drop'
|
meta_format
|
Literal['v1', 'v2', 'v3'] | None
|
How to read KCell metainfo from the gds. |
None
|
set_meta_data()
¶
Set metadata of the Cell.
Currently, ports, settings and info will be set.
show(lyrdb=None, l2n=None, keep_position=True, save_options=None, use_libraries=True, library_save_options=None, technology=None)
¶
Stream the gds to klive.
Will create a temporary file of the gds and load it in KLayout via klive
to_dtype()
¶
Convert the kcell to a um kcell.
to_itype()
¶
Convert the kcell to a dbu kcell.
transform(inst_or_trans, trans=None, /, *, transform_ports=True)
¶
Transforms the instance or cell with the transformation given.
write(filename, save_options=None, convert_external_cells=False, set_meta_data=True, autoformat_from_file_extension=True)
¶
Write a KCell to a GDS.
See [KCLayout.write][kfactory.kcell.KCLayout.write] for more info.
write_bytes(save_options=None, convert_external_cells=False, set_meta_data=True)
¶
Write a KCell to a binary format as oasis.
See [KCLayout.write][kfactory.kcell.KCLayout.write] for more info.
Bases: int, Enum
Class for having the layers stored and a mapping int <-> layer,datatype.
This Enum can also be treated as a tuple, i.e. it implements __getitem__
and __len__.
Attributes:
| Name | Type | Description |
|---|---|---|
layer |
int
|
layer number |
datatype |
int
|
layer datatype |
__getitem__(key)
¶
Retrieve layer number[0] / datatype[1] of a layer.
__init__(layer, datatype)
¶
Just here to make sure klayout knows the layer name.
__iter__()
¶
Allow for loops to iterate over the LayerEnum.
__len__()
¶
A layer has length 2, layer number and datatype.
__new__(layer, datatype)
¶
Create a new Enum.
Because it needs to act like an integer an enum is created and expanded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
int
|
Layer number of the layer. |
required |
datatype
|
int
|
Datatype of the layer. |
required |
__str__()
¶
Return the name of the LayerEnum.
Bases: BaseModel
Small extension to the klayout.db.Layout.
It adds tracking for the [KCell][kfactory.kcell.KCell] objects
instead of only the klayout.db.Cell objects.
Additionally it allows creation and registration through create_cell
All attributes of klayout.db.Layout are transparently accessible
Attributes:
| Name | Type | Description |
|---|---|---|
editable |
Whether the layout should be opened in editable mode (default: True) |
|
rename_function |
Callable[..., None]
|
function that takes an iterable object of ports and renames them |
dbu
property
¶
Get the database unit.
dkcells
cached
property
¶
DKCells is a mapping of int to DKCell.
kcells
cached
property
¶
KCells is a mapping of int to KCell.
__getattr__(name)
¶
If KCLayout doesn't have an attribute, look in the KLayout Cell.
__getitem__(obj)
¶
Retrieve a cell by name(str) or index(int).
Attrs
obj: name of cell or cell_index
__init__(name, layer_enclosures=None, enclosure=None, infos=None, sparameters_path=None, interconnect_cml_path=None, layer_stack=None, constants=None, base_kcl=None, port_rename_function=rename_clockwise_multi, copy_base_kcl_layers=True, info=None, default_cell_output_type=KCell, connectivity=None, technology_file=None)
¶
Create a new KCLayout (PDK). Can be based on an old KCLayout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the PDK. |
required |
layer_enclosures
|
dict[str, LayerEnclosure] | LayerEnclosureModel | None
|
Additional KCellEnclosures that should be available except the KCellEnclosure |
None
|
enclosure
|
KCellEnclosure | None
|
The standard KCellEnclosure of the PDK. |
None
|
infos
|
type[LayerInfos] | None
|
A LayerInfos describing the layerstack of the PDK. |
None
|
sparameters_path
|
Path | str | None
|
Path to the sparameters config file. |
None
|
interconnect_cml_path
|
Path | str | None
|
Path to the interconnect file. |
None
|
layer_stack
|
LayerStack | None
|
maps name to layer numbers, thickness, zmin, sidewall_angle. if can also contain material properties (refractive index, nonlinear coefficient, sheet resistance ...). |
None
|
constants
|
type[Constants] | None
|
A model containing all the constants related to the PDK. |
None
|
base_kcl
|
KCLayout | None
|
an optional basis of the PDK. |
None
|
port_rename_function
|
Callable[..., None]
|
Which function to use for renaming kcell ports. |
rename_clockwise_multi
|
copy_base_kcl_layers
|
bool
|
Copy all known layers from the base if any are defined. |
True
|
info
|
dict[str, MetaData] | None
|
Additional metadata to put into info attribute. |
None
|
__setattr__(name, value)
¶
Use a custom setter to automatically set attributes.
If the attribute is not in this object, set it on the Layout object.
assign(layout)
¶
Assign a new Layout object to the KCLayout object.
cell(_func=None, /, *, output_type=None, set_settings=True, set_name=True, check_ports=True, check_pins=True, check_instances=None, snap_ports=True, add_port_layers=True, cache=None, basename=None, drop_params=('self', 'cls'), register_factory=True, overwrite_existing=None, layout_cache=None, info=None, post_process=None, debug_names=None, tags=None, lvs_equivalent_ports=None, ports=None, schematic_function=None)
¶
cell(
*,
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: Callable[
KCellParams, TSchematic[Any]
],
) -> Callable[
[Callable[KCellParams, KC]], Callable[KCellParams, KC]
]
cell(
*,
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: None = None,
) -> Callable[
[Callable[KCellParams, KC]], Callable[KCellParams, KC]
]
cell(
*,
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
post_process: Iterable[Callable[[KC_contra], None]],
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: Callable[
KCellParams, TSchematic[Any]
],
) -> Callable[
[Callable[KCellParams, KC]], Callable[KCellParams, KC]
]
cell(
*,
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
post_process: Iterable[Callable[[KC_contra], None]],
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: None = None,
) -> Callable[
[Callable[KCellParams, KC]], Callable[KCellParams, KC]
]
cell(
*,
output_type: type[KC],
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
post_process: Iterable[Callable[[KC_contra], None]],
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: Callable[
KCellParams, TSchematic[Any]
],
) -> Callable[
[Callable[KCellParams, ProtoTKCell[Any]]],
Callable[KCellParams, KC],
]
cell(
*,
output_type: type[KC],
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
post_process: Iterable[Callable[[KC_contra], None]],
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: None = None,
) -> Callable[
[Callable[KCellParams, ProtoTKCell[Any]]],
Callable[KCellParams, KC],
]
cell(
*,
output_type: type[KC],
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: Callable[
KCellParams, TSchematic[Any]
],
) -> Callable[
[Callable[KCellParams, ProtoTKCell[Any]]],
Callable[KCellParams, KC],
]
cell(
*,
output_type: type[KC],
set_settings: bool = ...,
set_name: bool = ...,
check_ports: bool = ...,
check_pins: bool = ...,
check_instances: CheckInstances | None = ...,
snap_ports: bool = ...,
add_port_layers: bool = ...,
cache: Cache[int, Any] | dict[int, Any] | None = ...,
basename: str | None = ...,
drop_params: list[str] = ...,
register_factory: bool = ...,
overwrite_existing: bool | None = ...,
layout_cache: bool | None = ...,
info: dict[str, MetaData] | None = ...,
debug_names: bool | None = ...,
tags: list[str] | None = ...,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
schematic_function: None = None,
) -> Callable[
[Callable[KCellParams, ProtoTKCell[Any]]],
Callable[KCellParams, KC],
]
Decorator to cache and auto name the cell.
This will use functools.cache to cache the function call.
Additionally, if enabled this will set the name and from the args/kwargs of the
function and also paste them into a settings dictionary of the
[KCell][kfactory.kcell.KCell].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
type[KC] | None
|
The type of the cell to return. |
None
|
set_settings
|
bool
|
Copy the args & kwargs into the settings dictionary |
True
|
set_name
|
bool
|
Auto create the name of the cell to the functionname plus a string created from the args/kwargs |
True
|
check_ports
|
bool
|
Check uniqueness of port names. |
True
|
check_pins
|
bool
|
Check uniqueness of pin names. |
True
|
check_instances
|
CheckInstances | None
|
Check for any complex instances. A complex instance is a an instance that has a magnification != 1 or non-90° rotation. Depending on the setting, an error is raised, the cell is flattened, a VInstance is created instead of a regular instance, or they are ignored. |
None
|
snap_ports
|
bool
|
Snap the centers of the ports onto the grid (only x/y, not angle). |
True
|
add_port_layers
|
bool
|
Add special layers of |
True
|
cache
|
Cache[int, Any] | dict[int, Any] | None
|
Provide a user defined cache instead of an internal one. This can be used for example to clear the cache. expensive if the cell is called often). |
None
|
basename
|
str | None
|
Overwrite the name normally inferred from the function or class name. |
None
|
drop_params
|
Sequence[str]
|
Drop these parameters before writing the [settings][kfactory.kcell.KCell.settings] |
('self', 'cls')
|
register_factory
|
bool
|
Register the resulting KCell-function to the
|
True
|
layout_cache
|
bool | None
|
If true, treat the layout like a cache, if a cell with the
same name exists already, pick that one instead of using running the
function. This only works if |
None
|
overwrite_existing
|
bool | None
|
If cells were created with the same name, delete other
cells with the same name. Can be globally configured through
|
None
|
info
|
dict[str, MetaData] | None
|
Additional metadata to put into info attribute. |
None
|
post_process
|
Iterable[Callable[[KC_contra], None]] | None
|
List of functions to call after the cell has been created. |
None
|
debug_names
|
bool | None
|
Check on setting the name whether a cell with this name already exists. |
None
|
tags
|
list[str] | None
|
Tag cell functions with user defined tags. |
None
|
Returns: A wrapped cell function which caches responses and modifies the cell according to settings.
clear(keep_layers=True)
¶
Clear the Layout.
If the layout is cleared, all the LayerEnums and
clear_kcells()
¶
Clears all cells in the Layout object.
create_cell(name, *args, allow_duplicate=False)
¶
Create a new cell in the library.
This shouldn't be called manually. The constructor of KCell will call this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The (initial) name of the cell. |
required |
allow_duplicate
|
bool
|
Allow the creation of a cell with the same name which
already is registered in the Layout.
This will create a cell with the name |
False
|
args
|
str
|
additional arguments passed to
|
()
|
Returns:
| Type | Description |
|---|---|
Cell
|
klayout.db.Cell: klayout.db.Cell object created in the Layout |
create_layer_enclosure(sections=[], name=None, main_layer=None, dsections=None)
¶
Create a new LayerEnclosure in the KCLayout.
delete_cell(cell)
¶
Delete a cell in the kcl object.
delete_cell_rec(cell_index)
¶
Deletes a KCell plus all subcells.
delete_cells(cell_index_list)
¶
Delete a sequence of cell by indexes.
dkcell(name=None, ports=None)
¶
Create a new cell based ont he pdk's layout object.
dup(init_cells=True)
¶
Create a duplication of the ~KCLayout object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_cells
|
bool
|
initialize the all cells in the new KCLayout object |
True
|
Returns:
| Type | Description |
|---|---|
KCLayout
|
Copy of itself |
find_layer(*args, **kwargs)
¶
find_layer(
info: kdb.LayerInfo,
*,
allow_undefined_layers: Literal[True] = True,
) -> LayerEnum | int
Try to find a registered layer. Throws a KeyError if it cannot find it.
Can find a layer either by name, layer and datatype (two args), LayerInfo, or all three of layer, datatype, and name.
get_cell(obj, cell_type=KCell, error_search_limit=10)
¶
Retrieve a cell by name(str) or index(int).
Attrs
obj: name of cell or cell_index cell_type: type of cell to return
get_dcross_section(cross_section)
¶
Get a cross section by name or specification.
get_enclosure(enclosure)
¶
Gets a layer enclosure by name specification or the layerenclosure itself.
get_icross_section(cross_section)
¶
Get a cross section by name or specification.
get_meta_data()
¶
Read KCLayout meta info from the KLayout object.
get_symmetrical_cross_section(cross_section)
¶
Get a cross section by name or specification.
kcell(name=None, ports=None)
¶
Create a new cell based ont he pdk's layout object.
layerenum_from_dict(name='LAYER', *, layers)
¶
Create a new [LayerEnum][kfactory.kcell.LayerEnum] from this KCLayout.
layout_cell(name)
¶
Get a cell by name or index from the Layout object.
read(filename, options=None, register_cells=None, test_merge=True, update_kcl_meta_data='skip', meta_format=None)
¶
Read a GDS file into the existing Layout.
Any existing meta info (KCell.info and KCell.settings) will be overwritten if a KCell already exists. Instead of overwriting the cells, they can also be loaded into new cells by using the corresponding cell_conflict_resolution.
This will fail if any of the read cells try to load into a locked KCell.
Layout meta infos are ignored from the loaded layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Path of the GDS file. |
required |
options
|
LoadLayoutOptions | None
|
KLayout options to load from the GDS. Can determine how merge conflicts are handled for example. See https://www.klayout.de/doc-qt5/code/class_LoadLayoutOptions.html |
None
|
register_cells
|
bool | None
|
If |
None
|
test_merge
|
bool
|
Check the layouts first whether they are compatible (no differences). |
True
|
update_kcl_meta_data
|
Literal['overwrite', 'skip', 'drop']
|
How to treat loaded KCLayout info. overwrite: overwrite existing info entries skip: keep existing info values drop: don't add any new info |
'skip'
|
meta_format
|
Literal['v1', 'v2', 'v3'] | None
|
How to read KCell metainfo from the gds. |
None
|
rebuild()
¶
Rebuild the KCLayout based on the Layout object.
register_cell(kcell, allow_reregister=False)
¶
Register an existing cell in the KCLayout object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kcell
|
AnyTKCell
|
KCell 56 be registered in the KCLayout |
required |
allow_reregister
|
bool
|
Overwrite the existing KCell registration with this one. Doesn't allow name duplication. |
False
|
set_layers_from_infos(name, layers)
¶
Create a new LAYER enum based on the pdk's kcl.
set_meta_data()
¶
Set the info/settings of the KCLayout.
top_kcell()
¶
Return the top KCell if there is a single one.
top_kcells()
¶
Return the top KCells.
vcell(_func=None, /, *, output_type=None, set_settings=True, set_name=True, add_port_layers=True, cache=None, basename=None, drop_params=('self', 'cls'), register_factory=True, post_process=None, info=None, check_ports=True, check_pins=True, tags=None, lvs_equivalent_ports=None, ports=None)
¶
vcell(
*,
set_settings: bool = True,
set_name: bool = True,
add_port_layers: bool = True,
cache: Cache[int, Any] | dict[int, Any] | None = None,
basename: str | None = None,
drop_params: Sequence[str] = ("self", "cls"),
register_factory: bool = True,
info: dict[str, MetaData] | None = None,
check_ports: bool = True,
check_pins: bool = True,
tags: list[str] | None = None,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
) -> Callable[
[Callable[KCellParams, VK]], Callable[KCellParams, VK]
]
vcell(
*,
set_settings: bool = True,
set_name: bool = True,
add_port_layers: bool = True,
cache: Cache[int, Any] | dict[int, Any] | None = None,
basename: str | None = None,
drop_params: Sequence[str] = ("self", "cls"),
register_factory: bool = True,
post_process: Iterable[Callable[[VKCell], None]],
info: dict[str, MetaData] | None = None,
check_ports: bool = True,
check_pins: bool = True,
tags: list[str] | None = None,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
) -> Callable[
[Callable[KCellParams, VK]], Callable[KCellParams, VK]
]
vcell(
*,
output_type: type[VK],
set_settings: bool = True,
set_name: bool = True,
add_port_layers: bool = True,
cache: Cache[int, Any] | dict[int, Any] | None = None,
basename: str | None = None,
drop_params: Sequence[str] = ("self", "cls"),
register_factory: bool = True,
info: dict[str, MetaData] | None = None,
check_ports: bool = True,
check_pins: bool = True,
tags: list[str] | None = None,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
) -> Callable[
[Callable[KCellParams, VKCell]],
Callable[KCellParams, VK],
]
vcell(
*,
output_type: type[VK],
set_settings: bool = True,
set_name: bool = True,
add_port_layers: bool = True,
cache: Cache[int, Any] | dict[int, Any] | None = None,
basename: str | None = None,
drop_params: Sequence[str] = ("self", "cls"),
register_factory: bool = True,
post_process: Iterable[Callable[[VKCell], None]],
info: dict[str, MetaData] | None = None,
check_ports: bool = True,
check_pins: bool = True,
tags: list[str] | None = None,
lvs_equivalent_ports: list[list[str]] | None = None,
ports: PortsDefinition | None = None,
) -> Callable[
[Callable[KCellParams, VKCell]],
Callable[KCellParams, VK],
]
Decorator to cache and auto name the cell.
This will use functools.cache to cache the function call.
Additionally, if enabled this will set the name and from the args/kwargs of the
function and also paste them into a settings dictionary of the
[KCell][kfactory.kcell.KCell].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_settings
|
bool
|
Copy the args & kwargs into the settings dictionary |
True
|
set_name
|
bool
|
Auto create the name of the cell to the functionname plus a string created from the args/kwargs |
True
|
check_ports
|
bool
|
Check uniqueness of port names. |
True
|
check_pins
|
bool
|
Check uniqueness of pin names. |
True
|
add_port_layers
|
bool
|
Add special layers of |
True
|
cache
|
Cache[int, Any] | dict[int, Any] | None
|
Provide a user defined cache instead of an internal one. This can be used for example to clear the cache. |
None
|
basename
|
str | None
|
Overwrite the name normally inferred from the function or class name. |
None
|
drop_params
|
Sequence[str]
|
Drop these parameters before writing the [settings][kfactory.kcell.KCell.settings] |
('self', 'cls')
|
register_factory
|
bool
|
Register the resulting KCell-function to the
|
True
|
info
|
dict[str, MetaData] | None
|
Additional metadata to put into info attribute. |
None
|
post_process
|
Iterable[Callable[[VKCell], None]] | None
|
List of functions to call after the cell has been created. |
None
|
Returns: A wrapped vcell function which caches responses and modifies the VKCell according to settings.
vkcell(name=None)
¶
Create a new cell based ont he pdk's layout object.
write(filename, options=None, set_meta_data=True, convert_external_cells=False, autoformat_from_file_extension=True)
¶
Write a GDS file into the existing Layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
Path of the GDS file. |
required |
options
|
SaveLayoutOptions | None
|
KLayout options to load from the GDS. Can determine how merge conflicts are handled for example. See https://www.klayout.de/doc-qt5/code/class_LoadLayoutOptions.html |
None
|
set_meta_data
|
bool
|
Make sure all the cells have their metadata set |
True
|
convert_external_cells
|
bool
|
Whether to make KCells not in this KCLayout to |
False
|
autoformat_from_file_extension
|
bool
|
Set the format of the output file
automatically from the file extension of |
True
|
Bases: ProtoPort[float]
A port is the photonics equivalent to a pin in electronics.
In addition to the location and layer that defines a pin, a port also contains an orientation and a width. This can be fully represented with a transformation, integer and layer_index.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
String to name the port. |
width |
float
|
The width of the port in dbu. |
trans |
Trans
|
Transformation in dbu. If the port can be represented in 90° intervals this is the safe way to do so. |
dcplx_trans |
Transformation in micrometer. The port will autoconvert between trans and dcplx_trans on demand. |
|
port_type |
str
|
A string defining the type of the port |
layer |
LayerEnum | int
|
Index of the layer or a LayerEnum that acts like an integer, but can contain layer number and datatype |
info |
Info
|
A dictionary with additional info. Not reflected in GDS. Copy will make a (shallow) copy of it. |
d |
Info
|
Access port info in micrometer basis such as width and center / angle. |
kcl |
KCLayout
|
Link to the layout this port resides in. |
cross_section
property
writable
¶
Get the cross section of the port.
width
property
¶
Width of the port in um.
x
property
writable
¶
X coordinate of the port in um.
y
property
writable
¶
Y coordinate of the port in um.
__init__(name=None, *, width=None, layer=None, layer_info=None, port_type='optical', trans=None, dcplx_trans=None, orientation=0, center=(0, 0), mirror_x=False, port=None, kcl=None, info=None, cross_section=None, base=None)
¶
__init__(
name: str | None = None,
*,
width: float,
layer: LayerEnum | int,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: float,
layer: LayerEnum | int,
dcplx_trans: kdb.DCplxTrans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: float,
layer: LayerEnum | int,
port_type: str = "optical",
orientation: float,
center: tuple[float, float] = (0, 0),
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: float,
layer_info: kdb.LayerInfo,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: float,
layer_info: kdb.LayerInfo,
dcplx_trans: kdb.DCplxTrans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: float,
layer_info: kdb.LayerInfo,
port_type: str = "optical",
orientation: float,
center: tuple[float, float] = (0, 0),
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
cross_section: DCrossSection | SymmetricalCrossSection,
port_type: str = "optical",
orientation: float,
center: tuple[float, float],
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
cross_section: DCrossSection | SymmetricalCrossSection,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
port_type: str = "optical",
) -> None
Create a port from dbu or um based units.
copy(trans=kdb.Trans.R0, post_trans=kdb.Trans.R0)
¶
Get a copy of a port.
Transformation order which results in copy.trans:
- Trans: trans * port.trans * post_trans
- DCplxTrans: trans * port.dcplx_trans * post_trans
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trans
|
Trans | DCplxTrans
|
an optional transformation applied to the port to be copied. |
R0
|
post_trans
|
Trans | DCplxTrans
|
transformation to apply to the port after copying. |
R0
|
Returns:
| Name | Type | Description |
|---|---|---|
port |
DPort
|
a copy of the port |
copy_polar(d=0, d_orth=0, orientation=180, mirror=False)
¶
Get a polar copy of the port.
This will return a port which is transformed relatively to the original port's transformation (orientation, angle and position).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
float
|
The distance to the old port |
0
|
d_orth
|
float
|
Orthogonal distance (positive is positive y for a port which is facing angle=0°) |
0
|
orientation
|
float
|
Relative angle to the original port, in degrees. |
180
|
mirror
|
bool
|
Whether to mirror the port relative to the original port. |
False
|
Bases: ProtoPort[int]
A port is the photonics equivalent to a pin in electronics.
In addition to the location and layer that defines a pin, a port also contains an orientation and a width. This can be fully represented with a transformation, integer and layer_index.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
String to name the port. |
width |
int
|
The width of the port in dbu. |
trans |
Trans
|
Transformation in dbu. If the port can be represented in 90° intervals this is the safe way to do so. |
dcplx_trans |
Transformation in micrometer. The port will autoconvert between trans and dcplx_trans on demand. |
|
port_type |
str
|
A string defining the type of the port |
layer |
LayerEnum | int
|
Index of the layer or a LayerEnum that acts like an integer, but can contain layer number and datatype |
info |
Info
|
A dictionary with additional info. Not reflected in GDS. Copy will make a (shallow) copy of it. |
d |
Info
|
Access port info in micrometer basis such as width and center / angle. |
kcl |
KCLayout
|
Link to the layout this port resides in. |
cross_section
property
writable
¶
Get the cross section of the port.
width
property
¶
Width of the port in um.
x
property
writable
¶
X coordinate of the port in dbu.
y
property
writable
¶
Y coordinate of the port in dbu.
__init__(name=None, *, width=None, layer=None, layer_info=None, port_type='optical', trans=None, dcplx_trans=None, angle=None, center=None, mirror_x=False, port=None, kcl=None, info=None, cross_section=None, base=None)
¶
__init__(
*,
name: str | None = None,
width: int,
layer: LayerEnum | int,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
*,
name: str | None = None,
width: int,
layer: LayerEnum | int,
dcplx_trans: kdb.DCplxTrans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: int,
layer: LayerEnum | int,
port_type: str = "optical",
angle: int,
center: tuple[int, int],
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: int,
layer_info: kdb.LayerInfo,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: int,
layer_info: kdb.LayerInfo,
dcplx_trans: kdb.DCplxTrans | str,
kcl: KCLayout | None = None,
port_type: str = "optical",
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
width: int,
layer_info: kdb.LayerInfo,
port_type: str = "optical",
angle: int,
center: tuple[int, int],
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
cross_section: CrossSection | SymmetricalCrossSection,
port_type: str = "optical",
angle: int,
center: tuple[int, int],
mirror_x: bool = False,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
) -> None
__init__(
name: str | None = None,
*,
cross_section: CrossSection | SymmetricalCrossSection,
trans: kdb.Trans | str,
kcl: KCLayout | None = None,
info: dict[str, int | float | str] = ...,
port_type: str = "optical",
) -> None
Create a port from dbu or um based units.
copy(trans=kdb.Trans.R0, post_trans=kdb.Trans.R0)
¶
Get a copy of a port.
Transformation order which results in copy.trans:
- Trans: trans * port.trans * post_trans
- DCplxTrans: trans * port.dcplx_trans * post_trans
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trans
|
Trans | DCplxTrans
|
an optional transformation applied to the port to be copied. |
R0
|
post_trans
|
Trans | DCplxTrans
|
transformation to apply to the port after copying. |
R0
|
Returns:
| Name | Type | Description |
|---|---|---|
port |
Port
|
a copy of the port |
copy_polar(d=0, d_orth=0, angle=2, mirror=False)
¶
Get a polar copy of the port.
This will return a port which is transformed relatively to the original port's transformation (orientation, angle and position).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
int
|
The distance to the old port |
0
|
d_orth
|
int
|
Orthogonal distance (positive is positive y for a port which is facing angle=0°) |
0
|
angle
|
int
|
Relative angle to the original port (0=0°,1=90°,2=180°,3=270°). |
2
|
mirror
|
bool
|
Whether to mirror the port relative to the original port. |
False
|
Returns:
| Type | Description |
|---|---|
Port
|
Port copied relative to it's current position and angle/orientation. |