Skip to content

Split out Pyomo Controllers to separate files#549

Open
elenya-grant wants to merge 8 commits intoNatLabRockies:developfrom
elenya-grant:clean/dispatch
Open

Split out Pyomo Controllers to separate files#549
elenya-grant wants to merge 8 commits intoNatLabRockies:developfrom
elenya-grant:clean/dispatch

Conversation

@elenya-grant
Copy link
Collaborator

@elenya-grant elenya-grant commented Feb 25, 2026

Split out Pyomo Controllers to separate files

Split out the controllers in h2integrate/control/control_strategies/pyomo_controllers.py to separate files and removed some inheritance so that the logic is easier to follow. Also refactored the HeuristicLoadFollowingController to no longer inherit the SimpleBatteryControllerHeuristic class (the SimpleBatteryControllerHeuristic has been removed and the functionality now exists in the HeuristicLoadFollowingController).

These changes are intended to make further development of the pyomo controllers easier by making the individual control strategies easier to understand through the removal of inheritance and being able to look at a single file containing the entire control strategy of interest (the individual files also make it easier to determine which attributes are being used and which ones aren't).

Removed n_horizon_window from the PyomoControllerBaseConfig and PySAMBatteryPerformanceModelConfig because it was unused.

Follow-on work may look at refactoring the PyomoControllerBaseConfig, HeuristicLoadFollowingControllerConfig, and OptimizedDispatchControllerConfig to remove unused attributes.

Section 1: Type of Contribution

  • Feature Enhancement
    • Framework
    • New Model
    • Updated Model
    • Tools/Utilities
    • Other (please describe):
  • Bug Fix
  • Documentation Update
  • CI Changes
  • Other (please describe): clean-up

Section 2: Draft PR Checklist

  • Open draft PR
  • Describe the feature that will be added
  • Fill out TODO list steps
  • Describe requested feedback from reviewers on draft PR
  • Complete Section 7: New Model Checklist (if applicable)

TODO:

  • Step 1
  • Step 2

Type of Reviewer Feedback Requested (on Draft PR)

Structural feedback:

Implementation feedback:

Other feedback:

Section 3: General PR Checklist

  • PR description thoroughly describes the new feature, bug fix, etc.
  • Added tests for new functionality or bug fixes
  • Tests pass (If not, and this is expected, please elaborate in the Section 6: Test Results)
  • Documentation
    • Docstrings are up-to-date
    • Related docs/ files are up-to-date, or added when necessary
    • Documentation has been rebuilt successfully
    • Examples have been updated (if applicable)
  • CHANGELOG.md has been updated to describe the changes made in this PR

Section 3: Related Issues

Section 4: Impacted Areas of the Software

Section 4.1: New Files

  • h2integrate/control/control_strategies/optimized_pyomo_controller.py: new file containing the OptimizedDispatchControllerConfig and OptimizedDispatchController
  • h2integrate/control/control_strategies/pyomo_controller_baseclass.py: new file containing the PyomoControllerBaseConfig, PyomoControllerBaseClass, and SolverOptions
  • h2integrate/control/control_strategies/heuristic_pyomo_controller.py: file containing the HeuristicLoadFollowingControllerConfig and HeuristicLoadFollowingController

Section 4.2: Modified Files

  • h2integrate/control/test/test_heuristic_controllers.py: updated import statement
  • h2integrate/control/control_strategies/passthrough_openloop_controller.py: no longer inherits ControllerBaseClass (the ControllerBaseClass was removed)
  • h2integrate/core/supported_models.py: updated import statements for the OptimizedDispatchController and HeuristicLoadFollowingController

Section 4.3: Removed Files

  • h2integrate/control/control_strategies/pyomo_controllers.py: old file containing the other controllers.
  • h2integrate/control/control_strategies/controller_baseclass.py: removed this very simplistic baseclass, was only used for its initialize() method

Section 5: Additional Supporting Information

Section 6: Test Results, if applicable

Section 7 (Optional): New Model Checklist

  • Model Structure:
    • Follows established naming conventions outlined in docs/developer_guide/coding_guidelines.md
    • Used attrs class to define the Config to load in attributes for the model
      • If applicable: inherit from BaseConfig or CostModelBaseConfig
    • Added: initialize() method, setup() method, compute() method
      • If applicable: inherit from CostModelBaseClass
  • Integration: Model has been properly integrated into H2Integrate
    • Added to supported_models.py
    • If a new commodity_type is added, update create_financial_model in h2integrate_model.py
  • Tests: Unit tests have been added for the new model
    • Pytest-style unit tests
    • Unit tests are in a "test" folder within the folder a new model was added to
    • If applicable add integration tests
  • Example: If applicable, a working example demonstrating the new model has been created
    • Input file comments
    • Run file comments
    • Example has been tested and runs successfully in test_all_examples.py
  • Documentation:
    • Write docstrings using the Google style
    • Model added to the main models list in docs/user_guide/model_overview.md
      • Model documentation page added to the appropriate docs/ section
      • <model_name>.md is added to the _toc.yml

@elenya-grant elenya-grant added ready for review This PR is ready for input from folks dispatch related to dispatch and control labels Feb 25, 2026
Copy link
Collaborator

@kbrunik kbrunik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is helpful! It makes it easier to track, which will help with future dispatch development. Thanks!

@bayc bayc self-requested a review February 26, 2026 20:45
Copy link
Collaborator

@jaredthomas68 jaredthomas68 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Collaborator

@genevievestarke genevievestarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good work @elenya-grant, thank you for taking this on!

control_strategy = self.options["tech_config"]["control_strategy"]["model"]

# TODO: implement optional kwargs for this method: maybe this will remove if statement here
if "Heuristic" in control_strategy:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These callouts for the heuristic and optimized control strategies are a little bit weird in the base class. This function meaningfully changes between the heuristic and optimized control schemes.
@johnjasa @bayc, thoughts on repeated code vs. these if callouts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird but this is what existed before... I think it'd be nice to remove this eventually

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this logic as-is; it's pretty clear. I like that it's just calling initialize_parameters in each case, good parallelism there. If the method had the same args expected then we wouldn't need the split logic; I don't think we should refactor that here though.

@johnjasa johnjasa requested a review from vijay092 February 27, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dispatch related to dispatch and control ready for review This PR is ready for input from folks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants