netlist ¤
circulax netlists.
Supports both kfnetlist.Netlist (primary) and SAX-format dicts (backward compat). SAX dicts are converted to kfnetlist.Netlist via :func:sax_to_kfnetlist before node-index assignment.
Functions:
| Name | Description |
|---|---|
build_net_map | Maps every port (e.g. 'R1,p1') to a generic Node Index (integer). |
build_net_map_kfnetlist | Map every port in a kfnetlist.Netlist to a node index. |
draw_circuit_graph | Visualize a circuit netlist as a connectivity graph. |
flatten_recursive_netlist | Flatten a |
prune_unreachable_instances | Drop instances that cannot influence the circuit's exposed ports. |
sax_to_kfnetlist | Convert a SAX-format netlist dict to a |
Attributes:
| Name | Type | Description |
|---|---|---|
circulaxNetlist | Legacy SAX-format netlist type. Prefer |
circulaxNetlist module-attribute ¤
circulaxNetlist = Annotated[
TypedDict(
"Netlist",
{
"instances": Instances,
"connections": NotRequired[Connections],
"ports": Ports,
"placements": NotRequired[Placements],
"settings": NotRequired[Settings],
},
),
bval(val_netlist),
]
Legacy SAX-format netlist type. Prefer kfnetlist.Netlist for new code.
build_net_map ¤
Maps every port (e.g. 'R1,p1') to a generic Node Index (integer).
Returns:
| Name | Type | Description |
|---|---|---|
port_to_idx | dict[str, int] | dict mapping 'Instance,Pin' -> int index |
num_nets | int | Total number of unique electrical nodes (excluding Ground). |
Source code in circulax/netlist.py
build_net_map_kfnetlist ¤
Map every port in a kfnetlist.Netlist to a node index.
Each Net in the netlist becomes one electrical node. Nets containing a ground instance port, or a synthetic net label containing "GND", are assigned node index 0.
Returns:
| Name | Type | Description |
|---|---|---|
port_to_idx | dict[str, int] |
|
num_nets | int | next free node index (== number of non-ground nets + 1). |
Source code in circulax/netlist.py
draw_circuit_graph ¤
draw_circuit_graph(
netlist: dict[str, dict] | Netlist, layout_attempts: int = 10, *, show: bool = True
) -> Figure
Visualize a circuit netlist as a connectivity graph.
Accepts either a SAX-format dict or a kfnetlist.Netlist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
netlist | dict[str, dict] | Netlist | Circuit description (SAX dict or kfnetlist.Netlist). | required |
show | bool | If | True |
layout_attempts | int | Number of spring-layout seeds to try. | 10 |
Returns:
| Name | Type | Description |
|---|---|---|
The | Figure | class: |
Source code in circulax/netlist.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |
flatten_recursive_netlist ¤
Flatten a RecursiveNetlist into a single SAX-format netlist.
A RecursiveNetlist is a dict[str, Netlist] where the first key is the top-level circuit and remaining keys define subcircuits. An instance whose component string matches a key in the dict is treated as a subcircuit and inlined with prefixed instance names.
Handles circulax connection extensions (tuple targets, nets lists) that SAX's own flatten_netlist does not support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recnet | dict[str, dict] | Mapping from circuit name to SAX-format netlist dict. | required |
sep | str | Separator for hierarchical instance names (default | '~' |
Returns:
| Type | Description |
|---|---|
dict | A flat SAX-format netlist dict. |
Source code in circulax/netlist.py
prune_unreachable_instances ¤
Drop instances that cannot influence the circuit's exposed ports.
An instance only matters to the simulation if some signal path connects it (directly or transitively, through shared nets) to one of its circuit's top-level ports. Structural/decorative cells (die frames, logos, marker rectangles) are typically wired to nothing — "ports": [] and no nets — so they take part in no signal path. Left in place, such a cell can abort compilation (or, upstream, an unmodeled-component walk that treats "no model" as "must be a composite to expand") with a spurious "Model not found" error for a component nobody asked to simulate. See gdsfactory/circulax#60.
Accepts a kfnl.Netlist, a flat SAX-format dict, or a RecursiveNetlist (dict of SAX dicts, i.e. subcircuit bodies keyed by name). For a flat netlist (kfnetlist or dict), the whole prune is skipped if it declares no top-level ports at all — with none, every instance would look unreachable, and a netlist driven purely by an internal source (e.g. a lone oscillator with no ports declared) would be emptied out.
For a RecursiveNetlist, that same guard applies only to the top circuit (the first key); once it passes, every sub-netlist — top included — is pruned against its own declared ports with no further guard, so a sub-netlist with no ports of its own is emptied out entirely. This matches sax.netlists.remove_unused_instances, and the already-shipped downstream fix in gdsfactoryplus#4883 relies on exactly this recursive emptying for nested inert cells.
Reimplemented natively here (rather than delegating to sax.netlists.remove_unused_instances) because circulax's own connections values may be a tuple/list of targets (one shared net for several refs), which sax's dict-oriented helper does not support.
Returns:
| Type | Description |
|---|---|
Netlist | dict | A new netlist of the same type as netlist, with unreachable |
Netlist | dict | instances (and the connections/nets that only touched them) removed. |
Netlist | dict | The input is not mutated. |
Source code in circulax/netlist.py
sax_to_kfnetlist ¤
Convert a SAX-format netlist dict to a kfnetlist.Netlist.
Pairwise SAX connections (and GDSFactory-style nets lists) are grouped into equivalence classes via union-find, then emitted as one kfnetlist.Net per class.
Returns:
| Type | Description |
|---|---|
Netlist | A 2-tuple |
dict[str, dict[str, Any]] | settings_override maps instance names to their full settings |
tuple[Netlist, dict[str, dict[str, Any]]] | dict (including non-JSON-safe values such as complex numbers). |
tuple[Netlist, dict[str, dict[str, Any]]] | When all settings are JSON-safe the override dict is empty. |
Source code in circulax/netlist.py
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 311 312 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 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |