Random testing and tweak optimisation on by default#3862
Merged
springfall2008 merged 9 commits intomainfrom May 4, 2026
Merged
Random testing and tweak optimisation on by default#3862springfall2008 merged 9 commits intomainfrom
springfall2008 merged 9 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a reproducible “random scenario” benchmarking workflow to exercise Predbat’s optimiser from the coverage/ directory, and changes the optimisation flow so that when the full second pass is disabled Predbat runs a faster tweak pass by default (removing the old calculate_tweak_plan switch).
Changes:
- Introduces random scenario generation/run/compare/profile commands to
apps/predbat/unit_test.py, plus supporting docs and helper scripts undercoverage/. - Removes the
calculate_tweak_planconfiguration option and wirestweak_plan()as the default “fast” fallback whencalculate_second_passis off. - Includes small optimiser/prediction adjustments and updated expected outputs/baseline artifacts for the new workflow.
Reviewed changes
Copilot reviewed 13 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| mkdocs.yml | Adds the new random scenarios documentation page to the MkDocs nav. |
| docs/random-scenarios.md | Documents the random scenario benchmarking workflow and CLI options. |
| docs/customisation.md | Removes the old calculate_tweak_plan switch documentation. |
| coverage/run_random_profile | Convenience script for profiling a scenario run. |
| coverage/run_random | Convenience script for running and comparing random scenario results. |
| coverage/cases/random_results.json | Baseline random-run results JSON for comparisons. |
| coverage/cases/predbat_debug_pre_saving1.yaml.expected.json | Updates expected debug-case output after optimisation behavior changes. |
| apps/predbat/unit_test.py | Adds CLI flags for random scenario generate/run/compare/profile and skips random_scenarios.yaml in debug cases. |
| apps/predbat/tests/test_single_debug.py | Removes now-obsolete commented calculate_tweak_plan toggles. |
| apps/predbat/tests/test_random_scenarios.py | Adds the random scenario framework implementation (generation, execution, comparison, profiling). |
| apps/predbat/tests/test_infra.py | Removes calculate_tweak_plan from the default test config. |
| apps/predbat/prediction.py | Removes a SOC rounding step within prediction. |
| apps/predbat/predbat.py | Removes calculate_tweak_plan reset initialization. |
| apps/predbat/plan.py | Adjusts optimiser heuristics, reduces copying overhead, changes tweak/second-pass flow, and makes tweak_plan return metrics. |
| apps/predbat/fetch.py | Stops reading the removed calculate_tweak_plan config option. |
| apps/predbat/config.py | Removes calculate_tweak_plan from CONFIG_ITEMS. |
| .cspell/custom-dictionary-workspace.txt | Adds spellings used by the new profiling/CLI docs. |
Comments suppressed due to low confidence (1)
docs/customisation.md:256
- The documentation for
switch.predbat_calculate_second_passnow implies that turning it off disables the “second pass” entirely, but the code falls back to runningtweak_plan()whencalculate_second_passis false. Please update this section to explain the new behavior (full second pass vs faster tweak pass) so users understand what happens when the switch is off.
**switch.predbat_calculate_second_pass** (_expert mode_) When turned On causes Predbat to perform a second pass optimisation across all the charge and export windows in time order.
Note: This feature is quite slow so may need a higher-performance machine so is turned Off by default.
This can help to slightly improve the plan for tariffs like Agile but can make it worse in some fixed rate tariffs in which you want to force export late.
| self.tweak_plan(self.end_record, best_metric, metric_keep) | ||
| else: | ||
| # Tweak plan (faster) | ||
| best_metric, best_cost, best_keep, best_cycle, best_carbon, best_import = self.tweak_plan(self.end_record, best_metric, metric_keep) |
Comment on lines
349
to
+363
| print("**** Starting Predbat tests ****") | ||
| my_predbat = create_predbat() | ||
| print("**** Testing Predbat ****") | ||
| failed = False | ||
|
|
||
| if args.random_run: | ||
| if not args.random_template: | ||
| print("ERROR: --random-template is required with --random-run") | ||
| sys.exit(1) | ||
| run_scenarios_from_file(my_predbat, args.random_scenarios, args.random_template, args.random_results, debug=args.full_debug, scenario_id=args.random_scenario) | ||
| sys.exit(0) | ||
|
|
||
| if args.random_compare: | ||
| compare_results(args.random_compare[0], args.random_compare[1]) | ||
| sys.exit(0) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.