Skip to main content

ElecSolver

Overview

ElecSolver formalizes electric systems as linear problems, suitable for both temporal and frequency-domain studies. It focuses on constructing the linear system representation, leaving the actual numerical resolution to the user.

This repository is not a general-purpose electrical system solver. Instead, it acts as a bridge between:

  • The graph-based description of an electric network
  • The corresponding sparse linear system to solve

Its main goal is to provide a friendly Python interface for simulating analog electric systems. While suitable for small circuit simulations, its strength lies in scalability—handling millions of nodes and components, provided that you possess sufficient computational resources.

Table of content

How to install

For now this package is distributed on pypi and can be installed using pip

pip install ElecSolver

For solving the linear systems we advise using MUMPS through pyMUMPS on linux that can be installed via pip

pip install pymumps

Components

FrequencySystemBuilder

This class handles frequency-domain analysis of linear electric systems.

Features

  • Supports tension and intensity sources
  • Models inductive and resistive mutuals
  • Detects and couples multiple subsystems
  • Accepts arbitrary complex impedances and mutuals
  • Constructs sparse linear systems (COO format)

Example

We would like to study the following system: Multiple system

this can simply be defined in the following manner (We took R=1, L=1 and M=2):

import numpy as np
from scipy.sparse.linalg import spsolve
from ElecSolver import FrequencySystemBuilder


# Complex and sparse impedance matrix
# notice coil impedence between points 0 and 2, and coil impedence between 3 and 4
impedence_coords = np.array([[0,0,1,3],[1,2,2,4]], dtype=int)
impedence_data = np.array([1, 1j, 1, 1j], dtype=complex)

# Mutual inductance or coupling
# The indexes here are the impedence indexes in impedence_data
# The coupling is inductive
mutuals_coords = np.array([[1],[3]], dtype=int)
mutuals_data = np.array([2.j], dtype=complex)

electric_sys = FrequencySystemBuilder(
    impedence_coords,
    impedence_data,
    mutuals_coords,
    mutuals_data
)

# Set node masses
# 2 values because 2 subsystems
electric_sys.set_mass(0, 3)
# Building system
electric_sys.build_system()
electric_sys.build_second_member_intensity(intensity=10, input_node=2, output_node=0)

# Get and solve the system
sys, b = electric_sys.get_system()
sol = spsolve(sys.tocsr(), b)
intensities, potentials = electric_sys.build_intensity_and_voltage_from_vector(sol)

## We see a tension appearing on the lonely coil (between node 3 and 4)
print(potentials[3]-potentials[4])

Adding a Parallel Resistance

We want to add components in parallel with existing components for instance inserting a resistor in parallel with the first inductance (between nodes 0 and 2) Parallel system

In python, simply add the resistance to the list of impedence in the very first lines of the script:

import numpy as np
from scipy.sparse.linalg import spsolve
from ElecSolver import FrequencySystemBuilder


# We add an additionnal resistance between 0 and 2
impedence_coords = np.array([[0,0,1,3,0],[1,2,2,4,2]], dtype=int)
impedence_data = np.array([1, 1j,1, 1j,1], dtype=complex)

# No need to change the couplings since indexes of the coils did not change
mutuals_coords = np.array([[1],[3]], dtype=int)
mutuals_data = np.array([2.j], dtype=complex)

TemporalSystemBuilder

This class models time-dependent systems using resistors, capacitors, coils, and mutuals.

Features

  • Supports tension and intensity sources
  • Models inductive and resistive mutuals
  • Detects and couples multiple subsystems
  • Accepts 3 dipole types: resistances, capacities and coils
  • Constructs sparse linear systems (COO format)

Example

We would like to study the following system: Temporal system

with R=1, L=0.1, C=2 this gives:

import numpy as np
from scipy.sparse.linalg import spsolve
from ElecSolver import TemporalSystemBuilder

## Defining resistances
res_coords  = np.array([[0,2],[1,3]],dtype=int)
res_data = np.array([1,1],dtype=float)
## Defining coils
coil_coords  = np.array([[1,0],[3,2]],dtype=int)
coil_data = np.array([0.1,0.1],dtype=float)
## Defining capacities
capa_coords = np.array([[1,3],[2,0]],dtype=int)
capa_data = np.array([2,2],dtype=float)

## Defining empty mutuals here
mutuals_coords=np.array([[],[]],dtype=int)
mutuals_data = np.array([],dtype=float)


res_mutuals_coords=np.array([[],[]],dtype=int)
res_mutuals_data = np.array([],dtype=float)

## initializing system
elec_sys = TemporalSystemBuilder(coil_coords,coil_data,res_coords,res_data,capa_coords,capa_data,mutuals_coords,mutuals_data,res_mutuals_coords,res_mutuals_data)
## Seting mass at point 0
elec_sys.set_mass(0)
## Build second member
elec_sys.build_system()
elec_sys.build_second_member_intensity(10,1,0)
# getting initial condition system
S_i,b = elec_sys.get_init_system()
# initial condition
sol = spsolve(S_i.tocsr(),b)
# get system (S1 is real part, S2 derivative part)
S1,S2,rhs = elec_sys.get_system()

## Solving using euler implicit scheme
dt=0.08
vals_res1 = []
vals_res2 = []
for i in range(50):
    currents_coil,currents_res,currents_capa,voltages,_ = elec_sys.build_intensity_and_voltage_from_vector(sol)
    vals_res1.append(currents_res[1])
    vals_res2.append(currents_res[0])
    ## implicit euler time iterations
    sol = spsolve(S2+dt*S1,b*dt+S2@sol)
import matplotlib.pyplot as plt
plt.xlabel("Time")
plt.ylabel("Intensity")
plt.plot(vals_res1,label="intensity res 1")
plt.plot(vals_res2,label="intensity res 2")
plt.legend()
plt.savefig("intensities_res.png")

This outputs the following graph that displays the intensity passing through the resistances Temporal system

Solver suggestions

  • For small or moderately sized systems, the built-in scipy.sparse.linalg.spsolve is effective.
  • For large-scale temporal problems, consider using MUMPS (via pyMUMPS). MUMPS is more efficient when only the second member (b) changes during time-stepping.

Metadata

Release files for ElecSolver 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for ElecSolver 0.1.4
File Interpreter ABI Platform Actions
elecsolver-0.1.4-py3-none-any.whl Python 3 none any Details for elecsolver-0.1.4-py3-none-any.whl

Release files / elecsolver-0.1.4-py3-none-any.whl

Download URL elecsolver-0.1.4-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c5d4e9e8f755a349b3b5e665a78166d6eff0b3b62d1cf9275a4e346c620fa17
BLAKE2b-256 checksum
How to use checksums
e369af70237aec588b94c446ea0b67c9a8f14b749093c5abfffef4b8a38e869c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 6, 2025.

Transparency log

Security for ElecSolver 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for elecsolver-0.1.4-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 6, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page