Skip to content

Pin

pin

DPin

Bases: ProtoPin[float]

Source code in kfactory/pin.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
class DPin(ProtoPin[float]):
    def __getitem__(self, key: int | str | None) -> DPort:
        if isinstance(key, int):
            return DPort(base=list(self._base.ports)[key])
        try:
            return DPort(
                base=next(
                    filter(lambda port_base: port_base.name == key, self._base.ports)
                )
            )
        except StopIteration as e:
            raise KeyError(
                f"{key=} is not a valid port name or index within the pin. "
                f"Available ports: {[v.name for v in self.ports]}"
            ) from e

    def copy(
        self,
        trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
        post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    ) -> DPin:
        """Get a copy of a pin.

        Transformation order which results in `copy.trans`:
            - Trans: `trans * pin.trans * post_trans`
            - DCplxTrans: `trans * pin.dcplx_trans * post_trans`

        Args:
            trans: an optional transformation applied to the pin to be copied.
            post_trans: transformation to apply to the pin after copying.

        Returns:
            pin: a copy of the pin
        """
        return DPin(base=self._base.transformed(trans=trans, post_trans=post_trans))

    @property
    def ports(self) -> list[DPort]:
        return [DPort(base=pb) for pb in self._base.ports]

    @ports.setter
    def ports(self, value: Iterable[ProtoPort[Any]]) -> None:
        self._base.ports = [p.base for p in value]

__getitem__

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

Get a port in the pin by index or name.

Source code in kfactory/pin.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def __getitem__(self, key: int | str | None) -> DPort:
    if isinstance(key, int):
        return DPort(base=list(self._base.ports)[key])
    try:
        return DPort(
            base=next(
                filter(lambda port_base: port_base.name == key, self._base.ports)
            )
        )
    except StopIteration as e:
        raise KeyError(
            f"{key=} is not a valid port name or index within the pin. "
            f"Available ports: {[v.name for v in self.ports]}"
        ) from e

copy

copy(
    trans: Trans | DCplxTrans = kdb.Trans.R0,
    post_trans: Trans | DCplxTrans = kdb.Trans.R0,
) -> DPin

Get a copy of a pin.

Transformation order which results in copy.trans: - Trans: trans * pin.trans * post_trans - DCplxTrans: trans * pin.dcplx_trans * post_trans

Parameters:

Name Type Description Default
trans Trans | DCplxTrans

an optional transformation applied to the pin to be copied.

R0
post_trans Trans | DCplxTrans

transformation to apply to the pin after copying.

R0

Returns:

Name Type Description
pin DPin

a copy of the pin

Source code in kfactory/pin.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def copy(
    self,
    trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
) -> DPin:
    """Get a copy of a pin.

    Transformation order which results in `copy.trans`:
        - Trans: `trans * pin.trans * post_trans`
        - DCplxTrans: `trans * pin.dcplx_trans * post_trans`

    Args:
        trans: an optional transformation applied to the pin to be copied.
        post_trans: transformation to apply to the pin after copying.

    Returns:
        pin: a copy of the pin
    """
    return DPin(base=self._base.transformed(trans=trans, post_trans=post_trans))

Pin

Bases: ProtoPin[int]

Source code in kfactory/pin.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
class Pin(ProtoPin[int]):
    def __getitem__(self, key: int | str | None) -> Port:
        if isinstance(key, int):
            return Port(base=list(self._base.ports)[key])
        try:
            return Port(
                base=next(
                    filter(lambda port_base: port_base.name == key, self._base.ports)
                )
            )
        except StopIteration as e:
            raise KeyError(
                f"{key=} is not a valid port name or index within the pin. "
                f"Available ports: {[v.name for v in self.ports]}"
            ) from e

    @property
    def ports(self) -> list[Port]:
        return [Port(base=pb) for pb in self._base.ports]

    @ports.setter
    def ports(self, value: Iterable[ProtoPort[Any]]) -> None:
        self._base.ports = [p.base for p in value]

    def copy(
        self,
        trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
        post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    ) -> Pin:
        """Get a copy of a pin.

        Transformation order which results in `copy.trans`:
            - Trans: `trans * pin.trans * post_trans`
            - DCplxTrans: `trans * pin.dcplx_trans * post_trans`

        Args:
            trans: an optional transformation applied to the pin to be copied.
            post_trans: transformation to apply to the pin after copying.

        Returns:
            pin: a copy of the pin
        """
        return Pin(base=self._base.transformed(trans=trans, post_trans=post_trans))

__getitem__

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

Get a port in the pin by index or name.

Source code in kfactory/pin.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def __getitem__(self, key: int | str | None) -> Port:
    if isinstance(key, int):
        return Port(base=list(self._base.ports)[key])
    try:
        return Port(
            base=next(
                filter(lambda port_base: port_base.name == key, self._base.ports)
            )
        )
    except StopIteration as e:
        raise KeyError(
            f"{key=} is not a valid port name or index within the pin. "
            f"Available ports: {[v.name for v in self.ports]}"
        ) from e

copy

copy(
    trans: Trans | DCplxTrans = kdb.Trans.R0,
    post_trans: Trans | DCplxTrans = kdb.Trans.R0,
) -> Pin

Get a copy of a pin.

Transformation order which results in copy.trans: - Trans: trans * pin.trans * post_trans - DCplxTrans: trans * pin.dcplx_trans * post_trans

Parameters:

Name Type Description Default
trans Trans | DCplxTrans

an optional transformation applied to the pin to be copied.

R0
post_trans Trans | DCplxTrans

transformation to apply to the pin after copying.

R0

Returns:

Name Type Description
pin Pin

a copy of the pin

