perf: precompute constraint arrays for device_scheduler callbacks#2291
Draft
Flix6x wants to merge 2 commits into
Draft
perf: precompute constraint arrays for device_scheduler callbacks#2291Flix6x wants to merge 2 commits into
Flix6x wants to merge 2 commits into
Conversation
Pyomo calls each Param/Set initialize callback once per index tuple, so per-index pandas .iloc and boolean-mask lookups cost O(devices x timesteps) slow scalar accesses. Precompute plain numpy arrays (and a j -> quantity dict per commitment) once and index into those instead, preserving NaN semantics via float dtype. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pxkeq64jtENY7fiWjwUsVS
Documentation build overview
7 files changed ·
|
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pxkeq64jtENY7fiWjwUsVS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Speed up
device_schedulermodel construction by precomputing plain numpy arrays (and aj -> quantitydict per commitment) for the constraint columns, instead of doing per-index pandas lookups inside Pyomoinitializecallbacks.Pyomo calls each
Param/Setinitialize callback once per index tuple, so a pandas.ilocscalar lookup (or worse, a boolean-mask filter as incommitment_quantity_select) inside a callback costs O(devices × timesteps) individual slow pandas accesses. Indexing into precomputed numpy arrays yields identical values (NaN semantics preserved via float dtype) at a fraction of the cost.Complementary to #2282 (recursive stock balance): that one speeds up constraint expression construction, this one speeds up parameter initialization.
Notes
ems_derivative_max_arr[g][j]).try/except KeyError) is now an explicitNonesentinel meaning "assume perfect efficiency".flexmeasures/data/models/planning/tests/test_solver.py(128 passed, 3 xfailed) andtest_commitments.py(14 passed) pass locally.To do before undrafting
🤖 Generated with Claude Code
https://claude.ai/code/session_01Pxkeq64jtENY7fiWjwUsVS