MODE — Model-based Ordinary Differential Optimisation Module

MODE is a next-generation library for Model Predictive Control (MPC), built directly on ordinary differential equations (ODEs). By grounding control in dynamic models instead of opaque black-box rules, MODE ensures robustness, interpretability, and scalability across a wide range of real-world applications.

At its core, MODE is founded on physics. Processes are expressed through ODEs, allowing each controller to reflect the actual behaviour of the system it governs. This approach ensures that models are not only accurate but also adaptable, whether they describe mass balances, energy transfers, kinetic reactions, or even hybridised data-driven relationships. With MODE, control ceases to be a collection of ad hoc rules and instead becomes a transparent framework rooted in the laws that govern the process.

The MODE workflow begins with model definition. A system is described in terms of its states, manipulated inputs, disturbances, and measured outputs. ODEs capture the evolution of states, while algebraic constraints and auxiliary variables can be added to account for system restrictions or secondary relationships. For example, a simple tank model may describe how the liquid level changes with inflow, outflow, and valve settings:

 
import mode as md
 
# Define the model with time step
model = md.Model(dt=0.5)
 
# States, inputs, disturbances, and outputs
x = model.state("TankLevel")
u = model.input("ValveOpening")
d = model.disturbance("FeedFlow")
y = model.output("LevelSensor")
 
# ODE: dH/dt = inflow - outflow
model.ode(x, d - 0.8*u)
 
# Measurement equation
model.measure(y, x)

Once the model is established, estimation closes the loop between the physical system and its mathematical representation. MODE integrates seamlessly with filters such as the Extended Kalman Filter (EKF), Unscented Kalman Filter (UKF), or Moving Horizon Estimation (MHE). These tools fuse sensor data with the underlying model to provide real-time estimates of states and parameters that cannot be directly measured.

 
# Estimator based on EKF
est = md.Estimator("ekf", model=model)

Building on this foundation, the predictive controller formulates an optimisation problem across a prediction horizon. The goal is to determine a sequence of control inputs that will minimise deviations from targets while simultaneously respecting physical, operational, and economic constraints. Actuator limits, rate restrictions, and both hard and soft bounds are natively supported. MODE allows objectives to be quadratic, nonlinear, or multi-objective, depending on the needs of the process.

 
# MPC with prediction and control horizons
mpc = md.MPC(model=model, horizon=30, control_horizon=10)
 
# Objective: track the tank level at 2.0 units
mpc.objective(track=y, target=2.0, weight=10)
 
# Input bounds
mpc.bounds(u, lo=0, hi=100)

Simulation provides a proving ground for the strategy before deployment. Within MODE, disturbances, actuator faults, or alternative operating scenarios can be introduced, allowing engineers to stress-test the controller. Performance metrics such as setpoint tracking, constraint handling, and efficiency can be quantified to evaluate robustness.

 
# Simulator to test full loop
sim = md.Simulator(model, est, mpc)
sim.run(steps=100)

Finally, MODE supports industrial deployment. Controllers developed in simulation can be connected to real systems through plant historians, OPC UA, MQTT protocols, or Python APIs. Its solvers are warm-start capable for real-time use, and watchdog safeguards ensure resilience under operational demands.

The range of MODE’s applications reflects its flexibility. In mineral processing, it can stabilise grinding circuits, regulate flotation froth levels, or manage thickener interfaces. In energy and utilities, it can optimise demand response, storage systems, or HVAC control. Robotics applications benefit from precise trajectory tracking under safety constraints, while finance and operations use MODE to optimise portfolios dynamically under turnover and liquidity limits.

The philosophy behind MODE is straightforward yet powerful: control is most effective when it is model-based. By coupling the predictive power of ODEs with state-of-the-art optimisation, MODE transforms equations into actionable, real-time strategies. From initial equations to execution on the plant floor, MODE provides a seamless, transparent path for advanced control.