TestRandomization / code /case2 /README_case2.md
harryzhang1018's picture
Add reproduction code and README
0c3dd1d verified
|
Raw History Blame Contribute Delete
17.4 kB

Case 2: HMMWV goal reaching, test randomization versus nominal ROM (Sim2Sim)

This folder reproduces Case 2 of the paper Screening Ground Vehicle Controllers via Test Randomization: Sim2Real and Sim2Sim Studies. PPO goal-reaching policies are trained on a reduced-order model (ROM) of the HMMWV. They are evaluated in the ROM (nominal and test-randomized, TR) and in a high-fidelity Chrono HMMWV model. The ROM policy orders are compared with the Chrono order. All results are Sim2Sim; Case 2 has no physical data.

The folder contains the training script and commands, the 24 trained policies, the four checkpoints of the secondary pool, the ROM and Chrono evaluation code, the test conditions, goal sets A and B, every per-episode ROM and Chrono record, and the analysis scripts with their outputs.

Quick start: paper numbers from the released records (under 2 min)

pip install -r requirements.txt
python analyze.py --set A --pool explore
python report_explore.py
python analyze_confirm.py --set B --rom-dir results/rom_B_confirm16 --chrono-dir results/chrono_B_confirm16 \
    --primary confirm --secondary confirm16 --out results/confirm_analysis.json
python behavior_stats.py B confirm16
python posthoc_confirm.py
python report_confirm.py
python paper_numbers.py          # prints every Case 2 number of the paper; writes results/paper_numbers.json

Run all commands from this folder. These steps read only the released records (results/rom_*, results/chrono_*) and the policies, and overwrite the released analysis outputs with identical files.

Contents

README_case2.md, requirements.txt
common.py             paths, goal sets A/B, policy registry, actor (SB3 PPO weights, clipped), observation
train_ppo.py          PPO training on the ROM (environment, reward and hyperparameters of the original training script)
train_all.sh          exact training commands of the 24 policies
register_policies.py  writes policies/registry.json (config, seed, SHA-256 of the 2 M-step checkpoint)
rom_batch.py          batched ROM (original GoalEnv.step) with perturbation parameters
variants.py           all exploration conditions on goal set A (nominal + 35 test conditions)
fixed_design.py       fixed TR design for the held-out evaluation on goal set B (primary TR = tr_rate)
run_rom.py            ROM evaluation of a policy pool on a goal set
make_chrono_jobs.py   Chrono job list (policy x goal)
chrono_runner.py      Chrono HMMWV evaluation (copy of the original evaluation loop)
merge_chrono_parts.py merges Chrono output directories of a split run
rankstats.py          rank rule, win rates, Kendall tau-b, goal bootstrap
analyze.py, report_explore.py                      exploration analysis (goal set A)
analyze_confirm.py                                 held-out analysis (goal set B), primary test and secondary outcomes
behavior_stats.py                                  throttle and steering behavior of each policy in nominal ROM
posthoc_confirm.py, report_confirm.py              post hoc summaries and held-out report
paper_numbers.py                                   collects the Case 2 numbers of the paper
verify_rom_parity.py                               optional: batched ROM versus the original training environment
policies/             24 trained policies, registry.json, released/ (4 checkpoints of the original repository)
results/              per-episode records and analysis outputs (see below)

Environment

  • Python 3.12.14, Linux x86_64. Pinned packages: requirements.txt (NumPy 2.5.2, SciPy 1.18.1, PyTorch 2.13.0, Stable-Baselines3 2.7.0, Gymnasium 1.2.2).
  • PyChrono 10.0.0 for the Chrono stages only (conda package): conda install -c projectchrono pychrono=10.0.0.
  • verify_rom_parity.py also needs gym==0.26.2 and a checkout of the original repository (see below).
  • All computation runs on the CPU. Runtimes below are for an AMD Ryzen 7 5800X (8 cores, 16 threads).

Policies

Pool name Policies Use
explore rel1-rel4 + 12 design policies (seeds 1001-1004) exploration on goal set A (16 policies)
confirm 12 held-out policies (seeds 2001-2004) primary pool on goal set B
confirm16 confirm + rel1-rel4 secondary pool on goal set B (16 policies)

Trained policies: policies/<config>_s<seed>/ckpt_4.zip (2 M steps), with train_meta.json (config values, seeds, hyperparameters, wall time, package versions) and episode_returns.npy (training episode returns). policies/registry.json lists config, seed and SHA-256 of each ckpt_4.zip. Intermediate checkpoints (0.5, 1.0, 1.5 M steps) are not included; no result uses them.

