This release is a pre-release and may not be stable for production use.
specsolve
Solve an optimisation model written in YAML. Attach your data as tables, and keep the solver loaded for quick updates and warm starts.
specsolve builds and solves math-spec models. The file states the math, and math-spec checks it before any data exists. specsolve attaches your tables, builds the model on polars, and hands it to HiGHS, Gurobi or Xpress.
- Tables in, tables out. Pass any Arrow table, such as polars, pandas or DuckDB, or a parquet path. Results come back as tables, and an archive keeps the model, its data and its results as parquet, ready for queries, plots or BI. Tables in, tables out →
- Sweeps and rolling horizons built in. One call runs scenario sweeps, rolling horizons and myopic pathways over the same model. Each window is checked against how the model couples before it runs. Sweep a model →
- Fast, and hard to get wrong. Tables hold only the rows that exist, so a
model's topology does not change its cost. The solver stays loaded:
update()puts new numbers on it, andkeep='progress'warm-starts from the last run. The API is a handful of verbs, with nothing to tune. Benchmarks → - Validated against PyPSA. PyPSA's model is one file here, grown rung by rung through storage, unit commitment, multi-period and stochastic runs. All 16 rungs match PyPSA's objective, and 12 match its duals row for row. The PyPSA ladder →
Example
# dispatch.yaml
dimensions:
snapshot: {dtype: int}
generator: {dtype: str}
parameters:
p_max: {dims: [generator]}
load: {dims: [snapshot]}
cost: {dims: [generator]}
variables:
p:
dims: [snapshot, generator]
where: "p_max > 0"
bounds: {lower: 0, upper: p_max}
constraints:
power_balance:
dims: [snapshot]
expression: sum(p, over=generator) == load
objective:
sense: minimize
expression: sum(p * cost)
import specsolve as sps, polars as pl
generators = ['wind', 'solar', 'gas']
sources = { # (1)!
'p_max': pl.DataFrame({'generator': generators, 'value': [100.0, 60.0, 200.0]}),
'cost': pl.DataFrame({'generator': generators, 'value': [1.0, 2.0, 50.0]}),
'load': pl.DataFrame({'snapshot': range(6), 'value': [80.0, 120.0, 150.0, 180.0, 140.0, 100.0]}),
'snapshot': range(6),
'generator': generators,
}
result = sps.solve('dispatch.yaml', sources, archive='runs/base/') # (2)!
print(result.objective) # 1920.0
print(result.primal('p')) # (3)!
print(result.dual('power_balance'))
base = sps.scan_archive('runs/base/') # (4)!
print(base.answer.primal('p').group_by('generator').agg(pl.col('value').sum()))
- A source is any table: polars, pandas, pyarrow or DuckDB. It can also be a
parquet path, such as
'load': 'load.parquet'. archive=writes the spec, the data and the answer toruns/base/as parquet files.- A tidy table, with one row per snapshot and generator.
scan_archivereads the archive where it lies.base.sourcesare parquet paths, sosps.solve(base.spec, base.sources)asks the same question again.
Documentation
The documentation is at https://specsolve.readthedocs.io. What a file may contain is math-spec's language reference.
Installation
pip install specsolve
That brings polars, HiGHS and the language. Add the [gurobi] or [xpress]
extra for those solvers. The bridges out of a result, to_pandas and
to_dataarray, need pandas and xarray, which you install yourself. To work on specsolve, see CONTRIBUTING.md.
Prior art
The YAML surface comes from Calliope, and linopy supplies the vocabulary, the oracle and every benchmark denominator. Prior art and credit says what came from each.
Status
Alpha, pre-1.0.
Breaking changes land without a deprecation cycle. Pin an exact version if you depend on this, and read the changelog before upgrading. A retired spelling fails at load and names its rewrite. Real models round-trip through solve and are tested against linopy. The accepted surface is not yet frozen.
Licence
MIT.
Release files for specsolve 0.1.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| specsolve-0.1.0rc1.tar.gz | 179.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| specsolve-0.1.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 390.1 kB
Release files / specsolve-0.1.0rc1.tar.gz
| Download URL | specsolve-0.1.0rc1.tar.gz |
|---|---|
| Size | 179.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e7f0430642c685afb6f68f69ea738cf5244153a50dd086cc476b1efe338bd1a
|
|
BLAKE2b-256 checksum How to use checksums |
c75eeae076faff156917ba4ddc4df1ad95b1a8d142bed5b843015e5d88750a53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / specsolve-0.1.0rc1-py3-none-any.whl
| Download URL | specsolve-0.1.0rc1-py3-none-any.whl |
|---|---|
| Size | 210.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d7e2567827f1abc46b74eecffcea5f9411387404e4923ae17cb572cdaa3a1e10
|
|
BLAKE2b-256 checksum How to use checksums |
f068bd278eda5d7edde301ab4ff7dd66df7a8c1726c8662bc7534c367bcd1b96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency log