AlphaEvolve Runtime Harness (evolve)¶
evolve
¶
Opt-In AlphaEvolve & Vertex AI Gemini Evolutionary Harness (scale_forecasting.evolve).
Provides opt-in runtime evolutionary code synthesis built directly on top of
:meth:~scale_forecasting.sdk.Forecaster.auto (auto.py / auto_policy.py) and governed by a
3-Gate Anti-Overfitting Ratchet:
- Dual-Backend Evolution Transport (:mod:
~scale_forecasting.evolve.client): backend="alphaevolve"(Default): Managed Gemini Enterprise Discovery Engine AlphaEvolve REST API (discoveryengine.googleapis.com/v1alpha), guarded by a fast pre-flight access probe (:func:probe_alphaevolve_access) before any backtests run.backend="vertex_gemini"(Backup Non-Default): Standard Vertex AI Gemini (aiplatform.googleapis.com, default"gemini-3.8-flash"or any user-specifiedmodel_name) with an in-memory multi-island MAP-Elites population buffer (:class:IslandPopulationBuffer) for projects without Gemini Enterprise licensing.backend="mock"(Offline Test Backend): Deterministic zero-network candidate replay.- Five
# EVOLVE-BLOCKTargets (:mod:~scale_forecasting.evolve.targets):"features"(:func:synthesize_evolved_features),"ensemble"(:func:compute_evolved_weights),"model"(:class:EvolvedForecaster),"policy"(:func:evolve_policy_weights), and"similarity_kernel"(:func:compute_evolved_similarity_kernel). - AST Security & Temporal Causality Sandbox (:mod:
~scale_forecasting.evolve.sandbox): Static AST whitelist (:func:validate_candidate_ast) plus the $+10^6$ future-target perturbation test (:func:verify_no_future_leakage). - 3-Gate Anti-Overfitting Ratchet (:mod:
~scale_forecasting.evolve.evaluator& :mod:~scale_forecasting.evolve.runner): Gate 1 (Inner Walk-Forward CV Lift), Gate 2 (Diebold–Mariano significance & worst-decile FVA guard), and Gate 3 (Held-Out Lockdown Fold never seen by the evolution loop).
AlphaEvolveClient
¶
AlphaEvolveClient(
project_id=None,
location="global",
*,
model_name=DEFAULT_GEMINI_MODEL,
timeout=30.0,
http_request=None,
)
Managed Discovery Engine AlphaEvolve REST transport (backend='alphaevolve').
Source code in src/scale_forecasting/evolve/client.py
acquire_programs
¶
Acquire mutated candidate programs via :acquirePrograms.
Source code in src/scale_forecasting/evolve/client.py
create_experiment
¶
Create a managed alphaEvolveExperiments resource in Discovery Engine.
Source code in src/scale_forecasting/evolve/client.py
probe_access
¶
Run the pre-flight access probe against discoveryengine.googleapis.com.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Acquire the next candidate program from the managed AlphaEvolve experiment.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Report candidate evaluation fitness back to Discovery Engine AlphaEvolve.
Source code in src/scale_forecasting/evolve/client.py
submit_evaluations
¶
Submit walk-forward evaluation scores via :submitProgramsEvaluations.
Source code in src/scale_forecasting/evolve/client.py
AutoPolicyWeights
dataclass
¶
AutoPolicyWeights(
intermittent_share_min=0.165,
log1p_level_vol_corr_min=0.635,
log1p_growth_ratio_min=1.336,
resid_hetero_min=0.3,
structural_break_share_min=0.251,
outlier_spike_share_min=0.195,
direct_horizon_decay_ratio_min=1.323,
resid_acf1_escalate_min=0.309,
fva_escalate_min_pct=3.077,
white_noise_growth_tol=0.179,
white_noise_acf_season_max=0.17,
require_white_noise_stop=True,
pass_decay_factor=0.7,
first_light_include_regression_lags=True,
first_light_selection_rule="best_single",
tree_n_estimators_fast=60,
enable_similarity_global=True,
similarity_silhouette_threshold=0.3,
action_weights=_default_action_weights(),
)
Typed container of evolutionary thresholds for :mod:scale_forecasting.auto_policy.
from_defaults
classmethod
¶
Construct :class:AutoPolicyWeights from auto_policy.evolved_policy_thresholds().
from_dict
classmethod
¶
Construct :class:AutoPolicyWeights from a plain threshold dictionary.
Source code in src/scale_forecasting/evolve/targets.py
to_dict
¶
Serialize policy weights to a dictionary compatible with auto_policy.
with_updates
¶
CandidateEvaluation
dataclass
¶
CandidateEvaluation(
candidate_id,
generation,
target,
backend,
code,
ast_valid,
causal_valid,
inner_cv_score,
baseline_score,
inner_fva_pct,
dm_stat,
dm_pvalue,
worst_decile_fva_pct,
gate1_passed,
gate2_passed,
lockdown_baseline_score,
lockdown_candidate_score,
gate3_passed,
promoted,
status,
rejection_reason,
wall_seconds,
series_losses_candidate=(),
series_losses_baseline=(),
point_losses_candidate=(),
point_losses_baseline=(),
)
Complete evaluation telemetry for one candidate program across all 3 ratchet gates.
to_row
¶
Convert candidate evaluation to a flat leaderboard row dictionary.
Source code in src/scale_forecasting/evolve/evaluator.py
EvolutionEvaluator
¶
EvolutionEvaluator(
data_df=None,
*,
from_runs=None,
from_run_ids=None,
dataset_id="scale_forecasting",
project_id=None,
region="us-central1",
target="features",
backend="alphaevolve",
tier="first_light",
where="local",
horizon=None,
significance_alpha=0.1,
worst_decile_floor=-0.02,
timeout_seconds=20.0,
ts_id_col="ts_id",
date_col="ds",
target_col="y",
freq=None,
)
Evaluates candidate # EVOLVE-BLOCK programs on top of Forecaster.auto() or prior runs.
Source code in src/scale_forecasting/evolve/evaluator.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 | |
evaluate_candidate_inner
¶
Evaluate code through Pre-Gate (AST + Causality), Gate 1, and Gate 2.
Source code in src/scale_forecasting/evolve/evaluator.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 | |
evaluate_lockdown_gate3
¶
Evaluate the winning inner-CV candidate once on the Held-Out Lockdown Fold.
Source code in src/scale_forecasting/evolve/evaluator.py
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 | |
materialize_ensemble_predictions
¶
Materialize blended forward forecasts with empirical conformal 80% intervals.
Source code in src/scale_forecasting/evolve/evaluator.py
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 | |
EvolveConfig
dataclass
¶
EvolveConfig(
target="features",
backend="alphaevolve",
tier="deep_sky",
where="local",
horizon=None,
max_evaluations=10,
significance_alpha=0.1,
worst_decile_floor=-0.02,
project_id=None,
location="global",
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
export_path=None,
random_seed=42,
decision_metric=None,
timeout_seconds=20.0,
dry_run=False,
mock_candidates=None,
candidate_programs=None,
lockdown_override_score=None,
from_runs=None,
from_run_ids=None,
dataset_id="scale_forecasting",
)
Configuration for an opt-in :func:run_evolution / :meth:Forecaster.evolve session.
model_dump
¶
model_validate
classmethod
¶
Validate a dictionary or :class:EvolveConfig instance.
Source code in src/scale_forecasting/evolve/runner.py
to_dict
¶
Serialize configuration to a plain JSON-friendly dictionary.
Source code in src/scale_forecasting/evolve/runner.py
EvolveResult
dataclass
¶
EvolveResult(
target,
backend_used,
promoted,
rejection_reason,
baseline_score,
inner_cv_score,
lockdown_baseline_score,
lockdown_candidate_score,
fva_pct,
dm_pvalue,
worst_decile_fva_pct,
champion_code,
export_path,
leaderboard_df,
forecaster=None,
assessment=None,
evaluations_run=0,
wall_seconds=0.0,
candidate_code="",
diagnostics=dict(),
predictions_df=None,
model_name=DEFAULT_GEMINI_MODEL,
)
Outcome of an evolutionary run governed by the 3-Gate Anti-Overfitting Ratchet.
emit_airflow_dag
¶
Render a standalone Cloud Composer 3 / Airflow DAG scheduling periodic evolution.
If output_path is provided, writes the DAG Python source to output_path and returns
the rendered DAG source code string.
Source code in src/scale_forecasting/evolve/runner.py
summary
¶
Return a concise human-readable summary of the 3-Gate Ratchet verdict.
Source code in src/scale_forecasting/evolve/runner.py
to_dict
¶
Serialize result summary and leaderboard to a JSON-compatible dictionary.
Source code in src/scale_forecasting/evolve/runner.py
EvolvedForecaster
¶
Bases: BaseModel
Custom evolutionary forecaster plugin (target='model').
Source code in src/scale_forecasting/evolve/targets.py
fit
¶
Fit evolutionary damped trend + harmonic seasonal + ridge exogenous model.
Source code in src/scale_forecasting/evolve/targets.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
predict
¶
Predict horizon steps ahead with calibrated residual intervals.
Source code in src/scale_forecasting/evolve/targets.py
IslandCandidate
dataclass
¶
One evaluated candidate program stored inside :class:IslandPopulationBuffer.
IslandPopulationBuffer
¶
In-memory multi-island MAP-Elites population buffer for backend='vertex_gemini'.
Source code in src/scale_forecasting/evolve/client.py
add
¶
Insert an evaluated candidate into its corresponding island and prune low performers.
Source code in src/scale_forecasting/evolve/client.py
best
¶
Return the global best candidate across all islands.
select_parent
¶
Select the lowest-loss parent from the active island for generation.
Source code in src/scale_forecasting/evolve/client.py
MockEvolutionClient
¶
MockEvolutionClient(
target="features",
candidates=None,
max_evaluations=10,
*,
model_name=DEFAULT_GEMINI_MODEL,
)
Offline deterministic evolution transport for fast unit testing and CI --dry-run.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Return deterministic candidate generation - 1 with zero network calls.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Append evaluation telemetry to self.recorded_evaluations.
Source code in src/scale_forecasting/evolve/client.py
SandboxValidationResult
dataclass
¶
TargetSpec
dataclass
¶
TargetSpec(
target,
entrypoint,
description,
seed_code,
system_instruction,
mutation_prompt_template,
)
Specification and seed program for one # EVOLVE-BLOCK evolutionary target.
VertexGeminiEvolutionClient
¶
VertexGeminiEvolutionClient(
project_id=None,
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
*,
n_islands=3,
temperature=0.4,
genai_client=None,
)
Backup non-default evolution transport using standard Vertex AI Gemini.
Uses google.genai.Client(vertexai=True, project=project_id, location=region) (default model
"gemini-3.8-flash", or any caller-supplied model_name) plus
:class:IslandPopulationBuffer to mutate # EVOLVE-BLOCK code from walk-forward diagnostic
feedback without requiring a Gemini Enterprise license.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Mutate # EVOLVE-BLOCK using Vertex AI Gemini + island population state.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Record candidate score and walk-forward diagnostics into the island buffer.
Source code in src/scale_forecasting/evolve/client.py
build_mutation_prompt
¶
Render a diagnostic-guided mutation prompt for target.
Source code in src/scale_forecasting/evolve/targets.py
compile_candidate_symbol
¶
Validate code with :func:validate_candidate_ast and return entrypoint.
Source code in src/scale_forecasting/evolve/sandbox.py
compute_evolved_similarity_kernel
¶
Synthesize an (N, N) similarity matrix in [0.0, 1.0] over per-series embeddings.
Source code in src/scale_forecasting/evolve/targets.py
compute_evolved_weights
¶
Compute global (dict[str, float]) or per-series (dict[str, dict[str, float]]) weights.
Source code in src/scale_forecasting/evolve/targets.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
create_evolution_client
¶
create_evolution_client(
backend,
*,
target="features",
project_id=None,
location="global",
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
max_evaluations=10,
mock_candidates=None,
genai_client=None,
alphaevolve_http_request=None,
)
Instantiate the requested evolution client backend.
Source code in src/scale_forecasting/evolve/client.py
deterministic_mock_candidates
¶
Return count deterministic, AST-safe, causal candidate programs for target.
Source code in src/scale_forecasting/evolve/targets.py
evolve_policy_weights
¶
Tune :class:AutoPolicyWeights thresholds for auto_policy (target='policy').
Source code in src/scale_forecasting/evolve/targets.py
execute_in_sandbox
¶
Compile and execute entrypoint(*args, **kwargs) with a hard wall-clock timeout.
Source code in src/scale_forecasting/evolve/sandbox.py
extract_evolve_block
¶
Extract the code lines between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END.
If the markers are absent from code, returns normalized dedented code.
Source code in src/scale_forecasting/evolve/targets.py
get_target_seed
¶
Return the canonical :class:TargetSpec for target.
Source code in src/scale_forecasting/evolve/targets.py
inject_evolve_block
¶
Inject block between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END in template.
Handles both:
- an inner snippet (indented to match # EVOLVE-BLOCK-START in template), and
- a full program that already contains # EVOLVE-BLOCK-START / # EVOLVE-BLOCK-END (its
inner block is extracted first and injected into template).
Source code in src/scale_forecasting/evolve/targets.py
main
¶
CLI entry point wrapper delegating to :func:scale_forecasting.evolve.__main__.main.
probe_alphaevolve_access
¶
Fast pre-flight check verifying Discovery Engine AlphaEvolve entitlement before backtests.
Raises :class:~scale_forecasting.errors.ConfigError (aliased as ConfigurationError) if
discoveryengine.googleapis.com is disabled or the project/organization lacks Gemini
Enterprise AlphaEvolve entitlement (HTTP 403 / 404).
Source code in src/scale_forecasting/evolve/client.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
run_evolution
¶
run_evolution(
data=None,
config=None,
*,
from_runs=None,
from_run_ids=None,
dataset_id=None,
target=None,
backend=None,
tier=None,
where=None,
horizon=None,
max_evaluations=None,
significance_alpha=None,
worst_decile_floor=None,
project_id=None,
location=None,
region=None,
model_name=None,
export_path=None,
random_seed=None,
decision_metric=None,
timeout_seconds=None,
dry_run=None,
mock_candidates=None,
candidates=None,
lockdown_override_score=None,
genai_client=None,
alphaevolve_http_request=None,
http_get=None,
ts_id_col="ts_id",
date_col="ds",
target_col="y",
freq=None,
)
Run opt-in evolutionary code synthesis on top of Forecaster.auto() or prior runs.
Source code in src/scale_forecasting/evolve/runner.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
split_inner_and_lockdown_panel
¶
Split a historical panel into (inner_df, lockdown_truth_df, lockdown_future_exog_df).
inner_df: rows $t \le T - H_{\text{lockdown}}$ per series (visible to evolution).lockdown_truth_df: last $H_{\text{lockdown}}$ historical rows per series with truey(withheld for Gate 3 verification).lockdown_future_exog_df: exogenous covariate rows for the lockdown window withyremoved so lockdown predictions cannot observe held-out targets.
Source code in src/scale_forecasting/evolve/evaluator.py
synthesize_evolved_features
¶
Synthesize causal evolved_feat_* columns without future target lookahead.
Source code in src/scale_forecasting/evolve/targets.py
validate_candidate_ast
¶
Parse code into an AST and reject prohibited imports, calls, and reflection.
Source code in src/scale_forecasting/evolve/sandbox.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
verify_no_future_leakage
¶
Verify that perturbing the last horizon target values by +1e6 does not alter
any engineered features or fitted values on earlier timestamps $t \le T - H$.
Returns True only when all outputs on $t \le T - H$ are bit-for-bit identical
(np.allclose(..., atol=1e-12, equal_nan=True)). Immediately returns False if the
candidate uses future information (such as .shift(-k), .bfill(), or full-series
global target aggregations).
Source code in src/scale_forecasting/evolve/sandbox.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
verify_oof_pool_compatibility
¶
verify_oof_pool_compatibility(
runs,
*,
project_id=None,
dataset_id="scale_forecasting",
region="us-central1",
horizon=None,
)
Verify OOF & horizon alignment across runs, disambiguate colliding models, and split.
Verifies how borrowing interacts with backtest, hpo, and ensemble:
- Requires non-empty overlapping (ts_id, ds) out-of-fold rows across all runs (and
overlapping (ts_id, forecast_date) horizon grids when forward predictions are present),
raising :class:~scale_forecasting.errors.ConfigError when disjoint.
- When multiple runs contain the same model_type, compares their aligned OOF yhat
trajectories: identical trajectories (same model_spec_hash) are deduplicated, whereas
distinct trajectories (different HPO winner, model_params, or ensemble pool) are
disambiguated as <model_type>@<run_short_id>.
- Splits the pooled oof_df temporally per series into inner_oof_df (for candidate
synthesis and Gates 1 & 2) and lockdown_oof_df (withheld for Gate 3).
Source code in src/scale_forecasting/evolve/evaluator.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
client
¶
Dual-backend evolution transport (alphaevolve, vertex_gemini, mock) and pre-flight probe.
Provides three evolution client implementations behind a unified candidate-generation and feedback interface:
- Primary Managed Backend (
backend="alphaevolve", Default): Connects to the Gemini Enterprise Discovery Engine AlphaEvolve REST API (https://discoveryengine.googleapis.com/v1alpha/projects/{project_id}/locations/{location}/alphaEvolveExperiments) using Application Default Credentials (ADC). Includes :func:probe_alphaevolve_accessfor fast pre-flight verification before any walk-forward backtests run, pluscreate_experiment,acquire_programs(:acquirePrograms), andsubmit_evaluations(:submitProgramsEvaluations). - Backup Non-Default Backend (
backend="vertex_gemini"): Uses standard Vertex AI Gemini (google.genai.Client(vertexai=True, project=project_id, location=region), default model"gemini-3.8-flash") paired with an in-memory multi-island MAP-Elites population buffer (:class:IslandPopulationBuffer) that mutates# EVOLVE-BLOCKcode from walk-forward econometric feedback (fva_pct,dm_pvalue,worst_decile_fva,horizon_decay). - Offline Deterministic Test Backend (
backend="mock"): Replays a caller-supplied or built-in deterministic sequence of candidate programs with zero network calls so unit tests and CI--dry-runcomplete in<2 seconds.
AlphaEvolveClient
¶
AlphaEvolveClient(
project_id=None,
location="global",
*,
model_name=DEFAULT_GEMINI_MODEL,
timeout=30.0,
http_request=None,
)
Managed Discovery Engine AlphaEvolve REST transport (backend='alphaevolve').
Source code in src/scale_forecasting/evolve/client.py
acquire_programs
¶
Acquire mutated candidate programs via :acquirePrograms.
Source code in src/scale_forecasting/evolve/client.py
create_experiment
¶
Create a managed alphaEvolveExperiments resource in Discovery Engine.
Source code in src/scale_forecasting/evolve/client.py
probe_access
¶
Run the pre-flight access probe against discoveryengine.googleapis.com.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Acquire the next candidate program from the managed AlphaEvolve experiment.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Report candidate evaluation fitness back to Discovery Engine AlphaEvolve.
Source code in src/scale_forecasting/evolve/client.py
submit_evaluations
¶
Submit walk-forward evaluation scores via :submitProgramsEvaluations.
Source code in src/scale_forecasting/evolve/client.py
IslandCandidate
dataclass
¶
One evaluated candidate program stored inside :class:IslandPopulationBuffer.
IslandPopulationBuffer
¶
In-memory multi-island MAP-Elites population buffer for backend='vertex_gemini'.
Source code in src/scale_forecasting/evolve/client.py
add
¶
Insert an evaluated candidate into its corresponding island and prune low performers.
Source code in src/scale_forecasting/evolve/client.py
best
¶
Return the global best candidate across all islands.
select_parent
¶
Select the lowest-loss parent from the active island for generation.
Source code in src/scale_forecasting/evolve/client.py
MockEvolutionClient
¶
MockEvolutionClient(
target="features",
candidates=None,
max_evaluations=10,
*,
model_name=DEFAULT_GEMINI_MODEL,
)
Offline deterministic evolution transport for fast unit testing and CI --dry-run.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Return deterministic candidate generation - 1 with zero network calls.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Append evaluation telemetry to self.recorded_evaluations.
Source code in src/scale_forecasting/evolve/client.py
VertexGeminiEvolutionClient
¶
VertexGeminiEvolutionClient(
project_id=None,
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
*,
n_islands=3,
temperature=0.4,
genai_client=None,
)
Backup non-default evolution transport using standard Vertex AI Gemini.
Uses google.genai.Client(vertexai=True, project=project_id, location=region) (default model
"gemini-3.8-flash", or any caller-supplied model_name) plus
:class:IslandPopulationBuffer to mutate # EVOLVE-BLOCK code from walk-forward diagnostic
feedback without requiring a Gemini Enterprise license.
Source code in src/scale_forecasting/evolve/client.py
propose_candidate
¶
Mutate # EVOLVE-BLOCK using Vertex AI Gemini + island population state.
Source code in src/scale_forecasting/evolve/client.py
record_evaluation
¶
Record candidate score and walk-forward diagnostics into the island buffer.
Source code in src/scale_forecasting/evolve/client.py
create_evolution_client
¶
create_evolution_client(
backend,
*,
target="features",
project_id=None,
location="global",
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
max_evaluations=10,
mock_candidates=None,
genai_client=None,
alphaevolve_http_request=None,
)
Instantiate the requested evolution client backend.
Source code in src/scale_forecasting/evolve/client.py
probe_alphaevolve_access
¶
Fast pre-flight check verifying Discovery Engine AlphaEvolve entitlement before backtests.
Raises :class:~scale_forecasting.errors.ConfigError (aliased as ConfigurationError) if
discoveryengine.googleapis.com is disabled or the project/organization lacks Gemini
Enterprise AlphaEvolve entitlement (HTTP 403 / 404).
Source code in src/scale_forecasting/evolve/client.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
targets
¶
Evolutionary targets (# EVOLVE-BLOCK) built on top of Forecaster.auto().
Defines the five bounded code-synthesis targets for scale_forecasting.evolve:
"features"(:func:synthesize_evolved_features) — synthesizes causal lag, rolling, harmonic, and exogenous interaction covariates (evolved_feat_*) strictly from past and contemporaneous context without future target lookahead."ensemble"(:func:compute_evolved_weights) — synthesizes custom out-of-fold (OOF) blending weights across the cached model bank produced byForecaster.auto()."model"(:class:EvolvedForecaster) — synthesizes a custom :class:~scale_forecasting.models.base_model.BaseModelsubclass usingnumpy/scipy/statsmodelsprimitives."policy"(:func:evolve_policy_weights) — tunes :class:AutoPolicyWeightsdecision thresholds and action confidence priors for :mod:scale_forecasting.auto_policy."similarity_kernel"(:func:compute_evolved_similarity_kernel) — synthesizes a custom positive-definite / pairwise time-series similarity kernel over multi-lens dynamical feature embeddings for analog transfer and cluster-aware cross-series pooling.
AutoPolicyWeights
dataclass
¶
AutoPolicyWeights(
intermittent_share_min=0.165,
log1p_level_vol_corr_min=0.635,
log1p_growth_ratio_min=1.336,
resid_hetero_min=0.3,
structural_break_share_min=0.251,
outlier_spike_share_min=0.195,
direct_horizon_decay_ratio_min=1.323,
resid_acf1_escalate_min=0.309,
fva_escalate_min_pct=3.077,
white_noise_growth_tol=0.179,
white_noise_acf_season_max=0.17,
require_white_noise_stop=True,
pass_decay_factor=0.7,
first_light_include_regression_lags=True,
first_light_selection_rule="best_single",
tree_n_estimators_fast=60,
enable_similarity_global=True,
similarity_silhouette_threshold=0.3,
action_weights=_default_action_weights(),
)
Typed container of evolutionary thresholds for :mod:scale_forecasting.auto_policy.
from_defaults
classmethod
¶
Construct :class:AutoPolicyWeights from auto_policy.evolved_policy_thresholds().
from_dict
classmethod
¶
Construct :class:AutoPolicyWeights from a plain threshold dictionary.
Source code in src/scale_forecasting/evolve/targets.py
to_dict
¶
Serialize policy weights to a dictionary compatible with auto_policy.
with_updates
¶
EvolvedForecaster
¶
Bases: BaseModel
Custom evolutionary forecaster plugin (target='model').
Source code in src/scale_forecasting/evolve/targets.py
fit
¶
Fit evolutionary damped trend + harmonic seasonal + ridge exogenous model.
Source code in src/scale_forecasting/evolve/targets.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
predict
¶
Predict horizon steps ahead with calibrated residual intervals.
Source code in src/scale_forecasting/evolve/targets.py
TargetSpec
dataclass
¶
TargetSpec(
target,
entrypoint,
description,
seed_code,
system_instruction,
mutation_prompt_template,
)
Specification and seed program for one # EVOLVE-BLOCK evolutionary target.
build_mutation_prompt
¶
Render a diagnostic-guided mutation prompt for target.
Source code in src/scale_forecasting/evolve/targets.py
compute_evolved_similarity_kernel
¶
Synthesize an (N, N) similarity matrix in [0.0, 1.0] over per-series embeddings.
Source code in src/scale_forecasting/evolve/targets.py
compute_evolved_weights
¶
Compute global (dict[str, float]) or per-series (dict[str, dict[str, float]]) weights.
Source code in src/scale_forecasting/evolve/targets.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
deterministic_mock_candidates
¶
Return count deterministic, AST-safe, causal candidate programs for target.
Source code in src/scale_forecasting/evolve/targets.py
evolve_policy_weights
¶
Tune :class:AutoPolicyWeights thresholds for auto_policy (target='policy').
Source code in src/scale_forecasting/evolve/targets.py
extract_evolve_block
¶
Extract the code lines between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END.
If the markers are absent from code, returns normalized dedented code.
Source code in src/scale_forecasting/evolve/targets.py
get_target_seed
¶
Return the canonical :class:TargetSpec for target.
Source code in src/scale_forecasting/evolve/targets.py
inject_evolve_block
¶
Inject block between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END in template.
Handles both:
- an inner snippet (indented to match # EVOLVE-BLOCK-START in template), and
- a full program that already contains # EVOLVE-BLOCK-START / # EVOLVE-BLOCK-END (its
inner block is extracted first and injected into template).
Source code in src/scale_forecasting/evolve/targets.py
synthesize_evolved_features
¶
Synthesize causal evolved_feat_* columns without future target lookahead.
Source code in src/scale_forecasting/evolve/targets.py
sandbox
¶
AST security sandbox, wall-clock timeout executor, and temporal lookahead leak detector.
Enforces three non-negotiable pre-gate invariants on every candidate program before any cross- validation fold is scored:
- AST Security Sandbox (:func:
validate_candidate_ast): Rejects prohibited system/network/file imports (os,sys,subprocess,socket,urllib,http,pathlib,shutil,ctypes,pickle,builtins,importlib) and dangerous builtins or reflection calls (eval,exec,open,compile,__import__,getattr,setattr,globals,locals). Only whitelisted scientific modules (numpy,pandas,scipy,statsmodels,sklearn,math,statistics,scale_forecasting) may be imported. - Temporal Causality & Future-Leakage Detector (:func:
verify_no_future_leakage): Perturbs the lasthorizontarget rows per series with+1e6sentinel noise and verifies that all engineered features or predictions at earlier timestamps $t \le T - H$ remain bit-for-bit identical (np.allclose(..., atol=1e-12)). - Bounded Sandbox Execution (:func:
execute_in_sandbox): Compiles AST-verified code inside a restricted builtins namespace under a strict wall-clock timeout.
SandboxValidationResult
dataclass
¶
compile_candidate_symbol
¶
Validate code with :func:validate_candidate_ast and return entrypoint.
Source code in src/scale_forecasting/evolve/sandbox.py
execute_in_sandbox
¶
Compile and execute entrypoint(*args, **kwargs) with a hard wall-clock timeout.
Source code in src/scale_forecasting/evolve/sandbox.py
validate_candidate_ast
¶
Parse code into an AST and reject prohibited imports, calls, and reflection.
Source code in src/scale_forecasting/evolve/sandbox.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
verify_no_future_leakage
¶
Verify that perturbing the last horizon target values by +1e6 does not alter
any engineered features or fitted values on earlier timestamps $t \le T - H$.
Returns True only when all outputs on $t \le T - H$ are bit-for-bit identical
(np.allclose(..., atol=1e-12, equal_nan=True)). Immediately returns False if the
candidate uses future information (such as .shift(-k), .bfill(), or full-series
global target aggregations).
Source code in src/scale_forecasting/evolve/sandbox.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
evaluator
¶
Walk-forward candidate evaluator and 3-Gate Anti-Overfitting Ratchet (evolve.evaluator).
Builds directly on :meth:~scale_forecasting.sdk.Forecaster.auto by splitting the input panel into:
- Inner Evolution Panel ($t \le T - H_{\text{lockdown}}$): Visible to the evolutionary loop.
Forecaster.auto()runs once on this inner panel to establish the baseline :class:Forecaster, :class:~scale_forecasting.auto_policy.PanelAutoProfile, cached out-of-fold predictions (oof_df), and reusable cell cache (reuse_prior_runs=True). - Held-Out Lockdown Fold (last $H_{\text{lockdown}}$ steps): Completely withheld from the evolutionary loop and evaluated only once at Gate 3 on the top inner-CV challenger.
The 3-Gate Anti-Overfitting Ratchet¶
- Pre-Gate (AST Security & Temporal Causality Probe): Candidate must pass
:func:
~scale_forecasting.evolve.sandbox.validate_candidate_astand :func:~scale_forecasting.evolve.sandbox.verify_no_future_leakage($y_{T-H:} \mathrel{+}= 10^6$ perturbation test). - Gate 1 (Inner Walk-Forward CV Lift):
inner_cv_score < baseline_score. - Gate 2 (Diebold–Mariano & Worst-Decile Tail Guard): Paired loss differential test via
:func:
~scale_forecasting.diagnostics.diebold_mariano_testrequiresdm_pvalue <= significance_alpha(when sample size permits) andworst_decile_fva_pct >= -0.02. - Gate 3 (Held-Out Lockdown Fold Verification): Evaluates the winning inner-CV candidate once
on the unseen Lockdown Fold and promotes (
promoted = True) only iflockdown_candidate_score < lockdown_baseline_score. Otherwise ratchets back to theForecaster.auto()baseline (promoted = False).
CandidateEvaluation
dataclass
¶
CandidateEvaluation(
candidate_id,
generation,
target,
backend,
code,
ast_valid,
causal_valid,
inner_cv_score,
baseline_score,
inner_fva_pct,
dm_stat,
dm_pvalue,
worst_decile_fva_pct,
gate1_passed,
gate2_passed,
lockdown_baseline_score,
lockdown_candidate_score,
gate3_passed,
promoted,
status,
rejection_reason,
wall_seconds,
series_losses_candidate=(),
series_losses_baseline=(),
point_losses_candidate=(),
point_losses_baseline=(),
)
Complete evaluation telemetry for one candidate program across all 3 ratchet gates.
to_row
¶
Convert candidate evaluation to a flat leaderboard row dictionary.
Source code in src/scale_forecasting/evolve/evaluator.py
EvolutionEvaluator
¶
EvolutionEvaluator(
data_df=None,
*,
from_runs=None,
from_run_ids=None,
dataset_id="scale_forecasting",
project_id=None,
region="us-central1",
target="features",
backend="alphaevolve",
tier="first_light",
where="local",
horizon=None,
significance_alpha=0.1,
worst_decile_floor=-0.02,
timeout_seconds=20.0,
ts_id_col="ts_id",
date_col="ds",
target_col="y",
freq=None,
)
Evaluates candidate # EVOLVE-BLOCK programs on top of Forecaster.auto() or prior runs.
Source code in src/scale_forecasting/evolve/evaluator.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 | |
evaluate_candidate_inner
¶
Evaluate code through Pre-Gate (AST + Causality), Gate 1, and Gate 2.
Source code in src/scale_forecasting/evolve/evaluator.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 | |
evaluate_lockdown_gate3
¶
Evaluate the winning inner-CV candidate once on the Held-Out Lockdown Fold.
Source code in src/scale_forecasting/evolve/evaluator.py
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 | |
materialize_ensemble_predictions
¶
Materialize blended forward forecasts with empirical conformal 80% intervals.
Source code in src/scale_forecasting/evolve/evaluator.py
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 | |
split_inner_and_lockdown_panel
¶
Split a historical panel into (inner_df, lockdown_truth_df, lockdown_future_exog_df).
inner_df: rows $t \le T - H_{\text{lockdown}}$ per series (visible to evolution).lockdown_truth_df: last $H_{\text{lockdown}}$ historical rows per series with truey(withheld for Gate 3 verification).lockdown_future_exog_df: exogenous covariate rows for the lockdown window withyremoved so lockdown predictions cannot observe held-out targets.
Source code in src/scale_forecasting/evolve/evaluator.py
verify_oof_pool_compatibility
¶
verify_oof_pool_compatibility(
runs,
*,
project_id=None,
dataset_id="scale_forecasting",
region="us-central1",
horizon=None,
)
Verify OOF & horizon alignment across runs, disambiguate colliding models, and split.
Verifies how borrowing interacts with backtest, hpo, and ensemble:
- Requires non-empty overlapping (ts_id, ds) out-of-fold rows across all runs (and
overlapping (ts_id, forecast_date) horizon grids when forward predictions are present),
raising :class:~scale_forecasting.errors.ConfigError when disjoint.
- When multiple runs contain the same model_type, compares their aligned OOF yhat
trajectories: identical trajectories (same model_spec_hash) are deduplicated, whereas
distinct trajectories (different HPO winner, model_params, or ensemble pool) are
disambiguated as <model_type>@<run_short_id>.
- Splits the pooled oof_df temporally per series into inner_oof_df (for candidate
synthesis and Gates 1 & 2) and lockdown_oof_df (withheld for Gate 3).
Source code in src/scale_forecasting/evolve/evaluator.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
runner
¶
End-to-end evolutionary runner (EvolveConfig, EvolveResult, run_evolution).
Orchestrates the closed-loop evolutionary cycle on top of
:meth:~scale_forecasting.sdk.Forecaster.auto:
- Pre-Flight Entitlement Check: When
backend="alphaevolve"(the default), calls :func:~scale_forecasting.evolve.client.probe_alphaevolve_accessbefore any backtests run so projects without Gemini Enterprise + AlphaEvolve entitlement fail fast with actionable guidance pointing toForecaster.auto()and thebackend="vertex_gemini"backup. - Temporal Lockdown Split &
Forecaster.auto()Baseline: Withholds the last $H_{\text{lockdown}}$ steps per series as the unseen Lockdown Fold and runsForecaster.auto()on the Inner Evolution Panel ($t \le T - H_{\text{lockdown}}$). - Iterative Mutation & Pre-Gate / Gate 1 / Gate 2 Filtering: Generates up to
max_evaluationscandidate# EVOLVE-BLOCKprograms viaalphaevolve,vertex_gemini, ormock, checking each through the AST security sandbox, the $+10^6$ temporal lookahead detector, Gate 1 (inner CV lift), and Gate 2 (Diebold–Mariano $p$-value + worst-decile FVA guard). - Gate 3 (Held-Out Lockdown Fold Promotion Ratchet): Evaluates the winning inner-CV
challenger once on the unseen Lockdown Fold and promotes
promoted = Trueonly whenlockdown_candidate_score < lockdown_baseline_score.
EvolveConfig
dataclass
¶
EvolveConfig(
target="features",
backend="alphaevolve",
tier="deep_sky",
where="local",
horizon=None,
max_evaluations=10,
significance_alpha=0.1,
worst_decile_floor=-0.02,
project_id=None,
location="global",
region="us-central1",
model_name=DEFAULT_GEMINI_MODEL,
export_path=None,
random_seed=42,
decision_metric=None,
timeout_seconds=20.0,
dry_run=False,
mock_candidates=None,
candidate_programs=None,
lockdown_override_score=None,
from_runs=None,
from_run_ids=None,
dataset_id="scale_forecasting",
)
Configuration for an opt-in :func:run_evolution / :meth:Forecaster.evolve session.
model_dump
¶
model_validate
classmethod
¶
Validate a dictionary or :class:EvolveConfig instance.
Source code in src/scale_forecasting/evolve/runner.py
to_dict
¶
Serialize configuration to a plain JSON-friendly dictionary.
Source code in src/scale_forecasting/evolve/runner.py
EvolveResult
dataclass
¶
EvolveResult(
target,
backend_used,
promoted,
rejection_reason,
baseline_score,
inner_cv_score,
lockdown_baseline_score,
lockdown_candidate_score,
fva_pct,
dm_pvalue,
worst_decile_fva_pct,
champion_code,
export_path,
leaderboard_df,
forecaster=None,
assessment=None,
evaluations_run=0,
wall_seconds=0.0,
candidate_code="",
diagnostics=dict(),
predictions_df=None,
model_name=DEFAULT_GEMINI_MODEL,
)
Outcome of an evolutionary run governed by the 3-Gate Anti-Overfitting Ratchet.
emit_airflow_dag
¶
Render a standalone Cloud Composer 3 / Airflow DAG scheduling periodic evolution.
If output_path is provided, writes the DAG Python source to output_path and returns
the rendered DAG source code string.
Source code in src/scale_forecasting/evolve/runner.py
summary
¶
Return a concise human-readable summary of the 3-Gate Ratchet verdict.
Source code in src/scale_forecasting/evolve/runner.py
to_dict
¶
Serialize result summary and leaderboard to a JSON-compatible dictionary.
Source code in src/scale_forecasting/evolve/runner.py
run_evolution
¶
run_evolution(
data=None,
config=None,
*,
from_runs=None,
from_run_ids=None,
dataset_id=None,
target=None,
backend=None,
tier=None,
where=None,
horizon=None,
max_evaluations=None,
significance_alpha=None,
worst_decile_floor=None,
project_id=None,
location=None,
region=None,
model_name=None,
export_path=None,
random_seed=None,
decision_metric=None,
timeout_seconds=None,
dry_run=None,
mock_candidates=None,
candidates=None,
lockdown_override_score=None,
genai_client=None,
alphaevolve_http_request=None,
http_get=None,
ts_id_col="ts_id",
date_col="ds",
target_col="y",
freq=None,
)
Run opt-in evolutionary code synthesis on top of Forecaster.auto() or prior runs.
Source code in src/scale_forecasting/evolve/runner.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |