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::print("x = {}, y = {}\n", 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.dev37.tar.gz (93.2 kB view details)

Uploaded Source

Built Distributions

sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-win_amd64.whl (402.3 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-manylinux_2_35_x86_64.whl (463.9 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-macosx_10_9_universal2.whl (462.2 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-win_amd64.whl (403.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-manylinux_2_35_x86_64.whl (464.6 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-macosx_10_9_universal2.whl (458.7 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-win_amd64.whl (402.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-manylinux_2_35_x86_64.whl (463.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-macosx_11_7_x86_64.whl (457.5 kB view details)

Uploaded CPython 3.10 macOS 11.7+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-macosx_10_9_universal2.whl (402.6 kB view details)

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

sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-win_amd64.whl (388.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-manylinux_2_35_x86_64.whl (464.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-macosx_11_7_x86_64.whl (457.5 kB view details)

Uploaded CPython 3.9 macOS 11.7+ x86-64

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37.tar.gz
Algorithm Hash digest
SHA256 ccdc7c97be643f6dc772c069837832f3a963b202e5879c168b99db59e9591abc
MD5 7ad908167e8c1027d20ec97c25ada745
BLAKE2b-256 3328755e2e5c58ecb431ce51a86893871b706807ceb470f7a0e5bddba1cf96ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 36d46cb44fe79391a07060219f9bcc4be21eddd4f14266ee477e0532fd875656
MD5 815b0dcaaaa8b379b223447136b44339
BLAKE2b-256 7602ed48e701a101e46907f6e8046a8095a14624b5a5ed3aed813ab316843fda

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 5fe7a1385ee39b5250b2fc2d2fe8fc015998660adf1252fe49f33feb258294aa
MD5 34a7199dbc36468efd81ad12bf72a5d5
BLAKE2b-256 f6bb7deeca0a358018bb9f07d995ccaa0cac233514c6e9ba178e4afb6efa89d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 13bc0117d21b17d7f5869676bb5bcf25a49492489f81f5d5fcaa9ce33cc4328d
MD5 d6533da89f16e3da7d3948d41af1078e
BLAKE2b-256 48544e57e65c1cf22e460b48eafa0d47cbf0eb665b2fd1a048ea5cb0bc6f044d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 33913731421ad5e392a367add0417682b57b3d4d7d6897d959516f0925e7692b
MD5 38ea43bf5ed47986634d875c081dc98f
BLAKE2b-256 314d449a737378ffae57c92d8e10c8530d2faa03f8d2c95b72ae9e395f6af792

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 2a185ee02707f7c48455c92b9168ab672ab0b107ee12beaf020b07a1ee9dcccc
MD5 1c223f84af3ed72ed1af7472441d0fb7
BLAKE2b-256 867c2333af0f408e7d67980dabf8d8f41b729f1d37a7273e02f00cbd8f2d8bb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c8bfcdc44a038dd7d23966ff1054e450b4f12b03dd7c63a1b90a2095977c96c8
MD5 7d3b9889143b1ac8c76bdf5ff62dd302
BLAKE2b-256 baaaefa278a562e879a11212b3fe3cb0cc6659be87840d27aa52b22d8414ccd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e6fff9cc6d5406bab5c9561220bcf682825c8316ccad825028a281dc8c1a230e
MD5 f5ccf82d24ca97aa2fbad8a86ae3bac9
BLAKE2b-256 7f9a8b45e34d379cee76df83c097f056a56971afa68d1e5e2e4ef1d58cda7ef5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ac4d3c2b5872c9c34bc4d55fdd4be0e825c2d466ee56f3370147e2939f30fa4d
MD5 7084e74e290bdf0bbdfa177ab5e54070
BLAKE2b-256 3eff7445f50831ba501bcc6966ec0088be42f2d7116bb660dcefce00c5e3ad06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 7d84af5e844a6adbaddde279ae76035e5210878430957b41d8442c2f6e46faa2
MD5 faf03700300d6ab0670afdaeba8b78ee
BLAKE2b-256 1ec9736e4bbef5d7c0b542b038e980c560e10946360b8dcdd37d7291083a1eb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e8a547039d6d7e4d5bb8de5f1ca28eeae631441440db3a16b78965dfd7e78330
MD5 b685e90e378e7d99884f9d929d8c530e
BLAKE2b-256 f3ed1286b14b55be0ea8c96c2746816b9abf08f6604fa93d47b62fbb0bb2af7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4327ea5ff9066f1e11e08d768253a8428d86a45b3b930bc64e4eb28085807caf
MD5 cf6bc0cd66c5116e3596b292db613cc4
BLAKE2b-256 52c1d9689f2b6846829f8783435e97ffa6772ee43503e9eb54d2860b7e1f661f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 b0a76d40d6c37972882a80efc7daa05f7813c0f0f244fde50176f30347b7bd29
MD5 0fbaf8f42d159619c82a3c3ab87d8ce3
BLAKE2b-256 d672b3ba503e410d8867fb87d2c64079d79dc6853535b6801b23b2bfc9290d3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev37-cp39-cp39-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 c247192df23ae223416e66020f8c364a330a0e21012d577173489bbe71fb93f8
MD5 b60d641867a6544577e76cb6d21d7dec
BLAKE2b-256 8507b98a6ed6171c96235e58c00d070d96f2068d82d855c2cf165ac3903bc552

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