Utilities
utilities
check_cell_ports
check_cell_ports(
p1: ProtoPort[Any], p2: ProtoPort[Any]
) -> int
Check if two ports are the same.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A bitwise representation of the differences between the two ports. |
Source code in kfactory/utilities.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
check_inst_ports
check_inst_ports(p1: Port, p2: Port) -> int
Check if two ports are the same.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A bitwise representation of the differences between the two ports. |
Source code in kfactory/utilities.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
dpolygon_from_array
dpolygon_from_array(
array: Iterable[tuple[float, float]],
) -> kdb.DPolygon
Create a DPolygon from a 2D array-like structure. (um version).
Array-like: [[x1,y1],[x2,y2],...]
Source code in kfactory/utilities.py
75 76 77 78 79 80 | |
ensure_build_directory
ensure_build_directory(
subdirectory: str = "mask",
create_gitignore: bool = True,
) -> Path | None
Ensure build directory exists with proper gitignore.
This function consolidates all build directory creation logic, including git repository detection and .gitignore creation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdirectory
|
str
|
Subdirectory under build/ (e.g., 'mask', 'session/kcls'). |
'mask'
|
create_gitignore
|
bool
|
Whether to create .gitignore in build directory. |
True
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to the build subdirectory or None if not in a git repo. |
Source code in kfactory/utilities.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
get_build_path
get_build_path(
filename: str,
subdirectory: str = "mask",
file_format: str = "gds",
) -> tuple[Path, bool]
Get the appropriate build path for a file.
Determines whether to use a git-tracked build directory or temp directory, and creates necessary directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Base filename (without extension). |
required |
subdirectory
|
str
|
Subdirectory under build/ (e.g., 'mask', 'gds', 'oas'). |
'mask'
|
file_format
|
str
|
File extension/format (e.g., 'gds', 'oas', 'lyrdb'). |
'gds'
|
Returns:
| Type | Description |
|---|---|
Path
|
Tuple of (file_path, should_delete): |
bool
|
|
tuple[Path, bool]
|
|
Source code in kfactory/utilities.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
get_session_directory
get_session_directory(
custom_dir: Path | None = None,
) -> Path
Get or create session cache directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_dir
|
Path | None
|
Optional custom directory override. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to session/kcls directory. |
Source code in kfactory/utilities.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
instance_port_name
instance_port_name(
inst: Instance, port: ProtoPort[Any]
) -> str
Create a name for an instance port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inst
|
Instance
|
The instance. |
required |
port
|
ProtoPort[Any]
|
The port. |
required |
Source code in kfactory/utilities.py
119 120 121 122 123 124 125 126 | |
load_layout_options
load_layout_options(
**attributes: Any,
) -> kdb.LoadLayoutOptions
Default options for loading GDS/OAS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
Any
|
Set attributes of the layout load option object. E.g. to set the
handling of cell name conflicts pass
|
{}
|
Source code in kfactory/utilities.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
polygon_from_array
polygon_from_array(
array: Iterable[tuple[int, int]],
) -> kdb.Polygon
Create a DPolygon from a 2D array-like structure. (dbu version).
Array-like: [[x1,y1],[x2,y2],...]
Source code in kfactory/utilities.py
67 68 69 70 71 72 | |
pprint_pins
pprint_pins(
pins: Iterable[Pin] | Iterable[DPin],
unit: Literal["dbu", "um"] | None = None,
) -> Table
Print ports as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pins
|
Iterable[Pin] | Iterable[DPin]
|
The pins which should be printed. |
required |
unit
|
Literal['dbu', 'um'] | None
|
Define the print type of the ports. If None, any port which can be represented accurately by a dbu representation will be printed in dbu otherwise in um. 'dbu'/'um' will force the printing to enforce one or the other representation |
None
|
Source code in kfactory/utilities.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
pprint_ports
pprint_ports(
ports: Iterable[ProtoPort[Any]],
unit: Literal["dbu", "um"] | None = None,
) -> Table
Print ports as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
Iterable[ProtoPort[Any]]
|
The ports which should be printed. |
required |
unit
|
Literal['dbu', 'um'] | None
|
Define the print type of the ports. If None, any port which can be represented accurately by a dbu representation will be printed in dbu otherwise in um. 'dbu'/'um' will force the printing to enforce one or the other representation |
None
|
Source code in kfactory/utilities.py
129 130 131 132 133 134 135 136 137 138 139 140 141 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 185 186 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 | |
save_layout_options
save_layout_options(
**attributes: Any,
) -> kdb.SaveLayoutOptions
Default options for saving GDS/OAS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attributes
|
Any
|
Set attributes of the layout save option object. E.g. to save the
gds without metadata pass |
{}
|
Source code in kfactory/utilities.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
update_default_trans
update_default_trans(
new_trans: dict[
str,
str | int | float | dict[str, str | int | float],
],
) -> None
Allows to change the default transformation for reading a yaml file.
Source code in kfactory/utilities.py
60 61 62 63 64 | |