Research question and scope
Model predictive control (MPC) repeatedly predicts how a modeled process may evolve and chooses bounded control actions. This guide addresses a simulation of a continuous stirred-tank reactor, not operation of a plant. The official do-mpc CSTR gallery separates model, controller, simulator, closed-loop execution and post-processing files. That separation makes each assumption reviewable.
Prerequisites
Use a local Python environment and the example files matching a recorded do-mpc release. Follow the installation guide for supported dependencies, including CasADi and solver components. Record Python, do-mpc, CasADi, solver and operating-system versions. Treat the gallery parameter values as teaching inputs, not approved process operating limits.
Workflow
- Download the example from the release matching your documentation. Read
template_model.pyfirst: list states, manipulated inputs, parameters, equations and units. The gallery CSTR model includes reactant concentrations and reactor/coolant temperatures. - Inspect
template_mpc.py: document prediction horizon, sampling interval, objective, bounds, scaling and solver options. Check that every numerical constraint has a stated meaning. - Inspect
template_simulator.py: note whether its dynamics match the controller model and which disturbances or parameter variations are represented. Run the example only in a sandboxed simulation environment. - Use the example’s
main.pyclosed-loop loop andpost_processing.pyto record state and input trajectories, solver status and any constraint violations. Repeat with a declared initial condition or disturbance variation. This article did not run the example.
How to interpret and check the output
Acceptance for an educational reproduction means: dependencies and versions documented, equations and units understood, simulation completed without hidden failures, trajectories retained and constraints checked. A controller can meet the simulated objective yet be unsafe under model mismatch. If the solver fails or a constraint becomes infeasible, record the failure and inspect the model, bounds and initialization rather than discarding the run.
Limits and common errors
The simulation does not validate process kinetics, sensors, actuators, emergency shutdown or real-time timing. Do not connect its output to a physical reactor without a separately reviewed process safety case, equipment-specific controls and human authorization. Even a successful numerical trajectory is not evidence of safe or scientifically validated plant operation.
Related ChemAI Atlas pages
Resources: do-mpc. Related guide: Evaluating AI workflows for chemical engineering.
Primary sources
- https://www.do-mpc.com/en/latest/example_gallery/CSTR.html (official source; accessed 2026-10-13)
- https://www.do-mpc.com/en/latest/getting_started.html (official source; accessed 2026-10-13)
- https://www.do-mpc.com/en/latest/installation.html (official source; accessed 2026-10-13)
- https://github.com/do-mpc/do-mpc (official source; accessed 2026-10-13)