PathSim - A System Simulation Framework

PathSim is a flexible block-based time-domain system simulation framework in Python with automatic differentiation capabilities and an event handling mechanism! It provides a variety of classes that enable modeling and simulating complex interconnected dynamical systems through Python scripting.

All of that with minimal dependencies, only numpy, scipy and matplotlib!

Key Features:

  • Hot-swappable blocks and solvers during simulation

  • Blocks are inherently MIMO (Multiple Input, Multiple Output) capable

  • Wide range of numerical integrators (implicit, explicit, high order, adaptive)

  • Modular and hierarchical modeling with (nested) subsystems

  • Event handling system to detect and resolve discrete events (zero-crossing detection)

  • Automatic differentiation for fully differentiable system simulations

  • Extensibility by subclassing the base Block class and implementing just a handful of methods

The source code can be found in the GitHub repository and is fully open source under MIT license. Consider starring PathSim to support its development.

Quickstart

  1. Install PathSim with pip:

pip install pathsim
  1. Build a dynamical system unsing blocks and connections. Here we just integrate a cosine:

cos integration block diagram

Which looks like this, translated to PathSim:

import numpy as np

from pathsim import Simulation, Connection
from pathsim.blocks import Source, Integrator, Scope

#these are the blocks of our system
Sr = Source(np.cos)
In = Integrator()
Sc = Scope(labels=["cos", "sin"])

#simulation instance with blocks and connections
Sim = Simulation(
    blocks=[Sr, In, Sc],
    connections=[
        Connection(Sr, In),
        Connection(Sr, Sc[0]),
        Connection(In, Sc[1]),
        ],
    dt=0.01
    )
  1. Run the simulation and look at the results:

#run for 10 time units
Sim.run(10)

#plot the scope
Sc.plot()
cos integration result

Table of Contents

This documentation is structured in the following way. There are a number of examples that almost have tutorial-charakter and of course the API-reference.

Indices and tables