-
Notifications
You must be signed in to change notification settings - Fork 13
Dynamic agents per world #148
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: carla_dev
Are you sure you want to change the base?
Conversation
…dling, env init pseudo code
* Adding Interaction features
Notes:
- Need to add safeguards to load each map only once
- Might be slow if we increase num_agents per scenario, next step will
be torch.
I added some tests to see the distance and ttc computations are correct,
and metrics_sanity_check looks okay. I'll keep making some plots to
validate it.
* Added the additive smoothing logic for Bernoulli estimate.
Ref in original code:
message BernoulliEstimate {
// Additive smoothing to apply to the underlying 2-bins histogram, to avoid
// infinite values for empty bins.
optional float additive_smoothing_pseudocount = 4 [default = 0.001];
}
* Little cleanup of estimators.py
* Towards map-based realism metrics:
First step: extract the map from the vecenv
* Second step: Map features (signed distance to road edges)
A bunch of little tests in test_map_metric_features.py to ensure this do what it is supposed to do.
python -m pufferlib.ocean.benchmark.test_map_metrics
Next steps should be straightforward.
Will need to check at some point if doing this on numpy isnt too slow
* Map-based features.
This works, and passes all the tests, I would still want to make additionnal checks with the renderer because we never know.
With this, we have the whole set of WOSAC metrics (except for traffic lights), and we might also have the same issue as the original WOSAC code: it is slow.
Next step would be to transition from numpy to torch.
* Added a visual sanity check, plot random trajectories and indicate when WOSAC sees an offorad or a collision
python pufferlib/ocean/benchmark/visual_sanity_check.py
* Update WOSAC control mode and ids.
* Eval mask for tracks_to_predict agents
* Replacing numpy by torch for the computation of interaction and map metrics.
It makes the computation way faster, and all the tests pass.
I didn't switch kinematics to torch because it was already fast, but I might make the change for consistency.
* Precommit
* Resolve small comments.
* More descriptive error message when going OOM.
---------
Co-authored-by: WaelDLZ <wawa@CRE1-W60060.vnet.valeo.com>
Co-authored-by: Waël Doulazmi <wawa@10-20-1-143.dynapool.wireless.nyu.edu>
Co-authored-by: Waël Doulazmi <wawa@Waels-MacBook-Air.local>
Co-authored-by: Daphne Cornelisse <cor.daphne@gmail.com>
Co-authored-by: Pragnay Mandavilli <pm3881@gr052.hpc.nyu.edu>
* Add option for targeted experiments. * Rename for clarity. * Minor * Remove tag * Add to help message and make deepcopy of args to prevent state pollution.
) * Little optimizations to use less memory in interaction_features.py They mostly consist in using in-place operations and deleting unused variables. Code passes the tests. Next steps: - clean the .cpu().numpy() in ttc computation - memory optimization for the map_features as well * Add future todo. --------- Co-authored-by: Waël Doulazmi <waeldoulazmi@gmail.com>
Greptile OverviewGreptile SummaryThis PR introduces dynamic agent initialization per world, allowing configurable numbers of agents to be spawned in each environment. Additionally, it significantly enhances the WOSAC evaluation framework with new interaction metrics (collision detection, time-to-collision, distance-to-nearest-object) and map-based metrics (distance-to-road-edge, offroad detection). Key Changes:
Issues Found:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Python as drive.py
participant Binding as binding.c
participant Config as env_config.h
participant Core as drive.h/drive.c
participant GridMap as GridMap
User->>Python: Initialize Drive(init_mode="dynamic_no_agents")
Python->>Binding: shared(num_agents, num_maps, ini_file)
Binding->>Config: ini_parse(ini_file, handler)
Config-->>Binding: env_init_config with init_mode
alt Dynamic Agents Mode
Binding->>Binding: Allocate num_agents_per_world per map
Binding->>Core: load_map_binary(map_file)
Core->>Core: Read only road entities from binary
Core->>Core: Create placeholder vehicle entities
Core-->>Binding: entities with uninitialized agents
else Standard Mode
Binding->>Core: load_map_binary(map_file)
Core->>Core: Read all entities from binary
Core->>Core: set_active_agents()
Core-->>Binding: entities with active agents
Binding->>Binding: Skip maps with no controllable agents
end
Binding-->>Python: agent_offsets, map_ids, num_envs
Python->>Binding: env_init() for each environment
Binding->>Core: Initialize Drive environment
Core->>GridMap: Build grid map with roads
Core->>Core: Initialize dynamic spawn if needed
Core-->>Python: Environment ready
User->>Python: reset()
Python->>Binding: vec_reset()
Binding->>Core: c_reset()
alt Dynamic Agents Mode
Core->>Core: get_valid_goal() for each agent
Core->>Core: is_valid_spawn_point()
Core->>Core: Initialize agent at valid position
else Standard Mode
Core->>Core: Reset to init_steps position
end
Core-->>Python: Initial observations
User->>Python: step(actions)
Python->>Binding: vec_step()
Binding->>Core: c_step() for each env
Core->>Core: Apply agent actions
Core->>Core: Update physics/dynamics
Core->>Core: Check collisions via GridMap
Core->>Core: Compute rewards
Core-->>Python: obs, rewards, terminals
User->>Python: get_global_agent_state()
Python->>Binding: vec_get_global_agent_state()
Binding->>Core: c_get_global_agent_state()
Core-->>Python: x, y, z, heading, id, length, width
User->>Python: get_road_edge_polylines()
Python->>Binding: vec_get_road_edge_polylines()
Binding->>Core: c_get_road_edge_polylines()
Core-->>Python: Road edge geometry data
|
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.
28 files reviewed, 1 comment
| if(env_config->num_agents_per_world <= 0 && env_config->init_mode == DYNAMIC_AGENTS_PER_ENV) { | ||
| raise_error_with_message(ERROR_INVALID_CONFIG, "num_agents_per_world must be positive for dynamic_agents_per_env init_mode"); | ||
| } |
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.
logic: validation depends on init_mode being set, but init_mode may not have been parsed yet
If the INI file has num_agents_per_world before init_mode, the validation check on line 117 will use an uninitialized or default value for init_mode, causing incorrect behavior.
Parse init_mode first before validating num_agents_per_world, or defer validation until after all config values are read.
Prompt To Fix With AI
This is a comment left during a code review.
Path: pufferlib/ocean/env_config.h
Line: 117:119
Comment:
**logic:** validation depends on `init_mode` being set, but `init_mode` may not have been parsed yet
If the INI file has `num_agents_per_world` before `init_mode`, the validation check on line 117 will use an uninitialized or default value for `init_mode`, causing incorrect behavior.
Parse `init_mode` first before validating `num_agents_per_world`, or defer validation until after all config values are read.
How can I resolve this? If you propose a fix, please make it concise.
No description provided.