sleipnirgroup-jormungandr

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

https://github.com/sleipnirgroup/sleipnir

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.2%) to scientific vocabulary

Keywords

interior-point-method optimization solver
Last synced: 6 months ago · JSON representation ·

Repository

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

Basic Info
  • Host: GitHub
  • Owner: SleipnirGroup
  • License: bsd-3-clause
  • Language: C++
  • Default Branch: main
  • Homepage:
  • Size: 6.9 MB
Statistics
  • Stars: 63
  • Watchers: 5
  • Forks: 11
  • Open Issues: 12
  • Releases: 0
Topics
interior-point-method optimization solver
Created over 3 years ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README.md

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.

```cpp

include

include

int main() { // Find the x, y pair with the largest product for which x + 3y = 36 slp::Problem problem;

auto x = problem.decisionvariable(); auto y = problem.decisionvariable();

problem.maximize(x * y); problem.subject_to(x + 3 * y == 36); problem.solve();

// x = 18.0, y = 6.0 std::println("x = {}, y = {}", x.value(), y.value()); } ```

```python

!/usr/bin/env python3

from jormungandr.optimization import Problem

def main(): # Find the x, y pair with the largest product for which x + 3y = 36 problem = Problem()

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) 15.1.1 20250425

The following thirdparty software was used in the benchmarks:

  • CasADi 3.7.0 (autodiff and NLP solver frontend)
  • Ipopt 3.14.17 (NLP solver backend)
  • MUMPS 5.7.3 (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

  • Windows
  • Linux
    • OS: Ubuntu 24.04
    • Runtime: GCC 14 libstdc++ (run sudo apt install g++-14)
  • macOS
    • OS: macOS 14.5
    • Runtime: Apple Clang 16.0.0 libc++ from Xcode 16.2 (run xcode-select --install)

C++ library

To install Sleipnir system-wide, see the build instructions.

To use Sleipnir within a CMake project, add the following to your CMakeLists.txt: ```cmake include(FetchContent)

fetchcontentdeclare( Sleipnir GITREPOSITORY https://github.com/SleipnirGroup/Sleipnir GITTAG main EXCLUDEFROMALL SYSTEM ) fetchcontentmakeavailable(Sleipnir)

targetlinklibraries(MyApp PUBLIC Sleipnir::Sleipnir) ```

Python library

bash 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.5 or greater, install the Xcode 16.2 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.10 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
  • small_vector
  • 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.

```bash

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.

```bash

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/plottestproblem_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: ```bash

Install CasADi and [matplotlib, numpy, scipy] pip packages first

cmake -B build -S . -DBUILD_BENCHMARKS=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.

Owner

  • Name: Sleipnir Group
  • Login: SleipnirGroup
  • Kind: organization

Develops and maintains the Sleipnir constrained optimization problem solver

Citation (CITATION.cff)

cff-version: 1.2.0
title: Sleipnir
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - name: Sleipnir contributors
repository-code: 'https://github.com/SleipnirGroup/Sleipnir'
url: 'https://github.com/SleipnirGroup/Sleipnir'
abstract: >-
  A linearity-exploiting sparse nonlinear constrained
  optimization problem solver that uses the interior-point
  method.
keywords:
  - optimization
  - solver
license: BSD-3-Clause

GitHub Events

Total
  • Issues event: 11
  • Watch event: 13
  • Issue comment event: 12
  • Push event: 236
  • Pull request review comment event: 19
  • Pull request review event: 18
  • Pull request event: 472
  • Fork event: 1
  • Create event: 1
Last Year
  • Issues event: 11
  • Watch event: 13
  • Issue comment event: 12
  • Push event: 236
  • Pull request review comment event: 19
  • Pull request review event: 18
  • Pull request event: 472
  • Fork event: 1
  • Create event: 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 24
  • Total pull requests: 532
  • Average time to close issues: about 2 months
  • Average time to close pull requests: about 1 hour
  • Total issue authors: 5
  • Total pull request authors: 4
  • Average comments per issue: 0.79
  • Average comments per pull request: 0.01
  • Merged pull requests: 495
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 7
  • Pull requests: 240
  • Average time to close issues: 2 days
  • Average time to close pull requests: about 1 hour
  • Issue authors: 3
  • Pull request authors: 3
  • Average comments per issue: 1.29
  • Average comments per pull request: 0.0
  • Merged pull requests: 224
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • calcmogul (20)
  • jgillis (1)
  • spacey-sooty (1)
  • rremilian (1)
  • Glaycia (1)
Pull Request Authors
  • calcmogul (524)
  • spacey-sooty (6)
  • bugger2 (1)
  • pietroglyph (1)
Top Labels
Issue Labels
enhancement (9) type: enhancement (4) component: linear system solver (3) type: bug (2) component: ipm (2) bug (2) wontfix (1) component: autodiff (1) component: solver-ipm (1) component: solver-sqp (1) component: solver-newton (1) documentation (1)
Pull Request Labels
enhancement (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 4,949 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 468
  • Total maintainers: 1
pypi.org: sleipnirgroup-jormungandr

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

  • Documentation: https://sleipnirgroup.github.io/Sleipnir/
  • License: Copyright (c) Sleipnir contributors Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Latest release: 0.1.0
    published 8 months ago
  • Versions: 468
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 4,949 Last month
Rankings
Dependent packages count: 9.9%
Stargazers count: 15.0%
Forks count: 15.4%
Average: 26.4%
Dependent repos count: 65.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • numworks/setup-emscripten latest composite
.github/workflows/documentation.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v3 composite
  • mattnotmitt/doxygen-action 1.9.5 composite
.github/workflows/lint-format.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
.github/workflows/sanitizers.yml actions
  • actions/checkout v3 composite
.github/workflows/website.yml actions
  • actions/checkout v3 composite
  • actions/configure-pages v2 composite
  • actions/deploy-pages v1 composite
  • actions/upload-pages-artifact v1 composite
  • mattnotmitt/doxygen-action 1.9.5 composite
pyproject.toml pypi
  • numpy *