Source code in kfactory/pin.py
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def copy(
    self,
    trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
) -> Pin:
    """Get a copy of a pin.

    Transformation order which results in `copy.trans`:
        - Trans: `trans * pin.trans * post_trans`
        - DCplxTrans: `trans * pin.dcplx_trans * post_trans`

    Args:
        trans: an optional transformation applied to the pin to be copied.
        post_trans: transformation to apply to the pin after copying.

    Returns:
        pin: a copy of the pin
    """
    return Pin(base=self._base.transformed(trans=trans, post_trans=post_trans))

ProtoPin

Bases: ABC

Base class for kf.Pin, kf.DPin.

Source code in kfactory/pin.py
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
class ProtoPin[T: (int, float)](ABC):
    """Base class for kf.Pin, kf.DPin."""

    yaml_tag: str = "!Pin"
    _base: BasePin

    def __init__(self, *, base: BasePin) -> None:
        self._base = base

    @property
    def base(self) -> BasePin:
        """Get the BasePin associated with this Pin."""
        return self._base

    @property
    def name(self) -> str | None:
        """Name of the pin."""
        return self._base.name

    @name.setter
    def name(self, value: str) -> None:
        self._base.name = value

    @property
    def kcl(self) -> KCLayout:
        """KCLayout associated to the pin."""
        return self._base.kcl

    @kcl.setter
    def kcl(self, value: KCLayout) -> None:
        self._base.kcl = value

    @property
    def pin_type(self) -> str:
        """Type of the pin."""
        return self._base.pin_type

    @pin_type.setter
    def pin_type(self, value: str) -> None:
        self._base.pin_type = value

    @property
    def info(self) -> Info:
        """Additional info about the pin."""
        return self._base.info

    @info.setter
    def info(self, value: Info) -> None:
        self._base.info = value

    @property
    @abstractmethod
    def ports(self) -> list[Any]: ...  # because mypy... should be list[ProtoPort[Any]]

    @ports.setter
    @abstractmethod
    def ports(self, value: Iterable[ProtoPort[T]]) -> None: ...

    def to_itype(self) -> Pin:
        """Convert the pin to a dbu pin."""
        return Pin(base=self._base)

    def to_dtype(self) -> DPin:
        """Convert the pin to a um pin."""
        return DPin(base=self._base)

    def __repr__(self) -> str:
        """String representation of pin."""
        return (
            f"{self.__class__.__name__}({self.name},"
            f"ports={self.ports}, pin_type={self.pin_type})"
        )

    @abstractmethod
    def __getitem__(self, key: int | str | None) -> ProtoPort[T]:
        """Get a port in the pin by index or name."""
        ...

    @abstractmethod
    def copy(
        self,
        trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
        post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    ) -> ProtoPin[T]:
        """Copy the port with a transformation."""
        ...

base property

base: BasePin

Get the BasePin associated with this Pin.

info property writable

info: Info

Additional info about the pin.

kcl property writable

kcl: KCLayout

KCLayout associated to the pin.

name property writable

name: str | None

Name of the pin.

pin_type property writable

pin_type: str

Type of the pin.

__getitem__ abstractmethod

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

Get a port in the pin by index or name.

Source code in kfactory/pin.py
127
128
129
130
@abstractmethod
def __getitem__(self, key: int | str | None) -> ProtoPort[T]:
    """Get a port in the pin by index or name."""
    ...

__repr__

__repr__() -> str

String representation of pin.

Source code in kfactory/pin.py
120
121
122
123
124
125
def __repr__(self) -> str:
    """String representation of pin."""
    return (
        f"{self.__class__.__name__}({self.name},"
        f"ports={self.ports}, pin_type={self.pin_type})"
    )

copy abstractmethod

copy(
    trans: Trans | DCplxTrans = kdb.Trans.R0,
    post_trans: Trans | DCplxTrans = kdb.Trans.R0,
) -> ProtoPin[T]

Copy the port with a transformation.

Source code in kfactory/pin.py
132
133
134
135
136
137
138
139
@abstractmethod
def copy(
    self,
    trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
    post_trans: kdb.Trans | kdb.DCplxTrans = kdb.Trans.R0,
) -> ProtoPin[T]:
    """Copy the port with a transformation."""
    ...

to_dtype

to_dtype() -> DPin

Convert the pin to a um pin.

Source code in kfactory/pin.py
116
117
118
def to_dtype(self) -> DPin:
    """Convert the pin to a um pin."""
    return DPin(base=self._base)

to_itype

to_itype() -> Pin

Convert the pin to a dbu pin.

Source code in kfactory/pin.py
112
113
114
def to_itype(self) -> Pin:
    """Convert the pin to a dbu pin."""
    return Pin(base=self._base)

filter_regex

filter_regex(
    pins: Iterable[TPin], regex: str
) -> filter[TPin]

Filter iterable/sequence of pins by port name.

Source code in kfactory/pin.py
245
246
247
248
249
250
251
252
253
254
def filter_regex(pins: Iterable[TPin], regex: str) -> filter[TPin]:
    """Filter iterable/sequence of pins by port name."""
    pattern = re.compile(regex)

    def regex_filter(p: TPin) -> bool:
        if p.name is not None:
            return bool(pattern.match(p.name))
        return False

    return filter(regex_filter, pins)

filter_type

filter_type(
    pins: Iterable[TPin], pin_type: str
) -> filter[TPin]

Filter iterable/sequence of pins by port_type.

Source code in kfactory/pin.py
257
258
259
260
261
262
263
def filter_type(pins: Iterable[TPin], pin_type: str) -> filter[TPin]:
    """Filter iterable/sequence of pins by port_type."""

    def pt_filter(p: TPin) -> bool:
        return p.pin_type == pin_type

    return filter(pt_filter, pins)