Skip to main content

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

Project description

Sleipnir

Build C++ Documentation 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 <fmt/core.h>
#include <sleipnir/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
  fmt::println("x = {}, y = {}", x.Value(), y.Value());
}
#!/usr/bin/env python3

import jormungandr as jmg


def main():
    # Find the x, y pair with the largest product for which x + 3y = 36
    problem = jmg.optimization.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 on a AMD Ryzen 7 7840U with 64 GB RAM. The following thirdparty software was used in the benchmarks:

  • CasADi 3.6.4 (autodiff and NLP solver frontend)
  • Ipopt 3.14.13 (NLP solver backend)
  • MUMPS 5.5.1 (linear solver)

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

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.

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.

Examples

See the examples and optimization unit tests.

Dependencies

  • C++20 compiler
    • On Windows, install Visual Studio Community 2022 and select the C++ programming language during installation
    • On Linux, install GCC 11 or greater via sudo apt install gcc
    • On macOS, install the Xcode command-line build tools via xcode-select --install. Xcode 13 or later is required.
  • 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.11 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
  • fmtlib (internal only)
  • pybind11 (build only)
  • Catch2 (tests only)

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

If CasADi is installed locally, the benchmark executables will be built.

Build instructions

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

C++ library

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

# Build
cmake --build build

# Test
cd build
ctest
cd ..

# 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

# 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.

Branding

Logo

SVG, PNG (1000px)
Font: Centaur

Color palette

Purple Yellow
6D3D94 FDB813

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.dev48.tar.gz (95.2 kB view details)

Uploaded Source

Built Distributions

sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-win_amd64.whl (411.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-manylinux_2_35_x86_64.whl (476.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-macosx_10_9_universal2.whl (472.3 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-win_amd64.whl (412.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-manylinux_2_35_x86_64.whl (476.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-macosx_10_9_universal2.whl (468.5 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-win_amd64.whl (412.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-manylinux_2_35_x86_64.whl (474.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-macosx_11_7_x86_64.whl (466.9 kB view details)

Uploaded CPython 3.10 macOS 11.7+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-macosx_10_9_universal2.whl (410.4 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-win_amd64.whl (397.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-manylinux_2_35_x86_64.whl (474.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-macosx_11_7_x86_64.whl (467.0 kB view details)

Uploaded CPython 3.9 macOS 11.7+ x86-64

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48.tar.gz
Algorithm Hash digest
SHA256 fbc3712d2c7a8a31059440100f7356e38307130ab49c4015ee230304ae36e42e
MD5 4abef00b50100d55ebae17f1a397863a
BLAKE2b-256 c0f8c558bda61b72eadb32cfe9737be6d83372bfc378b232ade3d316cb944b0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 025a3ce7547b020e562ddf04270089efa7d09b0e08ebfd16a73691ce6dc39783
MD5 62b73cfea491b960b4c310d150e21c57
BLAKE2b-256 a078f5ba4e0040165da47bc9e6bbae741094c325948cbce249ea3cf0e2c19885

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 874571f179a25dfebed07c6cf15ded6ea54c6a5595966722de3aefb91b8f6df9
MD5 4fd3f05327d3b20fe726b92cb105ecca
BLAKE2b-256 0da546016b23d233d55f27942a81ab23d60dbc8d0aa6ee0a3859b80a967269b2

See more details on using hashes here.

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 68b97479729234755162b995fc8a643647bc048f3edcad7ac34d06fc7ccad633
MD5 9db9320cba1c18e7e9f1b8f52e55271e
BLAKE2b-256 a4ed7f2410de472cfb2f3b18d8a8d9422b01deff293546605c0d8628de55c4d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 04f928ac7299e89b179b287bdd0de69abb7e72cbf9fcc35cf3bd1a024e6e8884
MD5 4af88d4e9688f11e8b0d86bbfabca3f1
BLAKE2b-256 7ff50b6c3b4f60cf2967d639fd6ab78a06066b34f4fecab3fa5b8e9a217e3f60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 0b8ecc2a39771f13e8c23e8337fe3552959430f614195d4fa95295a7557ee356
MD5 7f212f5dbb507530d0825e4058ad8ac1
BLAKE2b-256 971fdf0b55b5d8f867c0fd513bcde1fe0fc5268ea96cdc177191f6a0c275f931

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4b112a2aeddbc1325b21a279c2b2d86ce86d967b9530ba5a40e3be8fc7e46f9d
MD5 ad50a53362e5d0b355eb36b445c7b8e0
BLAKE2b-256 8fc4b4a988e4ec467485e1b7af3e97f1fc9672dabf562e4c8f308425d22e0e6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cfb9ad4fb84cdeef74b67db1c94414ec6331217c3706db55acf96af7fd5db58e
MD5 daf598fd69a7e50784718c93253af56c
BLAKE2b-256 2f690104c1df984b0fd62106f531fdd8d2c665785411c86920c8895750660049

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1a2afc99cee05034e1aa1f780e83e3b5150c6b464c2858715c2dac35fe2887ee
MD5 dd91121bfd6a5afd6cc5664a778db5b7
BLAKE2b-256 33d2d90f02d58d7e6138a6590112e4fb058ec1f3bd4594c94155de42ee7d294b

See more details on using hashes here.

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-macosx_11_7_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 f79a7a94485766cbe513917a59faf14df47ce33536c231f8078471cdd61ed711
MD5 210f8d4439bec63a7f47bb8f9680288d
BLAKE2b-256 c649afeb3ac4b6b6453399416c4c91c6b51b2656fffa94b44cfbdd924861decd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9d90ecf0c139bc2ac521a8021cef3e25ed2406f84b734881f4fdfaa4e3f7d177
MD5 8cc4c80109797c8d50a497738351aabb
BLAKE2b-256 bb0f05cc194245c887f8e902896b66bea2375def9927a6af011602875ca62fa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 44740e33be4582413679c4da1015b59993319a7179e664add38ed28618e4322c
MD5 8586f2ea2d391f9b12d2a85325ac6234
BLAKE2b-256 a48aab6d9517c6c0a6c5e41485e470729b55a93dd5cee82635b5c4a9be1034f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a099b60832a1ed2e0b9c6d79a8cba8a5777dd450302e46d828ddda40bd546bd2
MD5 517603ad2c6350a744be4b00c865c599
BLAKE2b-256 ff0b9ac6a2d7e3b90e1dcd1989f86fe436088006f530d5164197e054bcd921f2

See more details on using hashes here.

File details

Details for the file sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-macosx_11_7_x86_64.whl.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev48-cp39-cp39-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 b65951c07e5ea8cbc4366e2c5951dbc7f2ede003d6059c4067b37397f5b63818
MD5 7608353a25b2a05e654dae34ac011f54
BLAKE2b-256 1c1ff64c0542eaef7789406541d4fa5570f60599591c2de900262f726e55b497

See more details on using hashes here.

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