# numra-ocp
**ODE-constrained optimization for the [Numra](https://numra-rs.org/) workspace — single and multiple shooting, direct collocation, adjoint gradients, and parameter estimation for ODE models against measured data.**
[](https://crates.io/crates/numra-ocp)
[](https://docs.rs/numra-ocp)
Bridges `numra-ode` and `numra-optim`: the ODE solver runs in the inner loop, the optimizer minimizes over parameters / initial conditions / controls. Gradients can come from forward sensitivity (via `ParametricOdeSystem`), adjoint methods, or autodiff bridges.
## Example
```rust
use numra_ocp::{OdeSolverChoice, ParamEstProblem};
// Recover k from data generated by y' = -k·y with k = 2
let t_data: Vec<f64> = (0..11).map(|i| i as f64 * 0.1).collect();
let r = ParamEstProblem::new(1, 1)
.model(|_t, y: &[f64], dy: &mut [f64], p: &[f64]| dy[0] = -p[0] * y[0])
.data(t_data, y_data)
.params(vec![1.0])
.initial_state(vec![1.0])
.ode_solver(OdeSolverChoice::DoPri5)
.solve()
.unwrap();
assert!((r.params[0] - 2.0).abs() < 0.1);
```
## What's in this crate
- **`ParamEstProblem`** — declarative parameter-estimation builder for ODE models against time-series data
- **`ShootingProblem`** — single-shooting optimal control
- **`MultipleShootingProblem`** — multiple-shooting variant for unstable systems
- **`CollocationProblem`** — direct collocation with configurable `CollocationScheme`
- **`adjoint_gradient` / `AdjointResult`** — adjoint-method gradients for the cost functional
- **`forward_sensitivity` / `SensitivityResult`** — forward sensitivity matrices (re-exposed for OCP callers)
## Composes with
- [`numra-ode`](https://docs.rs/numra-ode) — inner ODE solver in shooting / collocation
- [`numra-optim`](https://docs.rs/numra-optim) — outer optimizer for the parameter / control problem
- [`numra-autodiff`](https://docs.rs/numra-autodiff) — analytical Jacobians for ODE sensitivity
- [`numra-fit`](https://docs.rs/numra-fit) — alternative residual-based fitting for simple models
See [interop workflows](https://github.com/moussaoutlook/numra-rs/blob/main/numra/tests/interop_workflows.rs) for the verified parameter-estimation → sensitivity → uncertainty workflow.
## Install
```toml
[dependencies]
numra-ocp = "0.1"
```
Or via the umbrella crate:
```toml
[dependencies]
numra = "0.1"
```
## Documentation
- **API**: <https://docs.rs/numra-ocp>
- **Book**: [Parameter estimation](https://book.numra-rs.org/ch10-optimal-control/parameter-estimation/) · [Shooting methods](https://book.numra-rs.org/ch10-optimal-control/shooting-methods/) · [Collocation](https://book.numra-rs.org/ch10-optimal-control/collocation/) · [Adjoint methods](https://book.numra-rs.org/ch10-optimal-control/adjoint-methods/)
- **Source**: <https://github.com/moussaoutlook/numra-rs/tree/main/numra-ocp>
## License
Numra Academic & Research License (Non-Commercial). Academic and research use is free; commercial use requires a separate license — contact `contact@spectralautomata.com`. See [LICENSE](https://github.com/moussaoutlook/numra-rs/blob/main/LICENSE).