v0.1.14; add wave terrain; finish LevelPipeline

This commit is contained in:
wty-yy
2025-12-25 00:02:43 +08:00
parent 50126ec9aa
commit 11908747ce
19 changed files with 296 additions and 57 deletions

22
.vscode/launch.json vendored
View File

@@ -5,16 +5,34 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Python 调试程序: run.py", "name": "go2 moe flat single pipeline",
"type": "debugpy", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/robogauge/scripts/run.py", "program": "${workspaceFolder}/robogauge/scripts/run.py",
"args": [ "args": [
"--task", "go2_moe_flat", "--task", "go2_moe_flat",
"--experiment-name", "debug", "--experiment-name", "debug",
"--seed", "0",
"--friction", "1.6",
"--headless" "--headless"
], ],
"console": "integratedTerminal" "console": "integratedTerminal"
} },
{
"name": "go2 moe slope level pipeline",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/robogauge/scripts/run.py",
"args": [
"--task", "go2_moe_slope",
"--experiment-name", "debug",
"--seed", "0",
"--search-max-level",
"--seeds", "0", "1", "2",
"--frictions", "1",
"--headless"
],
"console": "integratedTerminal"
},
] ]
} }

14
CMD.md
View File

@@ -1,4 +1,4 @@
# Single Run # Single Pipeline
```bash ```bash
python robogauge/scripts/run.py \ python robogauge/scripts/run.py \
--task go2_moe_flat \ --task go2_moe_flat \
@@ -6,7 +6,7 @@ python robogauge/scripts/run.py \
--headless --headless
``` ```
# Multi Run # Multi Pipeline
```bash ```bash
python robogauge/scripts/run.py \ python robogauge/scripts/run.py \
--task go2_moe_flat \ --task go2_moe_flat \
@@ -23,6 +23,16 @@ python robogauge/scripts/run.py \
--headless --headless
``` ```
# Level Pipeline
```bash
python robogauge/scripts/run.py \
--task go2_slope \
--experiment-name debug \
--seed 0 \
--headless \
--search-max-level --seeds 0 1 2 --frictions 1
```
# Radar/Bar Plot # Radar/Bar Plot
将Multi Run结果绘制在雷达图中 将Multi Run结果绘制在雷达图中
```bash ```bash

View File

@@ -1,5 +1,9 @@
# UPDATE # UPDATE
TODO: 处理LevelPipeline返回的result信息 ## 20251224
### v0.1.14
1. 处理LevelPipeline返回的result信息, 保存最高等级可通过地形返回的aggregated_results和level等级
2. 完成wave地形的LevelPipeline支持
3. 各种Pipeline的run直接返回dict信息, 不再是路径
## 20251222 ## 20251222
### v0.1.13 ### v0.1.13
1. 即使模型崩溃也要继续测完后续的goals, 但是跳过当前的sub goals 1. 即使模型崩溃也要继续测完后续的goals, 但是跳过当前的sub goals

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_1">
<!-- Terrain Type: wave, Level: 1, Wave amplitude: 0.0200 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.08000000000000002 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_10">
<!-- Terrain Type: wave, Level: 10, Wave amplitude: 0.2000 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.8 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_2">
<!-- Terrain Type: wave, Level: 2, Wave amplitude: 0.0400 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.16000000000000003 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_3">
<!-- Terrain Type: wave, Level: 3, Wave amplitude: 0.0600 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.24 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_4">
<!-- Terrain Type: wave, Level: 4, Wave amplitude: 0.0800 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.32000000000000006 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_5">
<!-- Terrain Type: wave, Level: 5, Wave amplitude: 0.1000 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.4 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_6">
<!-- Terrain Type: wave, Level: 6, Wave amplitude: 0.1200 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.48 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_7">
<!-- Terrain Type: wave, Level: 7, Wave amplitude: 0.1400 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.5599999999999999 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_8">
<!-- Terrain Type: wave, Level: 8, Wave amplitude: 0.1600 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.6400000000000001 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -0,0 +1,20 @@
<mujoco model="wave_9">
<!-- Terrain Type: wave, Level: 9, Wave amplitude: 0.1800 -->
<statistic center="0 0 0.1" extent="0.8" />
<visual>
<headlight diffuse="0.6 0.6 0.6" ambient="0.3 0.3 0.3" specular="0 0 0" />
<rgba haze="0.15 0.25 0.35 1" />
<global azimuth="-130" elevation="-20" />
</visual>
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="3072" />
<texture type="2d" name="groundplane" builtin="checker" mark="edge" rgb1="0.2 0.3 0.4" rgb2="0.1 0.2 0.3" markrgb="0.8 0.8 0.8" width="300" height="300" />
<material name="groundplane" texture="groundplane" texuniform="true" texrepeat="5 5" reflectance="0.0" />
<hfield name="wave_hfield" file="wave.png" size="5 5 0.7200000000000001 0.1" />
</asset>
<worldbody>
<light pos="0 0 1.5" dir="0 0 -1" directional="true" />
<geom name="floor" size="0 0 0.05" type="plane" material="groundplane" />
<geom type="hfield" hfield="wave_hfield" pos="5 0 0" rgba="0.5 0.5 0.5 1" />
</worldbody>
</mujoco>

View File

@@ -22,5 +22,16 @@ class TerrainLevelsConfig(Config):
class wave: class wave:
levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] levels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
targets = [] targets = [
[6.5, 0.0, 0.08],
[6.5, 0.0, 0.16],
[6.5, 0.0, 0.24],
[6.5, 0.0, 0.32],
[6.5, 0.0, 0.40],
[6.5, 0.0, 0.48],
[6.5, 0.0, 0.56],
[6.5, 0.0, 0.64],
[6.5, 0.0, 0.72],
[6.5, 0.0, 0.80],
]

View File

@@ -14,14 +14,14 @@ class WaveGaugeConfig(BaseGaugeConfig):
class assets(BaseGaugeConfig.assets): class assets(BaseGaugeConfig.assets):
terrain_name = "wave" terrain_name = "wave"
terrain_level = 1 # 1-10 terrain_level = 10 # 1-10
terrain_xml = '{ROBOGAUGE_ROOT_DIR}/resources/terrains/wave/wave_1.xml' terrain_xml = '{ROBOGAUGE_ROOT_DIR}/resources/terrains/wave/wave_10.xml'
terrain_spawn_pos = [1.5, 0, 1] # x y z [m], robot freejoint spawn position on the terrain terrain_spawn_pos = [1.5, 1.25, 1.0] # x y z [m], robot freejoint spawn position on the terrain
class goals: class goals:
class target_pos_velocity: # goal to reach a target position by velocity command class target_pos_velocity: # goal to reach a target position by velocity command
enabled = True enabled = True
target_pos = [4, 0, 1.0] # x y z [m], target position in the environment, used for target position goal target_pos = [6.5, 0.0, 0.8] # x y z [m], target position in the environment, used for target position goal
lin_vel_x = 1.0 # +/- m/s lin_vel_x = 1.0 # +/- m/s
lin_vel_y = 1.0 # +/- m/s lin_vel_y = 1.0 # +/- m/s
ang_vel_yaw = 1.5 # +/- rad/s ang_vel_yaw = 1.5 # +/- rad/s

View File

@@ -117,7 +117,7 @@ class BasePipeline:
logger.info("✅ Pipeline execution finished.") logger.info("✅ Pipeline execution finished.")
logger.info(f"📁 Logging saved at: {logger.log_dir}") logger.info(f"📁 Logging saved at: {logger.log_dir}")
return logger.log_dir, error return self.gauge.results, error
def reset_sim_and_robot(self, sim_data: SimData): def reset_sim_and_robot(self, sim_data: SimData):
self.sim.reset() self.sim.reset()

View File

