Skip to content

New block : NetlistStateSpace - #6

Open
Pimss wants to merge 18 commits into
pathsim:mainfrom
Pimss:main
Open

Pimss wants to merge 18 commits into
pathsim:mainfrom
Pimss:main

Conversation

@Pimss

@Pimss Pimss commented Sep 28, 2026

Copy link
Copy Markdown

Summary

This PR adds support for importing linear SPICE-like netlists into PathSim as state-space models.

The new NetlistStateSpace block converts RLC circuits and independent sources into an explicit state-space representation using Modified Nodal Analysis (MNA), allowing circuits described by netlists to be directly integrated into PathSim simulations.

Main changes

  • Added netlist_to_statespace.py with:

    • SPICE-like netlist parsing
    • SI unit and .param handling
    • R, L, C, V and I elements
    • coupled inductors through K elements
    • behavioral current and voltage source support
    • Modified Nodal Analysis formulation
    • algebraic-variable elimination
    • explicit state-space generation
    • symbolic and fast reduction modes
    • configurable voltage and current outputs
    • inline netlist string support
    • netlist file support
  • Added NetlistStateSpace to the public pathsim_rf API.

  • Added sympy as a dependency for symbolic reduction.

  • Added python-mumps as a dependency for fast numerical reduction.

  • Added parser tests covering:

    • SI unit parsing
    • parameter substitution
    • behavioral sources
    • invalid elements
    • invalid outputs
    • current-source handling
    • MUMPS fallback
    • voltage and current output selection
  • Added state-space tests covering:

    • netlist file input
    • inline netlist input
    • feedback current-source inputs
    • voltage and current outputs
    • symbolic reduction
    • fast numerical reduction
    • fast/symbolic equivalence
    • invalid inputs
  • Added validation netlists:

    • tests/filter.net
    • tests/filter_without_load.net
  • Added the netlist_import.ipynb documentation example demonstrating:

    • netlist import
    • PathSim state-space generation
    • comparison against a manually constructed PathSim model
    • behavioral load feedback

Files added

  • src/pathsim_rf/netlist_to_statespace.py
  • tests/test_netlist_parser.py
  • tests/test_netlist_statespace.py
  • tests/filter.net
  • tests/filter_without_load.net
  • docs/source/examples/netlist_import.ipynb

Files modified

  • src/pathsim_rf/__init__.py
  • pyproject.toml

Validation

The new test suite validates the netlist parser and the generated state-space models. Both symbolic and fast reduction paths are tested, including their numerical equivalence.

The added documentation example provides an end-to-end validation of a netlist-derived state-space model against an equivalent PathSim implementation.

Updated env to add sympy and optional python-mumps, not available in Pyodide
Added NetlistStateSpace class in pathsim_rf for netlist integration
cover the new class as well as associated subclass
import only NetlistStateSpace as to keep netlist parser not accessible directly
@Pimss

Pimss commented Sep 29, 2026

Copy link
Copy Markdown
Author

Small problem, python_mumps is only compatible with python>=3.11 and pathsim_rf has release starting from 3.9.
Currently looking into it

@milanofthe

Copy link
Copy Markdown
Member

Do we really need mumps? Wouldnt scipy superLU do for the sparse solve?

@Pimss

Pimss commented Sep 29, 2026 via email •

Copy link
Copy Markdown
Author

@Pimss

Pimss commented Sep 29, 2026 •

Copy link
Copy Markdown
Author

0.0.3 is compatible with python 3.9 but there may be some rework to do. I intend to make python-mumps only available starting python 3.11. The code already have a fallback to sympy if python-mumps is not installed so this would work with python<=3.10 (sympy), python>= 3.11 (sympy and/or python-mumps)

@Pimss

Pimss commented Sep 29, 2026

Copy link
Copy Markdown
Author

There may be some other issues. python-mumps package from pypi do not include mumps... (conda/mamba package does)
env install may works, but tests will most likely fail.

@Pimss

Pimss commented Sep 29, 2026

Copy link
Copy Markdown
Author

note : the addition of K coupling can make the system not that sparse. on a netlist with 396 k, mumps implementation takes 0.8s, scipy more than 10 minutes.

improve significantly the time for large netlist with k couplings
@Pimss

Pimss commented Sep 29, 2026 •

Copy link
Copy Markdown
Author

Current status : passed sympy LU to scipy LU solve.

On a netlist with 31 L, 64 R and 397 k
sympy LU >=10 minutes (not finished - removed)
sympy + scipy LU = 21 s (latest commit)
mumps =0.58 s (latest commit)

python-mumps is installed with mamba and pypi have no way of installing mumps (pypi python-mumps install does not have mumps included)

I see two options:
- Leave the code as it is, remove python-mumps from pyproject.toml and leave the user install python-mumps (and pathsim) with a conda env
- Remove all python-mumps implementation to simplify the code

I recommend solution 1, test including python-mumps will be skipped (TestFastReduction class in tests/test_netlist_statespace.py)

@milanofthe

Copy link
Copy Markdown
Member

I will check it. Factor of almost 40 between scipy superLU and mumps seems insane. Also a linear system of n roughly 100 should solve way faster then that.

Generally I am for less dependencies.

@Pimss

Pimss commented Sep 30, 2026 •

Copy link
Copy Markdown
Author

Here is the use case I'm using MediumCoupled.txt
Mumps is very efficent. Maybe the factor 40 is a bit much, however I used it on systems with more that 16M k (in another implementation) and mumps is impressive.

Nevertheless the argument of less dependencies is perfectly understandable.

from pathsim_rf.netlist_to_statespace import NetlistStateSpace
state_space_sym = NetlistStateSpace("MediumCoupled.txt", output_voltages=["N3"], reduction_mode="symbolic")
state_space_mumps = NetlistStateSpace("MediumCoupled.txt", output_voltages=["N3"], reduction_mode="fast")

@milanofthe

Copy link
Copy Markdown
Member

Thanks for the netlist. The time goes into sp.nsimplify while stamping (18.9 s); float64 stamping with scipy splu gives the same model in 6 ms. Please stamp with numpy and reduce with scipy only, and drop sympy and python-mumps.

Second issue: this netlist has inductor cutsets (no capacitors, 22 node groups reach ground only through inductors). G_alg_a is singular and gets silently regularized, which adds 22 eigenvalues around 1e17 to A. That needs a proper reduction or a clear error.

@Pimss

Pimss commented Sep 30, 2026

Copy link
Copy Markdown
Author

Yes, my current tests are consistent with this

@Pimss

Pimss commented Sep 30, 2026 •

Copy link
Copy Markdown
Author

Current implementation remove mumps and sympy dependencies.
Tests, doc and env updated.
This version was tested on a netlist with 738718 k, 1215 R and 1215 L.
Scipy performance is not a bottleneck (around 7 sec for this use case), so mumps is not mandatory
The eigenvalues issue is not resolved yet.

@milanofthe

Copy link
Copy Markdown
Member

Is this because the circuits are degenerate and you have cutsets of inductors etc?

@Pimss

Pimss commented Oct 1, 2026 •

Copy link
Copy Markdown
Author

The matrix E can be singular in my use cases. Matrix L is dense due to k couplings. I expect to code to work for classic circuit topologies but this may be a problem for heavy coupled problem like the few I'm using.
I have a plan, I already encounter this issue, and some friends helped. They gave me some advice on how to proceed.
So I will try a new implementation using MassMatrixDAE

@Pimss

Pimss commented Oct 2, 2026 •

Copy link
Copy Markdown
Author

New implementation

from mass_matrix_netlist import MMDAENetlist
test_mmn = MMDAENetlist("filter.net")

This expose the full problem to pathsim so wiring is more convenient with labels

conn_0 = Connection(pulsesource[0], test_mmn["V1"])
...
conn_14 = Connection(test_mmn["V(n1)"],  scope[5])

I believe Pathview only use index so this will be a problem for large netlist.
Despite been ordered in the following order : L currents, R currents, C currents, voltage node and Source currents, indexes will be confusing for any gui user.

@milanofthe

Copy link
Copy Markdown
Member

PathView can use the port labels of the block. So if there is a way that you construct them from the netlist (net labels, or even from the parameters) this should work.

Pimss added 2 commits October 4, 2026 11:13
Added test for string input path handling and updated netlist path handling in existing tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants