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.
  • 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.15.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.15.0
File Size Uploaded Provenance Actions
lunopt-0.15.0.tar.gz 215.5 kB With provenance Details for lunopt-0.15.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lunopt 0.15.0
File Interpreter ABI Platform Actions
lunopt-0.15.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.26+ x86-64 Details for lunopt-0.15.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
lunopt-0.15.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.26+ x86-64 Details for lunopt-0.15.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
lunopt-0.15.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.15.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Total release size: 2.3 MB

Release files / lunopt-0.15.0.tar.gz

Download URL lunopt-0.15.0.tar.gz
Size 215.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d247ad18c5fc3736c5fba8237602fb4f3eb7414d041eba4ff4c59e4ee381415f
BLAKE2b-256 checksum
How to use checksums
a9cb2e0a54c483a78e338239dcdb2954af35ddb7564c4f2db44a0fe348a32095
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 28, 2026.

Transparency log

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

Download URL lunopt-0.15.0-cp314-cp314-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 693.7 kB
Tags CPython 3.14 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4fea516556172e2c9ef32aa37145cce299b0ec838d4c80ab647a9de2ec07b7f8
BLAKE2b-256 checksum
How to use checksums
37ff8f9440c12f80af1a14d35e1e1b0f8fc0716a80f418739bf6d52cb941cdf9
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 28, 2026.

Transparency log

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

Download URL lunopt-0.15.0-cp313-cp313-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 693.3 kB
Tags CPython 3.13 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
cecbf9f3e1ea6364333756843c39c76a593333dd51483833447d54a71f989ef4
BLAKE2b-256 checksum
How to use checksums
58bc34ae5e974fcb4ec50b34707e72a0995dcbd1b8ea24d1695ab6eb30fdee7a
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 28, 2026.

Transparency log

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

Download URL lunopt-0.15.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 693.5 kB
Tags CPython 3.12 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
731920a97958fe90ceb4eb7322fc6db2629e87d5dfeb8c21d11ef39cd56b8e69
BLAKE2b-256 checksum
How to use checksums
b3f89122a41fb48f86cbf42bb8ff9b6035b3448ec22b42df2c7617b0d15ef199
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 28, 2026.

Transparency log

Security for lunopt 0.15.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.15.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 28, 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