@@ -16,7 +16,6 @@ class LevelPipeline:
def __init__(self, args): def __init__(self, args):
self.args = args self.args = args
self.seeds = args.seeds self.seeds = args.seeds
self.model_path = None
logger.create(args.experiment_name+'_level', args.run_name) logger.create(args.experiment_name+'_level', args.run_name)
def run(self): def run(self):
@@ -25,30 +24,39 @@ class LevelPipeline:
# binary search levels # binary search levels
l, r = 0, 10 l, r = 0, 10
all_level_results = {}
while l < r: while l < r:
level = (l + r + 1) // 2 level = (l + r + 1) // 2
if self.test_level(level): all_success, results = self.test_level(level)
all_level_results[level] = results
if all_success:
l = level l = level
else: else:
r = level - 1 r = level - 1
if l >= 1: level = l
logger.info(f"🏆 Found maximum level: {l}") level_results = all_level_results.get(l, {
'model_path': results['model_path'],
'terrain_name': results['terrain_name'],
'terrain_level': 0,
})
if level >= 1:
logger.info(f"🏆 Found maximum level: {level}")
else: else:
logger.info(f"❌ No valid level found [1-10].") logger.info(f"❌ No valid level found [1-10].")
with open(logger.log_dir / "level_search_results.yaml", 'w') as f:
yaml.dump(level_results, f, allow_unicode=True, sort_keys=False)
return level, level_results
def test_level(self, level: int) -> bool: def test_level(self, level: int) -> bool:
logger.info(f"🔍 Testing level {level}...") logger.info(f"🔍 Testing level {level}...")
self.args.level = level self.args.level = level
multi_pipeline = MultiPipeline(self.args) multi_pipeline = MultiPipeline(self.args)
log_dir = multi_pipeline.run() aggregated_results = multi_pipeline.run()
# load results.yaml success_mean = float(aggregated_results['success']['mean'].split(' ')[0])
with open(log_dir / "aggregated_results.yaml", 'r') as f:
results = yaml.safe_load(f)
self.model_path = results['model_path']
success_mean = float(results['success']['mean'].split(' ')[0])
all_success = success_mean == 1.0 all_success = success_mean == 1.0
if all_success: if all_success:
logger.info(f"✅ Level {level} passed all tests.") logger.info(f"✅ Level {level} passed all tests.")
else: else:
logger.info(f"❌ Level {level} failed some tests.") logger.info(f"❌ Level {level} failed some tests.")
return all_success return all_success, aggregated_results

View File

