Skip to content

Types

Dbu module-attribute

Dbu: TypeAlias = Annotated[Int, 'value in database units']

DirectivePointsDbu module-attribute

DirectivePointsDbu: TypeAlias = list[
    PositionWithDirectionDbu
]

Float module-attribute

Float: TypeAlias = float | float64

Int module-attribute

Int: TypeAlias = int | int_

Layer module-attribute

Layer: TypeAlias = tuple[int, int]

LayerLike module-attribute

LayerLike: TypeAlias = tuple[Int, Int] | LayerEnum | str

Number module-attribute

Number: TypeAlias = Int | Float

OrientationChar module-attribute

OrientationChar: TypeAlias = Literal[
    "n", "e", "s", "w", "o"
]

OrientationDegree module-attribute

OrientationDegree: TypeAlias = Literal[0, 90, 180, 270, -90]

OrientationLike module-attribute

OrientationLike: TypeAlias = (
    OrientationChar
    | OrientationWord
    | OrientationDegree
    | Int
    | Float
    | None
)

OrientationTransition module-attribute

OrientationTransition: TypeAlias = tuple[
    OrientationChar, OrientationChar
]

OrientationWord module-attribute

OrientationWord: TypeAlias = Literal[
    "north", "east", "south", "west", "none"
]

PointsDbu module-attribute

PointsDbu: TypeAlias = list[PositionDbu]

PointsUm module-attribute

PointsUm: TypeAlias = list[tuple[Float, Float]]

PointsWgu module-attribute

PointsWgu: TypeAlias = list[tuple[Wgu, Wgu]]

PortLike module-attribute

PositionAny module-attribute

PositionAny: TypeAlias = PositionUm | PositionDbu

PositionDbu module-attribute

PositionDbu: TypeAlias = Annotated[
    tuple[Dbu, Dbu], "x, y position in database units"
]

PositionUm module-attribute

PositionUm: TypeAlias = Annotated[
    tuple[Um, Um], "x, y position in micrometer"
]

PositionWithDirectionDbu module-attribute

PositionWithDirectionDbu: TypeAlias = Annotated[
    tuple[Dbu, Dbu, OrientationChar],
    "x[dbu] y[dbu] d[n|e|s|w|o]",
]

PositionWithDirectionUm module-attribute

PositionWithDirectionUm: TypeAlias = Annotated[
    tuple[Um, Um, OrientationChar], "x[um] y[um] d[neswo]"
]

StepDbu

Bases: TypedDict

Attributes:

Name Type Description
dx NotRequired[Dbu]
dy NotRequired[Dbu]
x NotRequired[Dbu]
y NotRequired[Dbu]

dx instance-attribute

dy instance-attribute

x instance-attribute

y instance-attribute

Um module-attribute

Um: TypeAlias = Annotated[Float, 'value in micrometer']

Wgu module-attribute

Wgu: TypeAlias = Annotated[Int, "value in 'wg width units'"]

DInstance

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 kdb.Instance reference

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

Methods:

Name Description
__getitem__

Returns port from instance.

__init__

Create an instance from a KLayout Instance.

Attributes:

Name Type Description
cell DKCell

Parent KCell of the Instance.

kcl
parent_cell DKCell

Gets the cell this instance is contained in.

ports DInstancePorts

Gets the transformed ports of the KCell.

yaml_tag str

_instance instance-attribute

_instance = instance

cell property writable

cell: DKCell

Parent KCell of the Instance.

kcl instance-attribute

kcl = kcl

parent_cell property writable

parent_cell: DKCell

Gets the cell this instance is contained in.

ports property

ports: DInstancePorts

Gets the transformed ports of the KCell.

yaml_tag class-attribute

yaml_tag: str = '!Instance'

__getitem__

__getitem__(
    key: (
        int | str | tuple[int | str | None, int, int] | None
    ),
) -> DPort

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__

__init__(kcl: KCLayout, instance: Instance) -> None

Create an instance from a KLayout Instance.

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 kdb.Instance reference

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

Methods:

Name Description
__getitem__

Returns port from instance.

__init__

Create an instance from a KLayout Instance.

to_yaml

Convert the instance to a yaml representation.

Attributes:

Name Type Description
cell KCell

Parent KCell of the Instance.

kcl
parent_cell KCell

Gets the cell this instance is contained in.

ports InstancePorts

Gets the transformed ports of the KCell.

yaml_tag str

_instance instance-attribute

_instance = instance

cell property writable

cell: KCell

Parent KCell of the Instance.

kcl instance-attribute

kcl = kcl

parent_cell property writable

parent_cell: KCell

Gets the cell this instance is contained in.

ports property

ports: InstancePorts

Gets the transformed ports of the KCell.

yaml_tag class-attribute

yaml_tag: str = '!Instance'

__getitem__

__getitem__(
    key: (
        int | str | tuple[int | str | None, int, int] | None
    ),
) -> Port

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__

__init__(kcl: KCLayout, instance: Instance) -> None

Create an instance from a KLayout Instance.

to_yaml classmethod

to_yaml(
    representer: BaseRepresenter, node: Self
) -> MappingNode

Convert the instance to a yaml representation.

DKCell

Bases: ProtoTKCell[float], UMGeometricObject

Cell with floating point units.

Methods:

Name Description
__getitem__

Returns port from instance.

__init__

Constructor of KCell.

__lshift__

Convenience function for create_inst.

create_inst
create_port

Create a port in the cell.

get_cross_section

Attributes:

Name Type Description
insts DInstances

Instances associated with the cell.

ports DPorts

Ports associated with the cell.

yaml_tag str

