Singulax solves the fed-batch bioreactor problem "how should I feed substrate over time to maximise product at harvest?" Because the feed rate enters the dynamics linearly, the optimal policy is a sequence of arcs — full feed, no feed, and singular arcs on which the classical optimality condition degenerates. Those singular arcs are where the interesting behaviour lives (the feed tracks the culture so that substrate is held at its productivity-optimal level), and they are also what makes the problem numerically awkward.
The approach here is a two-stage hybrid direct → indirect method: a robust low-accuracy direct solve discovers the arc structure and seeds the adjoints, then an indirect PMP shooting solve refines everything to machine precision. Every derivative in the pipeline — costate equations, Lie brackets, the singular feed law, sparse NLP Jacobians — is obtained by automatic differentiation, so switching to a new kinetic model means writing three rate functions and nothing else.
Built on JAX, diffrax, optimistix and IPOPT.
Requires Python ≥ 3.12.
Singulax depends on cyipopt. On Linux and macOS, PyPI
only ships cyipopt as source, so it is compiled at install time against an IPOPT library that
must already be installed on the system (found via pkg-config). If it is missing,
pip/uv fails while building cyipopt with an error like Package ipopt was not found.
Install IPOPT first:
yay -S coin-or-ipopt # Arch (AUR; or paru)
sudo apt install coinor-libipopt-dev pkg-config build-essential # Ubuntu / Debian
brew install ipopt pkg-config # macOSOn Windows, PyPI provides prebuilt cyipopt wheels with IPOPT included, so no extra step is
needed. Without system install rights (e.g. on a cluster), conda install -c conda-forge cyipopt
provides both cyipopt and IPOPT as binaries.
You can check that IPOPT is visible with pkg-config --modversion ipopt.
pip install singulaxOr with uv, you can add Singulax to an existing project, or install it into the active environment:
uv add singulax # add to your project's dependencies and install
uv pip install singulax # install into the current environmentSingulax exposes the building blocks of the optimal control problem: the state and costate
dynamics, the switching function
import jax
jax.config.update("jax_enable_x64", True) # required: the shooting residuals need float64
import jax.numpy as jnp
from singulax.substrate_product_inhibition import get_phi, get_Fsin, vector_field
S_F, V_max, F_min, F_max = 150.0, 10.0, 0.0, 2.0
x = jnp.array([10.0, 5.0, 2.0, 3.0]) # [XV, SV, PV, V]
lam = jnp.array([1.0, 0.05, 1.0, -7.5]) # costate
y = jnp.concatenate([x, lam])
print("phi =", get_phi(y)) # switching function
print("F_sing =", get_Fsin(y, (S_F, V_max, F_min, F_max))) # singular feed
print("ydot =", vector_field(0.0, y, (S_F, 1.0))) # augmented state-costate RHSEnabling jax_enable_x64 is not optional, and it must happen before any array is created.
In float32 the shooting residuals cannot reach their convergence tolerance.
Each inhibition case is a self-contained subpackage:
| import | model |
|---|---|
singulax.substrate_inhibition |
Haldane kinetics |
singulax.substrate_product_inhibition |
Shin & Lim ethanol kinetics |
singulax.collocation |
Stage-1 direct transcription, shared by both cases |
Case-specific names (mu, sigma, get_phi, get_Fsin, vector_field, …) exist in both
case subpackages and are deliberately not re-exported at the top level — import them from the
relevant subpackage so it is always clear which model you are using.
The scripts/ tree holds one runnable script per control structure. Each is self-contained,
prints its Stage-1 and Stage-2 diagnostics, and writes PNG figures next to itself:
uv run python scripts/substrate_and_product_inhibition/hybrid_spi.py
uv run python scripts/substrate_inhibition/singular_arc/hybrid_approach/hybrid_si_sing.pyScripts under analytical_sol/ and analytical_and_pmp/ finish in seconds; the
hybrid_approach/ ones invoke IPOPT and take roughly one to five minutes.
- Foroozandeh, Z., Shamsi, M., & de Pinho, M. d. R. (2018). A Hybrid Direct–Indirect Approach for Solving the Singular Optimal Control Problems of Finite and Infinite Order. Iranian Journal of Science and Technology, Transactions A: Science, 42(3), 1545–1554. doi:10.1007/s40995-017-0176-2 — the two-stage hybrid method and the cart-pole benchmark.
- Shin, H. S., & Lim, H. C. Fed-Batch Cultures. Example 13.E.3 (ethanol from glucose by
S. cerevisiae) — the substrate + product inhibition kinetics and the reference
$PV(t_f) = 764.47$ g.