Reverse mode autodiff library and NLP solver DSL
Actively maintained. Last release 5 days ago, commits in 23 of the last 26 weeks. A safe choice.
pip install sleipnirgroup-jormungandrSleipnir
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>
int main() {
// 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.0
std::println("x = {}, y = {}", x.value(), y.value());
}
#!/usr/bin/env python
from sleipnir.optimization import Problem
def main():
# Find the x, y pair with the largest product for which x + 3y = 36
problem = 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.0
print(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.