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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.12 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev49-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.dev49-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.dev49-cp311-cp311-win_amd64.whl (412.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev49-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.dev49-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.dev49-cp310-cp310-win_amd64.whl (412.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev49-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.dev49-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.dev49-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.dev49-cp39-cp39-win_amd64.whl (397.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleipnirgroup_jormungandr-0.0.1.dev49-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.dev49-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.dev49.tar.gz.

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49.tar.gz
Algorithm Hash digest
SHA256 17bfc9521d57af8eb47f5c512c00cfeadae781fc1e88f9b77415ea58f572e088
MD5 1f4a4c0b749baef0853bf5962b69a80f
BLAKE2b-256 88df9ee219d9966dded0d83bebac1fb42b9cfcf75163753173d5d71f327537d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c5cc59c2a6e8be6225b3f0fcfe6dfe232ec5e67cec488fcb06d152d2837b0e6a
MD5 f9aaed8886fb39a9ca687093c9a2fcdb
BLAKE2b-256 a02ccd1460e6707ef51e174cecce948707a2e2d1cf82fcb7176daa2f69c17b9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4e1babc588603e92247982a4c99fe767e226ff0b7d845f2ac9e22f9af8b70ce1
MD5 5c98fa603bebf5837b2889b5e5b9e95d
BLAKE2b-256 78ebc637df634a25b9ff81065f9c3d9862cc07c4868ec4760c9e49ffd79d34fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp312-cp312-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6e1f4f0751c61e05c31fdea245e95e71e51050b43687aeac4c30778601919a82
MD5 da36f06c6d466cf1bfc04781b04698ab
BLAKE2b-256 71dc0b2b114269016be6798fe30dd036ac07c3391e0b0f2df6ed2745393511f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e13e7d158e40045600edee6e032350703e83eca06cd394a6b265cae8066c0200
MD5 b0b6ffe0eb9ce7335bfa23292bfacb05
BLAKE2b-256 c61b873254ecf1030db366c04ba6bf11a4ebf80d0aeadb9b02d7b6152c537ddd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 910679ea1e55acd39db50ef946b2808f75823a431bc73727f8343fd6ebaf2106
MD5 d4b2bd44c5058fd9b9f72480e18924ef
BLAKE2b-256 abb8aa5cff5b65b78fed8d0bf93b275e2a6c5160865066fc44c208fed9d2b691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 26608d7a53e88029cc38c088839dc1e7a7de61a79866ea350cf7cea6406e46b2
MD5 509701fabb0a5ba4f202cd912e7e0b9d
BLAKE2b-256 e7c6474502e1be6df1bc2f084233e74cb309d4e8d9fcaa63999d4326f2e48bf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1a3043e52af14c822e39cc9efda54740b24da81d74bacff3be6aa3cc1c20a0f3
MD5 ca540b4617849f155a2ad2d249552336
BLAKE2b-256 8a158a136e19bc2970832ec576054ecf525b70acac546e7a4f25ef1dbe8cd0ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f7495e5a7081e1c55333bca712d1f8ac59b5377096e86ba3aed0b21d481b1dc1
MD5 8890f26fc5aa24d80fec8e0096853d51
BLAKE2b-256 f84f9b28e87a66f3c372ba2873bc98075add19233e7a4f0915c32878edc86938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp310-cp310-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 82f88ade78754fc28b5fe9e441bf6c5e3deb7992a5eaf78a3172ebeb4ee5bee6
MD5 69a5f38431aa2e78255360d6e57c20cc
BLAKE2b-256 c3a1df2a3d4118b8ef80cf9fd60b8f86c6281aaa2db379e969799a0d94105d0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 cda07ff442b44fda09251ee1b07920eb7afb5af5bab454f96e1c1c04e2811b3b
MD5 dc9fe729d2ec888b85999366fdb4deb4
BLAKE2b-256 8c507ec96ea111faf8b9f5a458ae133c74304bf7ac5c6a4f01a1815ebfb1481a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6826ded8882d3e56d2251a778b6baf15fd9cad2260574d53a9db28900b4d5614
MD5 361a5f2b7fa5e9369f434fac282d5954
BLAKE2b-256 69961d94b8558fd1fe5e0920b0adcef25e1b7da749bf1cbec45b920811d99feb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 bdb1473938db6147dd3bccbe235e05fc0272b4df527d90a26652530ad0c1bb8f
MD5 c00971862a43190c51d5652504404b97
BLAKE2b-256 38918a0413bdadd5ad048c238c1c8ae1121af2d08f8e035c98020ac1ddf7759f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sleipnirgroup_jormungandr-0.0.1.dev49-cp39-cp39-macosx_11_7_x86_64.whl
Algorithm Hash digest
SHA256 0f64f77a46785c256854c5d67d40165f6c72e9e431890f27e24b66661a20d413
MD5 445bfc74614b9a627945a0a6eb26e90b
BLAKE2b-256 518870c836e735cec8546f9b6915d5bc808377dcbe680dc0777a984f27fbcb7c

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