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

Uploaded Source

Built Distributions

sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-win_amd64.whl (424.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-manylinux_2_35_x86_64.whl (488.1 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-macosx_10_9_universal2.whl (506.8 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-win_amd64.whl (425.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-manylinux_2_35_x86_64.whl (487.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-macosx_10_9_universal2.whl (502.6 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-win_amd64.whl (424.8 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-manylinux_2_35_x86_64.whl (486.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-macosx_11_7_x86_64.whl (501.5 kB view details)

Uploaded CPython 3.10 macOS 11.7+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-macosx_10_9_universal2.whl (434.2 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-win_amd64.whl (410.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-manylinux_2_35_x86_64.whl (486.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-macosx_11_7_x86_64.whl (501.5 kB view details)

Uploaded CPython 3.9 macOS 11.7+ x86-64

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69.tar.gz
Algorithm Hash digest
SHA256 d636133d459a7a72f3d54816c10d5ba3b45836b2cade80c689d1b0754a291659
MD5 cad818d2707e7210b00adeac30ebe0dc
BLAKE2b-256 8484e0998393c74f0dc3939b189f1cd31e3670af7c1e9291687eb2b0355c10f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 99671cc76dfe5fd33d66fe0aa3a6ba6f1b30e230e3800c6e9e46730f0beb6c4e
MD5 e9f718643a109e6778ab07c4767f62f0
BLAKE2b-256 19ba9a2365b6a2d29eb83da526dd3c8d9dd0110aff254fcb4d837dfbc64781df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 21e007559716b6f4d826e7982937376786fb29ce8ad1378256f278ab30d06c64
MD5 18b4d201ed5f1c75ee675ba1bafd42ec
BLAKE2b-256 d1140ba5847dd7382d43be95960b7fa795461bcb216853447b8fb325b28e9b8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 16ac73ffcd51370003d9f25bef6779fee3a7e68ac0318fd45a05eeb667182af7
MD5 3f78f94cebcbb2c51a8235d32119e9ec
BLAKE2b-256 745d9ed3d6a57adb35a21c998be770e97f622779b74015ec03465bb2abdbe838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5d9de5e3140344249ec37ba7607f314fd2b3da2edeefba708a159a59555b70e8
MD5 f0eace2c47c76d3cac2ce59026ad0c6c
BLAKE2b-256 5fa5fe12566ce96201427fbb84817f1f194e9189f4ebb52573b2b479f1f33891

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d08744d207b69e29eae17935a7c2640edb6ace87063862047071341d45050b92
MD5 85f7a33f371ea0866f00f7b2308f28a4
BLAKE2b-256 734c17c50ca0abace0cd2ba47028f02e121c6271aa9ff017705887e57fe51f07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 02d06f3462c0a5a8f5c6c2a58637091f5da856b76d153040b69403e9754f683d
MD5 afc775f4762df2046ade52c1ca0a0fb0
BLAKE2b-256 b4415ec3bc167f19cce1b2e96159b77772c2630560ca02bab765f5218edeed48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dc99a249ae8fef1dd67c434a628420f7698e0f045c9d45b7e427c7e54f90dacd
MD5 b96cbc745adfe1b81f4448af8f204667
BLAKE2b-256 50605f6a8d686e4da9ae9c0faa54cbfb8a99f880c5b24e267ce2512fce9cea46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a829f1a37642c10b1f3c95b1821e37de8887663a003e46b435abf6ae8deae47c
MD5 8c0f3143606f45bb1274dd67fe1ed595
BLAKE2b-256 c9ac6b8a7981fed5f36043828f4af320271a9f9822ae32a8a5e28213e45bd3c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 f74b2281eff4aad5474855582ea663c5b78def04220018d1401723d8e4d65e6a
MD5 7262334563558d1933c036074fac75dc
BLAKE2b-256 74110c355920ff41f113a183e28dbaccba228bf5a34b37043b2fb3d5466b5859

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b9838d5f42fc8e8f5577317a4e6f329ec11b3796af2d604427566f91f6561636
MD5 01656a4f199ccffd639ba15b0cc24a28
BLAKE2b-256 e195070f28db960796d3581708c4d867a39b7c8d51fdfc177777bf8dc64d49fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b5fac9f1e6c8e53c559b0279461419374029670b6111ca326b2e817f33404440
MD5 3fbe561858cd86fd1164a8d7d6ff028e
BLAKE2b-256 62590a8367f4188a88e38b79d54afc4d1d2e179e186fb74bdad558ae5f520a33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 85cce68241a1839098a9ffbfd3c1cccd8596b1914387e3fabedd0ed03f6ec27d
MD5 6830505fa4b6a6264de00dc8dd7256ed
BLAKE2b-256 6104b445cdf715b749371d5d23ff271ac5fdad6b393428ba5fde614de5b0ac30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev69-cp39-cp39-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 aebe82a2d6418dd16c991f5769352f62bbdf7fc583adb86865891c2dbf66e524
MD5 9ffd5370459159242798ebf1ee254e79
BLAKE2b-256 beb506596607b08209c8ca9e948d0c32d4b12144274da7cc2f8ca74faf3307ea

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