Skip to main content

A linearity-exploiting sparse nonlinear constrained optimization problem solver that uses the interior-point method.

Project description

Sleipnir

C++ Build Python Build PyPI Downloads Website C++ API Python API Discord

Sparsity and Linearity-Exploiting Interior-Point solver - Now Internally Readable

Named after Odin's eight-legged horse from Norse mythology, Sleipnir is a linearity-exploiting sparse nonlinear constrained optimization problem solver that uses the interior-point method.

#include <print>

#include <sleipnir/optimization/OptimizationProblem.hpp>

int main() {
  // Find the x, y pair with the largest product for which x + 3y = 36
  sleipnir::OptimizationProblem problem;

  auto x = problem.DecisionVariable();
  auto y = problem.DecisionVariable();

  problem.Maximize(x * y);
  problem.SubjectTo(x + 3 * y == 36);
  problem.Solve();

  // x = 18.0, y = 6.0
  std::println("x = {}, y = {}", x.Value(), y.Value());
}
#!/usr/bin/env python3

from jormungandr.optimization import OptimizationProblem


def main():
    # Find the x, y pair with the largest product for which x + 3y = 36
    problem = OptimizationProblem()

    x = problem.decision_variable()
    y = problem.decision_variable()

    problem.maximize(x * y)
    problem.subject_to(x + 3 * y == 36)
    problem.solve()

    # x = 18.0, y = 6.0
    print(f"x = {x.value()}, y = {y.value()}")


if __name__ == "__main__":
    main()

Sleipnir's internals are intended to be readable by those who aren't domain experts with links to explanatory material for its algorithms.

Benchmarks

flywheel-scalability-results cart-pole-scalability-results
flywheel-scalability-results-casadi.csv
flywheel-scalability-results-sleipnir.csv
cart-pole-scalability-results-casadi.csv
cart-pole-scalability-results-sleipnir.csv

Generated by tools/generate-scalability-results.sh from benchmarks/scalability source.

  • CPU: AMD Ryzen 7 7840U
  • RAM: 64 GB, 5600 MHz DDR5
  • Compiler version: g++ (GCC) 14.2.1 20240805

The following thirdparty software was used in the benchmarks:

  • CasADi 3.6.7 (autodiff and NLP solver frontend)
  • Ipopt 3.14.16 (NLP solver backend)
  • MUMPS 5.7.0 (linear solver)

Ipopt uses MUMPS by default because it has free licensing. Commercial linear solvers may be much faster.

See benchmark details for more.

Install

Minimum system requirements

Sleipnir requires somewhat newer operating systems and C++ runtimes for std::print().

  • Windows
  • Linux
    • OS: Ubuntu 24.04
    • Runtime: GCC 14 libstdc++ (run sudo apt install g++-14)
  • macOS
    • OS: macOS 14
    • Runtime: Apple Clang 15.0.0 libc++ from Xcode 15.3 (run xcode-select --install)

C++ library

See the build instructions.

Python library

pip install sleipnirgroup-jormungandr

API docs

See the C++ API docs and Python API docs.

Examples

See the examples, C++ optimization unit tests, and Python optimization unit tests.

Build

Dependencies

  • C++23 compiler
    • On Windows 10 or greater, install Visual Studio Community 2022 and select the C++ programming language during installation
    • On Ubuntu 24.04 or greater, install GCC 14 via sudo apt install g++-14
    • On macOS 14 or greater, install the Xcode 15.3 command-line build tools via xcode-select --install
  • CMake 3.21 or greater
    • On Windows, install from the link above
    • On Linux, install via sudo apt install cmake
    • On macOS, install via brew install cmake
  • Python 3.9 or greater
    • On Windows, install from the link above
    • On Linux, install via sudo apt install python
    • On macOS, install via brew install python
  • Eigen
  • nanobind (build only)
  • Catch2 (tests only)

Library dependencies which aren't installed locally will be automatically downloaded and built by CMake.

The benchmark executables require CasADi to be installed locally.

C++ library

On Windows, open a Developer PowerShell. On Linux or macOS, open a Bash shell.

# Clone the repository
git clone git@github.com:SleipnirGroup/Sleipnir
cd Sleipnir

# Configure; automatically downloads library dependencies
cmake -B build -S .

# Build
cmake --build build

# Test
ctest --test-dir build --output-on-failure

