Skip to content
EMSL-ComputingPublic

About

Optimal control for process-based ecological ODE models (CasADi + direct collocation).

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

eco_opt

Version Python Docs

Process-based ecological ODEs as constrained optimal-control problems. The right-hand side is the user’s mass balance; states, controls, and the criterion $J$ are declared; CasADi collocation and IPOPT produce $u^*(\cdot)$.

Python implementation of the Yop modeling workflow (Leek, 2016).

Complete first script: First solve (microbial growth). Goddard and other OCPs: Examples.

Capabilities

Capability
Single-phase collocation Legendre or Radau; piecewise-constant $u$
Algebraic states System(algebraics=n); model returns (dx, dz, y) (single-phase)
Multi-phase Ocp.st(phases=[...]); optional continuity of time and state
Sweeps build → set_constraints / optimize on a frozen mesh
Open loop ocp.simulate(sol) or eco_opt.simulate
Closed loop shrinking or receding horizon (ocp.closed_loop)

Automatic scaling is not implemented. Algebraics are not supported in multi-phase problems. The keyword plant= is the simulated process model (control-theory name), not vegetation.

Public names: System, Ocp, OcpResults, Phase, PhaseTrajectory, t_0, t_f, TimepointExpression, Namespace, simulate, closed_loop, SimulationResults, ClosedLoopResults, control_from_solution.

Install

git clone git@github.com:EMSL-Computing/eco_opt.git
cd eco_opt
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate
python -m pip install -e ".[test]"
python -c "import eco_opt; print(eco_opt.__version__)"
python -m pytest -q

Not on PyPI. Python 3.9+, CasADi, and IPOPT. .[test] includes matplotlib and scipy. Plot scripts without pytest: python -m pip install -e ".[examples]". Example folders are in this clone. Full notes: Install. HTTPS clone: https://github.com/EMSL-Computing/eco_opt.git.

Examples

From the repository root (python -m pip install -e ".[examples]"):

cd examples/microbial_growth
python microbial_growth.py

Expect success=True, (T\approx 1.518), (J\approx 0.1518), and (C(T)) near zero. The script prints those values and the path of the comparison figure it writes, for example:

OcpResults(success=True, status='Solve_Succeeded', objective=0.15185, t0=0.0, tf=1.51819)
objective (integral of G): 0.15184969799373968
final time (resource exhaustion): 1.5181904140430988
C(tf): 1.1349772462111628e-08
Wrote: /path/to/eco_opt/examples/microbial_growth/figs/microbial_growth_vs_analytical.png

IPOPT may print a license banner first. The Wrote: line is the figure path on your machine.

Folder Topic
microbial_growth Finite-substrate uptake
opt_lignin Ligninolytic investment
root_opt Plant–soil C and N allocation

Every example page starts its run block with cd examples/<folder>. Further examples: docs/examples.

Documentation

https://emsl-computing.github.io/eco_opt/ (GitHub Pages; needs Pages enabled, and typically a public repository). Local preview:

Page Contents
Results and plots sol arrays and matplotlib
Posing a problem Roles, costs, open vs closed loop
CasADi expressions cs.exp, if_else, interpolants in the model
Transcription Piecewise-constant $u$, collocation, mesh
Constraints and time Boxes, path, $t_0$/$t_f$, horizon
Guesses, mesh, scaling Cold start, mesh, units
Build and optimize Frozen mesh, bound and parameter sweeps
Examples Ecological models and textbook OCPs
API Public contract
Troubleshooting IPOPT options and failures

Development and questions

Issues, fixes, docs, and small examples are welcome if you have access to this repository. Open a pull request from a branch, or email if you cannot. See CONTRIBUTING.md.

Please do not add code or data whose license would conflict with this project (restricted datasets, snippets that cannot be reused or modified).

Questions: arjun.chakrawal@pnnl.gov.

Citation

Chakrawal, A., Schwarz, E., Mudunuru, M. K., Leek, V., and Colombi, T. (2026). The eco_opt package: From process models to optimal strategies. Manuscript in preparation.

Cite the software as eco_opt 0.1. See Cite and CITATION.cff.

Acknowledgments

This research was supported by the computing facility at the Environmental Molecular Sciences Laboratory, a DOE Office of Science User Facility sponsored by the Biological and Environmental Research program under Contract No. DE-AC05-76RL01830.

Disclaimer

This material was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government nor the United States Department of Energy, nor Battelle, nor any of their employees, nor any jurisdiction or organization that has cooperated in the development of these materials, makes any warranty, express or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness or any information, apparatus, product, software, or process disclosed, or represents that its use would not infringe privately owned rights.

Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or any agency thereof, or Battelle Memorial Institute. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or any agency thereof.

PACIFIC NORTHWEST NATIONAL LABORATORY operated by BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY under Contract DE-AC05-76RL01830

About

Optimal control for process-based ecological ODE models (CasADi + direct collocation).

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages