Skip to main content

Modern Python control systems framework with distributed multi-agent simulation

Project description

Synapsys logo

Synapsys

Modern Python control systems framework with distributed multi-agent simulation

CI PyPI version Python Docs License: MIT Coverage Code style: ruff

📖 Documentation · 🚀 Quickstart · 📦 PyPI · 💡 Examples · 📋 Changelog


Overview

Synapsys is an open-source Python library for modelling, simulating, and deploying control systems. It provides a MATLAB-compatible API built on SciPy, a modern multi-agent simulation framework, and a pluggable transport layer (shared memory / ZeroMQ) that scales from a single laptop to distributed lab setups.

from synapsys.api import tf, ss, feedback, step, c2d

# SISO
G    = tf([1], [1, 2, 1])    # G(s) = 1 / (s² + 2s + 1)
T    = feedback(G)            # closed-loop: T = G / (1 + G)
t, y = step(T)                # step response
Gd   = c2d(G, dt=0.02)       # ZOH discretisation at 50 Hz

# MIMO
G_mimo = tf([[[ 1], [0]],     # 2×2 transfer-function matrix
             [[ 0], [1]]],
            [[[1,1],[1]],
             [[1],[1,2]]])
T_mimo = feedback(G_mimo)     # state-space closed-loop
pip install synapsys

See it in action

Neural-LQR controller on a 2-DOF mass-spring-damper — MLP initialized with LQR optimal gains tracking setpoint x₂ = 1 m:

Neural-LQR 2-DOF simulation — position tracking, velocities, control force and phase portrait

Full walkthrough: SIL + Neural-LQR example →


Features

Feature Description
MATLAB-Compatible API tf(), ss(), c2d(), step(), bode(), feedback(), lsim() — same names, pure Python
📐 LTI Core TransferFunction, StateSpace, and TransferFunctionMatrix with operator overloading, poles, zeros, stability
🔀 MIMO Support TransferFunctionMatrix for multi-input multi-output plants · MIMO feedback() · transmission zeros via Rosenbrock pencil
🧮 Control Algorithms Discrete PID with anti-windup · LQR via algebraic Riccati equation (Q/R validated)
🤖 Multi-Agent Simulation PlantAgent and ControllerAgent with lock-step and wall-clock sync
🔗 Pluggable Transport Zero-copy shared memory (single-host) · ZeroMQ PUB/SUB and REQ/REP (distributed)
🔌 Hardware Abstraction HardwareInterface contract enables seamless MIL → SIL → HIL transitions
🧱 Matrix Builders StateEquations, mat(), col(), row() — define state-space models from named equations

Installation

pip install synapsys

Requirements: Python ≥ 3.10 · NumPy ≥ 1.24 · SciPy ≥ 1.10 · pyzmq ≥ 25.0

For development:

git clone https://github.com/synapsys-lab/synapsys.git
cd synapsys
uv sync --extra dev

Quickstart

1 · LTI systems and frequency analysis

from synapsys.api import tf, ss, bode, feedback, c2d

# SISO second-order transfer function
G = tf([1], [1, 2, 1])

# Closed-loop with unity negative feedback
T = feedback(G)

# Frequency response
w, mag, phase = bode(G)

# ZOH discretisation at 50 Hz
Gd = c2d(G, dt=0.02)

# MIMO: 2×2 transfer-function matrix
G_mimo = tf(
    [[[1], [0]], [[0], [1]]],           # numerators
    [[[1, 1], [1]], [[1], [1, 2]]],     # denominators
)
T_mimo = feedback(G_mimo)               # returns StateSpace

2 · Control algorithms

from synapsys.algorithms import PID, lqr
import numpy as np

# Discrete PID with anti-windup saturation
pid = PID(Kp=3.0, Ki=0.5, Kd=0.1, dt=0.01, u_min=-10.0, u_max=10.0)
u   = pid.compute(setpoint=5.0, measurement=y)

# LQR — solves the algebraic Riccati equation
A = np.array([[0., 1.], [-2., -3.]])
B = np.array([[0.], [1.]])
K, P = lqr(A, B, Q=np.eye(2), R=np.eye(1))
# Control law: u = −K · x

3 · State-space from named equations

from synapsys.utils import StateEquations

m, c, k = 1.0, 0.1, 2.0

eqs = (
    StateEquations(states=["x1", "x2", "v1", "v2"], inputs=["F"])
    .eq("x1", v1=1).eq("x2", v2=1)
    .eq("v1", x1=-2*k/m, x2=k/m,  v1=-c/m)
    .eq("v2", x1=k/m,  x2=-2*k/m, v2=-c/m, F=1/m)
)

print(eqs.A)   # 4×4 system matrix
print(eqs.B)   # 4×1 input matrix

4 · Multi-agent closed-loop simulation

from synapsys.api import ss, c2d
from synapsys.agents import PlantAgent, ControllerAgent, SyncEngine, SyncMode
from synapsys.algorithms import PID
from synapsys.transport import SharedMemoryTransport
import numpy as np

# Discretise G(s) = 1/(s+1) at 100 Hz
plant_d = c2d(ss([[-1]], [[1]], [[1]], [[0]]), dt=0.01)

with SharedMemoryTransport("demo", {"y": 1, "u": 1}, create=True) as bus:
    bus.write("y", np.zeros(1))
    bus.write("u", np.zeros(1))

    pid  = PID(Kp=4.0, Ki=1.0, dt=0.01)
    law  = lambda y: np.array([pid.compute(setpoint=3.0, measurement=y[0])])
    sync = SyncEngine(SyncMode.WALL_CLOCK, dt=0.01)

    PlantAgent("plant", plant_d, bus, sync).start(blocking=False)
    ControllerAgent("ctrl",  law,  bus, sync).start(blocking=True)

5 · MIL → SIL → HIL — swap transport, keep algorithm

# MIL — shared memory, single host
from synapsys.transport import SharedMemoryTransport
bus = SharedMemoryTransport("demo", {"y": 1, "u": 1}, create=True)

# SIL — ZeroMQ, cross-process / cross-machine
from synapsys.transport import ZMQTransport
bus = ZMQTransport("tcp://localhost:5555", mode="pub")

# HIL — real hardware
from synapsys.agents import HardwareAgent
from synapsys.hw import MockHardwareInterface   # replace with your driver
hw    = MockHardwareInterface(n_inputs=1, n_outputs=1, plant_fn=my_hw)
agent = HardwareAgent("hw", hw, bus, sync)

# PlantAgent / ControllerAgent stay exactly the same in all three modes

Examples

Example Description
basic/step_response.py Step response of a 2nd-order system
distributed/plant.py + controller.py Two-process PID loop via shared memory
distributed/plant_zmq.py Same loop over ZeroMQ (cross-machine)
advanced/01_custom_signals.py Custom reference signals with lsim()
advanced/02a_sil_plant.py + 02b_sil_ai_controller.py SIL + Neural-LQR PyTorch controller
advanced/03_realtime_scope.py Text-mode real-time oscilloscope
advanced/04_realtime_matplotlib.py Live matplotlib oscilloscope
advanced/05_digital_twin.py Digital twin with mechanical wear detection
quickstart_en.ipynb Interactive Jupyter notebook walkthrough

Architecture

synapsys/
├── api/            # MATLAB-compatible façade  (tf, ss, c2d, step, bode, feedback, …)
├── core/           # LTI math — TransferFunction, StateSpace, TransferFunctionMatrix, LTIModel
├── algorithms/     # PID (discrete, anti-windup), LQR (ARE solver)
├── agents/         # PlantAgent, ControllerAgent, HardwareAgent, SyncEngine
├── transport/      # SharedMemoryTransport, ZMQTransport, ZMQReqRepTransport
├── hw/             # HardwareInterface (abstract) + MockHardwareInterface
└── utils/          # StateEquations, mat(), col(), row()

The transport layer is the key abstraction: agents communicate exclusively through a TransportStrategy interface. Swapping the concrete transport (shared memory ↔ ZMQ ↔ real hardware) requires changing one line — algorithms and agents are untouched.


Testing

uv run pytest                      # run all tests
uv run pytest --cov=synapsys       # with coverage report
uv run mypy synapsys               # type checking
uv run ruff check synapsys tests   # linting
Metric Value
Test suite 184 tests
Coverage 90 %
Type checking mypy strict — 0 errors
Python versions 3.10 · 3.11 · 3.12

Roadmap

Version Status Features
v0.1.0 ✅ Released SISO LTI, PID, LQR, multi-agent, shared memory, ZMQ, hardware abstraction, Neural-LQR example
v0.2.0 ✅ Released MIMO support — TransferFunctionMatrix, MIMO feedback(), transmission zeros (Rosenbrock pencil), LQR Q/R validation, covariant LTI type annotations
v0.3 🔜 Planned margin(), rlocus(), pole_placement() · State estimation — Kalman filter, Luenberger observer
v0.5 🔜 Planned Real hardware drivers (serial, CAN, FPGA via PYNQ)

See CHANGELOG.md for the full release history.


Citing

If you use Synapsys in academic work, please cite it as:

BibTeX

@software{synapsys2026,
  author    = {Farias, Oseias D. and contributors},
  title     = {Synapsys: A Python Framework for Modelling and
               Real-Time Simulation of Linear Control Systems},
  year      = {2026},
  url       = {https://github.com/synapsys-lab/synapsys},
  license   = {MIT},
}

APA

Farias, O. D., & contributors. (2026). Synapsys: A Python framework for
modelling and real-time simulation of linear control systems.
https://github.com/synapsys-lab/synapsys

For the version number, use the version shown on PyPI.


Contributing

Contributions are welcome! Please open an issue to discuss what you'd like to change before submitting a pull request.

git clone https://github.com/synapsys-lab/synapsys.git
cd synapsys
uv sync --extra dev
uv run pytest          # make sure everything passes before you start

License

MIT © 2026 Synapsys Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapsys-0.2.1.tar.gz (11.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapsys-0.2.1-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file synapsys-0.2.1.tar.gz.

File metadata

  • Download URL: synapsys-0.2.1.tar.gz
  • Upload date:
  • Size: 11.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for synapsys-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2fe399a7de7ed0ba844b3b172aec162a8c149cd4064cf6cdbcd84953189161df
MD5 95717ba69a459eef1d4679a1135c63c1
BLAKE2b-256 f84772119f7306db32d7b3b8b51597235d805afca9f63fa9c8879fce0c69ab0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for synapsys-0.2.1.tar.gz:

Publisher: publish.yml on synapsys-lab/synapsys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file synapsys-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: synapsys-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 37.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for synapsys-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73a8185c4b17d178fd6827c239a4a3e4563a865b7a5fbaf461204cc2b30e5a30
MD5 17a5e8da885760e306185942389d0648
BLAKE2b-256 9db2b85c6834c43f884c4b05507804c51ddacd8afc60af889932e3a7fdadba83

See more details on using hashes here.

Provenance

The following attestation bundles were made for synapsys-0.2.1-py3-none-any.whl:

Publisher: publish.yml on synapsys-lab/synapsys

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page