newton_sos/
lib.rs

1//! The `newton_sos` crate defines and solves optimization problems of the form:
2//! $$\max_{c\in\mathbb{R}, B \in \mathbb{S}^n_+} c - \lambda \text{Tr}(B) + t \log \det (B) \qquad \text{s.t. }\quad f_i - c = \Phi_i^T B \Phi_i, \\:\\:\forall i\in[\\![1, N]\\!]$$
3//! using a damped Newton method. Such problems arise from sum-of-squares optimization,
4//! especially in the Kernel Sum-of-Squares (KernelSOS) framework.
5//!
6//! ## Overview
7//! The main components of the crate are:
8//! - [`problem::Problem`]: A struct representing the optimization problem, including data and parameters.
9//! - [`solver::solve`]: A function to solve the optimization problem.
10//!
11//! ## Feature Flags
12//! - `python`: Enables Python bindings using PyO3.
13
14#[cfg(feature = "python")]
15use pyo3::prelude::*;
16
17pub mod problem;
18pub mod solver;
19
20#[cfg(feature = "python")]
21mod py_problem;
22#[cfg(feature = "python")]
23mod py_solver;
24
25#[cfg(test)]
26mod tests;
27
28#[cfg(feature = "python")]
29#[pymodule]
30fn newton_sos(newton_sos: &Bound<'_, PyModule>) -> PyResult<()> {
31    newton_sos.add_class::<py_problem::PyProblem>()?;
32
33    newton_sos.add_class::<py_solver::PySolveResult>()?;
34    newton_sos.add_function(wrap_pyfunction!(py_solver::py_solve, newton_sos)?)?;
35    newton_sos.add_function(wrap_pyfunction!(py_solver::py_solve_parallel, newton_sos)?)?;
36    Ok(())
37}