Skip to main content

Python library for building indexed linear and mixed-integer programs in polars; assembles into HiGHS, exportable as MPS.

Project description

polar-high

PyPI Python versions License tests docs Ruff

A Python library for building and solving large indexed linear and mixed-integer programs. Variables and parameters are polars DataFrames, expressions are joined and grouped lazily, and the matrix is assembled directly through HiGHS — or exported as MPS for any other LP solver. The kernel is intentionally domain-free: it has no opinions about energy systems, supply chains, or any specific application.

Install

pip install polar-high

Requires Python 3.11+. HiGHS ships in highspy, no separate install.

Quickstart

A tiny dispatch LP — wind + coal over three hours, minimise cost subject to capacity and per-hour demand.

import polars as pl
from polar_high import Problem, Param, Sum

p = Problem()

v_idx = pl.DataFrame({
    "unit": ["wind", "wind", "wind", "coal", "coal", "coal"],
    "hour": [1, 2, 3, 1, 2, 3],
})
v_production = p.add_var("v_production", dims=("unit", "hour"),
                         index=v_idx, lower=0.0)

cost = Param(("unit",),
             pl.DataFrame({"unit": ["wind", "coal"],
                           "value": [2.0, 8.0]}))

cap = Param(("unit", "hour"), pl.DataFrame({
    "unit":  ["wind", "wind", "wind", "coal", "coal", "coal"],
    "hour":  [1, 2, 3, 1, 2, 3],
    "value": [3.0, 1.0, 4.0, 10.0, 10.0, 10.0],
}))

demand = Param(("hour",),
               pl.DataFrame({"hour": [1, 2, 3], "value": [5.0, 6.0, 4.0]}))

p.set_objective(cost * v_production, sense="min")

p.add_cstr("capacity", over=v_idx, sense="<=",
           lhs_terms={"production": v_production},
           rhs_terms={"cap": cap})

p.add_cstr("demand_balance",
           over=v_idx.select("hour").unique().sort("hour"),
           sense="==",
           lhs_terms={"production": Sum(v_production, over=("unit",))},
           rhs_terms={"demand": demand})

sol = p.solve()
print(sol.obj, sol.value("v_production"))

Documentation

Full docs at https://nodal-tools.fi/polar-high/ — published with MkDocs + mike for per-version reads.

  • Concepts — the indexed-frame mental model (Var, Param, Sum, Where, Lag, broadcasting/join semantics).
  • Guide — warm-starting, Lagrangian decomposition, performance tuning, debugging.
  • API reference — autogenerated from docstrings.
  • Compare — how polar-high relates to Pyomo, JuMP, gurobipy, linopy, and GNU MathProg.

Build locally: pip install -e ".[docs]" && mkdocs serve.

Used by

polar-high is the build engine behind the FlexTool energy-system modelling toolkit. FlexTool's fleet of system tests (from earlier GNU MathProg to HiGHS implementation) has been used to test polar-high in real modelling use cases. In addition polar-high kernel has its own set of unit and system tests.

Created by

polar-high was created by Juha Kiviluoma of Nodal-Tools using Claude Opus.

License

Apache-2.0 — see LICENSE and NOTICE. Changelog: CHANGELOG.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polar_high-1.1.1.tar.gz (50.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polar_high-1.1.1-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file polar_high-1.1.1.tar.gz.

File metadata

  • Download URL: polar_high-1.1.1.tar.gz
  • Upload date:
  • Size: 50.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polar_high-1.1.1.tar.gz
Algorithm Hash digest
SHA256 592600a2020a9eaee51a8834ff3006ab4823aa03ec82aa5b4c8681edf4f3aa70
MD5 dc35f745290cdca86d2560a5cc13a58c
BLAKE2b-256 3cd802064d809129ff557eace35b37bebda81eaae3a7a98fbd4e24eddae48bb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for polar_high-1.1.1.tar.gz:

Publisher: release.yml on nodal-tools/polar-high

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polar_high-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: polar_high-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for polar_high-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa7f63321ebb6edf140473d221637ddd486a4bb187736298d027e3fbd996f39c
MD5 103a6602a20f9da89deaea27234e66ac
BLAKE2b-256 66f7055901e2302af58c9ca229a8f1e3276037abb496b65927e98cd41ebae9f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for polar_high-1.1.1-py3-none-any.whl:

Publisher: release.yml on nodal-tools/polar-high

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page