insts property

insts: DInstances

Instances associated with the cell.

ports property writable

ports: DPorts

Ports associated with the cell.

yaml_tag class-attribute

yaml_tag: str = '!DKCell'

__getitem__

__getitem__(key: int | str | None) -> DPort

Returns port from instance.

__init__

__init__(*, base: TKCell) -> None
__init__(
    name: str | None = None,
    kcl: KCLayout | None = None,
    kdb_cell: Cell | None = None,
    ports: Iterable[ProtoPort[Any]] | None = None,
    info: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None,
) -> None
__init__(
    name: str | None = None,
    kcl: KCLayout | None = None,
    kdb_cell: Cell | None = None,
    ports: Iterable[ProtoPort[Any]] | None = None,
    info: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None,
    *,
    base: TKCell | None = None
) -> None

Constructor of KCell.

Parameters:

Name Type Description Default
base TKCell | None

If not None, a KCell will be created from and existing KLayout Cell

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, a KCell will be created from and existing KLayout Cell

None
ports Iterable[ProtoPort[Any]] | None

Attach an existing [Ports][kfactory.kcell.Ports] object to the KCell, if None create an empty one.

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__

__lshift__(cell: AnyTKCell) -> DInstance

Convenience function for create_inst.

Parameters:

Name Type Description Default
cell AnyTKCell

The cell to be added as an instance

required

create_inst

