Commit 0b4a395
authored
Add FlowSystemStatus enum and restructure validation architecture (#598)
* Move validation to FlowsData mostly
* Summary: Validation Split for All Interface Classes
Classes Updated with validate_config()
┌──────────────────┬───────────────┬────────────────────────────────────────────────────────────────────────────┐
│ Class │ Location │ Config Checks │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Component │ elements.py │ unique flow labels, status→flows.size │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Bus │ elements.py │ no flows connected │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Flow │ elements.py │ status→size, fixed_profile→size, load_factor→size, previous_flow_rate type │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Effect │ effects.py │ period dimension for over_periods constraints │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ EffectCollection │ effects.py │ circular loops, unknown effect refs │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ LinearConverter │ components.py │ conversion_factors XOR piecewise, degrees_of_freedom, flow refs │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Storage │ components.py │ initial_charge_state string, balanced→InvestParams, final_charge→capacity │
├──────────────────┼───────────────┼────────────────────────────────────────────────────────────────────────────┤
│ Transmission │ components.py │ bus consistency, balanced→InvestParams │
└──────────────────┴───────────────┴────────────────────────────────────────────────────────────────────────────┘
*Data Classes with validate()
┌───────────────────┬────────────┬─────────────────────────────────────────────────────────────────────────┐
│ Class │ Location │ DataArray Checks │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ FlowsData │ batched.py │ relative_min ≤ max, size required for bounds │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ StoragesData │ batched.py │ capacity for relative bounds, initial vs capacity, balanced size compat │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ BusesData │ batched.py │ imbalance_penalty == 0 warning │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ TransmissionsData │ batched.py │ balanced size compatibility │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ EffectsData │ batched.py │ delegates to validate_config() │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ ComponentsData │ batched.py │ delegates to validate_config() │
├───────────────────┼────────────┼─────────────────────────────────────────────────────────────────────────┤
│ ConvertersData │ batched.py │ delegates to validate_config() │
└───────────────────┴────────────┴─────────────────────────────────────────────────────────────────────────┘
Updated FlowSystem
_run_plausibility_checks() now creates temporary *Data instances and calls validate() on each, which handles both config and DataArray checks in a centralized way.
* Summary: Cached *Data in BatchedAccessor
What Changed
*1. BatchedAccessor now caches all Data classes:
class BatchedAccessor:
@Property
def flows(self) -> FlowsData: ...
@Property
def storages(self) -> StoragesData: ...
@Property
def intercluster_storages(self) -> StoragesData: ...
@Property
def buses(self) -> BusesData: ...
@Property
def effects(self) -> EffectsData: ...
@Property
def components(self) -> ComponentsData: ...
@Property
def converters(self) -> ConvertersData: ...
@Property
def transmissions(self) -> TransmissionsData: ...
2. FlowSystemModel.build_model() now uses cached instances:
batched = self.flow_system.batched
self.effects = EffectsModel(self, batched.effects) # reuses cached
self._flows_model = FlowsModel(self, batched.flows) # reuses cached
# etc.
3. _run_plausibility_checks() simplified:
batched = self.batched
batched.flows.validate()
batched.buses.validate()
# etc.
Benefits
- No duplicate creation: Same *Data objects used for validation AND model building
- Early validation: Errors caught during connect_and_transform()
- Proper invalidation: _batched = None when status drops below CONNECTED
- Cleaner code: No temporary object creation in validation or build_model
* Temp
* Improve organization of validation
* Bug Found
When a Bus has no flows connected, FlowsData.validate() crashed with a cryptic TypeError instead of raising a clear ValueError message.
Root Cause
In _run_validation(), the validation order was:
1. batched.flows.validate() ← crashed on empty DataArray operations
2. batched.buses.validate() ← would have caught the error
* Add warning for no relative_minimum=0 with status
* Improve validation by using helpers1 parent fce9638 commit 0b4a395
9 files changed
Lines changed: 575 additions & 233 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
195 | 200 | | |
196 | 201 | | |
197 | 202 | | |
| |||
220 | 225 | | |
221 | 226 | | |
222 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
223 | 232 | | |
224 | 233 | | |
225 | 234 | | |
| |||
495 | 504 | | |
496 | 505 | | |
497 | 506 | | |
498 | | - | |
499 | | - | |
500 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
501 | 512 | | |
502 | | - | |
| 513 | + | |
503 | 514 | | |
504 | | - | |
505 | | - | |
| 515 | + | |
506 | 516 | | |
507 | | - | |
| 517 | + | |
508 | 518 | | |
509 | | - | |
510 | 519 | | |
511 | | - | |
| 520 | + | |
512 | 521 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | 522 | | |
524 | 523 | | |
525 | 524 | | |
| |||
531 | 530 | | |
532 | 531 | | |
533 | 532 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
| 533 | + | |
567 | 534 | | |
568 | 535 | | |
569 | 536 | | |
| |||
572 | 539 | | |
573 | 540 | | |
574 | 541 | | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
583 | 548 | | |
584 | 549 | | |
585 | 550 | | |
| |||
737 | 702 | | |
738 | 703 | | |
739 | 704 | | |
740 | | - | |
741 | | - | |
742 | | - | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
743 | 713 | | |
744 | | - | |
745 | | - | |
746 | | - | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
747 | 718 | | |
748 | | - | |
749 | | - | |
750 | | - | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
751 | 723 | | |
| 724 | + | |
752 | 725 | | |
753 | 726 | | |
754 | 727 | | |
755 | 728 | | |
756 | 729 | | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
765 | 737 | | |
766 | 738 | | |
767 | 739 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
294 | 299 | | |
295 | 300 | | |
296 | 301 | | |
| |||
301 | 306 | | |
302 | 307 | | |
303 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
304 | 313 | | |
305 | 314 | | |
306 | 315 | | |
| |||
813 | 822 | | |
814 | 823 | | |
815 | 824 | | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
816 | 833 | | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
838 | 840 | | |
839 | 841 | | |
840 | 842 | | |
| |||
0 commit comments