resopt
resopt is a Rust crate for declarative residual optimization with optional linear constraints.
It models problems of the form:
minimize_x loss(Ax - b)
subject to Cx = d
Gx <= h
l <= x <= u
The crate is designed around a small public API:
- build a residual problem from matrices and vectors
- add equality constraints, inequality constraints, and bounds
- validate and classify the problem structure
- solve with a backend such as Clarabel
Features
clarabel(default): enables the Clarabel backend
Current backend support:
Loss::L2Squared: solved by the Clarabel backendLoss::L1,Loss::LInf,Loss::Huber: accepted by the model API, but not yet solved by Clarabel
Installation
[]
= "0.2.0"
To disable the default backend:
[]
= { = "0.2.0", = false }
Quick Start
use ;
Constrained Example
use ;
See examples/basic_l2.rs and
examples/clarabel_constrained_l2.rs for runnable examples.
Crate Status
The core modeling API is stable enough for experimentation, but the solver surface is still intentionally small.
For Loss::L2Squared, the Clarabel backend now applies an explicit residual formulation and
optional scaling through SolveOptions, which improves robustness on poorly scaled problems.
If you publish results or build production workflows on top of resopt, pin the crate version and validate solver behavior on your problem family.
Development
The repository includes a pre-commit hook installer:
./scripts/install-git-hooks.ps1
The hook runs:
cargo fmt --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-features