Skip to content

Random testing and tweak optimisation on by default#3862

Merged
springfall2008 merged 9 commits intomainfrom
feat/random2
May 4, 2026
Merged

Random testing and tweak optimisation on by default#3862
springfall2008 merged 9 commits intomainfrom
feat/random2

Conversation

@springfall2008
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 4, 2026 18:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 under coverage/.
  • Removes the calculate_tweak_plan configuration option and wires tweak_plan() as the default “fast” fallback when calculate_second_pass is 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_pass now implies that turning it off disables the “second pass” entirely, but the code falls back to running tweak_plan() when calculate_second_pass is 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.

Comment thread apps/predbat/plan.py Outdated
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 thread apps/predbat/tests/test_random_scenarios.py Outdated
Comment thread apps/predbat/unit_test.py
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)
springfall2008 and others added 2 commits May 4, 2026 19:12
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008 springfall2008 merged commit d4fedae into main May 4, 2026
1 check passed
@springfall2008 springfall2008 deleted the feat/random2 branch May 4, 2026 18:25
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.

2 participants