Repository navigation
Expand file tree
/
Copy pathexperiment_gap.py
More file actions
78 lines (66 loc) · 2.49 KB
/
Copy pathexperiment_gap.py
File metadata and controls
78 lines (66 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import subprocess
import numpy as np
import matplotlib.pyplot as plt
# configuration
MODEL_PATH = "/home/asethi04/proj/diffusion-trait-steering/logs/gym-dsrl/gym_walker_dsrl_2025-12-24_04-48-08_1/2025-12-24_04-48-08_1/checkpoint/ft_policy_80000_steps.zip"
GAP_TARGETS = [0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25]
FIXED_SPEED = 1.5
EPISODES = 5
GPU = "2"
results = []
for gap in GAP_TARGETS:
print(f"\n>>> Testing Thigh Gap Target: {gap}")
cmd = [
"python", "run_inference.py",
"--config-name=dsrl_walker.yaml",
f"model_path={MODEL_PATH}",
f"trait_values=[{gap}, {FIXED_SPEED}]",
"trait_mask=[1, 0]",
f"eval_episodes={EPISODES}",
"deterministic_eval=True",
"record_video=False"
]
env = os.environ.copy()
env["CUDA_VISIBLE_DEVICES"] = GPU
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, env=env)
mean_gap = None
mean_return = None
for line in process.stdout:
print(line, end="")
if "mean_return=" in line:
try:
mean_return = float(line.split("mean_return=")[1].split()[0])
except (IndexError, ValueError):
pass
if "metric_trait_thigh_gap_gap=" in line:
try:
mean_gap = float(line.split("metric_trait_thigh_gap_gap=")[1])
except (IndexError, ValueError):
pass
process.wait()
results.append({"target": gap, "actual": mean_gap, "return": mean_return})
# plotting
targets = [r["target"] for r in results]
actuals = [r["actual"] for r in results if r["actual"] is not None]
valid_targets_actual = [r["target"] for r in results if r["actual"] is not None]
returns = [r["return"] for r in results if r["return"] is not None]
valid_targets_return = [r["target"] for r in results if r["return"] is not None]
plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
if actuals:
plt.plot(valid_targets_actual, actuals, 'o-')
plt.xlabel("Thigh Gap Target")
plt.ylabel("Actual Thigh Gap")
plt.title("Gap Interpolation")
plt.grid(True)
plt.subplot(1, 2, 2)
if returns:
plt.plot(valid_targets_return, returns, 'o-r')
plt.xlabel("Thigh Gap Target")
plt.ylabel("Mean Return")
plt.title("Return vs Gap Target")
plt.grid(True)
plt.tight_layout()
plt.savefig("experiment_gap_results.png")
print("\nDone! Results saved to experiment_gap_results.png")