fix: allow expand() on clustered FlowSystem without a solution#646
fix: allow expand() on clustered FlowSystem without a solution#646
Conversation
Previously, expand() required a solved FlowSystem, which prevented using it to inspect expanded data (e.g. clustering_data()) without solving first. Now the solution expansion is skipped when no solution is present. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughexpand_flow_system no longer assumes a solution exists: solution-variable expansion is executed only when a reduced solution is present. Validation for expansion no longer requires a solution, only clustering. Tests updated to reflect successful expansion when no solution is available. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
flixopt/transform_accessor.py (1)
1896-1911:⚠️ Potential issue | 🟡 MinorStale docstring in
expand()method.The
_validate_for_expansion()changes look correct. However, the docstring forexpand()(lines 1932-1934) still lists:Raises: ValueError: If the FlowSystem was not created with ``cluster()``. ValueError: If the FlowSystem has no solution.The second
ValueErroris no longer raised and should be removed to keep documentation accurate.📝 Suggested docstring fix (outside selected range)
In the
expand()method docstring around line 1932-1934, remove the stale error documentation:Raises: ValueError: If the FlowSystem was not created with ``cluster()``. - ValueError: If the FlowSystem has no solution.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flixopt/transform_accessor.py` around lines 1896 - 1911, The docstring for the expand() method still documents two ValueError cases but only one is actually raised; update the expand() docstring to remove the stale "ValueError: If the FlowSystem has no solution." entry so it matches the current implementation that uses _validate_for_expansion() (which raises the cluster-related ValueError). Locate the expand() method and remove the second ValueError line from its Raises: section, leaving only the cluster-related ValueError documented.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@flixopt/transform_accessor.py`:
- Around line 1896-1911: The docstring for the expand() method still documents
two ValueError cases but only one is actually raised; update the expand()
docstring to remove the stale "ValueError: If the FlowSystem has no solution."
entry so it matches the current implementation that uses
_validate_for_expansion() (which raises the cluster-related ValueError). Locate
the expand() method and remove the second ValueError line from its Raises:
section, leaving only the cluster-related ValueError documented.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 31e7e5f9-a124-4be2-90ef-5f3e6f905fe5
📒 Files selected for processing (2)
flixopt/transform_accessor.pytests/test_clustering/test_cluster_reduce_expand.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
_validate_for_expansion(), soexpand()can be called on unsolved clustered FlowSystemsexpand_flow_system()conditional (if reduced_solution is not None)flow_system.transform.expand().transform.clustering_data()raisingValueErrorwhen no solution existsTest plan
expand()works on an unsolved clustered FlowSystemexpand()still correctly expands solutions when they exist🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests