Memory usage and debug read fixes#4025
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets two operational concerns in Predbat: reducing memory pressure from SoC→rate curve caching, and improving robustness when loading older debug YAML snapshots.
Changes:
- Reduced cache-key churn in charge/discharge rate curve lookups by rounding SoC inputs (intended to improve cache hit-rate and memory usage).
- Optimised
rate_min_forward_calc()from an O(n²) slice-min approach to an O(n) right-to-left running-min scan. - Added backwards-compatible handling for old-format
octopus_slotsin debug YAML, plus a new unit test forrate_min_forward_calc().
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| coverage/cases/predbat_debug_agile1.yaml.expected.json | Updates expected outputs to match small numeric differences from the SoC rounding change. |
| apps/predbat/utils.py | Rounds SoC before cached curve evaluation to reduce cache key cardinality (memory/perf). |
| apps/predbat/userinterface.py | Adds migration logic for old debug YAML octopus_slots format. |
| apps/predbat/unit_test.py | Registers a new test module in the unit test runner. |
| apps/predbat/tests/test_rate_min_forward_calc.py | Adds coverage for rate_min_forward_calc() behavior and edge cases. |
| apps/predbat/fetch.py | Replaces O(n²) forward-min computation with an O(n) running-min implementation. |
Comment on lines
996
to
+1000
| def get_charge_rate_curve(soc, charge_rate_setting, soc_max, battery_rate_max_charge, battery_charge_power_curve, battery_rate_min, battery_temperature, battery_temperature_curve): | ||
| """ | ||
| Compute true charging rate from SoC and charge rate setting | ||
| """ | ||
| return get_charge_rate_curve_cached(soc, charge_rate_setting, soc_max, battery_rate_max_charge, charge_curve_to_tuple(battery_charge_power_curve), battery_rate_min, battery_temperature, charge_curve_to_tuple(battery_temperature_curve)) | ||
| return get_charge_rate_curve_cached(round(soc, 1), charge_rate_setting, soc_max, battery_rate_max_charge, charge_curve_to_tuple(battery_charge_power_curve), battery_rate_min, battery_temperature, charge_curve_to_tuple(battery_temperature_curve)) |
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.
No description provided.