create_inst(
    cell: ProtoTKCell[Any] | int,
    trans: DTrans | DVector | DCplxTrans | None = None,
    *,
    a: DVector | None = None,
    b: DVector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> DInstance

create_port

create_port(**kwargs: Any) -> DPort

Create a port in the cell.

get_cross_section

get_cross_section(
    cross_section: (
        str
        | dict[str, Any]
        | Callable[..., CrossSection | DCrossSection]
        | SymmetricalCrossSection
    ),
    **cross_section_kwargs: Any
) -> DCrossSection

KCell

Bases: ProtoTKCell[int], DBUGeometricObject

Cell with integer units.

Methods:

Name Description
__getitem__

Returns port from instance.

__init__

Constructor of KCell.

__lshift__

Convenience function for create_inst.

create_inst
create_port

Create a port in the cell.

from_yaml

Internal function used by the placer to convert yaml to a KCell.

get_cross_section
to_yaml

Internal function to convert the cell to yaml.

Attributes:

Name Type Description
insts Instances

Instances associated with the cell.

ports Ports

Ports associated with the cell.

yaml_tag str

insts property

insts: Instances

Instances associated with the cell.

ports property writable

ports: Ports

Ports associated with the cell.

yaml_tag class-attribute

yaml_tag: str = '!KCell'

__getitem__

__getitem__(key: int | str | None) -> Port

Returns port from instance.

__init__

__init__(*, base: TKCell) -> None
__init__(
    name: str | None = None,
    kcl: KCLayout | None = None,
    kdb_cell: Cell | None = None,
    ports: Iterable[ProtoPort[Any]] | None = None,
    info: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None,
) -> None
__init__(
    name: str | None = None,
    kcl: KCLayout | None = None,
    kdb_cell: Cell | None = None,
    ports: Iterable[ProtoPort[Any]] | None = None,
    info: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None,
    *,
    base: TKCell | None = None
) -> None

Constructor of KCell.

Parameters:

Name Type Description Default
base TKCell | None

If not None, a KCell will be created from and existing KLayout Cell

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, a KCell will be created from and existing KLayout Cell

None
ports Iterable[ProtoPort[Any]] | None

Attach an existing [Ports][kfactory.kcell.Ports] object to the KCell, if None create an empty one.

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__

__lshift__(cell: AnyTKCell) -> Instance

Convenience function for create_inst.

Parameters:

Name Type Description Default
cell AnyTKCell

The cell to be added as an instance

required

create_inst

create_inst(
    cell: AnyTKCell | int,
    trans: Trans | Vector | ICplxTrans | None = None,
    *,
    a: Vector | None = None,
    b: Vector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> Instance

create_port

create_port(**kwargs: Any) -> Port

Create a port in the cell.

from_yaml classmethod

from_yaml(
    constructor: SafeConstructor,
    node: Any,
    verbose: bool = False,
) -> Self

Internal function used by the placer to convert yaml to a KCell.

get_cross_section

get_cross_section(
    cross_section: (
        str
        | dict[str, Any]
        | Callable[..., CrossSection | DCrossSection]
        | SymmetricalCrossSection
    ),
    **cross_section_kwargs: Any
) -> CrossSection

to_yaml classmethod

to_yaml(
    representer: BaseRepresenter, node: Self
) -> MappingNode

Internal function to convert the cell to yaml.

ProtoTKCell

Bases: ProtoKCell[TUnit, TKCell], Generic[TUnit], ABC

Methods:

Name Description
__copy__

Enables use of copy.copy and copy.deep_copy.

__eq__
__getattr__

If KCell doesn't have an attribute, look in the KLayout Cell.

__getitem__

Returns port from instance.

__hash__

Hash the KCell.

__init__
__lshift__
auto_rename_ports

Rename the ports with the schema angle -> "NSWE" and sort by x and y.

cell_index

Gets the cell index.

circuit

Create the circuit of the KCell in the given netlist.

connectivity_check

Create a ReportDatabase for port problems.

convert_to_static

Convert the KCell to a static cell if it is pdk KCell.

create_inst
create_port

Proxy for [Ports.create_port][kfactory.kcell.Ports.create_port].

dbbox
dcreate_inst

Add an instance of another KCell.

delete

Delete the cell.

destroyed
draw_ports

Draw all the ports on their respective layer.

dup

Copy the full cell.

each_inst

Iterates over all child instances (which may actually be instance arrays).

each_overlapping_inst

Gets the instances overlapping the given rectangle.

each_touching_inst

Gets the instances overlapping the given rectangle.

flatten

Flatten the cell.

get_cross_section
get_meta_data

Read metadata from the KLayout Layout object.

ibbox
icreate_inst

Add an instance of another KCell.

insert

Inserts a cell instance given by another reference.

insert_vinsts

Insert all virtual instances and create Instances of real KCells.

l2n

Generate a LayoutToNetlist object from the port types.

layout
library
plot

Display cell.

read

Read a GDS file into the existing KCell.

set_meta_data

Set metadata of the Cell.

shapes
show

Stream the gds to klive.

to_dtype

Convert the kcell to a um kcell.

to_itype

Convert the kcell to a dbu kcell.

transform

Transforms the instance or cell with the transformation given.

write

Write a KCell to a GDS.

Attributes:

Name Type Description
boundary DPolygon | None
ghost_cell bool

Returns a value indicating whether the cell is a "ghost cell".

insts ProtoTInstances[TUnit]
kdb_cell Cell
name str
prop_id int

Gets the properties ID associated with the cell.

_base instance-attribute

_base = TKCell(
    kcl=kcl_,
    info=Info(**info or {}),
    settings=KCellSettings(**settings or {}),
    kdb_cell=kdb_cell_,
    ports=[base for port in ports] if ports else [],
    vinsts=VInstances(),
)

boundary property writable

boundary: DPolygon | None

ghost_cell property writable

ghost_cell: bool

Returns a value indicating whether the cell is a "ghost cell".

insts abstractmethod property

insts: ProtoTInstances[TUnit]

kdb_cell property

kdb_cell: Cell

name property writable

name: str

prop_id property writable

prop_id: int

Gets the properties ID associated with the cell.

__copy__

__copy__() -> Self

Enables use of copy.copy and copy.deep_copy.

__eq__

__eq__(other: object) -> bool

__getattr__

__getattr__(name: str) -> Any

If KCell doesn't have an attribute, look in the KLayout Cell.

__getitem__ abstractmethod

__getitem__(key: int | str | None) -> ProtoPort[TUnit]

Returns port from instance.

__hash__

__hash__() -> int

Hash the KCell.

__init__

__init__(
    *,
    base: TKCell | None = None,
    name: str | None = None,
    kcl: KCLayout | None = None,
    kdb_cell: Cell | None = None,
    ports: Iterable[ProtoPort[Any]] | None = None,
    info: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None
) -> None

__lshift__ abstractmethod

__lshift__(cell: AnyTKCell) -> ProtoTInstance[TUnit]

_get_ci

_get_ci(
    cell: ProtoTKCell[Any],
    libcell_as_static: bool = False,
    static_name_separator: str = "__",
) -> int

_ipython_display_

_ipython_display_() -> None

Display a cell in a Jupyter Cell.

Usage: Pass the kcell variable as an argument in the cell at the end

_kdb_copy

_kdb_copy() -> Cell

auto_rename_ports

auto_rename_ports(
    rename_func: Callable[..., None] | None = None,
) -> 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

cell_index() -> int

Gets the cell index.

circuit

circuit(
    l2n: LayoutToNetlist,
    port_types: Iterable[str] = ("optical",),
) -> None

Create the circuit of the KCell in the given netlist.

connectivity_check

connectivity_check(
    port_types: list[str] | None = None,
    layers: list[int] | None = None,
    db: ReportDatabase | None = None,
    recursive: bool = True,
    add_cell_ports: bool = False,
    check_layer_connectivity: bool = True,
) -> ReportDatabase

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

convert_to_static(recursive: bool = True) -> None

Convert the KCell to a static cell if it is pdk KCell.

create_inst abstractmethod

create_inst(
    cell: ProtoTKCell[Any] | int,
    trans: Trans | Vector | ICplxTrans | None = None,
    *,
    a: Vector | None = None,
    b: Vector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> Instance
create_inst(
    cell: ProtoTKCell[Any] | int,
    trans: DTrans | DVector | DCplxTrans | None = None,
    *,
    a: DVector | None = None,
    b: DVector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> DInstance
create_inst(
    cell: ProtoTKCell[Any] | int,
    trans: (
        Trans
        | Vector
        | ICplxTrans
        | DTrans
        | DVector
        | DCplxTrans
        | None
    ) = None,
    *,
    a: Vector | DVector | None = None,
    b: Vector | DVector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> Instance | DInstance

create_port

create_port(**kwargs: Any) -> ProtoPort[TUnit]

Proxy for [Ports.create_port][kfactory.kcell.Ports.create_port].

dbbox

dbbox(layer: int | None = None) -> DBox

dcreate_inst

dcreate_inst(
    cell: ProtoTKCell[Any] | int,
    trans: DTrans | DVector | DCplxTrans | None = None,
    *,
    a: DVector | None = None,
    b: DVector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> DInstance

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 a

1
nb int

Number of elements in direction of b

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() -> None

Delete the cell.

destroyed

destroyed() -> bool

draw_ports

draw_ports() -> None

Draw all the ports on their respective layer.

dup

dup() -> Self

Copy the full cell.

Sets _locked to False

Returns:

Name Type Description
cell Self

Exact copy of the current cell. The name will have $1 as duplicate names are not allowed

each_inst

each_inst() -> Iterator[Instance]

Iterates over all child instances (which may actually be instance arrays).

each_overlapping_inst

each_overlapping_inst(b: Box | DBox) -> Iterator[Instance]

Gets the instances overlapping the given rectangle.

each_touching_inst

each_touching_inst(b: Box | DBox) -> Iterator[Instance]

Gets the instances overlapping the given rectangle.

flatten

flatten(merge: bool = True) -> None

Flatten the cell.

Parameters:

Name Type Description Default
merge bool

Merge the shapes on all layers.

True

get_cross_section abstractmethod

get_cross_section(
    cross_section: (
        str
        | dict[str, Any]
        | Callable[..., CrossSection | DCrossSection]
        | SymmetricalCrossSection
    ),
    **cross_section_kwargs: Any
) -> TCrossSection[TUnit]

get_meta_data

get_meta_data(
    meta_format: Literal["v1", "v2", "v3"] | None = None,
) -> None

Read metadata from the KLayout Layout object.

ibbox

ibbox(layer: int | None = None) -> Box

icreate_inst

icreate_inst(
    cell: ProtoTKCell[Any] | int,
    trans: Trans | Vector | ICplxTrans | None = None,
    *,
    a: Vector | None = None,
    b: Vector | None = None,
    na: int = 1,
    nb: int = 1,
    libcell_as_static: bool = False,
    static_name_separator: str = "__"
) -> Instance

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 a

1
nb int

Number of elements in direction of b

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

insert(
    inst: Instance | CellInstArray | DCellInstArray,
) -> Instance
insert(
    inst: CellInstArray | DCellInstArray, property_id: int
) -> Instance
insert(
    inst: Instance | CellInstArray | DCellInstArray,
    property_id: int | None = None,
) -> Instance

Inserts a cell instance given by another reference.

insert_vinsts

insert_vinsts(recursive: bool = True) -> None

Insert all virtual instances and create Instances of real KCells.

l2n

l2n(
    port_types: Iterable[str] = ("optical",)
) -> LayoutToNetlist

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',)

layout

layout() -> Layout

library

library() -> Library

plot

plot(
    lyrdb: Path | str | None = None,
    display_type: Literal["image", "widget"] | None = None,
) -> 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

read(
    filename: str | Path,
    options: LoadLayoutOptions | None = None,
    register_cells: bool = False,
    test_merge: bool = True,
    update_kcl_meta_data: Literal[
        "overwrite", "skip", "drop"
    ] = "drop",
    meta_format: Literal["v1", "v2", "v3"] | None = None,
) -> list[int]

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 True create KCells for all cells in the GDS.

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. v1 had stored port transformations as strings, never versions have them stored and loaded in their native KLayout formats.

None

set_meta_data

set_meta_data() -> None

Set metadata of the Cell.

Currently, ports, settings and info will be set.

shapes

shapes(layer: int | LayerInfo) -> Shapes

show

show(
    lyrdb: ReportDatabase | Path | str | None = None,
    l2n: LayoutToNetlist | Path | str | None = None,
    keep_position: bool = True,
    save_options: SaveLayoutOptions | None = None,
    use_libraries: bool = True,
    library_save_options: SaveLayoutOptions | None = None,
) -> None

Stream the gds to klive.

Will create a temporary file of the gds and load it in KLayout via klive

to_dtype

to_dtype() -> DKCell

Convert the kcell to a um kcell.

to_itype

to_itype() -> KCell

Convert the kcell to a dbu kcell.

transform

transform(
    inst: Instance,
    trans: Trans | DTrans | ICplxTrans | DCplxTrans,
    /,
    *,
    transform_ports: bool = True,
) -> Instance
transform(
    trans: Trans | DTrans | ICplxTrans | DCplxTrans,
    /,
    *,
    transform_ports: bool = True,
) -> None
transform(
    inst_or_trans: (
        Instance | Trans | DTrans | ICplxTrans | DCplxTrans
    ),
    trans: (
        Trans | DTrans | ICplxTrans | DCplxTrans | None
    ) = None,
    /,
    *,
    transform_ports: bool = True,
) -> Instance | None

Transforms the instance or cell with the transformation given.

write

write(
    filename: str | Path,
    save_options: SaveLayoutOptions | None = None,
    convert_external_cells: bool = False,
    set_meta_data: bool = True,
    autoformat_from_file_extension: bool = True,
) -> None

Write a KCell to a GDS.

See KCLayout.write for more info.

LayerEnum

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

Methods:

Name Description
__getitem__

Retrieve layer number[0] / datatype[1] of a layer.

__init__

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__

Create a new Enum.

__str__

Return the name of the LayerEnum.

Attributes:

Name Type Description
datatype int
layer int
layout constant[Layout]
name str

datatype instance-attribute

datatype: int

layer instance-attribute

layer: int

layout instance-attribute

layout: constant[Layout]

name instance-attribute

name: str

__getitem__

__getitem__(key: int) -> int

Retrieve layer number[0] / datatype[1] of a layer.

__init__

__init__(layer: int, datatype: int) -> None

Just here to make sure klayout knows the layer name.

__iter__

__iter__() -> Iterator[int]

Allow for loops to iterate over the LayerEnum.

__len__

__len__() -> int

A layer has length 2, layer number and datatype.

__new__

__new__(layer: int, datatype: int) -> LayerEnum

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
kcl

Base Layout object to register the layer to.

required

__str__

__str__() -> str

Return the name of the LayerEnum.

KCLayout

Bases: BaseModel

Small extension to the klayout.db.Layout.

It adds tracking for the 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

Methods:

Name Description
__getattr__

If KCLayout doesn't have an attribute, look in the KLayout Cell.

__getitem__

Retrieve a cell by name(str) or index(int).

__init__

Create a new KCLayout (PDK). Can be based on an old KCLayout.

__repr__
__setattr__

Use a custom setter to automatically set attributes.

assign

Assign a new Layout object to the KCLayout object.

cell

Decorator to cache and auto name the cell.

clear

Clear the Layout.

clear_kcells

Clears all cells in the Layout object.

create_cell

Create a new cell in the library.

create_layer_enclosure

Create a new LayerEnclosure in the KCLayout.

delete_cell

Delete a cell in the kcl object.

delete_cell_rec

Deletes a KCell plus all subcells.

delete_cells

Delete a sequence of cell by indexes.

dkcell

Create a new cell based ont he pdk's layout object.

dup

Create a duplication of the ~KCLayout object.

find_layer

Try to find a registered layer. Throws a KeyError if it cannot find it.

get_cell

Retrieve a cell by name(str) or index(int).

get_component
get_dcross_section

Get a cross section by name or specification.

get_enclosure

Gets a layer enclosure by name specification or the layerenclosure itself.

get_icross_section

Get a cross section by name or specification.

get_meta_data

Read KCLayout meta info from the KLayout object.

get_symmetrical_cross_section

Get a cross section by name or specification.

kcell

Create a new cell based ont he pdk's layout object.

layerenum_from_dict

Create a new LayerEnum from this KCLayout.

layout_cell

Get a cell by name or index from the Layout object.

read

Read a GDS file into the existing Layout.

rebuild

Rebuild the KCLayout based on the Layout object.

register_cell

Register an existing cell in the KCLayout object.

set_layers_from_infos

Create a new LAYER enum based on the pdk's kcl.

set_meta_data

Set the info/settings of the KCLayout.

to_dbu

Convert Shapes or values in dbu to DShapes or floats in um.

to_um

Convert Shapes or values in dbu to DShapes or floats in um.

top_kcell

Return the top KCell if there is a single one.

top_kcells

Return the top KCells.

vcell

Decorator to cache and auto name the cell.

vkcell

Create a new cell based ont he pdk's layout object.

write

Write a GDS file into the existing Layout.

Attributes:

Name Type Description
constants Constants
cross_sections CrossSectionModel
dbu float

Get the database unit.

decorators Decorators
default_cell_output_type type[KCell | DKCell]
dkcells DKCells

DKCells is a mapping of int to DKCell.

enclosure KCellEnclosure
factories Factories[AnyTKCell]
future_cell_name str | None
info Info
infos LayerInfos
interconnect_cml_path Path | str | None
kcells KCells

KCells is a mapping of int to KCell.

layer_enclosures LayerEnclosureModel
layer_stack LayerStack
layers type[LayerEnum]
layout Layout
library Library
name str
netlist_layer_mapping dict[LayerEnum | int, LayerEnum | int]
rename_function Callable[..., None]
settings KCellSettings
sparameters_path Path | str | None
thread_lock RLock
tkcells dict[int, TKCell]
virtual_factories Factories[VKCell]

_registered_functions instance-attribute

_registered_functions: dict[int, Callable[..., TKCell]]

constants instance-attribute

constants: Constants

cross_sections instance-attribute

cross_sections: CrossSectionModel

dbu property

dbu: float

Get the database unit.

decorators instance-attribute

decorators: Decorators

default_cell_output_type class-attribute instance-attribute

default_cell_output_type: type[KCell | DKCell] = KCell

dkcells cached property

dkcells: DKCells

DKCells is a mapping of int to DKCell.

enclosure instance-attribute

enclosure: KCellEnclosure = enclosure

factories instance-attribute

factories: Factories[AnyTKCell]

future_cell_name instance-attribute

future_cell_name: str | None

info class-attribute instance-attribute

info: Info = Field(default_factory=Info)

infos instance-attribute

infos: LayerInfos

interconnect_cml_path instance-attribute

interconnect_cml_path: Path | str | None = (
    interconnect_cml_path
)

kcells cached property

kcells: KCells

KCells is a mapping of int to KCell.

layer_enclosures instance-attribute

layer_enclosures: LayerEnclosureModel

layer_stack instance-attribute

layer_stack: LayerStack

layers instance-attribute

layers: type[LayerEnum]

layout instance-attribute

layout: Layout

library instance-attribute

library: Library

name instance-attribute

name: str

netlist_layer_mapping class-attribute instance-attribute

netlist_layer_mapping: dict[
    LayerEnum | int, LayerEnum | int
] = Field(default_factory=dict)

rename_function instance-attribute

rename_function: Callable[..., None]

settings class-attribute instance-attribute

settings: KCellSettings = Field(frozen=True)

sparameters_path instance-attribute

sparameters_path: Path | str | None = sparameters_path

thread_lock class-attribute instance-attribute

thread_lock: RLock = Field(default_factory=RLock)

tkcells class-attribute instance-attribute

tkcells: dict[int, TKCell] = Field(default_factory=dict)

virtual_factories instance-attribute

virtual_factories: Factories[VKCell]

__getattr__

__getattr__(name: str) -> Any

If KCLayout doesn't have an attribute, look in the KLayout Cell.

__getitem__

__getitem__(obj: str | int) -> KCell

Retrieve a cell by name(str) or index(int).

Attrs

obj: name of cell or cell_index

__init__

__init__(
    name: str,
    layer_enclosures: (
        dict[str, LayerEnclosure]
        | LayerEnclosureModel
        | None
    ) = None,
    enclosure: KCellEnclosure | None = None,
    infos: type[LayerInfos] | None = None,
    sparameters_path: Path | str | None = None,
    interconnect_cml_path: Path | str | None = None,
    layer_stack: LayerStack | None = None,
    constants: type[Constants] | None = None,
    base_kcl: KCLayout | None = None,
    port_rename_function: Callable[
        ..., None
    ] = rename_clockwise_multi,
    copy_base_kcl_layers: bool = True,
    info: dict[str, MetaData] | None = None,
    default_cell_output_type: type[KCell | DKCell] = KCell,
) -> 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

__repr__

__repr__() -> str

__setattr__

__setattr__(name: str, value: Any) -> None

Use a custom setter to automatically set attributes.

If the attribute is not in this object, set it on the Layout object.

_cells

_cells(name: str) -> list[Cell]
_cells() -> int
_cells(name: str | None = None) -> int | list[Cell]

_validate_layers classmethod

_validate_layers(data: dict[str, Any]) -> dict[str, Any]

assign

assign(layout: Layout) -> None

Assign a new Layout object to the KCLayout object.

cell

cell(
    _func: KCellFunc[KCellParams, K],
) -> KCellFunc[KCellParams, K]
cell(
    *,
    set_settings: bool = ...,
    set_name: bool = ...,
    check_ports: 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[[K], None]] = ...,
    debug_names: bool | None = ...,
    tags: list[str] | None = ...
) -> Callable[
    [KCellFunc[KCellParams, K]], KCellFunc[KCellParams, K]
]
cell(
    *,
    output_type: type[K],
    set_settings: bool = ...,
    set_name: bool = ...,
    check_ports: 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[[K], None]] = ...,
    debug_names: bool | None = ...,
    tags: list[str] | None = ...
) -> Callable[
    [KCellFunc[KCellParams, AnyTKCell]],
    KCellFunc[KCellParams, K],
]
cell(
    _func: KCellFunc[KCellParams, K] | None = None,
    /,
    *,
    output_type: type[K] | None = None,
    set_settings: bool = True,
    set_name: bool = True,
    check_ports: bool = True,
    check_instances: CheckInstances | None = None,
    snap_ports: 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,
    overwrite_existing: bool | None = None,
    layout_cache: bool | None = None,
    info: dict[str, MetaData] | None = None,
    post_process: Iterable[Callable[[K], None]] = tuple(),
    debug_names: bool | None = None,
    tags: list[str] | None = None,
) -> (
    KCellFunc[KCellParams, K]
    | Callable[
        [KCellFunc[KCellParams, K]],
        KCellFunc[KCellParams, K],
    ]
    | Callable[
        [KCellFunc[KCellParams, AnyTKCell]],
        KCellFunc[KCellParams, K],
    ]
)

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.

Parameters:

Name Type Description Default
output_type type[K] | 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_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 netlist_layer_mapping to the ports if the port layer is in the mapping.

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 factories

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 set_name is true. Can be globally configured through config.cell_layout_cache.

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 config.cell_overwrite_existing.

None
info dict[str, MetaData] | None

Additional metadata to put into info attribute.

None
post_process Iterable[Callable[[K], None]]

List of functions to call after the cell has been created.

tuple()
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. With this, cell functions can then be retrieved with kcl.factories.tags[my_tag] or if filtered for multiple kcl.factories.for_tags([my_tag1, my_tag2, ...]).

None

clear

clear(keep_layers: bool = True) -> None

Clear the Layout.

If the layout is cleared, all the LayerEnums and

clear_kcells

clear_kcells() -> None

Clears all cells in the Layout object.

create_cell

create_cell(
    name: str, *args: str, allow_duplicate: bool = False
) -> Cell

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 name + $1 or 2..n increasing by the number of existing duplicates

False
args str

additional arguments passed to klayout.db.Layout.create_cell

()

Returns:

Type Description
Cell

klayout.db.Cell: klayout.db.Cell object created in the Layout

create_layer_enclosure

create_layer_enclosure(
    sections: Sequence[
        tuple[LayerInfo, int] | tuple[LayerInfo, int, int]
    ] = [],
    name: str | None = None,
    main_layer: LayerInfo | None = None,
    dsections: (
        Sequence[
            tuple[LayerInfo, float]
            | tuple[LayerInfo, float, float]
        ]
        | None
    ) = None,
) -> LayerEnclosure

Create a new LayerEnclosure in the KCLayout.

delete_cell

delete_cell(cell: AnyTKCell | int) -> None

Delete a cell in the kcl object.

delete_cell_rec

delete_cell_rec(cell_index: int) -> None

Deletes a KCell plus all subcells.

delete_cells

delete_cells(cell_index_list: Sequence[int]) -> None

Delete a sequence of cell by indexes.

dkcell

dkcell(
    name: str | None = None, ports: DPorts | None = None
) -> DKCell

Create a new cell based ont he pdk's layout object.

dup

dup(init_cells: bool = True) -> KCLayout

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

find_layer(name: str) -> LayerEnum
find_layer(info: LayerInfo) -> LayerEnum
find_layer(layer: int, datatype: int) -> LayerEnum
find_layer(
    layer: int, dataytpe: int, name: str
) -> LayerEnum
find_layer(
    name: str,
    *,
    allow_undefined_layers: Literal[True] = True
) -> LayerEnum | int
find_layer(
    info: LayerInfo,
    *,
    allow_undefined_layers: Literal[True] = True
) -> LayerEnum | int
find_layer(
    layer: int,
    datatype: int,
    *,
    allow_undefined_layers: Literal[True] = True
) -> LayerEnum | int
find_layer(
    layer: int,
    dataytpe: int,
    name: str,
    allow_undefined_layers: Literal[True] = True,
) -> LayerEnum | int
find_layer(
    *args: int | str | LayerInfo,
    **kwargs: int | str | LayerInfo | bool
) -> 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

get_cell(obj: str | int, cell_type: type[K] = KCell) -> K

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_component

get_component(
    spec: KCellSpec,
    *,
    output_type: type[K],
    **cell_kwargs: Any
) -> K
get_component(spec: int) -> KCell
get_component(
    spec: str, **cell_kwargs: Any
) -> ProtoTKCell[Any]
get_component(
    spec: Callable[..., K], **cell_kwargs: Any
) -> K
get_component(spec: K) -> K
get_component(
    spec: KCellSpec,
    *,
    output_type: type[K] | None = None,
    **cell_kwargs: Any
) -> ProtoTKCell[Any]

get_dcross_section

get_dcross_section(
    cross_section: (
        str
        | SymmetricalCrossSection
        | CrossSectionSpec[float]
        | DSymmetricalCrossSection
    ),
) -> DCrossSection

Get a cross section by name or specification.

get_enclosure

get_enclosure(
    enclosure: str | LayerEnclosure | LayerEnclosureSpec,
) -> LayerEnclosure

Gets a layer enclosure by name specification or the layerenclosure itself.

get_icross_section

get_icross_section(
    cross_section: (
        str
        | SymmetricalCrossSection
        | CrossSectionSpec[int]
        | DSymmetricalCrossSection
    ),
) -> CrossSection

Get a cross section by name or specification.

get_meta_data

get_meta_data() -> tuple[dict[str, Any], dict[str, Any]]

Read KCLayout meta info from the KLayout object.

get_symmetrical_cross_section

get_symmetrical_cross_section(
    cross_section: (
        str
        | SymmetricalCrossSection
        | CrossSectionSpec[int]
        | DSymmetricalCrossSection
    ),
) -> SymmetricalCrossSection

Get a cross section by name or specification.

kcell

kcell(
    name: str | None = None, ports: Ports | None = None
) -> KCell

Create a new cell based ont he pdk's layout object.

layerenum_from_dict

layerenum_from_dict(
    name: str = "LAYER", *, layers: LayerInfos
) -> type[LayerEnum]

Create a new LayerEnum from this KCLayout.

layout_cell

layout_cell(name: str | int) -> Cell | None

Get a cell by name or index from the Layout object.

read

read(
    filename: str | Path,
    options: LoadLayoutOptions | None = None,
    register_cells: bool | None = None,
    test_merge: bool = True,
    update_kcl_meta_data: Literal[
        "overwrite", "skip", "drop"
    ] = "skip",
    meta_format: Literal["v1", "v2", "v3"] | None = None,
) -> LayerMap

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 True create KCells for all cells in the GDS.

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. v1 had stored port transformations as strings, never versions have them stored and loaded in their native KLayout formats.

None

rebuild

rebuild() -> None

Rebuild the KCLayout based on the Layout object.

register_cell

register_cell(
    kcell: AnyTKCell, allow_reregister: bool = False
) -> None

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

set_layers_from_infos(
    name: str, layers: LayerInfos
) -> type[LayerEnum]

Create a new LAYER enum based on the pdk's kcl.

set_meta_data

set_meta_data() -> None

Set the info/settings of the KCLayout.

to_dbu

to_dbu(other: None) -> None
to_dbu(other: float) -> int
to_dbu(other: DPoint) -> Point
to_dbu(other: DVector) -> Vector
to_dbu(other: DBox) -> Box
to_dbu(other: DPolygon) -> Polygon
to_dbu(other: DPath) -> Path
to_dbu(other: DText) -> Text
to_dbu(
    other: (
        float
        | DPoint
        | DVector
        | DBox
        | DPolygon
        | DPath
        | DText
        | None
    ),
) -> (
    int
    | Point
    | Vector
    | Box
    | Polygon
    | Path
    | Text
    | None
)

Convert Shapes or values in dbu to DShapes or floats in um.

to_um

to_um(other: None) -> None
to_um(other: int) -> float
to_um(other: Point) -> DPoint
to_um(other: Vector) -> DVector
to_um(other: Box) -> DBox
to_um(other: Polygon) -> DPolygon
to_um(other: Path) -> DPath
to_um(other: Text) -> DText
to_um(
    other: (
        int
        | Point
        | Vector
        | Box
        | Polygon
        | Path
        | Text
        | None
    ),
) -> (
    float
    | DPoint
    | DVector
    | DBox
    | DPolygon
    | DPath
    | DText
    | None
)

Convert Shapes or values in dbu to DShapes or floats in um.

top_kcell

top_kcell() -> KCell

Return the top KCell if there is a single one.

top_kcells

top_kcells() -> list[KCell]

Return the top KCells.

vcell

vcell(
    _func: Callable[KCellParams, VKCell],
) -> Callable[KCellParams, VKCell]
vcell(
    *,
    set_settings: bool = True,
    set_name: bool = True,
    check_ports: bool = True,
    basename: str | None = None,
    drop_params: Sequence[str] = ("self", "cls"),
    register_factory: bool = True
) -> Callable[
    [Callable[KCellParams, VKCell]],
    Callable[KCellParams, VKCell],
]
vcell(
    _func: Callable[KCellParams, VKCell] | None = None,
    /,
    *,
    set_settings: bool = True,
    set_name: bool = True,
    check_ports: 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,
) -> (
    Callable[KCellParams, VKCell]
    | Callable[
        [Callable[KCellParams, VKCell]],
        Callable[KCellParams, VKCell],
    ]
)

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.

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 whether there are any non-90° ports in the cell and throw a warning if there are

True
snap_ports

Snap the centers of the ports onto the grid (only x/y, not angle).

required
add_port_layers bool

Add special layers of netlist_layer_mapping to the ports if the port layer is in the mapping.

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
rec_dicts

Allow and inspect recursive dictionaries as parameters (can be expensive if the cell is called often).

required
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 factories

True

vkcell

vkcell(name: str | None = None) -> VKCell

Create a new cell based ont he pdk's layout object.

write

write(
    filename: str | Path,
    options: SaveLayoutOptions | None = None,
    set_meta_data: bool = True,
    convert_external_cells: bool = False,
    autoformat_from_file_extension: bool = True,
) -> None

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 filename. This is necessary for the options. If not set, this will default to GDSII.

True

DPort

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 DCplxTrans

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.

Methods:

Name Description
__init__

Create a port from dbu or um based units.

copy

Get a copy of a port.

copy_polar

Get a polar copy of the port.

Attributes:

Name Type Description
center
cross_section DCrossSection
mirror_x
orientation
width float

Width of the port in um.

x float

X coordinate of the port in um.

y float

Y coordinate of the port in um.

_base instance-attribute

_base = base

center instance-attribute

center = center

cross_section property writable

cross_section: DCrossSection

mirror_x instance-attribute

mirror_x = mirror_x

orientation instance-attribute

orientation = orientation

width property

width: float

Width of the port in um.

x property writable

x: float

X coordinate of the port in um.

y property writable

y: float

Y coordinate of the port in um.

__init__

__init__(
    name: str | None = None,
    *,
    width: float,
    layer: LayerEnum | int,
    trans: 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: 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: LayerInfo,
    trans: 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: LayerInfo,
    dcplx_trans: 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: 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: Trans | str,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] = ...,
    port_type: str = "optical"
) -> None
__init__(
    name: str | None = None,
    *,
    cross_section: DCrossSection | SymmetricalCrossSection,
    dcplx_trans: DCplxTrans | str,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] = ...,
    port_type: str = "optical"
) -> None
__init__(*, base: BasePort) -> None
__init__(*, port: ProtoPort[Any]) -> None
__init__(
    name: str | None = None,
    *,
    width: float | None = None,
    layer: int | None = None,
    layer_info: LayerInfo | None = None,
    port_type: str = "optical",
    trans: Trans | str | None = None,
    dcplx_trans: DCplxTrans | str | None = None,
    orientation: float = 0,
    center: tuple[float, float] = (0, 0),
    mirror_x: bool = False,
    port: ProtoPort[Any] | None = None,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] | None = None,
    cross_section: (
        DCrossSection | SymmetricalCrossSection | None
    ) = None,
    base: BasePort | None = None
) -> None

Create a port from dbu or um based units.

copy

copy(
    trans: Trans | DCplxTrans = R0,
    post_trans: Trans | DCplxTrans = R0,
) -> DPort

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

copy_polar(
    d: float = 0,
    d_orth: float = 0,
    orientation: float = 180,
    mirror: bool = False,
) -> DPort

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

Port

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.

Methods:

Name Description
__init__

Create a port from dbu or um based units.

copy

Get a copy of a port.

copy_polar

Get a polar copy of the port.

Attributes:

Name Type Description
cross_section CrossSection
dcplx_trans
width int

Width of the port in um.

x int

X coordinate of the port in dbu.

y int

Y coordinate of the port in dbu.

_base instance-attribute

_base = base

cross_section property writable

cross_section: CrossSection

dcplx_trans instance-attribute

dcplx_trans = dcplx_trans_

width property

width: int

Width of the port in um.

x property writable

x: int

X coordinate of the port in dbu.

y property writable

y: int

Y coordinate of the port in dbu.

__init__

__init__(
    *,
    name: str | None = None,
    width: int,
    layer: LayerEnum | int,
    trans: 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: 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: LayerInfo,
    trans: 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: LayerInfo,
    dcplx_trans: 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: 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: Trans | str,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] = ...,
    port_type: str = "optical"
) -> None
__init__(
    name: str | None = None,
    *,
    cross_section: CrossSection | SymmetricalCrossSection,
    dcplx_trans: DCplxTrans | str,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] = ...,
    port_type: str = "optical"
) -> None
__init__(*, base: BasePort) -> None
__init__(*, port: ProtoPort[Any]) -> None
__init__(
    name: str | None = None,
    *,
    width: int | None = None,
    layer: int | None = None,
    layer_info: LayerInfo | None = None,
    port_type: str = "optical",
    trans: Trans | str | None = None,
    dcplx_trans: DCplxTrans | str | None = None,
    angle: int | None = None,
    center: tuple[int, int] | None = None,
    mirror_x: bool = False,
    port: ProtoPort[Any] | None = None,
    kcl: KCLayout | None = None,
    info: dict[str, int | float | str] | None = None,
    cross_section: (
        CrossSection | SymmetricalCrossSection | None
    ) = None,
    base: BasePort | None = None
) -> None

Create a port from dbu or um based units.

copy

copy(
    trans: Trans | DCplxTrans = R0,
    post_trans: Trans | DCplxTrans = R0,
) -> Port

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

copy_polar(
    d: int = 0,
    d_orth: int = 0,
    angle: int = 2,
    mirror: bool = False,
) -> Port

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

KCellSpec module-attribute

KCellSpec: TypeAlias = (
    "int | str | KCellSpecDict | ProtoTKCell[Any] | Callable[..., ProtoTKCell[Any]]"
)