testbench ¤
Test-bench helpers for wrapping device netlists with sources and loads.
A device netlist (e.g. from GDSFactory or hand-written SAX) describes the device only — its connectivity and external ports mapping. Running it in circulax additionally requires every external port to be terminated: driven by a source, loaded by a detector, or tied to GND.
:func:attach_testbench wraps the device into a runnable netlist by adding the requested terminations and wiring them to the device's external ports.
Functions:
| Name | Description |
|---|---|
attach_testbench | Wrap a device netlist with sources, loads, and GND terminations. |
attach_testbench ¤
attach_testbench(
device: dict,
*,
sources: dict[str, dict[str, Any]] | None = None,
loads: dict[str, dict[str, Any]] | None = None,
gnd: Iterable[str] | None = None
) -> dict
Wrap a device netlist with sources, loads, and GND terminations.
Each entry in sources and loads is a 2-port SAX instance spec. Its p1 port is wired to the named device port; its p2 is tied to GND,p1. Entries listed in gnd are wired directly to GND with no intervening component.
The output netlist uses the nets list format and inherits all instances and connectivity from the device. A "GND" instance is added if not already present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device | dict | Device netlist. Must have | required |
sources | dict[str, dict[str, Any]] | None |
| None |
loads | dict[str, dict[str, Any]] | None | Same format as | None |
gnd | Iterable[str] | None | Device ports to tie directly to GND. The | None |
Returns:
| Type | Description |
|---|---|
dict | A new netlist with |
dict | func: |
Raises:
| Type | Description |
|---|---|
ValueError | If a device port appears in more than one of |
Example
mzi_nl = mzi.get_netlist() # GDSFactory device netlist bench = attach_testbench( ... mzi_nl, ... sources={"o1": {"name": "Laser", ... "component": "source", ... "settings": {"power": 1.0}}}, ... loads={"o3": {"name": "PD", ... "component": "resistor", ... "settings": {"R": 1.0}}}, ... gnd=["o2", "o4"], ... ) circuit = compile_circuit(bench, models, is_complex=True)
Source code in circulax/testbench.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 | |