@@ -36,18 +36,19 @@ def run_single_process(args, data):
console_output=False console_output=False
) )
pipeline = task_register.make_pipeline(args=local_args, create_logger=False) pipeline = task_register.make_pipeline(args=local_args, create_logger=False)
log_dir, error = pipeline.run() results, error = pipeline.run()
if error is None: if error is None:
ret = { ret = {
'status': 'success', 'status': 'success',
'log_dir': log_dir, 'results': results,
'model_path': pipeline.robot_cfg.control.model_path, 'model_path': pipeline.robot_cfg.control.model_path,
} }
else: else:
logger.error(f"❌ Process with seed={seed}, base_mass={base_mass}, friction={friction} failed with error: {error}") logger.error(f"❌ Process with seed={seed}, base_mass={base_mass}, friction={friction} failed with error: {error}")
ret = { ret = {
'status': 'error', 'status': 'error',
'log_dir': log_dir, 'results': results,
'model_path': pipeline.robot_cfg.control.model_path,
'data': data, 'data': data,
'error_msg': str(error), 'error_msg': str(error),
'traceback': traceback.format_exc() 'traceback': traceback.format_exc()
@@ -61,9 +62,15 @@ class MultiPipeline:
self.frictions = args.frictions self.frictions = args.frictions
self.base_masses = args.base_masses self.base_masses = args.base_masses
self.num_processes = args.num_processes self.num_processes = args.num_processes
self.model_path = None self.static_info = {}
logger.create(args.experiment_name+'_multi', args.run_name+'_multi') logger.create(args.experiment_name+'_multi', args.run_name+'_multi')
def add_static_info(self, key: str, value):
if key not in self.static_info:
self.static_info[key] = value
else:
assert self.static_info[key] == value, f"Static info key '{key}' has conflicting values: {self.static_info[key]} vs {value}"
def run(self): def run(self):
logger.info(f"🚀 Starting Multi-Process Evaluation with {self.num_processes} processes.") logger.info(f"🚀 Starting Multi-Process Evaluation with {self.num_processes} processes.")
logger.info(f"🔢 Seeds: {self.seeds}, Frictions: {self.frictions}, Base masses: {self.base_masses}") logger.info(f"🔢 Seeds: {self.seeds}, Frictions: {self.frictions}, Base masses: {self.base_masses}")
@@ -71,32 +78,30 @@ class MultiPipeline:
workers_data = list(product(self.seeds, self.base_masses, self.frictions)) workers_data = list(product(self.seeds, self.base_masses, self.frictions))
ctx = multiprocessing.get_context('spawn') ctx = multiprocessing.get_context('spawn')
worker_func = functools.partial(run_single_process, self.args) worker_func = functools.partial(run_single_process, self.args)
result_log_dirs = [] results_list = []
success_flags = [] success_flags = []
with ctx.Pool(processes=self.num_processes) as pool: with ctx.Pool(processes=self.num_processes) as pool:
iterator = pool.imap_unordered(worker_func, workers_data) iterator = pool.imap_unordered(worker_func, workers_data)
for results in tqdm(iterator, total=len(workers_data), desc="Evaluation"): for results in tqdm(iterator, total=len(workers_data), desc="Evaluation"):
success_flags.append(results['status'] == 'success') success_flags.append(results['status'] == 'success')
result_log_dirs.append(results['log_dir']) results_list.append(results['results'])
if results['status'] == 'success': self.add_static_info('model_path', results['model_path'])
if self.model_path is None: self.add_static_info('terrain_name', results['results']['terrain_name'])
self.model_path = results['model_path'] self.add_static_info('terrain_level', results['results']['terrain_level'])
else: if results['status'] != 'success':
assert self.model_path == results['model_path'], "Model paths do not match across runs."
else:
data = results['data'] data = results['data']
logger.error(f"❌ Process with seed={data[0]}, base_mass={data[1]}, friction={data[2]} failed with error: {results['error_msg']}") logger.error(f"❌ Process with seed={data[0]}, base_mass={data[1]}, friction={data[2]} failed with error: {results['error_msg']}")
logger.info("✅ Multi-Process Evaluation Completed.") logger.info("✅ Multi-Process Evaluation Completed.")
self.aggregate_results(result_log_dirs, success_flags, workers_data) aggregated_results = self.aggregate_results(results_list, success_flags, workers_data)
return logger.log_dir return aggregated_results
def aggregate_results(self, log_dirs, success_flags, workers_data): def aggregate_results(self, all_results, success_flags, workers_data):
""" Process results.yaml from each log_dir """ """ Process results from all processes and aggregate them. """
logger.info("📊 Aggregating Results from all runs...") logger.info("📊 Aggregating Results from all runs...")
summary = {'model_path': self.model_path, 'success': {}} summary = {'success': {}, **self.static_info}
finish_msg = ( finish_msg = (
f"""\n{'='*20} Run Finish Summary {'='*20}\n""" f"""\n{'='*20} Run Finish Summary {'='*20}\n"""
f"""{'Seed':^10}{'Base Mass':^15}{'Friction':^15}{'Status':^10}\n""" f"""{'Seed':^10}{'Base Mass':^15}{'Friction':^15}{'Status':^10}\n"""
@@ -109,27 +114,9 @@ class MultiPipeline:
finish_msg += f"""{'='*88}""" finish_msg += f"""{'='*88}"""
logger.info(finish_msg) logger.info(finish_msg)
all_results = []
all_yaml_paths = []
for path in log_dirs:
yaml_path = Path(path) / "results.yaml"
if not yaml_path.exists():
logger.warning(f"Results file not found: {yaml_path}, skipping.")
continue
with open(yaml_path, 'r') as file:
data = yaml.safe_load(file)
if data:
all_results.append(data)
all_yaml_paths.append(yaml_path)
if not all_results: if not all_results:
logger.error("No results to aggregate.") logger.error("No results to aggregate.")
return return
yaml_paths_str = '\n'.join([str(p) for p in all_yaml_paths])
logger.info(
f"""\n{'='*20} Results Files {'='*20}\n"""
f"""{yaml_paths_str}\n"""
f"""{'='*56}"""
)
value_collections = defaultdict(lambda: defaultdict(list)) value_collections = defaultdict(lambda: defaultdict(list))
for result in all_results: for result in all_results:
@@ -156,3 +143,4 @@ class MultiPipeline:
f"""{yaml.dump(summary, allow_unicode=True)}""" f"""{yaml.dump(summary, allow_unicode=True)}"""
f"""{'='*60}""" f"""{'='*60}"""
) )
return summary