Repository navigation
feat(spec): dim_order sets the axis order of a spec build - #1179
Merged
Merged
Conversation
The dims dim_order names come first in every variable, constraint and named expression the spec builds, before labels are allocated; the rest keep today's layout. None keeps the name order exactly.
Merging this PR will not alter performance1 note
Comparing Footnotes
|
FabianHofmann
pushed a commit
to PyPSA/PyPSA
that referenced
this pull request
Nov 18, 2026
… dim_order linopy's dim_order (PyPSA/linopy#1179) puts each component's unit dim first in every entry. Before, the order relied on the capitalised unit dim names sorting before lower-case dims. The layout is unchanged.
This was referenced Nov 18, 2026
FabianHofmann
pushed a commit
that referenced
this pull request
Nov 18, 2026
Master has failed 'Check types' since #1179.
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes item 4 of PyPSA/PyPSA#2139.
Note
The following content was generated by AI.
Changes proposed in this Pull Request
Model.from_spec(spec, sources, dim_order=None)sets the axis order of every variable, constraint and named expression a spec builds. PyPSA can then ask for(store, snapshot)directly, instead of relying on capital-letter dim names to sort first (PyPSA/PyPSA#2173).Rule. The dims
dim_ordernames come first, in its order. The rest keep the layoutNonegives: name order, except that a dim only the data side of a constraint carries (e.g. the breakpoint dim of piecewisedomain_lo/hirows) comes last, as onmaster. A name an entry lacks is ignored.Nonebuilds exactly whatmasterbuilds.How. One helper,
Context.frame(dims), used wherever declared dims set a layout: variable coords,_framed(constraints and named expressions),fold, and the NaN dual of a skipped constraint. The order is set before labels are allocated; nothing is relabelled or transposed after the build. Ifdim_ordernames a dim the variable side of a row lacks,_framedspreads the term onto it first; sparse stays sparse. SOS sets and piecewise expansions follow their variables and rows.linopy.spec.evaluatetakes the samedim_order, as it doesrename. Astror a repeated name is refused.Tests (
test/test_spec_api.py, dense and sparse): layout of every entry for thelp,sos2andincrementalpiecewise methods; adim_orderthat agrees with name order gives a model equal to the default; solution, duals and folded expressions equal the default up to transposition.Build time is within noise. Median of 15 alternating builds:
dim_ordercommitment.yaml,["snapshot"]piecewise_lp.yaml,["snapshot", "bp"](spreadsbp)Verification details
test_quadratic_model_wo_constraint[gurobi-mps-*], MPS read error) also fail onmaster.MATHSPEC_EXAMPLESset: 644 spec tests pass.dim_order= all its dims in reverse name order, solved and compared with the default: layout rule holds; objective, solution and folded expressions equal up to transposition. 28 pass; the 2 the suite already marks as refused on synthetic data are skipped.pypsa.yamlwas not benchmarked: synthetic data breaks several of its assumptions.All benchmark rows:
Checklist
AGENTS.md).doc.doc/release-notes.mdof the upcoming release is included.Generated by Claude Code