sky

minilink

Abstract

Write the equations once. Simulate, analyze, control, plan, optimize, learn.

Minilink is an open-source Python framework for dynamical systems, control, optimization, and learning. Write a physical model once in pure textbook ODE equations as the core object in Minilink: a System. Compose models and blocks into complex block diagrams, which are also just new Systems. This unified System is the standard interface to all tools: classical and modern control, optimal control (DP, RRT, trajectory optimization, MPC, MPPI), machine learning (neural networks, reinforcement learning), and parameter optimization.

Three mathematical foundations hold the framework together:

  • The Model (System): continuous differential equations dx/dt = f(x, u, t; p), observations y = h(x, u, t; p), and 3D poses T = tf(x, u, t; p).
  • The Task (PlanningProblem): the model paired with boundary sets (X, U, Xf), cost J, and time horizon tf.
  • The Solver Boundary (MathematicalProgram & Optimizer): standard nonlinear program min J(z; p) s.t. g(z; p) ≤ 0, h(z; p) = 0 connecting problems to plug-and-play numerical solvers.

The Minilink Backbone: System, PlanningProblem, MathematicalProgram and Optimizer

All core equation paths are pure functions — arrays in, arrays out — allowing the exact same code to run on a minimalist NumPy/SciPy/Matplotlib setup or a high-performance JAX backend to compile, batch, and autodifferentiate the same equations. Minilink is the successor of Pyro.

Continuous Core & Diagrams as Code

Functional purity means equations are stateless: no simulation time or state is mutated on self. Wiring blocks together with algebraic shortcuts — ctrl @ plant (feedback), a >> b (series), a + b (parallel), sys % Δ (zero-order hold sampling) — yields a new System that flattens to one state vector and one f.

import numpy as np from minilink import DynamicSystem, PID class MassSpringDamper(DynamicSystem): def __init__(self): super().__init__(n=2, input_dim=1, output_dim=1) def f(self, x, u, t=0, params=None): m, k, b = 1.0, 4.0, 0.3 p, v = x a = (u[0] - b * v - k * p) / m return np.array([v, a]) def h(self, x, u, t=0, params=None): return np.array([x[0]]) # sensor measures position only plant = MassSpringDamper() ctrl = PID(kp=10.0, ki=1.0, kd=2.0) # Feedback composition: loop is itself a pure DynamicSystem loop = ctrl @ plant loop.plot_diagram() loop.compute_trajectory(tf=10.0)

Auto-generated closed-loop diagram

Because a composite diagram is itself a DynamicSystem, every analysis verb works identically on closed loops: loop.linearize(), loop.bode(), loop.nyquist(), loop.root_locus(), loop.pzmap(), loop.step_response(), and loop.kalman().

Differentiable & Accelerated with JAX

The exact same equation f(x, u, t; p) traces under JAX without rewriting physics. One evaluator provides exact machine-precision sensitivities, GPU-batched rollouts via vmap, and closed-loop objective gradients ∇J connecting into the unified MathematicalProgram and Optimizer boundary (gd, adam, l-bfgs, slsqp, ipopt):

import jax import numpy as np from minilink import PID, Optimizer, Pendulum, PlanningProblem, QuadraticCost plant = Pendulum() # Exact machine-precision Jacobians A = plant.jacobian("f", "x", x_eq) S = plant.jacobian("f", "params", x_eq) # Vectorized rollouts over 1,000 rod lengths in a single call ev = plant.compile(backend="jax") x0s = np.tile([1.0, 0.0], (1000, 1)) lengths = np.linspace(0.5, 2.0, 1000) xs = ev.rollout_batch(x0s, n_steps=1000, dt=0.005, params=dict(plant.params, l=lengths)) # Closed-loop gradient descent on gains and physical parameters tuning = PlanningProblem(plant, x_start=[1.0, 0.0], cost=QuadraticCost.from_system(plant), tf=4.0) pe = tuning.compile(PID(2.0, 0.5, 1.0), dt=0.02) dJ = jax.grad(lambda p: pe.evaluate(p).objective)(pe.params) best = Optimizer(pe.program(wrt=["controller.Kp", "plant.l"]), method="l-bfgs").solve()

Measured on an Apple M4 Max: 1,000 rollouts of 1,000 RK4 steps take 27 ms as a compiled batch versus 32 s in pure Python.

One Problem, Every Planner

A PlanningProblem bundles the physical plant, boundary sets, cost function, and horizon. The identical problem definition is handed to distinct solver paradigms — Dynamic Programming (VI), Tree Search (RRT), Trajectory Optimization (direct collocation & shooting), Model Predictive Control (MPC / MPPI), and Reinforcement Learning (PPO / SAC) — and every planner returns a PlanningSolution whose policy closes the loop via policy @ plant:

import numpy as np from minilink import ( BallSet, DynamicProgrammingPlanner, Pendulum, PlanningProblem, QuadraticCost, RRTPlanner, TrajectoryOptimizationPlanner, compare, ) plant = Pendulum() x_down, x_up = np.array([0.0, 0.0]), np.array([np.pi, 0.0]) problem = PlanningProblem( sys=plant, x_start=x_down, Xf=BallSet(x_up, 0.2), tf=4.0, cost=QuadraticCost.from_system(plant, Q=np.eye(2), R=np.eye(1), xbar=x_up), X=plant.state.box, U=plant.input_box, ) vi = DynamicProgrammingPlanner(problem, x_grid=(101, 101), u_grid=(11,), dt=0.05) rrt = RRTPlanner(problem, seed=0) opt = TrajectoryOptimizationPlanner(problem, n_steps=40, transcription="direct_collocation") vi_sol = vi.solve() # policy is a lookup controller rrt_sol = rrt.solve() # kinodynamic trajectory opt_sol = opt.solve() # continuous trajectory solution # Closed-loop composition & objective benchmark across solver paradigms loop = vi_sol.policy @ plant print(compare(problem, VI=vi_sol, RRT=rrt_sol, TrajOpt=opt_sol, dt=0.05))

Project Media

Cart-pole swing-up by trajectory optimization
Trajectory optimization (direct collocation)
UR5 arm under task-space impedance control in the meshcat 3D viewer
UR5 task-space impedance (interactive 3-D)
UdeS racecar under model predictive control in the meshcat 3D viewer
Model predictive control (interactive 3-D)
Rocket landing policy trained by reinforcement learning
Reinforcement learning (PPO rocket landing)

Project Details

Status
Active open-source library
Date
2025–present
Team
Prof. Alexandre Girard
License
MIT
Keywords
JAX, automatic differentiation, compiled simulation, diagrams, trajectory optimization, MPC, learning.