malkhut(optim): vectorized reward + Ray parallel eval + VBT post-analysis
1. Vectorized reward path (cwm/core.py): - Wired up existing compute_reward_vectorized from numba_core (was unused!) - Eliminates FeatureVector dict allocation + Python dict lookups on hot path - Numba path used when _HAS_NUMBA=True, Python fallback otherwise - Bit-identical: same math operations, just via numba JIT 2. Ray-based parallel eval (training/ray_eval.py): - Industrial multi-core execution via Ray (used by OpenAI/Anyscale) - ray.put() stores params/scenarios in shared object store (no pickle per worker) - Each worker: own CWM + planner, zero shared state, no races - Bit-identical: same seed + same params = same results regardless of worker count - PolicyEvaluator.evaluate_candidate: new use_ray=True parameter 3. VBT post-analysis (training/vbt_analysis.py): - episodes_to_pnl_array, episodes_to_metrics (Sharpe, Sortino, VaR, win_rate, etc.) - cross_asset_comparison, parameter_sensitivity - format_metrics for human-readable output - Analysis tool only — runs AFTER engine produces results 4. numba_core.py: added missing 'import math' for compute_reward_vectorized 13 new tests: vectorized reward bit-identity, Ray determinism, Ray result fields, VBT metrics structure, cross-asset comparison, parameter sensitivity, edge cases. Total: 1178 tests, 50 files, all green, zero regressions.
This commit is contained in:
@@ -964,8 +964,13 @@ class PolicyEvaluator:
|
||||
record_to_matrix: bool = False,
|
||||
matrix: Optional[Any] = None,
|
||||
workers: int = 0,
|
||||
use_ray: bool = False,
|
||||
) -> Tuple[float, list[EpisodeResult]]:
|
||||
if workers > 1 and len(scenarios) > 1:
|
||||
if use_ray and workers > 1 and len(scenarios) > 1:
|
||||
from malkhut.training.ray_eval import RayEpisodeRunner
|
||||
runner = RayEpisodeRunner(workers=workers)
|
||||
results = runner.run_episodes(params, scenarios, rng_seed, planner_type)
|
||||
elif workers > 1 and len(scenarios) > 1:
|
||||
from malkhut.training.parallel_eval import ParallelEpisodeRunner
|
||||
runner = ParallelEpisodeRunner(workers=workers)
|
||||
results = runner.run_episodes(params, scenarios, rng_seed, planner_type)
|
||||
|
||||
Reference in New Issue
Block a user