# Install
cmake --install build --prefix pkgdir

The following build types can be specified via -DCMAKE_BUILD_TYPE during CMake configure:

  • Debug
    • Optimizations off
    • Debug symbols on
  • Release
    • Optimizations on
    • Debug symbols off
  • RelWithDebInfo (default)
    • Release build type, but with debug info
  • MinSizeRel
    • Minimum size release build
  • Asan
    • Enables address sanitizer
  • Tsan
    • Enables thread sanitizer
  • Ubsan
    • Enables undefined behavior sanitizer
  • Perf
    • RelWithDebInfo build type, but with frame pointer so perf utility can use it

Python library

On Windows, open a Developer PowerShell. On Linux or macOS, open a Bash shell.

# Clone the repository
git clone git@github.com:SleipnirGroup/Sleipnir
cd Sleipnir

# Setup
pip install --user build

# Build
python -m build --wheel

# Install
pip install --user dist/sleipnirgroup_jormungandr-*.whl

# Test
pytest

Test diagnostics

Passing the --enable-diagnostics flag to the test executable enables solver diagnostic prints.

Some test problems generate CSV files containing their solutions. These can be plotted with tools/plot_test_problem_solutions.py.

Benchmark details

Running the benchmarks

Benchmark projects are in the benchmarks folder. To compile and run them, run the following in the repository root:

# Install CasADi and [matplotlib, numpy, scipy] pip packages first
cmake -B build -S .
cmake --build build
./tools/generate-scalability-results.sh

See the contents of ./tools/generate-scalability-results.sh for how to run specific benchmarks.

How we improved performance

Make more decisions at compile time

During problem setup, equality and inequality constraints are encoded as different types, so the appropriate setup behavior can be selected at compile time via operator overloads.

Reuse autodiff computation results that are still valid (aka caching)

The autodiff library automatically records the linearity of every node in the computational graph. Linear functions have constant first derivatives, and quadratic functions have constant second derivatives. The constant derivatives are computed in the initialization phase and reused for all solver iterations. Only nonlinear parts of the computational graph are recomputed during each solver iteration.

For quadratic problems, we compute the Lagrangian Hessian and constraint Jacobians once with no problem structure hints from the user.

Use a performant linear algebra library with fast sparse solvers

Eigen provides these. It also has no required dependencies, which makes cross compilation much easier.

Use a pool allocator for autodiff expression nodes

This promotes fast allocation/deallocation and good memory locality.

We could mitigate the solver's high last-level-cache miss rate (~42% on the machine above) further by breaking apart the expression nodes into fields that are commonly iterated together. We used to use a tape, which gave computational graph updates linear access patterns, but tapes are monotonic buffers with no way to reclaim storage.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleipnirgroup_jormungandr-0.0.1.dev251.tar.gz (120.6 kB view details)

Uploaded Source

Built Distributions

sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-win_amd64.whl (469.8 kB view details)

Uploaded CPython 3.13 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-manylinux_2_35_x86_64.whl (410.0 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-macosx_10_13_universal2.whl (683.4 kB view details)

Uploaded CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64)

sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-win_amd64.whl (469.8 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-manylinux_2_35_x86_64.whl (410.0 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-macosx_10_13_universal2.whl (683.4 kB view details)

Uploaded CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)

sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-win_amd64.whl (469.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-manylinux_2_35_x86_64.whl (410.3 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-macosx_10_9_universal2.whl (684.2 kB view details)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-win_amd64.whl (469.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-manylinux_2_35_x86_64.whl (410.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-macosx_10_9_universal2.whl (684.6 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-win_amd64.whl (470.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-manylinux_2_35_x86_64.whl (410.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251.tar.gz.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251.tar.gz
Algorithm Hash digest
SHA256 02efaaf3ee70ff6f3b16af0461a26b1c9f15ab4fbad6b6c862da00a58530b229
MD5 9f8785ad7bc9b550e89bbe681ced422b
BLAKE2b-256 d778db009f567de4beded9f56398164c23d39c456c5192d1117e90c75f9a98ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251.tar.gz:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6a8e4a56cac16ad742294f027b923ead8585e115664a5fa2bd1483679a6795d7
MD5 658a66f34d4659aad60dcc1053720e13
BLAKE2b-256 f91f103c33798425c37e5772e64b04f70b50963cca35c66c5d104b71595cf1e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-win_amd64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9b4d84c733ae0d603cee4cff8bf23118e37b131a5ac32176d5444e79327aeff0
MD5 d73c35ced4acb931c28b72847e691b35
BLAKE2b-256 3e0c9ede1cb442410e101334cdcaf92a704ae32dbee5702f395950f98f4a61e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-manylinux_2_35_x86_64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 0af43f4bff7f516f159ab9188953feba15e1a8e0714f797a76e1ca4bdb24274e
MD5 afcdadd7579545725595ec3fe0a598fb
BLAKE2b-256 fb384a8a5ab65edae447e1161ad497e80af4774e6247604a14d0081796183e0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4d4154784f538c8f0a06fa59ffac8fd7e516efbc445c7c136cbee07de8a5aae8
MD5 c0b8a29728995f67aa4fa4284799b32f
BLAKE2b-256 4ee311638609f972713a4a975e5dd18fd56351bfa1596981261e6226be12f06a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-win_amd64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c4599e71ebe02cf377288bb4bf5d6d29b33d3c5b043ba6bbee2b378ab0126ff1
MD5 73afa5e9534339c1885c093373512067
BLAKE2b-256 114fa1092b83b97aa7996fc8919ab40850bd4bf5832c54f4303460f1b12d14cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-manylinux_2_35_x86_64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b8bf57d8db030cbeca51644e282d9379d5d9b3663963eca3395465d0c6a3aee8
MD5 4aac42d63803b385206ad605d46b986c
BLAKE2b-256 ce5253b461f37502adb9fdff3b9ea54201fe97f2b5832b42cd069ba3b7e2dd70

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5ea144b6e190571e93d0d0aa202ff2dcf87a05906cc139ab3e9e29fd4e6b372a
MD5 8bd97f5b6fd4c8bfe7819295c0ff5cdb
BLAKE2b-256 85769526b6c988b8ff7cfea0e88388a45cdd8d04259b533f53ef4ca6df3d94ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-win_amd64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 33c0906de3a4b79fb7d7d7b43597b6718f07feed203b4ba3ad04523c62a18392
MD5 82dfd015183f90fe4bda231a7fc5e0e3
BLAKE2b-256 1d4bea263d3a17ef764169e91fac7a34318d4d0f119b3d6a63e6f3d11c41bd36

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-manylinux_2_35_x86_64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 089ecc49b01eea8410275823cc42be98e86e618835972226963f43771f4d3493
MD5 d061a2631f7f8432ab31d567f66d4315
BLAKE2b-256 abd76ab4d2e062d7e57e0c53ffeb7f931c50de133bdc91312b732e8a6037d009

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1c22cb0c3f0d20517de2bd6d73ff8a991e887369aef475c9cc27d243f38e107c
MD5 99ad17edc8dbbea41a925ce716d786c8
BLAKE2b-256 725fb303e1c9fb629b624c8759d0a5817f14e57a2f4afe2c74971fafb98e4f4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-win_amd64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 372bd3772a68d12771444ac04779b92bf8a07e6ead48fa94e48e56c020ad2ea1
MD5 259d9451045eeb15081c224faa1f74fc
BLAKE2b-256 c98b584b2ce001ec59d0291987cd3fd9664c0568e23e2785aa1db4a2d4fc84be

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-manylinux_2_35_x86_64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9324a111e63a69e41259e6564bced358a73a25cb486c0b53ba37e64b1b2ca6cb
MD5 8c655aeebc7e4593255e95acde23f133
BLAKE2b-256 502d9e95b523ff3aad3e28a9f5854bc7f4d527507715e9dcbfaee8c4508da6e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c2118e30ad00c283e6efbb84d319d4f243c19d9b314a7842c2747699708918c1
MD5 abd976d5561a44e45eeab3d0d7a83009
BLAKE2b-256 1c85c1d4fa263b480668ff45eddaf0b757fdfc332dad03bc43f738a35beac9ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-win_amd64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6edbe03baa5bc1615690f28007d433460983a7bde69422e24077e829e0774d40
MD5 fd97850a48dc7959a009b917b8a32caa
BLAKE2b-256 ad305f853ada2e56871f151a19884d4ccb5d5bcbc74fb5f36ceeda77fdf4da2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev251-cp39-cp39-manylinux_2_35_x86_64.whl:

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page