feat: Phase D — RL integration (training, benchmark, visualization)#1
Open
Balghanimi wants to merge 10 commits intomainfrom
Open
feat: Phase D — RL integration (training, benchmark, visualization)#1Balghanimi wants to merge 10 commits intomainfrom
Balghanimi wants to merge 10 commits intomainfrom
Conversation
Covers SurfaceDiscoveryEnv, PPO/SAC trainer, benchmark suite (17 controllers x 5 plants), and visualization module. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes from review: IntegralSlidingSurface params, Quadrotor disturbance format, exact switching law in benchmark, pytest skip patterns, Gym registration, unused import removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TDD: 20 tests written first (all failed), then implementation created. All 20 tests pass. No regressions in existing 193 tests. Gymnasium environment where RL agent outputs sigma (sliding variable) directly, and a fixed switching control law converts to control input. Supports 5 plants (double_integrator, inverted_pendulum, crane, quadrotor, pmsm), 4 disturbance types, RK4 integration, and configurable control gains. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ensures consistency with plant dynamics for non-salient motors (Ld != Lq). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements train_surface() and train_all_surfaces() with VecNormalize, ISE evaluation callback, and best-model saving. 9/9 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- _load_sb3 now tries PPO first then falls back to SAC on any exception - use_4d_obs parameter pads observations to [e, edot, 0.0, 0.0] for models trained with 4-element observation spaces - 2 new tests covering both behaviours (11 total, all passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two-table benchmark comparing RL-discovered surfaces against all 17 classical controllers across 5 plants and 4 disturbance types: - Table 1 (Fixed Law): surfaces evaluated with u = -K*sat(s/phi) - lam*s using standalone RK4 loop matching training environment - Table 2 (Matched Controller): each controller uses its own compute() via Simulator.run() for practical performance comparison - BenchmarkResults dataclass with to_latex(), to_json(), summary() - 9/9 tests passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 plotting functions (training_curve, surface_heatmap, contour_overlay, radar_chart, cross_plant_radar, benchmark_bars, time_domain) with corresponding 7 pytest tests using Agg backend. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- opensmc/rl/__init__.py: lazy __getattr__ for SurfaceDiscoveryEnv, trainer (train_surface/train_all_surfaces/TrainingResult), benchmark/BenchmarkResults, and visualize module - pyproject.toml: add pandas>=1.5 to rl extras (required by benchmark) - examples/train_and_fingerprint.py: PPO training + fingerprint + plots - examples/full_benchmark.py: classical controller benchmark runner Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The __getattr__ pattern caused infinite recursion when attribute names matched submodule names (benchmark, visualize). Switched to try/except conditional imports. Renamed benchmark() to run_benchmark() in public API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.
Summary
Stats
Test plan
from opensmc.rl import RLDiscoveredSurface, SurfaceDiscoveryEnv, train_surface, run_benchmark, visualizeexamples/train_and_fingerprint.pyend-to-end (PPO training + fingerprinting + plots)examples/full_benchmark.pyend-to-end (benchmark + LaTeX tables)🤖 Generated with Claude Code