Skip to content

fix: filter solution/dual arrays to own model components in extra outputs#246

Merged
aoustry merged 2 commits into
claude/fix-extra-output-comparison-237from
claude/pr-240-review-bugs-rv1puc
Jul 9, 2026
Merged

fix: filter solution/dual arrays to own model components in extra outputs#246
aoustry merged 2 commits into
claude/fix-extra-output-comparison-237from
claude/pr-240-review-bugs-rv1puc

Conversation

@aoustry

@aoustry aoustry commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Process ID

[GP-02] Fix minimum()/maximum() in extra outputs when multiple models coexist

Process: Follow-up to #240 / #237, addressing Juliette Gerbaux's review

Description

PR #240 added support for comparisons and minimum()/maximum() in post-solve
extra-output expressions. Juliette flagged a bug during review: when multiple
models coexist in the same problem, linopy's merged solution/dual Datasets
outer-join their component coordinates, so a model's own variable/dual arrays
get padded with NaN entries for other models' components. minimum()/maximum()
(implemented via xr.where, which requires exact coordinate alignment) then
raise an AlignmentError instead of evaluating.

This PR filters var_solution_arrays and constraint_dual_arrays back down to
each model's own components in simulation_table.py::_collect_extra_outputs /
_collect_constraint_duals, mirroring the guard already present in the sibling
method _collect_vars_outputs. test_extra_output_min_on_variable is extended
with a second, unrelated model/component (OTHER_MODEL / comp_2) to reproduce
the outer-join scenario and guard against regressions, per Juliette's inline
suggestions on #240.

Verified the new test fails with xarray.structure.alignment.AlignmentError
before this fix and passes after.

Impact Analysis

simulation/simulation_table.py — only affects extra-output evaluation when a
study has multiple models with disjoint component sets; solver output values
for existing single-model tests are unchanged.

Checklist

  • Unit tests pass (pytest)
  • Type checking passes (mypy)
  • Formatting passes (black, isort)
  • pyproject.toml version bumped if applicable
  • AGENTS.md reviewed for impact and updated if needed

Generated by Claude Code

…puts

When multiple models coexist in a problem, linopy's merged solution/dual
Datasets outer-join their component coordinates, padding each model's
variable and constraint-dual arrays with NaN entries for other models'
components. minimum()/maximum() in extra outputs use xr.where, which
requires aligned coordinates and breaks on this padding.

Filter var_solution_arrays and constraint_dual_arrays back down to each
model's own components in simulation_table.py, mirroring the existing
guard in _collect_vars_outputs. Extends test_extra_output_min_on_variable
with a second coexisting model to reproduce and guard against the issue,
per Juliette Gerbaux's review on #240.
@aoustry
aoustry changed the base branch from main to claude/fix-extra-output-comparison-237 July 9, 2026 13:55
Comment thread tests/unittests/simulation/test_simulation_table_extra_outputs.py Outdated
@aoustry
aoustry merged commit 25fab1c into claude/fix-extra-output-comparison-237 Jul 9, 2026
2 checks passed
@aoustry
aoustry deleted the claude/pr-240-review-bugs-rv1puc branch July 9, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants