fix: extra output comparison #240
Merged
Merged
Conversation
Extra-output expressions such as `dual(balance) >= unsupplied_cost - 5` previously raised NotImplementedError at post-solve evaluation because VectorizedExtraOutputBuilder inherited the base comparison() that unconditionally rejects ComparisonNode. Override comparison() in the post-solve builder to evaluate both operands (concrete DataArrays) element-wise and return a float indicator (1.0 where the condition holds, 0.0 otherwise). The base builder still rejects comparisons, since pre-solve they are constraints, not values. min()/max() already worked post-solve; add regression tests covering both the min and comparison extra-output cases. Bump version to 0.1.3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmfPS89otsiw1q7LDGwumU
Keep the version at 0.1.2 (revert pyproject.toml and uv.lock) and record the extra-output comparison-operator bug fix under an [Unreleased] changelog section. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmfPS89otsiw1q7LDGwumU
aoustry
commented
Jun 26, 2026
aoustry
commented
Jun 26, 2026
Collaborator
Author
|
Closes #237 |
20 tasks
| variables=[float_variable("a", lower_bound=literal(5), upper_bound=literal(5))], | ||
| extra_outputs={"capped": minimum(var("a"), param("cap"))}, | ||
| ) | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| OTHER_MODEL = model( | |
| id="OTHER_MODEL", | |
| parameters=[float_parameter("p")], | |
| variables=[float_variable("b", lower_bound=literal(1), upper_bound=literal(1))], | |
| ) |
| ) | ||
|
|
||
| database = DataBase() | ||
| comp = create_component(model=SIMPLE_MODEL, id="comp_1") |
Contributor
There was a problem hiding this comment.
Suggested change
| comp = create_component(model=SIMPLE_MODEL, id="comp_1") | |
| other_comp = create_component(model=OTHER_MODEL, id="comp_2") |
|
|
||
| database = DataBase() | ||
| comp = create_component(model=SIMPLE_MODEL, id="comp_1") | ||
| database.add_data("comp_1", "cap", ConstantData(3.0)) |
Contributor
There was a problem hiding this comment.
Suggested change
| database.add_data("comp_1", "cap", ConstantData(3.0)) | |
| database.add_data("comp_2", "p", ConstantData(0.0)) |
| database.add_data("comp_1", "cap", ConstantData(3.0)) | ||
|
|
||
| system = System("test_min_extra") | ||
| system.add_component(comp) |
Contributor
There was a problem hiding this comment.
Suggested change
| system.add_component(comp) | |
| system.add_component(other_comp) |
Juliette-Gerbaux
requested changes
Jun 29, 2026
Juliette-Gerbaux
left a comment
Contributor
There was a problem hiding this comment.
When multiple models coexist in a problem, linopy's outer join causes solution DataArrays to include NaN-filled entries for components of other models. This breaks minimum()/maximum(), which use xr.where and require aligned coordinates.
Fix: Filter solution/dual/reduced-cost arrays to the current model's own components before passing them to the VectorizedExtraOutputBuilder.
5 tasks
…puts (#246) * fix: filter solution/dual arrays to own model components in extra outputs 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.
Juliette-Gerbaux
approved these changes
Jul 10, 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.
Process ID
[GP-02] Fix expressions in extra-outputs with <= and min
#237
Description
Expressions in extra-output such as : dual(balance) >= unsupplied_cost - 5 and min(variable, parameter) shouldn't raise errors.
Impact Analysis
simulation/extra_outputs.py
Checklist
pytest)mypy)black,isort)pyproject.tomlversion bumped if applicableAGENTS.mdreviewed for impact and updated if needed