Conversation
Greptile SummaryThis PR adds a
The PR also includes a clean refactor of
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[c_step: move_dynamics called] --> B[Agent moves: dx, dy computed]
B --> C[cumulative_displacement += sqrt dx² + dy²]
C --> D{collision_state?}
D -->|NO_COLLISION| E["logs[i].distance_without_collision = cumulative_displacement"]
D -->|VEHICLE_COLLISION / OFFROAD| F[agent.collided_before_goal = 1]
F --> G{collision_behavior?}
G -->|STOP_AGENT| H[agent.stopped = 1, velocity = 0]
G -->|REMOVE_AGENT| I[agent.removed = 1]
G -->|default| J[Agent continues moving]
H --> K[Next step: move_dynamics returns early]
K --> L[cumulative_displacement frozen]
E --> M{Goal reached + GOAL_RESPAWN?}
M -->|Yes| N[respawn_agent: cumulative_displacement = 0]
N --> O["Next NO_COLLISION step overwrites distance_without_collision with near-zero value"]
M -->|No| P[Metric preserved until episode end]
Last reviewed commit: a8f57d8 |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@greptileai can you reevalute the PR ? |
| if (collision_state == NO_COLLISION) { | ||
| env->logs[i].distance_without_collision = agent->cumulative_displacement; | ||
| } |
There was a problem hiding this comment.
Metric resets to 0 after respawn
When GOAL_RESPAWN is active, respawn_agent resets cumulative_displacement to 0 (line 2177), but distance_without_collision is set via absolute assignment (not +=). This means on the next collision-free step after respawn, distance_without_collision is overwritten with the new (near-zero) cumulative_displacement, discarding the value accumulated before respawn.
This differs from other log metrics like episode_return and collisions_per_agent which accumulate across respawns. If the intent is to track total collision-free distance over the full episode, you'd want to either:
- Use
+=instead of=and accumulate the delta, or - Not reset
cumulative_displacementinrespawn_agent
If the intent is only "distance since last respawn without collision," the current code is correct but the semantic may surprise consumers of the metric.
eugenevinitsky
left a comment
There was a problem hiding this comment.
we can improve it later but this seems useful relative to the current state of the world so we should just merge it
Add the distance without collision metric.
I used the fact that the Agent datatype already had a cumulative_displacement field but it was never updated in drive.h
So I updated it in move_dynamics (and I set it at 0 in set_start_position)
Then I log distance_without_collision, in c_step:
Validation run:
Important notes to consider between merging this:
I guess that if collision_behavior isn't set to "STOP", this metrics will stop making sense. But it is easy to also add a variable to track if the agent did collide at least once in the episode. I didn't add it yet because it depends on your intended usage of the metric.
If an agent goes back and forth without really moving, he can artifically increase the metric a lot. I think it's okay because it's not a reward but a metric, but let me know what you think
I took the liberty to make a little refactoring of move_dynamics, nothing wild