Config Action noise sd (throttle, steering) Powertrain sd (tau0, omega0) Powertrain draw Actuation delay
nonoise 0 0, 0 (tau0 = 1000 N m, omega0 = 2600 rad/s) fixed 0
release 0.05 50, 100 once per environment (default of the original script) 0
robust 0.10 100, 200 every episode 0, 1 or 2 steps (0-0.2 s), every episode

PPO (Stable-Baselines3): learning rate 3e-4, n_steps 1200, batch 64, 20 epochs, gamma 0.99, clip 0.2, policy and value networks [64, 128, 128, 64] with ReLU, 2e6 steps. PPO seed = --seed, environment seed = --seed + 7.

Released checkpoints rel1-rel4 = policies/released/ppo_<k>.zip: copies of 2024/PathFollowingSim2real/hmmwv_goal_reach/data/rl_model/ppo_<k>.zip of https://github.com/uwsbel/sbel-reproducibility, four checkpoints of one training run at 0.5, 1.0, 1.5 and 2.0 M steps. BSD-3-Clause; the license text is in policies/released/LICENSE.

Policy SHA-256
rel1 (ppo_1.zip) 2d7e38353d82d64a95ca011f0eed550d75ea1c94a6239104277bba567b971972
rel2 (ppo_2.zip) 98793edc940c271b886bb8583cabe5aa9e6daee5cb108a6f8c03617a3e096241
rel3 (ppo_3.zip) 372440b4c691eca0b4916e431283f4fa720ea53d36af4d13016038ec6e779bc2
rel4 (ppo_4.zip) 831e518be7321006289789a0b7c42c70acc349c298394775d126053a6171b2eb

Goal sets

Uniform radius and uniform bearing around the start point (0, 0), common.make_goal_set:

Set Seed Goals Use File
A 2026110401 50 ID (10-20 m) + 50 OOD (20-40 m) exploration (TR design) results/rom_A_explore/goals.json
B 2026110499 75 ID (10-20 m) + 75 OOD (20-40 m) held-out evaluation results/rom_B_confirm16/goals.json

Test conditions

variants.py (EXPLORE) lists every condition tried on goal set A: nominal ROM and 35 test conditions in 11 families. fixed_design.py lists the nine conditions of the held-out evaluation; it was fixed before any goal-set-B run. Each condition is a set of per-trial parameter distributions and a number of trials per goal (20 for random conditions, 1 for deterministic ones). All policies see the same parameter draws and noise (common random numbers). The condition names seed the random streams (run_rom.seed_of); do not rename them.

Paper Condition name
Nominal ROM nominal
Noise-only TR paper_tr
TR, random steering rate tr_rate (goal set B); same specification as rate_rand_paper (goal set A)
rate range halved / doubled / uniform rate tr_rate_half / tr_rate_double / tr_rate_uniform
random delay, no rate tr_delay
Fixed rate limit 0.1 det_rate_0.1
Fixed ROM, HMMWV values det_calibrated
Exploration: random steering-rate limit (0.82), random actuation delay (0.80) rate_rand_paper, delay_rand03

Stages

