Commit 3945200
authored
Feature/simplify structure (#464)
* refactoring to tighten the coupling between FlowSystem and Elements
* implemented the helper methods in the Interface base class
* made calling .do_modeling() optional
* eliminated all circular dependencies in the Submodel architecture by implementing a two-phase modeling pattern:
Phase 1 - Variable Creation (_create_variables()):
- Called during __init__
- Creates all variables and submodels
- No constraints allowed (to avoid circular dependencies)
Phase 2 - Constraint Creation (_create_constraints()):
- Called from FlowSystemModel.do_modeling() after all models exist
- Safely accesses variables from child/sibling models
- Creates all constraints and relationships
* Added explicit calls to _create_constraints() for nested submodel
* Fix
* Revert changes
* Revert changes
* Revert changes
* Revert changes
* Revert changes
* Add more validation to add_elements()
* Fixed inconsistent argument passing for _fit_effect_coords
* Refactored _set_flow_system to be a method on each Interface subclass
* Add missing _set_flow_system
* Add missing type hints
* Change timing of validate_system_integrity() and improve cache invalidation
* 1. calculation.py - Modeling State Consistency
Updated the modeled property to use the _modeled flag instead of checking self.model is not None, ensuring consistent state tracking throughout
the Calculation class.
2. features.py - PieceModel Type Hints
Improved the dims parameter type from FlowSystemDimensions | None to Collection[FlowSystemDimensions] | None in both PieceModel and
PiecewiseModel to accurately reflect actual usage with tuples like ('period', 'scenario').
3. features.py - ShareAllocationModel Error Message
Updated the validation error message from "Both max_per_hour and min_per_hour cannot be used..." to "max_per_hour and min_per_hour require
'time' dimension in dims" to match the actual condition being checked.
4. features.py - PiecewiseModel Zero-Point Documentation
Added clarifying comments explaining that the zero_point binary variable acts as a gate: when enabled (=1), at most one segment is active; when
disabled (=0), all segments remain inactive.
5. effects.py - Penalty Temporal Coupling
Added a comment in EffectCollectionModel._do_modeling noting that penalty shares are added after the objective is set, explaining the temporal
coupling in the design.
6. structure.py - Interface Documentation
Updated the class-level docstring to reflect the correct transform_data(name_prefix='') signature instead of the outdated
transform_data(flow_system).
7. components.py - Model Class Docstrings
Replaced generic docstrings with specific descriptions:
- TransmissionModel: "Create transmission efficiency equations and optional absolute loss constraints for both flow directions"
- LinearConverterModel: "Create linear conversion equations or piecewise conversion constraints between input and output flows"
- StorageModel: "Create charge state variables, energy balance equations, and optional investment submodels"
All changes improve code clarity, consistency, and maintainability without altering functionality.
* Update CHANGELOG.md
* Update CHANGELOG.md1 parent 2033d52 commit 3945200
9 files changed
Lines changed: 416 additions & 160 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
67 | 74 | | |
68 | 75 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | | - | |
78 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
102 | | - | |
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
| |||
228 | 226 | | |
229 | 227 | | |
230 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
231 | 234 | | |
232 | 235 | | |
233 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
184 | 190 | | |
185 | 191 | | |
186 | 192 | | |
| |||
211 | 217 | | |
212 | 218 | | |
213 | 219 | | |
214 | | - | |
| 220 | + | |
215 | 221 | | |
216 | | - | |
| 222 | + | |
217 | 223 | | |
218 | | - | |
| 224 | + | |
219 | 225 | | |
220 | 226 | | |
221 | | - | |
| 227 | + | |
222 | 228 | | |
223 | | - | |
| 229 | + | |
224 | 230 | | |
225 | 231 | | |
226 | 232 | | |
227 | 233 | | |
228 | 234 | | |
229 | 235 | | |
230 | | - | |
| 236 | + | |
231 | 237 | | |
232 | 238 | | |
233 | 239 | | |
| |||
433 | 439 | | |
434 | 440 | | |
435 | 441 | | |
436 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
437 | 449 | | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
442 | 453 | | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 454 | + | |
| 455 | + | |
451 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
452 | 460 | | |
453 | | - | |
| 461 | + | |
454 | 462 | | |
455 | 463 | | |
456 | | - | |
| 464 | + | |
457 | 465 | | |
458 | 466 | | |
459 | | - | |
| 467 | + | |
460 | 468 | | |
461 | 469 | | |
462 | | - | |
| 470 | + | |
463 | 471 | | |
464 | 472 | | |
465 | 473 | | |
466 | 474 | | |
467 | | - | |
| 475 | + | |
468 | 476 | | |
469 | 477 | | |
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
473 | | - | |
| 481 | + | |
474 | 482 | | |
475 | | - | |
| 483 | + | |
476 | 484 | | |
477 | 485 | | |
478 | 486 | | |
| |||
719 | 727 | | |
720 | 728 | | |
721 | 729 | | |
722 | | - | |
| 730 | + | |
723 | 731 | | |
724 | | - | |
725 | | - | |
726 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
727 | 735 | | |
728 | 736 | | |
729 | 737 | | |
| |||
738 | 746 | | |
739 | 747 | | |
740 | 748 | | |
741 | | - | |
| 749 | + | |
742 | 750 | | |
743 | 751 | | |
744 | 752 | | |
| |||
779 | 787 | | |
780 | 788 | | |
781 | 789 | | |
| 790 | + | |
782 | 791 | | |
783 | | - | |
| 792 | + | |
| 793 | + | |
784 | 794 | | |
785 | 795 | | |
786 | 796 | | |
| |||
826 | 836 | | |
827 | 837 | | |
828 | 838 | | |
| 839 | + | |
829 | 840 | | |
830 | 841 | | |
| 842 | + | |
831 | 843 | | |
832 | 844 | | |
833 | 845 | | |
| |||
838 | 850 | | |
839 | 851 | | |
840 | 852 | | |
| 853 | + | |
841 | 854 | | |
842 | 855 | | |
843 | 856 | | |
| |||
862 | 875 | | |
863 | 876 | | |
864 | 877 | | |
| 878 | + | |
865 | 879 | | |
866 | 880 | | |
867 | 881 | | |
| |||
883 | 897 | | |
884 | 898 | | |
885 | 899 | | |
| 900 | + | |
886 | 901 | | |
887 | 902 | | |
888 | 903 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
| 345 | + | |
345 | 346 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 347 | + | |
| 348 | + | |
350 | 349 | | |
351 | | - | |
| 350 | + | |
352 | 351 | | |
353 | 352 | | |
354 | | - | |
355 | | - | |
| 353 | + | |
| 354 | + | |
356 | 355 | | |
357 | | - | |
| 356 | + | |
358 | 357 | | |
359 | 358 | | |
360 | 359 | | |
361 | | - | |
| 360 | + | |
362 | 361 | | |
363 | 362 | | |
364 | | - | |
| 363 | + | |
365 | 364 | | |
366 | 365 | | |
367 | | - | |
| 366 | + | |
368 | 367 | | |
369 | 368 | | |
370 | | - | |
| 369 | + | |
371 | 370 | | |
372 | 371 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
| 372 | + | |
| 373 | + | |
377 | 374 | | |
378 | | - | |
| 375 | + | |
379 | 376 | | |
380 | 377 | | |
381 | 378 | | |
| |||
396 | 393 | | |
397 | 394 | | |
398 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| |||
661 | 661 | | |
662 | 662 | | |
663 | 663 | | |
| 664 | + | |
664 | 665 | | |
| 666 | + | |
| 667 | + | |
665 | 668 | | |
666 | 669 | | |
| 670 | + | |
| 671 | + | |
667 | 672 | | |
668 | 673 | | |
669 | 674 | | |
670 | 675 | | |
671 | 676 | | |
| 677 | + | |
672 | 678 | | |
673 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
674 | 684 | | |
675 | 685 | | |
676 | 686 | | |
| |||
0 commit comments