Skip to main content
Version: 0.2.7

Physics Simulators

synapsys.simulators provides nonlinear continuous-time physics simulators with a unified interface for control design, testing, and reinforcement learning.


Available simulators

ClassSystemStatesInputsOutputs
MassSpringDamperSim1-DOF linear MSD[q, q̇][F][q]
InvertedPendulumSimNonlinear pendulum on fixed pivot[θ, θ̇][τ][θ]
CartPoleSimLagrangian cart-pole[p, ṗ, θ, θ̇][F][p, θ]

Common interface

Every simulator inherits from SimulatorBase and exposes the same API:

from synapsys.simulators import CartPoleSim

sim = CartPoleSim()
y = sim.reset() # reset → initial observation
y, info = sim.step(u, dt=0.02) # advance one step
ss = sim.linearize(x0, u0) # numerical linearisation → StateSpace

step() info dict

y, info = sim.step(u, dt=0.02)
info["x"] # full state after step
info["t_step"] # integration time (= dt)
info["failed"] # True when the system left its safe region

Integrators

All simulators support three numerical integration methods selectable at construction:

MethodAccuracySpeedRecommended use
"euler"LowFastestVery small dt (≤ 1 ms), RL inner loops
"rk4"HighFastDefault — good balance
"rk45"Very highSlowerReference / validation
sim = CartPoleSim(integrator="rk4")   # default
sim = CartPoleSim(integrator="euler") # fastest

Noise and disturbances

sim = InvertedPendulumSim(noise_std=0.01, disturbance_std=0.05)
  • noise_std — Gaussian noise added to every observation (sensor noise model)
  • disturbance_std — Gaussian noise injected into the control input (process noise)

Thread-safe parameter updates

All simulators support live parameter changes from a separate thread:

sim.set_params(m=0.5)     # InvertedPendulumSim
sim.set_params(m_c=2.0) # CartPoleSim

Failure detection

y, info = sim.step(u, dt)
if info["failed"]:
sim.reset()
SimulatorFailure condition
CartPoleSim|p| > 4.8 m or |θ| > π/3 rad
InvertedPendulumSim|θ| > π/2 rad
MassSpringDamperSimnever (always stable)

Linearisation

Every simulator exposes linearize(x0, u0) which returns a continuous-time StateSpace via central finite differences — ready for LQR design:

from synapsys.algorithms.lqr import lqr

ss = sim.linearize(np.zeros(4), np.zeros(1))
K, _ = lqr(ss.A, ss.B, Q, R)