Skip to content

Tiered charge bug fix and additions - #63

Open
dalyw wants to merge 3 commits into
mainfrom
tiered-charge-fixes
Open

Tiered charge bug fix and additions#63
dalyw wants to merge 3 commits into
mainfrom
tiered-charge-fixes

Conversation

@dalyw

@dalyw dalyw commented Sep 2, 2026

Copy link
Copy Markdown
Contributor
  1. Contributes to resolving flex-pse issue BUG: opex.py never forwards consumption_estimate, so tiered charges silently price at zero flex-pse/flex-pse#73

flex-pse identified EECO bugs/limitation:

  • EECO's tiered-charge pricing mutates the charge arrays it is given in place, even though subsequent calculate_cost calls might use different tiers
  • Helpful to have warnings for charge tiers that are zeroed

Updates in costs.py:

  • Add a ValueError for a consumption_estimate that isn't a scalar or has the wrong length.
  • Only apply convex relaxation for tier with a finite next_limit or an hour-specific rate. Allowing flat topmost-tier scenarios to be represented exactly / for an LP without requiring consumption estimate
  1. Resolves Demand-charge epigraph: scope to the assessed window, bound _max, expose a handle #60
    With these changes:

utils.py

  • index_set, lower_bound, and initialize arguments to ut.max(), passed through to add_component()

costs.py

  • adding get_charge_window() helper and using it in get_prev_demand_dict and calculate_demand_cost where it calls ut.max()
  • in calculate_demand_cost, calling ut.max() first to get the timesteps that matter for demand charges

tests

  • adding test casess to test_max_pyo
  • Adding epigraph expectation to test_calculate_cost_pyo_non_standard_index
  • New test_get_charge_window.

Code edits and new test cases written with prompting Claude Opus 5 then manually checked

Changes would be a minor version bump, no breaking changes

Pull request recommendations:

  • Name your pull request your-development-type/short-description. Ex: feature/gui
  • Link to any relevant issue in the PR description. Ex: Resolves [ENH: Support optimization of flexibility metrics #12]
  • Provide context of changes.
  • Provide relevant tests for your feature or bug fix.
  • Provide or update documentation for any feature added by your pull request.

Thanks for contributing!

- EECO's tiered-charge pricing mutates the charge arrays it is given in place, even though subsequent calculate_cost calls might use different tiers
- Helpful to have warnings for charge tiers that are zeroed

Warn if a tiered charge key is zeroed out due to missing consumption_estimate

Add a ValueError for a consumption_estimate that isn't a scalar or has the wrong length.

Only apply convex relaxation for tier with a finite next_limit or an hour-specific rate. Flat top-tiers can be represented exactly in LP.

Updating comments
@codecov-commenter

codecov-commenter commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.06%. Comparing base (fcbe040) to head (2f10eda).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
+ Coverage   95.21%   96.06%   +0.84%     
==========================================
  Files          10       10              
  Lines        1861     1929      +68     
==========================================
+ Hits         1772     1853      +81     
+ Misses         89       76      -13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

utils.py
- index_set, lower_bound, and initialize arguments to ut.max(), passed through to add_component()

costs.py
- adding get_charge_window()  helper and using it in get_prev_demand_dict and calculate_demand_cost where it calls ut.max()
- in calculate_demand_cost, calling ut.max() first to get the timesteps that matter for demand charges

adding test casess to test_max_pyo. Adding epigraph expectation to test_calculate_cost_pyo_non_standard_index. New test_get_charge_window
@dalyw
dalyw marked this pull request as ready for review September 2, 2026 18:50
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.

Demand-charge epigraph: scope to the assessed window, bound _max, expose a handle

2 participants