Skip to content

Commit 97ff529

Browse files
committed
Adding support to viz logs for all agents
1 parent ff79b67 commit 97ff529

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
@@ -3218,7 +3219,7 @@ void set_active_agents(Drive *env) {
32183219
}
32193220

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

@@ -3307,7 +3308,7 @@ void move_expert(Drive *env, float *actions, int agent_idx) {
33073308
return;
33083309
}
33093310

3310-
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY);
3311+
bool is_log_replay = (env->control_mode == CONTROL_SDC_ONLY || env->control_mode == CONTROL_NONE);
33113312

33123313
Agent *agent = &env->agents[agent_idx];
33133314
int t = env->timestep;
@@ -5076,13 +5077,16 @@ void c_step(Drive *env) {
50765077
int expert_idx = env->expert_static_agent_indices[i];
50775078
move_expert(env, env->actions, expert_idx);
50785079
}
5079-
// Move active agents with policy actions
5080+
// Move active agents with policy actions (or expert log if CONTROL_NONE)
50805081
for (int i = 0; i < env->active_agent_count; i++) {
50815082
env->logs[i].score = 0.0f;
50825083
env->logs[i].episode_length += 1;
50835084
int agent_idx = env->active_agent_indices[i];
5084-
move_dynamics(env, i, agent_idx);
5085-
// move_expert(env, env->actions, agent_idx);
5085+
if (env->control_mode == CONTROL_NONE) {
5086+
move_expert(env, env->actions, agent_idx);
5087+
} else {
5088+
move_dynamics(env, i, agent_idx);
5089+
}
50865090
}
50875091

50885092
// -> 2. Compute metrics and rewards

pufferlib/ocean/drive/drive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,11 @@ def __init__(
253253
self.control_mode = 2
254254
elif self.control_mode_str == "control_sdc_only":
255255
self.control_mode = 3
256+
elif self.control_mode_str == "control_none":
257+
self.control_mode = 4
256258
else:
257259
raise ValueError(
258-
"control_mode must be one of 'control_vehicles', 'control_agents', 'control_wosac', or "
259-
f"'control_sdc_only'. Got: {self.control_mode_str}"
260+
f"control_mode must be one of 'control_vehicles', 'control_agents', 'control_wosac', 'control_none', or 'control_sdc_only'. Got: {self.control_mode_str}"
260261
)
261262
if self.init_mode_str == "create_all_valid":
262263
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)