Sparse Circuit from a Netlist
This example simulates a pulse-driven LC low-pass filter with a resistive load using the NetlistCircuit block. ElecSolver parses the SPICE-like netlist; PathSim then integrates the circuit as a sparse linear differential-algebraic equation (DAE).
The block behaves like a state space model of the netlist:
- the inputs are the independent sources, named like in the netlist (
V1,Bload, ...) - the outputs are all node voltages
V(node)and all element currentsI(name)
so the circuit is wired to other blocks by name.
Before running: select a Python environment with pathsim, pathsim_rf, matplotlib, and the optional dependency ElecSolver (pip install ElecSolver). If you use local source checkouts, keep their directories on PYTHONPATH. Run the cells from top to bottom: inspect the available ports, select the measurements, connect the blocks, and run the simulation.
Netlist
The source V1 drives node in through a 0.5 mH series inductor (Lfilter). A 50 µF capacitor (Cfilter) connects the output node n1 to ground, node 0.
The 50 Ω load is represented by a behavioral current source, Bload. Its expression I=V(n1)/50 describes the intended load, but the block does not evaluate it: the current is an input supplied by the PathSim feedback connection below.
Likewise, the PULSE(...) waveform and .tran directive do not control the PathSim run. We set the matching pulse parameters in PulseSource and the timestep and duration in the simulation cells.
Circuit block
First, create a block with all outputs exposed and print the available port names. Inputs list voltage sources first, then current sources. Outputs list node voltages relative to ground (ground itself is excluded), then element currents. A current is positive from the first node to the second node in that element's netlist declaration.
The default initial state is zero: the capacitor is uncharged and the inductor carries no current. You can set these quantities by name with initial_value, for example {"V(n1)": 1.0, "I(Lfilter)": 0.5} (volts and amperes).
inputs : ['V1', 'Bload'] outputs: ['V(in)', 'V(n1)', 'I(Lfilter)', 'I(Cfilter)', 'I(V1)', 'I(Bload)']
Now replace the inspection block with one exposing only the two measurements used below: V(n1) for the load feedback and plot, and I(Lfilter) for the plot. The selection lists take bare node and element names, not the formatted port labels.
This reduces the rows of the sparse output matrices C and D inherited from SparseLinearDAE; it does not remove components or reduce the internal circuit state. Selecting outputs without direct feedthrough can also avoid unnecessary algebraic dependencies, but output selection alone does not guarantee that a feedback loop disappears.
inputs : ['V1', 'Bload'] outputs: ['V(n1)', 'I(Lfilter)']
Blocks and connections
The load feedback is implemented outside the circuit: V(n1) passes through a gain of 1/50 A/V and returns to the input Bload. This implements Ohm's law, drawing current from n1 to ground just like a 50 Ω resistor.
PulseSource drives V1 with a 0-to-1 V pulse at 9 kHz and 50% duty cycle, matching the netlist. The scope records the source voltage, filtered output voltage, and inductor current. Named circuit ports make these connections independent of their numeric port indices.
Simulation
Use the implicit BDF2 solver to integrate the circuit DAE, with an initial timestep of 0.5 µs. The simulation starts from the zero initial state described above; log=True enables progress logging. The next cell constructs the simulation; the final cell advances it for 40 ms.
13:59:14 - INFO - LOGGING (log: True) 13:59:14 - INFO - BLOCKS (total: 4, dynamic: 1, static: 3, eventful: 1) 13:59:14 - INFO - GRAPH (nodes: 4, edges: 6, alg. depth: 1, loop depth: 2, runtime: 0.161ms)
Results
Run the simulation and plot the three recorded signals. pulse V1 and V(n1) are in volts, while I(Lfilter) is in amperes, so their plotted magnitudes have different units.
Look for the LC startup oscillation and the smoothing of the input pulses at V(n1). With a 0-to-1 V input and 50% duty cycle, the long-term mean output should be near 0.5 V; zoom in on the end of the trace to inspect the remaining switching ripple.
13:59:14 - INFO - STARTING -> TRANSIENT (Duration: 0.04s) 13:59:15 - INFO - -------------------- 1% | 1.1s<01:17 | 1017.9 it/s 13:59:16 - INFO - -------------------- 2% | 2.1s<53.7s | 1454.2 it/s 13:59:17 - INFO - -------------------- 3% | 3.1s<59.4s | 1297.8 it/s 13:59:18 - INFO - -------------------- 4% | 4.1s<01:14 | 1022.1 it/s 13:59:19 - INFO - #------------------- 5% | 5.1s<01:38 | 766.0 it/s 13:59:20 - INFO - #------------------- 7% | 6.1s<01:13 | 1006.4 it/s 13:59:21 - INFO - #------------------- 8% | 7.1s<01:18 | 932.4 it/s 13:59:22 - INFO - #------------------- 9% | 8.1s<01:02 | 1150.1 it/s 13:59:23 - INFO - ##------------------ 10% | 9.1s<01:14 | 960.5 it/s 13:59:24 - INFO - ##------------------ 12% | 10.1s<01:09 | 1008.8 it/s 13:59:25 - INFO - ##------------------ 13% | 11.1s<01:10 | 982.6 it/s 13:59:26 - INFO - ##------------------ 14% | 12.1s<01:14 | 922.1 it/s 13:59:27 - INFO - ###----------------- 15% | 13.1s<01:12 | 934.8 it/s 13:59:28 - INFO - ###----------------- 16% | 14.1s<01:11 | 931.1 it/s 13:59:29 - INFO - ###----------------- 17% | 15.1s<01:08 | 952.1 it/s 13:59:30 - INFO - ###----------------- 19% | 16.1s<01:08 | 942.2 it/s 13:59:31 - INFO - ####---------------- 20% | 16.9s<01:11 | 899.9 it/s 13:59:32 - INFO - ####---------------- 21% | 17.9s<01:06 | 951.2 it/s 13:59:33 - INFO - ####---------------- 22% | 18.9s<01:07 | 920.9 it/s 13:59:34 - INFO - ####---------------- 24% | 19.9s<01:03 | 959.2 it/s 13:59:35 - INFO - #####--------------- 25% | 20.9s<01:01 | 978.6 it/s 13:59:36 - INFO - #####--------------- 26% | 21.9s<34.9s | 1687.1 it/s 13:59:37 - INFO - #####--------------- 28% | 22.9s<33.0s | 1732.3 it/s 13:59:38 - INFO - ######-------------- 30% | 23.9s<30.5s | 1812.1 it/s 13:59:39 - INFO - ######-------------- 32% | 24.9s<30.6s | 1753.6 it/s 13:59:40 - INFO - #######------------- 35% | 25.9s<30.0s | 1729.7 it/s 13:59:41 - INFO - #######------------- 37% | 26.9s<28.1s | 1785.4 it/s 13:59:42 - INFO - #######------------- 39% | 27.9s<29.1s | 1665.5 it/s 13:59:42 - INFO - ########------------ 40% | 28.1s<27.9s | 1718.1 it/s 13:59:43 - INFO - ########------------ 41% | 29.1s<49.2s | 950.5 it/s 13:59:44 - INFO - ########------------ 43% | 30.1s<33.3s | 1363.2 it/s 13:59:45 - INFO - ########------------ 44% | 31.1s<45.7s | 969.9 it/s 13:59:46 - INFO - #########----------- 45% | 32.1s<44.5s | 974.1 it/s 13:59:47 - INFO - #########----------- 47% | 33.1s<43.1s | 983.2 it/s 13:59:48 - INFO - #########----------- 48% | 34.1s<42.7s | 968.3 it/s 13:59:49 - INFO - #########----------- 49% | 35.1s<41.3s | 977.8 it/s 13:59:50 - INFO - ##########---------- 50% | 36.1s<40.8s | 966.8 it/s 13:59:51 - INFO - ##########---------- 51% | 37.1s<39.8s | 966.7 it/s 13:59:52 - INFO - ##########---------- 53% | 38.1s<38.5s | 975.2 it/s 13:59:53 - INFO - ##########---------- 54% | 39.1s<37.8s | 967.7 it/s 13:59:54 - INFO - ###########--------- 55% | 40.1s<36.8s | 966.1 it/s 13:59:55 - INFO - ###########--------- 56% | 41.1s<35.2s | 984.3 it/s 13:59:56 - INFO - ###########--------- 57% | 42.1s<40.6s | 829.7 it/s 13:59:57 - INFO - ###########--------- 59% | 43.1s<33.5s | 975.2 it/s 13:59:58 - INFO - ############-------- 60% | 43.9s<33.1s | 967.2 it/s 13:59:59 - INFO - ############-------- 61% | 44.9s<31.2s | 994.8 it/s 14:00:00 - INFO - ############-------- 62% | 45.9s<31.0s | 969.5 it/s 14:00:01 - INFO - ############-------- 63% | 46.9s<30.1s | 966.2 it/s 14:00:02 - INFO - ############-------- 64% | 47.9s<29.4s | 959.0 it/s 14:00:03 - INFO - #############------- 66% | 48.9s<15.7s | 1714.5 it/s 14:00:04 - INFO - #############------- 68% | 49.9s<15.1s | 1668.8 it/s 14:00:05 - INFO - ##############------ 70% | 50.9s<13.5s | 1743.5 it/s 14:00:06 - INFO - ##############------ 72% | 51.9s<12.2s | 1788.1 it/s 14:00:07 - INFO - ##############------ 74% | 52.9s<11.3s | 1779.1 it/s 14:00:08 - INFO - ###############----- 77% | 53.9s<10.0s | 1827.9 it/s 14:00:09 - INFO - ###############----- 79% | 54.9s<8.9s | 1856.4 it/s 14:00:09 - INFO - ################---- 80% | 55.2s<9.0s | 1769.9 it/s 14:00:10 - INFO - ################---- 82% | 56.2s<7.9s | 1807.6 it/s 14:00:11 - INFO - ################---- 84% | 57.2s<6.8s | 1825.2 it/s 14:00:12 - INFO - #################--- 86% | 58.2s<5.8s | 1828.7 it/s 14:00:13 - INFO - #################--- 88% | 59.2s<5.3s | 1688.0 it/s 14:00:14 - INFO - ##################-- 91% | 01:00<4.4s | 1645.9 it/s 14:00:15 - INFO - ##################-- 93% | 01:01<3.1s | 1740.2 it/s 14:00:16 - INFO - ###################- 95% | 01:02<2.2s | 1711.4 it/s 14:00:17 - INFO - ###################- 97% | 01:03<1.3s | 1646.4 it/s 14:00:18 - INFO - ###################- 99% | 01:04<0.2s | 1657.0 it/s 14:00:19 - INFO - #################### 100% | 01:04<--:-- | 1754.3 it/s 14:00:19 - INFO - FINISHED -> TRANSIENT (total steps: 80000, successful: 80000, runtime: 64391.54 ms)