Skip to main content

LUNOPT

The Lightweight Unified Nonlinear OPTimiser: a sparse SQP for smooth nonlinear programmes, by Luna Space. It is made for optimal control and trajectory optimisation (collocation, single and multiple shooting), tuned and measured on problems of up to about 10^4 unknowns; larger ones solve too, without that tuning.

  • Smooth objectives, equality constraints, inequality constraints and ranges (by slack unknowns: docs/algorithm.md section 1), and bounds.
  • A sparse exact-Hessian SQP. One sparse LDLᵀ factorisation of the KKT system serves the Newton step, the inertia correction, the interior point on the bounds, the second-order corrections and the projection back to feasibility. Its globalisation joins a filter line search to a trust region by regularisation; where it does not converge, a feasibility fallback keeps the best feasible point (or finds one) and improves it, and a time limit answers with the best feasible point met.
  • The Hessian by differences of the gradient, for problems with first derivatives alone: the unknowns grouped by the Hessian's sparsity (Powell and Toint's symmetric grouping), so that a Hessian costs one gradient and Jacobian a group (lunopt/differences.hpp).
  • A quasi-Newton Hessian for problems whose evaluations are dear (propagations: single and multiple shooting): each function's Hessian kept by symmetric rank-one updates of its own gradient's changes, at no evaluation beyond the iterations' (lunopt/quasi_newton.hpp).
  • An optimum's parametric sensitivity: the derivatives of the answer, its multipliers and its objective (to second order) with respect to the problem's parameters, by the KKT system on the active set, with the range over which the active set holds and one-sided derivatives at weakly active bounds (lunopt/sensitivity.hpp).
  • A diagnosis of a solve: the violated constraints, the prices, the bounds held, the dependent constraints and the unknowns nothing depends on.
  • A dense SQP with a damped BFGS update and an active-set QP, for small problems.
  • Header-only C++23 on Eigen 5; dual numbers for problems by automatic differentiation.
  • Python bindings (lunopt.minimise) and a pygmo algorithm (pygmo.algorithm( lunopt.sqp() )).

Use

#include <lunopt/ad.hpp>
#include <lunopt/sparse_sqp.hpp>

// min x0^2 + x1^2  subject to  x0 x1 = 1,  x0 >= 0.
const auto problem = lunopt::sparse_by_ad(
    { lunopt::Variable{ .name = "x0", .lower = 0.0 }, lunopt::Variable{ .name = "x1" } },
    { lunopt::Constraint{ .name = "product", .target = 1.0, .tolerance = 1e-10 } },
    []( const auto& x ) { return std::vector{ x[0] * x[1] }; },
    []( const auto& x ) { return x[0] * x[0] + x[1] * x[1]; } );
const auto r = lunopt::minimise_sparse( problem, Eigen::VectorXd{ { 2.0, 0.3 } } );
// r->z = ( 1, 1 ), r->converged; on failure, lunopt::diagnose( problem, *r ) says why.

(examples/readme.cpp, run by the tests.) A large problem gives its sparse Jacobian and the Lagrangian's Hessian itself (lunopt::SparseProblem). With CMake:

add_subdirectory(lunopt)  # or FetchContent; Eigen 5.0.1 fetched unless Eigen3::Eigen exists
target_link_libraries(your_target PRIVATE lunopt::lunopt)

Python

import numpy as np
import lunopt

# min x0^2 + x1^2  subject to  x0 x1 = 1,  x0 >= 0
problem = lunopt.Problem(
    objective=lambda x: x @ x,
    gradient=lambda x: 2 * x,
    constraints=lambda x: [x[0] * x[1] - 1.0],
    jacobian=lambda x: [[x[1], x[0]]],                       # or a scipy.sparse matrix, or ( rows, columns, entries )
    hessian=lambda x, s, y: [[2 * s, 0.0], [y[0], 2 * s]],   # of s f + y^T c; its lower triangle read
    lower=[0.0, -np.inf],
)
r = lunopt.minimise(problem, [2.0, 0.3], progress=True)     # r.x = ( 1, 1 ), r.multipliers = ( -2 ), r.converged

Constraints have ranges (constraint_lower, constraint_upper; equal bounds make an equation); without a Hessian the solver takes it by differences of the gradient (method="differences", on the problem's hessian_pattern or the one its derivatives' structure gives), by quasi-Newton updates where an evaluation is dear (method="quasi-newton"), or, for small problems, a damped BFGS matrix (method="bfgs"); a function may raise lunopt.PointRefused where it cannot evaluate a point, and the solver takes a shorter step; lunopt.diagnose( problem, r ) says why a solve ended where it did. An optimum's sensitivity to the problem's parameters q:

def problem_at(q):                      # the problem made at q (here x0 x1 = q[0]): anything of it may depend on q
    return lunopt.Problem(
        objective=lambda x: x @ x,
        gradient=lambda x: 2 * x,
        constraints=lambda x: [x[0] * x[1] - q[0]],
        jacobian=lambda x: [[x[1], x[0]]],
        hessian=lambda x, s, y: [[2 * s, 0.0], [y[0], 2 * s]],
        lower=[0.0, -np.inf],
    )

