Skip to content

Refactor imports and parameter names across notebooks and visualization module#454

Merged
vcharraut merged 3 commits into
emerge/temp_trainingfrom
vcha/update-notebooks
May 29, 2026
Merged

Refactor imports and parameter names across notebooks and visualization module#454
vcharraut merged 3 commits into
emerge/temp_trainingfrom
vcha/update-notebooks

Conversation

@vcharraut
Copy link
Copy Markdown
Collaborator

  • 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.

vcharraut added 2 commits May 29, 2026 21:33
…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.
Copilot AI review requested due to automatic review settings May 29, 2026 19:44
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

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 to obs_slots_* in pufferlib/viz.py and updated internal usages.
  • Updated notebooks to use env.* feature/slot counts directly instead of notebook_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_segmentsobs_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 **kwargs mapping to the new names, emitting a DeprecationWarning) 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_type as an int encoding (0/1/2), but the new int-coercion maps only binding.TARGET_STATIC to \"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",
@vcharraut vcharraut merged commit 60630e3 into emerge/temp_training May 29, 2026
13 of 14 checks passed
@vcharraut vcharraut deleted the vcha/update-notebooks branch May 29, 2026 19:55
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.

3 participants