Stage Command Inputs Outputs Runtime
1. Training (optional) ./train_all.sh 10 policies_retrained - policies_retrained/<config>_s<seed>/ (ckpt_1-4.zip, train_meta.json, episode_returns.npy) 39-56 min per run on one core; 24 runs
2. Registry python register_policies.py policies/*/train_meta.json, ckpt_4.zip policies/registry.json < 1 s
3. ROM, goal set A python run_rom.py --set A --pool explore --variants all policies, variants.py results/rom_A_explore/ 4 min
4. Chrono, goal set A python make_chrono_jobs.py A explore results/chrono_A_jobs.jsonl
python chrono_runner.py results/chrono_A_jobs.jsonl results/chrono_A_explore --workers 12
policies, goal set A results/chrono_A_explore/ 1600 episodes, about 1 h with 10-12 workers
5. Exploration analysis python analyze.py --set A --pool explore
python report_explore.py
stages 3, 4 results/analysis_A_explore.json, results/exploration_tau_table.json, results/exploration_report.md < 1 min
6. ROM, goal set B python run_rom.py --set B --pool confirm16 --table fixed policies, fixed_design.py results/rom_B_confirm16/ 1 min
7. Chrono, goal set B python make_chrono_jobs.py B confirm16 results/chrono_B_jobs.jsonl
python chrono_runner.py results/chrono_B_jobs.jsonl results/chrono_B_confirm16 --workers 12
policies, goal set B results/chrono_B_confirm16/ 2400 episodes, about 1.3 h with 12 workers
8. Held-out analysis python analyze_confirm.py --set B --rom-dir results/rom_B_confirm16 --chrono-dir results/chrono_B_confirm16 --primary confirm --secondary confirm16 --out results/confirm_analysis.json stages 6, 7 results/confirm_analysis.json < 1 min
9. Steering behavior python behavior_stats.py B confirm16 policies, goal set B (nominal ROM) results/behavior_B_confirm16.json < 10 s
10. Post hoc summaries, report python posthoc_confirm.py
python report_confirm.py
stages 8, 9 results/posthoc_confirm.json, results/heldout_report.md < 20 s
11. Paper numbers python paper_numbers.py stages 5, 8-10 results/paper_numbers.json < 10 s
Optional: ROM parity python verify_rom_parity.py <checkout>/2024/PathFollowingSim2real/hmmwv_goal_reach released checkpoints, original training script results/rom_parity.json < 1 min

Notes on re-running:

  • run_rom.py overwrites results/rom_<set>_<pool>/. Add --tag _rerun to write results/rom_<set>_<pool>_rerun/ instead and compare with the released records.
  • chrono_runner.py resumes: it skips episodes that are already in <out_dir>/episodes.jsonl. Use a new output directory to re-run episodes. A job list can be split into parts and the part directories merged with python merge_chrono_parts.py <out_dir> <part_dir> .... The Chrono episodes of both goal sets were run in parts and merged in this way; the runner is deterministic, so the split does not change any result.
  • The analysis scripts read the directory names above (rom_A_explore, chrono_A_explore, rom_B_confirm16, chrono_B_confirm16).
  • To retrain, train_all.sh writes to a new directory and does not touch policies/. To evaluate retrained policies, put their directories in policies/ and run register_policies.py. Bitwise identical retraining on other hardware or software is not guaranteed; compare SHA-256 values with policies/registry.json.

Paper item, script and output

paper_numbers.py collects all items below in results/paper_numbers.json. P = pools.primary (12 held-out policies) and S = pools.secondary (16 policies) of results/confirm_analysis.json; PH = pools.primary of results/posthoc_confirm.json.

Paper item Script Output
Exploration: nominal ROM and the test conditions on goal set A, 1600 Chrono episodes variants.py, run_rom.py, chrono_runner.py results/rom_A_explore/, results/chrono_A_explore/episodes.jsonl
Exploration tau_b: noise-only TR 0.55 vs nominal 0.53; random steering-rate limit 0.82; random delay 0.80 analyze.py, report_explore.py exploration_tau_table.json: all16.<paper_tr, nominal, rate_rand_paper, delay_rand03>.all; exploration_report.md
Nominal ROM: every held-out policy 100 % success; Chrono 60-65 % ID, 67-97 % OOD analyze_confirm.py P.conditions.nominal.rom.success_rate, P.chrono.success_rate
Held-out table: tau_b [95 % CI], ID, OOD for all nine conditions analyze_confirm.py P.conditions.<name>.vs_chrono.<all, id, ood>.kendall_tau_b, .all.kendall_ci95
Held-out table: Same / reversed (of the 48 Chrono-resolved pairs) posthoc_confirm.py PH.pair_resolution_vs_chrono.<name>
Primary test: difference +0.52 [0.33, 0.73] analyze_confirm.py primary_test
Chrono resolves 48 of 66 pairs; TR 45 same / 3 reversed; nominal 26 / 14 / 8 unresolved analyze_confirm.py, posthoc_confirm.py P.chrono.resolved_pairs; PH.pair_resolution_vs_chrono
Bang-bang steering: 8 policies 0.25-0.93, others 0.03-0.07 per step behavior_stats.py behavior_B_confirm16.json: <policy>.mean_abs_steer_change
Steering change vs Chrono OOD success: Spearman -0.76, p = 0.004 posthoc_confirm.py PH.chatter_vs_chrono_success.ood
Two smoothest policies: Chrono 1st/2nd, nominal ROM 11th/6th, TR 2nd/1st analyze_confirm.py, behavior_stats.py P.chrono.order, P.conditions.<nominal, tr_rate>.rom.order
Random delay tau_b 0.70; rate range halved/doubled barely changes the result analyze_confirm.py P.conditions.<tr_delay, tr_rate_half, tr_rate_double>.vs_chrono.all
Calibrated ROM tau_b 0.82; TR minus calibrated -0.09 [-0.21, 0.15] analyze_confirm.py, posthoc_confirm.py P.conditions.det_calibrated.vs_chrono.all; PH.delta_tau_primary_tr_minus.det_calibrated
OOD tau_b 0.64 (TR) vs 0.15 (nominal) analyze_confirm.py P.conditions.<tr_rate, nominal>.vs_chrono.ood.kendall_tau_b
Every held-out policy succeeds on more than half of the goals in Chrono analyze_confirm.py P.chrono.success_rate.all
Chrono / nominal ROM time 1.3-1.5 (held-out), up to 3.5 (checkpoints) analyze_confirm.py P and S .conditions.nominal.chrono_over_rom_time_ratio
Checkpoints: Chrono success 49/87/97/95 % ID, 69/99/97/99 % OOD analyze_confirm.py S.chrono.success_rate.<id, ood>.rel<k>
Checkpoints: nominal ROM order 4, 3, 2, 1 as Chrono; TR reverses 4 vs 3 and 4 vs 2, leaves 2 vs 3 unresolved analyze_confirm.py S.chrono.pairs, S.conditions.<nominal, tr_rate>.rom.pairs (summary: paper_numbers.json: checkpoints)
16-policy pool: tau_b 0.70 vs 0.55, difference +0.15 [-0.03, 0.25]; rate range halved 0.13, doubled 0.87 analyze_confirm.py S.conditions.<tr_rate, nominal, tr_rate_half, tr_rate_double>.vs_chrono.all
All 24 policies reach every goal in nominal ROM run_rom.py results/rom_A_explore/nominal.npz, results/rom_B_confirm16/nominal.npz: success

results/exploration_report.md and results/heldout_report.md show the same results as readable tables (all conditions, both pools, per-policy success, mean ranks and orders).

Result records

Path Content
results/rom_<set>_<pool>/<condition>.npz policies [P], goal_ids [G]; success, time_s (NaN if no success), terminal_distance_m, min_distance_m [P, G, K]; param_<name> [G, K]: sampled parameters of each trial
results/rom_<set>_<pool>/<condition>.json condition specification, trials per goal, goal set, parameter and noise seeds, policy paths and SHA-256, wall time of the original run
results/chrono_<set>_<pool>/episodes.jsonl one line per episode: policy, goal_id, goal x, y, success, time_s (null if no success), terminal_distance_m, min_distance_m, max_speed_mps, mean_throttle, rows, finite, wall_s, status
results/chrono_<set>_<pool>/traj/<policy>.npz one float32 array per goal id, 10 Hz rows: time (s), x, y, yaw, speed, policy throttle, rate-limited steering command (the vehicle is braked with zero inputs while t <= 1 s; the last row of a success has NaN commands). No paper number uses these trajectories.

Scoring: a ROM trial succeeds at the first step after which the distance to the goal is below 3 m; its time is (step index + 1) x 0.1 s. A Chrono episode succeeds when the distance is below 3 m at a control step; its time is that control-step time, rounded to 0.1 s in the analysis. Failures score the 40 s horizon.

Verification of this package

In a fresh copy of this folder (Python 3.12.14, PyTorch 2.13.0, PyChrono 10.0.0):

  • The analysis stages 5 and 8-11 reproduce every released analysis output byte for byte from the released records.
  • A full ROM re-evaluation (all 36 goal-set-A conditions incl. nominal and all 9 goal-set-B conditions, --tag _rerun) reproduces every array of the released ROM records exactly.
  • 48 Chrono episodes (first goal of set A and first two goals of set B, all 16 policies each) re-run with identical summaries and identical 10 Hz trajectories.
  • verify_rom_parity.py: 0 first-entry mismatches between the batched ROM and the original training environment for the 4 released checkpoints on 64 seeded goals.
  • register_policies.py regenerates policies/registry.json byte for byte; every SHA-256 in the registry and in the ROM manifests matches the released checkpoint files.

Provenance

train_ppo.py and rom_batch.py copy the environment, dynamics, reward and PPO hyperparameters of rl_script/rl_train_goal_reach.py, and chrono_runner.py mirrors simulation/sim_testing.py of the original hmmwv_goal_reach repository (changes are listed in the docstring of each file).