Migrate to linopy 0.9 - #191
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates tz-osemosys to support linopy 0.7 by bumping the dependency pin and applying the corresponding API change for summation across dimensions, plus making trade-solve tests robust to the new solution dimension ordering.
Changes:
- Bump dependency from
linopy==0.5.5tolinopy>=0.7,<0.8. - Replace
.sum(dims=...)with.sum(dim=...)across model expressions/constraints and memory profiling script. - Update trade solve assertions to use labelled xarray access (
.sel(...).item()) instead of positional.values[...]indexing.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pyproject.toml |
Updates the linopy dependency constraint to >=0.7,<0.8. |
tz/osemosys/model/objective.py |
Switches objective expression aggregation to .sum(dim=...) for linopy 0.7 compatibility. |
tz/osemosys/model/linear_expressions/activity.py |
Updates .sum(...) kwarg usage in activity linear expressions. |
tz/osemosys/model/linear_expressions/emissions.py |
Updates emissions expression reductions to .sum(dim=...). |
tz/osemosys/model/linear_expressions/financials.py |
Updates financials expression reductions to .sum(dim=...). |
tz/osemosys/model/linear_expressions/production.py |
Updates production/use expression reductions to .sum(dim=...). |
tz/osemosys/model/linear_expressions/re_production.py |
Updates RE production expression reductions to .sum(dim=...). |
tz/osemosys/model/linear_expressions/regiongroup.py |
Updates region-group expression reductions to .sum(dim=...). |
tz/osemosys/model/linear_expressions/reserve_margin.py |
Updates reserve margin expression reductions to .sum(dim=...). |
tz/osemosys/model/constraints/capacity_adequacy_b.py |
Updates constraint expression reductions to .sum(dim=...). |
tz/osemosys/model/constraints/re_targets.py |
Updates production target constraint reductions to .sum(dim=...). |
tz/osemosys/model/constraints/storage.py |
Updates storage balance constraint reduction to .sum(dim=...). |
tests/test_solve/test_solve.py |
Makes NetTrade assertions order-independent via .sel(...).item(). |
bin/memory_profile.py |
Updates memory profiling objective aggregation to .sum(dim=...). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
edwardxtg
force-pushed
the
linopy-0.7-upgrade
branch
from
July 27, 2026 10:56
97e3d7a to
fb564c3
Compare
Bumps the linopy pin to `>=0.9,<0.10` and adapts the model code and trade
solve tests to the linopy 0.7–0.9 API changes:
- pyproject.toml: `linopy==0.5.5` -> `linopy>=0.9,<0.10`.
- `.sum(dims=...)` -> `.sum(dim=...)`: 35 shipping-code sites + one in
`bin/memory_profile.py` (linopy aligned the kwarg with xarray; `dims=` is
a hard error in newer versions).
- `add_variables` coords: linopy 0.8+ no longer accepts xarray DataArray
coords entries; pass a pd.Index instead. Changed `ds.coords[...]` ->
`ds.indexes[...]` in the coordinate lists in
variables/{activity,capacity,storage}.py. The
`xr.DataArray(..., dims="YRTS")` constructor in constraints/storage.py is
left as-is (not a coords list).
- Trade tests: linopy changed the solved `NetTrade` solution dim order to
(REGION, TIMESLICE, FUEL, YEAR), breaking positional `.values[0][2][0][0]`
access. test_simple_trade / test_simple_trade_forced_min_activity now use
order-independent `.sel(REGION="R1", YEAR=2022).item()`.
Full suite green on linopy 0.9.0: 90 passed, 2 skipped.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
edwardxtg
force-pushed
the
linopy-0.7-upgrade
branch
from
July 27, 2026 10:59
fb564c3 to
ad29511
Compare
djwels
approved these changes
Jul 28, 2026
edwardxtg
pushed a commit
that referenced
this pull request
Sep 1, 2026
Resolves the conflict in capacity_adequacy_b.py: keeps this branch's RHS (sub-annual CapacityFactor removed from CAb1_PlannedMaintenance) with main's renamed linopy kwarg from #191 (.sum(dims=) -> .sum(dim=)). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch was previously deployed
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.
What
Moves tz-osemosys from
linopy==0.5.5tolinopy>=0.9,<0.10(latest linopy). This is the cross-repo prerequisite for the tz-mod PyPSA v1 / linopy 0.9 upgrade.Changes
pyproject.toml:linopy==0.5.5→linopy>=0.9,<0.10..sum(dims=…)→.sum(dim=…)— 35 shipping-code sites + 1 inbin/memory_profile.py(linopy aligned the kwarg with xarray). Thexr.DataArray(…, dims="YRTS")constructor inconstraints/storage.pyis intentionally unchanged.add_variablescoords (linopy 0.8+) — linopy no longer accepts xarrayDataArraycoord entries; it requires apd.Index. Changedds.coords[...]→ds.indexes[...]in the coordinate lists invariables/{activity,capacity,storage}.py(6 lists, 3 files).NetTradesolution dim order to(REGION, TIMESLICE, FUEL, YEAR), so the old positional.values[0][2][0][0]walked off an axis (IndexError).test_simple_trade/test_simple_trade_forced_min_activitynow use order-independent labelled access:.sel(REGION="R1", YEAR=2022).item().Verification
Full suite on linopy 0.9.0: 90 passed, 2 skipped. (Also verified green on 0.7.0 earlier; the
mask=breakage anticipated for 0.8+ did not materialise.)Notes
model_fieldsdeprecation is handled separately in Fix Pydantic 2.11 model_fields instance-access deprecation #190 (disjoint files).🤖 Generated with Claude Code