q = np.array([1.0])
r = lunopt.minimise(problem_at(q), [2.0, 0.3])
s = lunopt.sensitivity(problem_at, q, r, second_order=True)
# s.x: dx*/dq = ( 0.5, 0.5 ); s.objective, s.second: df*/dq = 2, d2f*/dq2 = 0 (f* = 2 q); s.range_ahead,
# s.range_behind: how far along each parameter the active set holds; s.predict( r.x, dq ), s.predict_objective( r.f,
# dq ): the optimum at q + dq

In pygmo:

import pygmo as pg
pop = pg.algorithm(lunopt.sqp()).evolve(pg.population(pg.problem(pg.hock_schittkowski_71()), 5))

The module is built by CMake (-DLUNOPT_PYTHON=ON, a Python 3.12+ with nanobind 3.1; the gate and clang presets use the repository's .venv-python) into build/<preset>/python/lunopt.

Install

  • C++: header-only. With CMake, add_subdirectory or FetchContent of this repository (Eigen 5.0.1 is fetched where the project has no Eigen3::Eigen target), or cmake --install it and find_package( lunopt ) (an installed Eigen 5 then); link lunopt::lunopt. A C++23 compiler: GCC 15 or 16, Clang 22.
  • Python: pip install lunopt (Linux wheels for CPython 3.12 to 3.14, from the first public release; numpy, and pygmo for lunopt.sqp), or from source with pip install . (scikit-build-core, CMake, a C++23 compiler).

Build and test

bash tools/check.sh            # the gate: GCC, Clang, the sanitizers, clang-format, clang-tidy
bash tools/check.sh gate       # one build and its tests (GCC)

The presets are in CMakePresets.json; the Python tests use Python 3.12 in .venv-python with nanobind 3.1.0 and pygmo. The benchmarks against IPOPT on CUTEst's problems are in docs/benchmarks.md, with how to run them (bench/).

Documentation

  • docs/algorithm.md: the algorithm, with the equations the code's comments cite.
  • docs/benchmarks.md: the measurements, on CUTEst's problems against IPOPT.
  • CHANGELOG.md: every version's changes.
  • The headers' comments document the C++ API; the Python functions' docstrings document theirs.

Status and roadmap

In development: the API may still change before 1.0. LUNOPT was extracted from Luna Space's flight dynamics engine, where it designs many-revolution low-thrust transfers. Next:

  • conda-forge, beside the Linux wheels on PyPI;
  • a stronger handling of inequality constraints, linear and nonlinear: 0.15.0 closed part of the gap to IPOPT on CUTEst's problems with inequalities, still the benchmarks' weakest part;
  • an API reference and a user's guide, with examples in C++ and Python;
  • LUNOPT as a pagmo algorithm in C++, beside the Python one for pygmo.

Licence

LUNOPT is free software under the Mozilla Public License 2.0: use it in any program, open or proprietary; changes to LUNOPT's own files are shared under the same licence when you distribute them. Copyright © 2026 Luna Space Ltd. Third-party software in the binary packages: THIRD_PARTY_NOTICES.md. Contributing: CONTRIBUTING.md; conduct: CODE_OF_CONDUCT.md; security reports: SECURITY.md.

Metadata

Release files for lunopt 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lunopt 0.17.0
File Size Uploaded Provenance Actions
lunopt-0.17.0.tar.gz 224.0 kB With provenance Details for lunopt-0.17.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lunopt 0.17.0
File Interpreter ABI Platform Actions
lunopt-0.17.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.26+ x86-64, Linux glibc 2.28+ x86-64 Details for lunopt-0.17.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
lunopt-0.17.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.26+ x86-64, Linux glibc 2.28+ x86-64 Details for lunopt-0.17.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
lunopt-0.17.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.26+ x86-64 Details for lunopt-0.17.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Total release size: 2.3 MB

Release files / lunopt-0.17.0.tar.gz

Download URL lunopt-0.17.0.tar.gz
Size 224.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4267fe4574c5d61954f1ed4aa1fcfd13cad981bd2f12ae837cbe8eccf457a615
BLAKE2b-256 checksum
How to use checksums
d5864c9edd44b002e972caf5ac289a4b084670ac6c45872da88819efe83cb96a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / lunopt-0.17.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Download URL lunopt-0.17.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 697.8 kB
Tags CPython 3.14 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
09a11a201a52ca44cbda60aebd5465954a193a8366e70577296e56bdfc297dda
BLAKE2b-256 checksum
How to use checksums
60dabf033d8c2bdc79f914045c5e5ce70cf121dba1a2f9834cb4c8e764f3ba00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / lunopt-0.17.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Download URL lunopt-0.17.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 697.5 kB
Tags CPython 3.13 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
15af0d8d5c042f62b1cb0c88157f24c6c381a23792a39258427e4b0a95eecce2
BLAKE2b-256 checksum
How to use checksums
f6c1590f7fe1c2f120826ebb39e3a5b573d9b195b7b4c9ae16dab3e307f47c34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / lunopt-0.17.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Download URL lunopt-0.17.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 697.6 kB
Tags CPython 3.12 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
55abd5a2b75b0e7d71c441c8a764041e97f44d706eedf263b09b9a273d1f5642
BLAKE2b-256 checksum
How to use checksums
3f77463e274ddaceac48cc74c592cb4128a2b5edf4fdd79d94b53f844bb4995a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for lunopt 0.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for lunopt-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page