Refactor imports and parameter names across notebooks and visualization module#454
Merged
Merged
Conversation
Collaborator
vcharraut
commented
May 29, 2026
- Simplified import statements in notebooks 02_rewards, 03_metrics, 04_training, and 05_inference by removing unnecessary line breaks.
- Updated parameter names in the unpack_obs and plot_observation functions in the viz.py module for clarity and consistency.
- Replaced max_partners, max_lane_segments, and max_boundary_segments with obs_slots_partners_n, obs_slots_lane_n, and obs_slots_boundary_n respectively.
…on module - Simplified import statements in notebooks 02_rewards, 03_metrics, 04_training, and 05_inference by removing unnecessary line breaks. - Updated parameter names in the unpack_obs and plot_observation functions in the viz.py module for clarity and consistency. - Replaced max_partners, max_lane_segments, and max_boundary_segments with obs_slots_partners_n, obs_slots_lane_n, and obs_slots_boundary_n respectively.
eugenevinitsky
approved these changes
May 29, 2026
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR refactors observation-slot parameter naming in the visualization utilities and simplifies notebook setup by relying more on environment-derived dimensions and consolidated imports.
Changes:
- Renamed
max_*keyword parameters toobs_slots_*inpufferlib/viz.pyand updated internal usages. - Updated notebooks to use
env.*feature/slot counts directly instead ofnotebook_dims. - Adjusted default notebook env configuration in
notebooks/notebook_utils.py(slot counts + added obs normalization/range fields).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pufferlib/viz.py | Renames observation-slot kwargs; adds target_type int→str coercion; updates replay JS header usage. |
| notebooks/notebook_utils.py | Changes default env config values and removes RNN helper/config wiring used by notebooks. |
| notebooks/01_observations.ipynb | Switches to direct pufferlib.viz imports and uses env.* dims for slicing/unpacking. |
| notebooks/02_rewards.ipynb | Simplifies imports/config; uses env.* dims and action-space fields. |
| notebooks/03_metrics.ipynb | Simplifies setup; uses env.num_agents and env.* dims. |
| notebooks/04_training.ipynb | Simplifies setup and replaces derived dims with env.* fields in slices/buffers. |
| notebooks/05_inference.ipynb | Cleans imports, removes RNN path, updates unpack_obs keyword args and analysis cells. |
| notebooks/06_architecture.ipynb | Uses env.* dims instead of notebook_dims; simplifies env creation. |
Comments suppressed due to low confidence (2)
pufferlib/viz.py:1
- Renaming keyword parameters (
max_partners/max_lane_segments/max_boundary_segments→obs_slots_*) is a breaking change for any downstream callers using keyword args. Consider supporting the old keyword names as deprecated aliases (e.g., accept them via explicit optional params or**kwargsmapping to the new names, emitting aDeprecationWarning) so existing user code doesn't break immediately.
"""Bird's Eye View visualization for PufferDrive scenarios using Matplotlib."""
pufferlib/viz.py:1
- The docstring documents
target_typeas an int encoding (0/1/2), but the new int-coercion maps onlybinding.TARGET_STATICto\"static\"and everything else to\"dynamic\". This is internally inconsistent and will silently mis-handle any int values beyond the single static constant. Update the docstring + type hint (e.g.,str | int), and replace the coercion with an explicit mapping/validation that either supports the documented int semantics or raises a clear error for unsupported values.
"""Bird's Eye View visualization for PufferDrive scenarios using Matplotlib."""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
64
to
+83
| "map_dir": MAP_DIR, | ||
| "collision_behavior": 1, | ||
| "offroad_behavior": 1, | ||
| "obs_slots_lane_n": 32, | ||
| "obs_slots_boundary_n": 32, | ||
| "obs_slots_lane_n": 80, | ||
| "obs_slots_boundary_n": 80, | ||
| "obs_slots_partners_n": 16, | ||
| "obs_slots_traffic_controls_n": 10, | ||
| "obs_slots_traffic_controls_n": 4, | ||
| "obs_dropout_lane": 0.0, | ||
| "obs_dropout_boundary": 0.0, | ||
| "obs_norm_goal_offset_m": 120.0, | ||
| "obs_norm_xy_offset_m": 120.0, | ||
| "obs_norm_veh_length_m": 15.0, | ||
| "obs_norm_veh_width_m": 10.0, | ||
| "obs_norm_road_seg_length_m": 10.0, | ||
| "obs_norm_road_seg_width_m": 5.0, | ||
| "obs_range_road_front_m": 120.0, | ||
| "obs_range_road_behind_m": 20.0, | ||
| "obs_range_road_side_m": 30.0, | ||
| "obs_range_partner_m": 100.0, | ||
| "obs_range_traffic_control_m": 100.0, |
Comment on lines
309
to
311
| " # Reshape (N,) -> (N, 1) for env.step with MultiDiscrete\n", | ||
| " env_actions = act.cpu().numpy().reshape(ACT_SHAPE)\n", | ||
| " env_actions = act.cpu().numpy().reshape(env.num_agents, len(env.single_action_space.nvec))\n", | ||
| " obs, rew, term, trunc, info = env.step(env_actions)\n", |
Comment on lines
+289
to
+292
| "for a in range(env.single_action_space.nvec[0]):\n", | ||
| " rews = []\n", | ||
| " for _ in range(STEPS_PER_ACTION):\n", | ||
| " actions = np.full(ACT_SHAPE, a, dtype=np.int64)\n", | ||
| " actions = np.full((env.num_agents, len(env.single_action_space.nvec)), a, dtype=np.int64)\n", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.