sqp-craft-solver
Optimization ecosystem ·
Shared solver-selection and agent guide
The native SQP driver for the sqp-craft
contracts: damped BFGS, an L1 merit line search, feasibility restoration,
elastic mode, second-order correction and batch solves of many starts. QP
backends: sqp-craft-clarabel
(default) and sqp-craft-activeset.
cargo add sqp-craft sqp-craft-solver sqp-craft-clarabel
use sqp_craft::{
Bounds, CancellationToken, CsrPattern, NlpProblem, Options, ProblemSpec, Result, SqpSolver,
Status,
};
use sqp_craft_clarabel::ClarabelQp;
use sqp_craft_solver::NativeSqp;
struct Toy;
impl NlpProblem for Toy {
fn functions(&mut self, x: &[f64], c: &mut [f64]) -> Result<f64> {
c[0] = x[0] + x[1];
Ok((x[0] - 1.0).powi(2) + (x[1] - 2.0).powi(2))
}
fn derivatives(&mut self, x: &[f64], g: &mut [f64], jac: &mut [f64]) -> Result<()> {
g.copy_from_slice(&[2.0 * (x[0] - 1.0), 2.0 * (x[1] - 2.0)]);
jac.copy_from_slice(&[1.0, 1.0]); Ok(())
}
}
fn main() -> Result<()> {
let spec = ProblemSpec::new(
Bounds::new(vec![0.0, 0.0], vec![4.0, 4.0]),
Bounds::new(vec![f64::NEG_INFINITY], vec![2.0]),
CsrPattern::dense(1, 2),
)?;
let result = NativeSqp::<ClarabelQp>::default().solve(
&spec,
&mut Toy,
&[0.2, 0.4],
&Options::default(),
&CancellationToken::default(),
None,
)?;
assert_eq!(result.status, Status::Converged); println!("{:?}", result.candidate); Ok(())
}
Limits: smooth objective and constraints with first derivatives; at most 256
variables (dense BFGS); a local method, so Converged is a first-order KKT
point within the tolerances, not a global optimum (use several starts for
multimodal models). For larger sparse problems an IPOPT-family solver fits
better. See the API documentation and the
AI agent guide.
Part of SQP-craft, which also holds the
Python package and the job worker. To build from source:
git clone https://github.com/dietmarwo/SQP-craft
cd SQP-craft
cargo test -p sqp-craft-solver --locked
MIT license.