Skip to content

Commit 3645ad0

Browse files
committed
Adding support to viz logs for all agents
1 parent 1fd2a56 commit 3645ad0

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

pufferlib/ocean/drive/drive.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#define CONTROL_AGENTS 1
6464
#define CONTROL_WOSAC 2
6565
#define CONTROL_SDC_ONLY 3
66+
#define CONTROL_NONE 4 // All agents follow log trajectories; policy output is ignored
6667

6768
// Simulation modes
6869
#define SIMULATION_GIGAFLOW 0
@@ -3220,7 +3221,7 @@ void set_active_agents(Drive *env) {
32203221
}
32213222

32223223
// In REPLAY mode, determine which agents to control
3223-
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY);
3224+
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY || env->control_mode == CONTROL_NONE);
32243225
// In log-replay mode, no cap on actors
32253226
int max_agents = is_log_replay ? env->num_total_agents : env->num_max_agents;
32263227

@@ -3309,7 +3310,7 @@ void move_expert(Drive *env, float *actions, int agent_idx) {
33093310
return;
33103311
}
33113312

3312-
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY);
3313+
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY || env->control_mode == CONTROL_NONE);
33133314

33143315
Agent *agent = &env->agents[agent_idx];
33153316
int t = env->timestep;
@@ -5078,13 +5079,16 @@ void c_step(Drive *env) {
50785079
int expert_idx = env->expert_static_agent_indices[i];
50795080
move_expert(env, env->actions, expert_idx);
50805081
}
5081-
// Move active agents with policy actions
5082+
// Move active agents with policy actions (or expert log if CONTROL_NONE)
50825083
for (int i = 0; i < env->active_agent_count; i++) {
50835084
env->logs[i].score = 0.0f;
50845085
env->logs[i].episode_length += 1;
50855086
int agent_idx = env->active_agent_indices[i];
5086-
move_dynamics(env, i, agent_idx);
5087-
// move_expert(env, env->actions, agent_idx);
5087+
if (env->control_mode == CONTROL_NONE) {
5088+
move_expert(env, env->actions, agent_idx);
5089+
} else {
5090+
move_dynamics(env, i, agent_idx);
5091+
}
50885092
}
50895093

50905094
// -> 2. Compute metrics and rewards

pufferlib/ocean/drive/drive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ def __init__(
258258
self.control_mode = 2
259259
elif self.control_mode_str == "control_sdc_only":
260260
self.control_mode = 3
261+
elif self.control_mode_str == "control_none":
262+
self.control_mode = 4
261263
else:
262264
raise ValueError(
263-
"control_mode must be one of 'control_vehicles', 'control_agents', 'control_wosac', or "
264-
f"'control_sdc_only'. Got: {self.control_mode_str}"
265+
f"control_mode must be one of 'control_vehicles', 'control_agents', 'control_wosac', 'control_none', or 'control_sdc_only'. Got: {self.control_mode_str}"
265266
)
266267
if self.init_mode_str == "create_all_valid":
267268
self.init_mode = 0

scripts/render_scenario.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
bev - ego-following ortho camera with wireframe boxes (view_mode=1)
2626
topdown_sim - fixed ortho camera over full map with 3D car models (view_mode=2)
2727
bev_all - ego-following top-down showing all agents (view_mode=3)
28+
29+
Other Options:
30+
control_mode - Use control_none to visualize all expert logs including ego, else defaults to control_sdc_only for replay and control_vehicles for gigaflow
2831
"""
2932

3033
import argparse

0 commit comments

Comments
 (0)