Refactor waypoint structure and metrics#483
Conversation
- Removed the 'kappa' field from the Waypoint structure in binding.c. - Renamed 'TTC_TFL_IDX' to 'DISTANCE_TO_COLLISION_IDX' in datatypes.h. - Updated references to 'TTC_TFL_IDX' in drive.h and related calculations to use 'DISTANCE_TO_COLLISION_IDX'. - Adjusted metric calculations in compute_metrics and compute_rewards functions to reflect the changes in the Waypoint structure and metrics. - Updated visualization labels in viz.py to match the new metric names.
There was a problem hiding this comment.
Pull request overview
Refactors waypoint/metrics plumbing in the Drive environment by removing waypoint curvature (kappa), moving some per-episode evaluation accumulators from Agent into Log, and rewiring TTC-related metrics to expose distance_to_collision instead of the prior ttc_tfl metric.
Changes:
- Replace
ttc_tflmetric wiring withdistance_to_collisionacross C metrics and Python viz labels. - Remove
Waypoint.kappaand related curvature computation/export from the C waypoint API. - Shift puffer/eval accumulator updates (wrong-way distance, speed violations, multi-lane time, TTC sampling) to
Logand plumblog_idxthrough metric computation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pufferlib/viz.py | Updates the metric label list to use distance_to_collision in place of ttc_tfl. |
| pufferlib/ocean/drive/drive.h | Refactors TTC + eval metric accumulation and removes waypoint curvature; updates offroad neighbor offsets constants and metric/reward plumbing. |
| pufferlib/ocean/drive/datatypes.h | Updates metric indices (adds DISTANCE_TO_COLLISION_IDX), removes Waypoint.kappa, and relocates traffic_control_in_scope. |
| pufferlib/ocean/drive/binding.c | Stops exporting the removed waypoint field kappa to Python. |
Comments suppressed due to low confidence (2)
pufferlib/ocean/drive/drive.h:593
compute_log_yaw_ratedivides bydtbut no longer guards againstdt <= 0, which can lead to division-by-zero / inf yaw rates ifdtis misconfigured (e.g., from INI). Please restore the defensive check (and keep the parameterconstsince the agent isn't mutated here).
int has_next = (next_t < agent->trajectory_length) && (agent->log_valid[next_t] == 1);
if (has_prev && has_next) {
float dtheta = normalize_heading(agent->log_heading[next_t] - agent->log_heading[prev_t]);
return dtheta / (2.0f * dt);
pufferlib/ocean/drive/drive.h:1836
compute_new_routeremoved clamping ofenv->num_target_waypointsbefore using it to derivemin_route_distance. Sincenum_target_waypointscan come from INI parsing (seedrive.c) without bounds checks, this can produce extreme route distances and unstable routing behavior. Please clamp (and ensure a positive value) locally like other goal/obs code paths do.
int num_target_waypoints = env->num_target_waypoints;
float min_route_distance;
// NOTE: make both multipliers config values and tune from a metric (route regenerations per 1k env steps).
if (env->target_type == TARGET_STATIC) {
min_route_distance = env->max_waypoint_spacing * num_target_waypoints * 2.0f;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| float z; | ||
| } DepthPoint; | ||
|
|
||
| static const int ROAD_OFFSETS[25][2] |
There was a problem hiding this comment.
think collision_offsets was maybe clearer?
There was a problem hiding this comment.
I disagree with that since collision is meant for objects also
| // Track at-fault collisions for evaluation metrics. | ||
| if (env->compute_eval_metrics && is_at_fault_collision(env, agent_idx, car_collided_with_index)) { | ||
| agent->at_fault_collision = 1; | ||
| log_agent->at_fault_collision_rate = 1.0f; |
There was a problem hiding this comment.
think the more natural version is agent_logs; log_agent implies an agent that is used for logging
Summary