← All projects

lpspec

Declarative LP/MILP models in YAML, built relationally and handed straight to the solver.

  • python
  • optimization
  • milp
  • polars
  • yaml
2026
fluxopt/lpspec Declarative LP/MILP models in YAML, built relationally and handed straight to the solver.

lpspec takes an optimization model written as a YAML file, attaches data at runtime, and solves it. The math lives in the file, not in Python code, so it can be read, diffed, and reviewed without knowing the implementation.

Under the hood the model is never a dense array. It’s a set of tidy tables built with polars: a masked-out variable is an absent row rather than a NaN, and a variable’s label is the solver’s own column index. The model goes to HiGHS in batches, with no LP file in between.

On the benchmark cases I measure it against (1M to 12M variables), getting from YAML and data to a loaded solver is 2–4x faster than linopy’s best path on four of five cases, and uses less peak memory on all five. The fifth case, where the data is dense over the whole variable space, is slower — that’s the shape array engines are built for.

The same file can also be built into a linopy.Model instead of being solved directly. linopy doubles as the reference every language feature is tested against.

The language itself is math-spec, which I split out of lpspec so other tools can use it too. lpspec is still alpha. I’m the author and main contributor.