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 . -DBUILD_BENCHMARKING=ON
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.dev254.tar.gz (120.6 kB view details)

Uploaded Source

Built Distributions

sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-win_amd64.whl (473.0 kB view details)

Uploaded CPython 3.13 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-manylinux_2_35_x86_64.whl (412.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-macosx_10_13_universal2.whl (687.3 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-win_amd64.whl (473.0 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-manylinux_2_35_x86_64.whl (412.5 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-macosx_10_13_universal2.whl (687.4 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-win_amd64.whl (472.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-manylinux_2_35_x86_64.whl (412.7 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-macosx_10_9_universal2.whl (687.9 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-win_amd64.whl (471.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-manylinux_2_35_x86_64.whl (412.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-macosx_10_9_universal2.whl (687.1 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev254-cp39-cp39-win_amd64.whl (472.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev254-cp39-cp39-manylinux_2_35_x86_64.whl (412.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254.tar.gz
Algorithm Hash digest
SHA256 f2f71bdc7a2d4697031476a068ede93b247a9de2a3e5ad6d2ad0a5e66e2e1601
MD5 ff63c9220fe4747dc4dcc5101a2dd242
BLAKE2b-256 f44c29b7424f3edf54b0d018b93213f80a794330a48ff57cea09ade918269bbb

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 686603679072bd38dbef44b6e96da1144a3a04979d3700d5c12d393a10e6aa8f
MD5 bb873906e04299c8b956664ec65c88ba
BLAKE2b-256 8531d8eeb902cb8a0890eae66638df7278e3a09e3f80b926d611326caa2a0ca7

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 80a8e848b5a6be99e5cdfd39fec7b5791cd9f73e055bee5b5a9a13e0698699d0
MD5 cfe3b683beceadc5ed6e5b78ed5d2138
BLAKE2b-256 6737ff357b5675d70b2500f98512fe4ae8a92a5e4e6b82f6338ae41b02dab62d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 faaf2ca3f7b9bda32c3ead2c35a51aaa5eeaa49c76f75f3b73b6f2c560f4e519
MD5 e159a55a0990ae9fc69ec85846dd8928
BLAKE2b-256 26db872a8905bb143c3256305e0ea46e3d0ffa47c5d5501fbb0d1450430d9c64

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 135e60805f579a3c18b93eac9e0b722c609adc2b0d823d5892193ce848a20b32
MD5 941f46802a8349077b0e248dac5939f4
BLAKE2b-256 104ef149a6d395edbed7edc9456fe0ac5a470ed6ef6e48feb8e2d3a202b9116d

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 113b3527efa28f3fb157a1d9ce379be48745396d98cabfd8984f98bd086fe364
MD5 f4ac9f46bf0e42553858e4bfa0dfcb55
BLAKE2b-256 d958ebee16a57d3e8e2a1c37ac60d088c71ac701b0c135481b474732005271d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 f66fea2876744c2a93b1a7438d60092e2122af1a2f7df985a3d7a7b84dbc5a61
MD5 05031924bd805aa27b6caca0bddc8d7d
BLAKE2b-256 fa599c2120786406bcf15f9d682831826f8cb8aa359f4b20dd895354baa750d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3f90311245c4c64c24b55ad63e0785a21a74702a95a6ecb76623309fd86f812a
MD5 acdf00095ecaf2ed527a537f9aaef791
BLAKE2b-256 0ec6d3309a90e015b2f8cf4feba8974ec04bb18c48cb3261c8c64a73acc3e18a

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 06fb71bac16d3285e811a9cca463e98970aed5ff9ac91f1551c3369499f1e66c
MD5 06a0884d9f781b38d70b1a676e34ea14
BLAKE2b-256 645eb7068f83ca58dd0ef71e2fd12a8d2e4ed173d9a2cb7560c4cd0af977df57

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5642808f64ca1d92d885b7bb738aea230ed04b6dc82e945b4b9db619aa94211e
MD5 a3c02458b902fcf23c7787432e87d551
BLAKE2b-256 bd1139a2f1430b4bd386dcf3e223d4a5afaca0e576eff7f62015ef061fcd9767

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bf3fd51a6a3af8cd87b83bb8a7ad9462dd236dc3c1711cf99e1829666d9be6ec
MD5 05c989464b9b69c42d16867be385edae
BLAKE2b-256 cc0bcb39846514640971e0c80465cf149aa81f34bd8f59d18979944bf196480f

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a023b92f2ebe40ed957fd21f7ad3d3638b989e12e4339b031994b09f3329b4e9
MD5 5313fcb872f9d9d78537c2bb5e16d708
BLAKE2b-256 e02a857da639345fa222ad47610b3b62c082df68320c1e955515d53626a4cc3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d2a5ce9e7d8b01362cd863862e49c2f9921c636b092cf8130c6983da64d16711
MD5 9dcd207303fd7286d92f0993f5d2cb2c
BLAKE2b-256 50e0c11d536e6259bc19afc27db736913d2fd06e1411a56bccc999c848ddef45

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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.dev254-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 530f0778292bb0e39bb5e0afe22976a1c29d3e7e2ef68a4b91e58e0667ef6aad
MD5 2f9b5de7a93bf23bd3f0324de8ba1548
BLAKE2b-256 869fd016eb31d731cdf9f320ae805fcff09cd0cda4cf0b7aecfa1a8b6969271a

See more details on using hashes here.

Provenance

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

Publisher: build-python.yml on SleipnirGroup/Sleipnir

Attestations:

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev254-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 42d7bf177e026374431f69b202c7aead9a8962a5aa1ae8a7e64b9079215cdecc
MD5 6ecd5de08920b1ae5e20d792ebfaf059
BLAKE2b-256 383499a1dc1e7fc8765ffcfb2f9eaa093dffbc10c68176e0c316b1793d245815

See more details on using hashes here.

Provenance

The following attestation bundles were made for sleipnirgroup_jormungandr-0.0.1.dev254-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