Skip to main content

Singulax

Version Python JAX Status

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.

Installation

Requires Python ≥ 3.12.

pip install singulax

Or 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 environment

Usage

As a library

Singulax exposes the building blocks of the optimal control problem: the state and costate dynamics, the switching function $\phi$, and the singular feed law derived from $\ddot{\phi}=0$.

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 RHS

Enabling 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 $\mu(S)$ — has a closed-form singular feed
singulax.substrate_product_inhibition Shin & Lim ethanol kinetics $\mu(S,P)$
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.

Running the case studies

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.py

Scripts under analytical_sol/ and analytical_and_pmp/ finish in seconds; the hybrid_approach/ ones invoke IPOPT and take roughly one to five minutes.


References

  1. 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.
  2. 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.

Metadata

Release files for singulax 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for singulax 0.1.0
File Size Uploaded Provenance Actions
singulax-0.1.0.tar.gz 6.1 MB With provenance Details for singulax-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for singulax 0.1.0
File Interpreter ABI Platform Actions
singulax-0.1.0-py3-none-any.whl Python 3 none any Details for singulax-0.1.0-py3-none-any.whl

Total release size: 6.1 MB

Release files / singulax-0.1.0.tar.gz

Download URL singulax-0.1.0.tar.gz
Size 6.1 MB
Tags Source
SHA-256 checksum
How to use checksums
59568e8ea3416450ff8a86338328d48afa7a9b68d273d8b216cb25fa3620565d
BLAKE2b-256 checksum
How to use checksums
5084531c75bc85ff80842a781bf0d9f95ee2f5210e324cf18c65c921f02f0fa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / singulax-0.1.0-py3-none-any.whl

Download URL singulax-0.1.0-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
311dcec0af5f5d03e74d1d8e2fba84de8a09c7c595537493938bd0864155c4f9
BLAKE2b-256 checksum
How to use checksums
f2853d59efbe2a29369a01021ad41a881e6a71107fc73308e1cbd7df495b6b35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for singulax 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for singulax-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page