Skip to content

Repository files navigation

Sleipnir

C++PythonPyPI DownloadsWebsiteC++ APIPython APIDiscord

Sleipnir is a reverse mode autodiff library, interior-point method, and NLP solver DSL for C++23 and Python. The DSL automatically chooses the best solver based on the problem structure.

#include<print>
#include<sleipnir/optimization/problem.hpp>intmain() {
// Find the x, y pair with the largest product for which x + 3y = 36
slp::Problem<double> problem;
auto x = problem.decision_variable();
auto y = problem.decision_variable();
problem.maximize(x * y);
problem.subject_to(x + 3 * y == 36);
problem.solve();
// x = 18.0, y = 6.0std::println("x = {}, y = {}", x.value(), y.value());
}
#!/usr/bin/env pythonfromsleipnir.optimizationimportProblemdefmain():
# Find the x, y pair with the largest product for which x + 3y = 36problem=Problem()
x, y=problem.decision_variable(2)
problem.maximize(x*y)
problem.subject_to(x+3*y==36)
problem.solve()
# x = 18.0, y = 6.0print(f"x = {x.value()}, y = {y.value()}")
if__name__=="__main__":
main()

Sleipnir supports easy cross-compilation via CMake toolchain files, provides good performance by default, and contains clean reference implementations of various solvers with links to explanatory material.

The C++ API also supports arbitrary scalar types, so users can specify higher precision floating-point types at the cost of speed.

Install

The following platforms are supported:

  • 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)

To use Sleipnir within a CMake project, add the following to CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(
Sleipnir
GIT_REPOSITORY https://github.com/SleipnirGroup/Sleipnir.git
GIT_TAG main
EXCLUDE_FROM_ALLSYSTEM
)
FetchContent_MakeAvailable(Sleipnir)
target_link_libraries(MyAppPUBLICSleipnir::Sleipnir)

To use Sleipnir in Python, install sleipnirgroup-jormungandr from PyPI:

pip install sleipnirgroup-jormungandr

If necessary, follow these instructions to build from source.

Docs

See the C++ API docs, Python API docs, and usage docs.

Examples

See the examples folder, C++ optimization unit tests, and Python optimization unit tests.

Benchmarks

See the benchmarks folder.

Contributing

See the contributing docs.

About

Reverse mode autodiff library, interior-point method, and NLP solver DSL for C++23 and Python

Topics

Resources

Contributing

Stars

78 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages