Package: sleipnirgroup-jormungandr
SleipnirSparsity and Linearity-Exploiting Interior-Point solver - Now Internally ReadableNamed 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>intmain(){// Find the x, y pair with the largest product for which x + 3y = 36sleipnir::OptimizationProblemproblem;autox=problem.DecisionVariable();autoy=problem.DecisionVariable();problem.Maximize(x*y);problem.SubjectTo(x+3*y==36);problem.Solve();// x = 18.0, y = 6.0fmt::print("x = {}, y = {}\n",x.Value(),y.Value());}#!/usr/bin/env python3importjormungandrasjmgdefmain():# Find the x, y pair with the largest product for which x + 3y = 36problem=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.0print(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.Benchmarksflywheel-scalability-results-casadi.csvflywheel-scalability-results-sleipnir.csvcart-pole-scalability-results-casadi.csvcart-pole-scalability-results-sleipnir.csvGenerated bytools/generate-scalability-results.shfrombenchmarks/scalabilitysource 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 performanceMake more decisions at compile timeDuring 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 solversEigenprovides these. It also has no required dependencies, which makes cross compilation much easier.Use a pool allocator for autodiff expression nodesThis 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 benchmarksBenchmark projects are in thebenchmarks folder. To compile and run them, run the following in the repository root:# Install CasADi and [matplotlib, numpy, scipy] pip packages firstcmake-Bbuild-S.
cmake--buildbuild
./tools/generate-scalability-results.shSee the contents of./tools/generate-scalability-results.shfor how to run specific benchmarks.ExamplesSee theexamplesandoptimization unit tests.DependenciesC++20 compilerOn Windows, installVisual Studio Community 2022and select the C++ programming language during installationOn Linux, install GCC 11 or greater viasudo apt install gccOn macOS, install the Xcode command-line build tools viaxcode-select --install. Xcode 13 or later is required.CMake3.21 or greaterOn Windows, install from the link aboveOn Linux, install viasudo apt install cmakeOn macOS, install viabrew install cmakePython3.11 or greaterOn Windows, install from the link aboveOn Linux, install viasudo apt install pythonOn macOS, install viabrew install pythonEigenfmtlib(internal only)pybind11(build only)Catch2(tests only)Library dependencies which aren't installed locally will be automatically downloaded and built by CMake.IfCasADiis installed locally, the benchmark executables will be built.Build instructionsOn Windows, open aDeveloper PowerShell. On Linux or macOS, open a Bash shell.Clone the repository.gitclonegit@github.com:SleipnirGroup/SleipnircdSleipnirC++ library# Configure; automatically downloads library dependenciescmake-Bbuild-S.# Buildcmake--buildbuild# Testcdbuild
ctestcd..# Installcmake--installbuild--prefixpkgdirThe following build types can be specified via-DCMAKE_BUILD_TYPEduring CMake configure:DebugOptimizations offDebug symbols onReleaseOptimizations onDebug symbols offRelWithDebInfo (default)Release build type, but with debug infoMinSizeRelMinimum size release buildAsanEnables address sanitizerTsanEnables thread sanitizerUbsanEnables undefined behavior sanitizerPerfRelWithDebInfo build type, but with frame pointer so perf utility can use itPython library# Setuppipinstall--userbuild# Buildpython-mbuild--wheel# Installpipinstall--userdist/sleipnirgroup_jormungandr-*.whl# TestpytestTest diagnosticsPassing the--enable-diagnosticsflag to the test executable enables solver diagnostic prints.Some test problems generate CSV files containing their solutions. These can be plotted withtools/plot_test_problem_solutions.py.BrandingLogoSVG,PNG (1000px)Font:CentaurColor palettePurpleYellow6D3D94FDB813