-
Notifications
You must be signed in to change notification settings - Fork 13
Puffer Scenario v0 #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Puffer Scenario v0 #107
Conversation
…ith memory management functions
…_observations functions
… bounds checks and updating trajectory handling in visualization functions
…y and consistency
pufferlib/ocean/drive/datatypes.h
Outdated
| int is_road_lane(int type){ | ||
| return (type >= 0 && type <= 9); | ||
| } | ||
|
|
||
| int is_drivable_road_lane(int type){ | ||
| return (type == LANE_FREEWAY || type == LANE_SURFACE_STREET); | ||
| } | ||
|
|
||
| int is_road_line(int type){ | ||
| return (type >= 10 && type <= 19); | ||
| } | ||
|
|
||
| int is_road_edge(int type){ | ||
| return (type >= 20 && type <= 29); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't have a solution for this yet but this seems very error prone since it relies on someone remembering to change this if they add a new road type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I agree on that
and I don't know if we want to merge certain types
pufferlib/ocean/drive/datatypes.h
Outdated
| int is_road_lane(int type){ | ||
| return (type >= 0 && type <= 9); | ||
| } | ||
|
|
||
| int is_drivable_road_lane(int type){ | ||
| return (type == LANE_FREEWAY || type == LANE_SURFACE_STREET); | ||
| } | ||
|
|
||
| int is_road_line(int type){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a second thing is that lane and line being separated by a single char also seems error prone
l1onh3art88
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think the addition does improve readability as types improve but there is some excess bloat on the loading the binaries function and arguably unnecessary variable creations throughout. ~100 lines or so could be cut.
One potential issue in load binaries if drive.py is not adjusted to write traffic objects as is. Please check on this if traffic logic is not in yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK if daphne's PR was already merged on the no active agent condition. But it would be good to also address that here because there is now additional freeing logic.
| return -1; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a good portion of the code bloat is from error handling here. Are all of these checks really necessary? I know they can be helpful b/c debugging here is tough, but it is a large addition with effectively no function for the sim.
| e->vy = 0; | ||
| e->vz = 0; | ||
| e->collided_before_goal = 0; | ||
| agent->sim_vx = 0.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did vz get removed or forgotten here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it, we don't use it and I don't think it is gonna be relevant for the next steps
| } | ||
|
|
||
| // Subtract mean from road elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set means should be refactorable to cut lines by half by combining loops.
pufferlib/ocean/drive/drive.h
Outdated
| agent->sim_heading = agent->log_heading[t]; | ||
| agent->sim_vx = agent->log_velocity_x[t]; | ||
| agent->sim_vy = agent->log_velocity_y[t]; | ||
| agent->sim_length = agent->log_length[t]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we setting length width height and valid here and resetting to 0 above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can be debateble, but for the data-driven approach, it might be better to have dynamic bounding boxes but it represents the perception noise better. Now because the noise comes the ego perception, it makes more sense to apply this in ghost mode (=control only sdc) rather than multi-agent
pufferlib/ocean/drive/drive.h
Outdated
| // Rotate to ego vehicle's frame | ||
| float rel_goal_x = goal_x*cos_heading + goal_y*sin_heading; | ||
| float rel_goal_y = -goal_x*sin_heading + goal_y*cos_heading; | ||
| float distance_to_goal = relative_distance_2d(0, 0, rel_goal_x, rel_goal_y); | ||
| // Shrink agent size | ||
| env->entities[agent_idx].width *= 0.7f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this was in the original GPU drive, so is this no longer relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, I added it back in set_start_position
pufferlib/ocean/drive/drive.h
Outdated
| int num_dynamic_agents, num_roads, num_traffic; | ||
| if (fread(&num_dynamic_agents, sizeof(int), 1, file) != 1 || | ||
| fread(&num_roads, sizeof(int), 1, file) != 1 || | ||
| fread(&num_traffic, sizeof(int), 1, file) != 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will break the loading of any map until traffic is in the .py file no? Should this not be an env variable passed through config to check and then read the header properly. I think if fread is used it jumps to the next mem slot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
- Refactors unified
Entitystruct into three specialized types:DynamicAgent,RoadMapElement, andTrafficControlElement - Updates binary format to include route information, lane connectivity, traffic control states, and scenario metadata
Confidence Score: 1/5
- This PR has critical memory management bugs that will cause leaks and potential crashes
- Multiple critical memory leaks found: double allocation of
static_agent_indicesandexpert_static_agent_indicesarrays, incorrect malloc usage forentry_lanes/exit_laneswhen counts are 0, and duplicate field declarations in structs pufferlib/ocean/drive/drive.hrequires immediate attention to fix memory leaks and duplicate declarations
Important Files Changed
| Filename | Overview |
|---|---|
| pufferlib/ocean/drive/drive.h | Refactored entity handling with three typed arrays, but contains critical memory leaks (double allocation, incorrect malloc patterns) and duplicate field declarations |
Sequence Diagram
sequenceDiagram
participant Binary as "Binary File"
participant LoadFunc as "load_map_binary()"
participant Drive as "Drive struct"
participant Memory as "Memory"
LoadFunc->>Binary: "Open and read header"
Binary-->>LoadFunc: "num_dynamic_agents, num_roads, num_traffic"
LoadFunc->>Memory: "Allocate dynamic_agents array"
LoadFunc->>Memory: "Allocate road_elements array"
LoadFunc->>Memory: "Allocate traffic_elements array"
loop For each dynamic agent
LoadFunc->>Binary: "Read agent metadata"
LoadFunc->>Memory: "Allocate trajectory arrays"
LoadFunc->>Binary: "Read trajectory data"
LoadFunc->>Binary: "Read route data"
end
loop For each road element
LoadFunc->>Binary: "Read road metadata"
LoadFunc->>Memory: "Allocate coordinate arrays"
LoadFunc->>Binary: "Read coordinates"
alt is_road_lane
LoadFunc->>Memory: "Allocate entry/exit lane arrays"
LoadFunc->>Binary: "Read lane connectivity"
end
end
loop For each traffic element
LoadFunc->>Binary: "Read traffic metadata"
LoadFunc->>Memory: "Allocate states array"
LoadFunc->>Binary: "Read traffic states"
end
LoadFunc->>Binary: "Read scenario metadata"
LoadFunc->>Drive: "Populate metadata fields"
LoadFunc->>Binary: "Close file"
Additional Comments (1)
-
pufferlib/ocean/drive/drive.h, line 241-258 (link)logic:
scenario_lengthfield is declared twice in the Drive struct
4 files reviewed, 5 comments
Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format
Data Format & Architecture Specification
I. Format Structure
1. Header
num_agents(int32)num_road_elements(int32)num_traffic_controls(int32)2. Agent Structure
Core Fields
id(int32)type(int32)trajectory_length(int32)Trajectory Arrays (Log - Ground Truth)
trajectory_lengthlog_trajectory_x,log_trajectory_y,log_trajectory_z(float32[])log_heading(float32[])log_velocity_x,log_velocity_y(float32[])log_length,log_width,log_height(float32[])log_valid(int32[])Route Information
routes_length(int32)routes(int32[]) - List of lane IDs (Note: Currently supports only the first route)goal_position(float32, float32, float32) - x, y, zmark_as_expert(int32)1: No routes (Expert/Uncontrollable)0: Routes exist (Controllable)3. RoadMapElement Structure
Core Fields
id(int32)type(int32)segment_length(int32)Geometry Arrays
segment_lengthx,y,z(float32[])Connectivity & Limits
num_entry(int32) &entry_lanes(int32[])num_exit(int32) &exit_lanes(int32)speed_limit(float32) - Unit: m/s4. TrafficControlElement Structure
Core Fields
id(int32)type(int32)x,y,z(float32, float32, float32)State & Control
state_length(int32) andstates(int32[])num_controlled_lanes(int32) andcontrolled_lanes(int32[])5. Metadata (Variable Length)
scenario_id(char[128])map_id(int32)dataset_name(char[64])length(int32) - Number of timestepssdc_index(int32) - Ego vehicle IDnum_objects_of_interest+ corresponding ID arraynum_tracks_to_predict+ corresponding ID arrayII. Major Architectural Changes
1. New Data Structure Separation (
datatypes.h)Replaced a single
Entitystruct with three specialized structures:2. Renamed Fields: "Log" vs. "Sim"
Agent fields now clearly distinguish between:
log_trajectory_x).sim_x,sim_y,sim_z).3. Metadata Tracking
Added key fields to the
Drivestruct to improve scenario management:scenario_id,map_index,dataset_name,log_length,sdc_index.4. Updated Road Type System
FREEWAY,SURFACE_STREET,BIKE_LANEBOUNDARY,MEDIAN,SIDEWALK.CROSSWALK,SPEED_BUMP,DRIVEWAY.5. Traffic Control Updates
TRAFFIC_LIGHT,STOP_SIGN,YIELD_SIGN.6. GridMap Entity Type System
GridMapEntitynow uses an explicitentity_typefield:7. Agent Dimensions
DynamicAgenttracks time-varying dimensions:log_length/width/heightarrays (per timestep).sim_length/width/height(current simulation values).8. Route Information
Added
route_lengthandroutearray toDynamicAgentto enable path planning and lane following.III. Routes Logic Details
Description
A list of lane IDs representing the path for an agent to follow. The path is calculated to be the closest possible match to the ground truth trajectory.
Conditions
Current Constraints
III. Note on nuPlan Data
The format functions correctly with nuPlan data, but the source data is noted to be "messy" (requires careful handling).