Jormungandr

raw JSON →
0.5.4 verified Sat May 09 auth: no python

Reverse mode automatic differentiation library and domain-specific language for nonlinear programming (NLP) solvers. Designed for efficient gradient and Hessian computations, it provides a Python DSL to formulate and solve optimization problems. Current version 0.5.4, requires Python >=3.12. Development is active with pre-1.0 breaking changes expected.

pip install sleipnirgroup-jormungandr
error ModuleNotFoundError: No module named 'jormungandr'
cause You installed the wrong package name or didn't install. The package is 'sleipnirgroup-jormungandr' but after install the import is 'jormungandr'.
fix
Run 'pip install sleipnirgroup-jormungandr' then import using 'import jormungandr'
error AttributeError: module 'jormungandr' has no attribute 'NlpSolver'
cause You tried to import NlpSolver from the top-level jormungandr module, but it is in the 'nlp' submodule.
fix
Use 'from jormungandr.nlp import NlpSolver' instead.
error ValueError: Gradient requires a list of variables
cause You passed a single variable instead of a list to Jormungandr.gradient(). The second argument must be a list even for one variable.
fix
Use 'Jormungandr.gradient(f, [x])' instead of 'Jormungandr.gradient(f, x)'
error TypeError: unsupported operand type(s) for +: 'Jormungandr' and 'int'
cause You tried to perform arithmetic directly on the Jormungandr class instead of a variable instance. The class is the factory; you must create a variable first.
fix
Use 'x = Jormungandr.variable('x')' then 'f = x + 2'
breaking API is unstable before 1.0. Expect changes in module names, function signatures, and behavior between minor versions. Pin your dependency to a specific minor version.
fix Pin for production: sleipnirgroup-jormungandr==0.5.4
gotcha The package name on PyPI is 'sleipnirgroup-jormungandr' but the import is 'jormungandr'. Do not use the hyphens in import statements.
fix Always use 'import jormungandr' or 'from jormungandr import ...'
deprecated The old autodiff API (e.g., `Jormungandr.auto_diff`) is deprecated in favor of `Jormungandr.gradient`. The old name may be removed in 0.6.
fix Replace `auto_diff` with `gradient` in your code.
gotcha Default variable types are symbolic scalars. To create vectors/matrices, use `Jormungandr.variable('x', shape=(3,))` or similar. Forgetting the shape leads to shape mismatch errors.
fix Explicitly specify shape when creating non-scalar variables.

Minimal example showing variable creation, expression evaluation with reverse mode autodiff, and NLP solving.

from jormungandr import Jormungandr

# Define variables
x = Jormungandr.variable('x')
y = Jormungandr.variable('y')

# Define expression
f = x**2 + y**2

# Compute gradient (reverse mode)
grad = Jormungandr.gradient(f, [x, y])
print('Gradient at (1,2):', grad.eval({'x': 1, 'y': 2}))

# Solve NLP
from jormungandr.nlp import NlpSolver
solver = NlpSolver()
solver.set_objective(f)
solver.set_initial_guess({'x': 0.0, 'y': 0.0})
solution = solver.solve()
print('Solution:', solution)