Skip to content

Conversation

@FBumann
Copy link
Member

@FBumann FBumann commented Feb 10, 2026

Summary

  • Moved all data stacking/pre-computation from Model classes into Data classes for BusesData, ComponentsData, ConvertersData, and TransmissionsData — aligning them with FlowsData/StoragesData/EffectsData which already followed this pattern
  • Model classes (BusesModel, ComponentsModel, ConvertersModel, TransmissionsModel) are now pure consumers of self.data.*, no longer responsible for stacking element parameters into arrays
  • ~475 lines removed from elements.py, ~460 lines added to batched.py

What moved where

Data Class Properties moved from Model → Data
BusesData balance_coefficients
ComponentsData status_data, status_params, previous_status_dict, flow_mask, flow_count, with_prevent_simultaneous
ConvertersData signed_coefficients, equation_mask, max_equations, n_equations_per_converter, piecewise_* (8 properties)
TransmissionsData relative_losses, absolute_losses, in1_mask, out1_mask, in2_mask, out2_mask, has_absolute_losses_mask, transmissions_with_abs_losses, bidirectional_ids, balanced_ids, balanced_in1_mask, balanced_in2_mask

Minor cleanups

  • FlowsData.dim_name: @cached_property@property (consistency with all other Data classes)
  • TransmissionsModel: No longer calls private d._build_flow_mask() — uses pre-computed balanced_in1_mask/balanced_in2_mask

Type of Change

  • Code refactoring

Testing

  • Existing tests still pass

Checklist

  • My code follows the project style
  • I have updated documentation if needed

  Summary

  Phase 1: TransmissionsData

  - Added flow_ids parameter to TransmissionsData.__init__
  - Moved 12 cached properties from TransmissionsModel to TransmissionsData: bidirectional_ids, balanced_ids, _build_flow_mask(), in1_mask, out1_mask, in2_mask, out2_mask,
  relative_losses, absolute_losses, has_absolute_losses_mask, transmissions_with_abs_losses
  - Updated TransmissionsModel.create_constraints() to use self.data.*
  - Updated BatchedAccessor.transmissions to pass flow_ids

  Phase 2: BusesData

  - Added balance_coefficients cached property to BusesData
  - Updated BusesModel.create_constraints() to use self.data.balance_coefficients

  Phase 3: ConvertersData

  - Added flow_ids and timesteps parameters to ConvertersData.__init__
  - Moved 13 cached properties from ConvertersModel to ConvertersData: factor_element_ids, max_equations, equation_mask, signed_coefficients, n_equations_per_converter,
  piecewise_element_ids, piecewise_segment_counts_dict, piecewise_max_segments, piecewise_segment_mask, piecewise_flow_breakpoints, piecewise_segment_counts_array,
  piecewise_breakpoints
  - Updated ConvertersModel methods to use self.data.*
  - Removed unused defaultdict and stack_along_dim imports from elements.py

  Phase 4: ComponentsData

  - Added flows_data, effect_ids, timestep_duration parameters to ComponentsData.__init__
  - Moved 6 cached properties from ComponentsModel to ComponentsData: with_prevent_simultaneous, status_params, previous_status_dict, status_data, flow_mask, flow_count
  - Moved _get_previous_status_for_component() helper to ComponentsData
  - Updated ComponentsModel to use self.data.* throughout

  Bug Fix

  - Discovered a stale cache issue: FlowsData.previous_states could be cached before all previous_flow_rate values were set (e.g., in from_old_results). Fixed by having
  ComponentsData._get_previous_status_for_component() compute previous status directly from flow attributes instead of going through the potentially-stale
  FlowsData.previous_states cache.
…n2_mask cached properties to TransmissionsData. TransmissionsModel now uses these instead of calling the

  private d._build_flow_mask().
  2. EffectsModel/elements: Confirmed not a bug — EffectsModel does not inherit from TypeModel and never accesses .elements on its data, so EffectsData not having elements is
  fine.
  3. FlowsData.dim_name: Changed from @cached_property to @Property to match all other Data classes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/element-data-classes+focus-on-data

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FBumann FBumann changed the title Feature/element data classes+focus on data Consolidate data stacking into *Data classes Feb 10, 2026
@FBumann FBumann merged commit e50b021 into feature/element-data-classes Feb 10, 2026
8 checks passed
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.

1 participant