Skip to content

Refactor waypoint structure and metrics#483

Merged
WaelDLZ merged 1 commit into
emerge/temp_trainingfrom
vcha/rework-log-metrics
Jun 12, 2026
Merged

Refactor waypoint structure and metrics#483
WaelDLZ merged 1 commit into
emerge/temp_trainingfrom
vcha/rework-log-metrics

Conversation

@vcharraut

@vcharraut vcharraut commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Move evaluation metric accumulators from Agent state into per-agent logs.
  • Replace the old ttc_tfl metric slot with distance_to_collision and update visualization labels.
  • Remove unused waypoint curvature/TTC cache state while computing TTC metrics directly from metric arrays.
  • Keep puffer score display fields updated during the episode.

- 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.
Copilot AI review requested due to automatic review settings June 12, 2026 14:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_tfl metric wiring with distance_to_collision across C metrics and Python viz labels.
  • Remove Waypoint.kappa and 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 Log and plumb log_idx through 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_rate divides by dt but no longer guards against dt <= 0, which can lead to division-by-zero / inf yaw rates if dt is misconfigured (e.g., from INI). Please restore the defensive check (and keep the parameter const since 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_route removed clamping of env->num_target_waypoints before using it to derive min_route_distance. Since num_target_waypoints can come from INI parsing (see drive.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.

@vcharraut vcharraut requested a review from WaelDLZ June 12, 2026 15:27

@WaelDLZ WaelDLZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only refactoring I trust you

@WaelDLZ WaelDLZ merged commit 9b30b32 into emerge/temp_training Jun 12, 2026
13 checks passed
@vcharraut vcharraut deleted the vcha/rework-log-metrics branch June 12, 2026 15:36
Comment thread pufferlib/ocean/drive/datatypes.h
Comment thread pufferlib/ocean/drive/datatypes.h
Comment thread pufferlib/ocean/drive/drive.h
float z;
} DepthPoint;

static const int ROAD_OFFSETS[25][2]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think collision_offsets was maybe clearer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with that since collision is meant for objects also

Comment thread pufferlib/ocean/drive/drive.h
// 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think the more natural version is agent_logs; log_agent implies an agent that is used for logging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants