Skip to content

Log avg_distance_per_infraction#417

Open
eugenevinitsky wants to merge 1 commit intopuffer-4from
ev/log-avg-distance-per-infraction
Open

Log avg_distance_per_infraction#417
eugenevinitsky wants to merge 1 commit intopuffer-4from
ev/log-avg-distance-per-infraction

Conversation

@eugenevinitsky
Copy link
Copy Markdown

Summary

  • Adds a new logged metric: env/avg_distance_per_infraction = total_distance_travelled / max(1, total_infractions). Tracks how far agents drive between offroad / collision / red-light events — a useful single-scalar driving-quality signal for wandb.
  • The two underlying log fields (total_distance_travelled, total_infractions) already existed in Log and were already accumulated per-step in add_log; only the binding-side ratio was missing.
  • Ported from emerge/temp_training (pufferlib/ocean/drive/binding.c:1820).

Implementation note

my_log gains an n parameter so it can recover totals from the per-agent-normalized aggregate produced by static_vec_aggregate_logs. Both call sites in vecenv.h updated to pass n. Without n, log->total_infractions is the per-agent rate and the fmaxf(1.0f, ...) clamp would mis-fire for any rate < 1.

Test plan

  • CPU build (mac arm64): builds clean
  • CUDA build on cluster
  • New metric appears in wandb under env/avg_distance_per_infraction

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 4, 2026 17:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new driving-quality metric to the Drive environment logs by deriving avg_distance_per_infraction from existing episode log totals in the binding layer.

Changes:

  • Added an n parameter to my_log so binding code can reconstruct totals from the normalized aggregate log.
  • Logged a new avg_distance_per_infraction metric in sim/binding.c.
  • Updated both vector-environment log call sites to pass the aggregate count through.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vecenv.h Updates the my_log declaration and both aggregate logging call sites to pass n.
sim/binding.c Computes and exports the new avg_distance_per_infraction metric from aggregated log data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sim/binding.c
Comment on lines 188 to +201
@@ -191,6 +198,7 @@ void my_log(Log *log, Dict *out) {
dict_set(out, "num_goals_reached", log->num_goals_reached);
dict_set(out, "avg_speed_per_agent", log->avg_speed_per_agent);
dict_set(out, "dnf_rate", log->dnf_rate);
dict_set(out, "avg_distance_per_infraction", avg_distance_per_infraction);
@eugenevinitsky eugenevinitsky force-pushed the ev/log-avg-distance-per-infraction branch from fa236fa to 65d79ea Compare May 4, 2026 17:56
Adds the metric:
  avg_distance_per_infraction = total_fleet_distance / max(1, total_fleet_infractions)
which tracks how far agents drive between offroad/collision/red-light
events — a useful single-scalar driving-quality signal for wandb.

The two underlying log fields already exist in puffer-4 and are already
aggregated per-step in add_log; only the binding-side ratio was missing.

my_log gains an `n` parameter and multiplies the per-agent-normalized
log->total_* fields by n to recover raw fleet totals. The ratio itself
is invariant to the 1/n scaling, but the un-normalization makes the
fmaxf(1.0f, total_infractions) clamp behave correctly: it floors the
denominator at "one infraction across the whole fleet", so a window
with zero infractions reports total fleet distance instead of
distance/epsilon. Both static_vec_log call sites in vecenv.h pass n.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@eugenevinitsky eugenevinitsky force-pushed the ev/log-avg-distance-per-infraction branch from 65d79ea to edae760 Compare May 4, 2026 18:09
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.

2 participants