Improve profile computation memory efficiency#525
Conversation
There was a problem hiding this comment.
Pull request overview
Updates PedPy’s profile computation APIs to avoid requiring a precomputed full grid×pedestrian intersection matrix, enabling per-frame intersection computation to reduce peak memory usage for large datasets.
Changes:
- Adds
_compute_frame_grid_intersectionand updates profile methods to compute intersections per frame whengrid_intersections_areais omitted. - Refactors
compute_profilesto iterate frame-by-frame and share per-frame intersections between density and speed computations. - Updates plotting title handling, notebooks/user guide examples, and pre-commit tooling (including nbstripout metadata stripping).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
pedpy/plotting/plotting.py |
Ensures plot titles aren’t overwritten by plot_walkable_area defaults. |
pedpy/methods/profile_calculator.py |
Implements per-frame intersection computation and updates profile APIs/logic accordingly. |
notebooks/user_guide.ipynb |
Updates examples to use the simplified API without precomputing intersections. |
notebooks/getting_started.ipynb |
Strips notebook kernel metadata (via nbstripout configuration). |
notebooks/fundamental_diagram_at_measurement_line.ipynb |
Strips notebook kernel metadata. |
notebooks/fundamental_diagram.ipynb |
Strips notebook kernel metadata. |
.pre-commit-config.yaml |
Bumps tool versions and configures nbstripout to remove kernel/language metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Benchmark resultsRan
Peak memory drops from 1.2 GB → 7 MB (~170× reduction) with a ~40% speed improvement on the combined path. The per-frame approach trades some compute overhead for dramatically lower memory usage, which was the goal. Benchmark script added in |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ecdceba to
a2ca5be
Compare
79f420b to
ebe7a36
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ebe7a36 to
c84a5c7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c84a5c7 to
5b164dd
Compare
1993bb7 to
0848ce9
Compare
0848ce9 to
e20b685
Compare
e20b685 to
877ab17
Compare
Adapt pre-commit config to keep the tags, jupyter and id metadata of the notebooks.
Profile functions (compute_density_profile, compute_speed_profile, compute_profiles) no longer require pre-computed grid intersections. When grid_intersections_area is not provided, intersections are computed per frame internally, avoiding the allocation of the full (grid_cells × pedestrians) matrix. - Add _compute_frame_grid_intersection helper for single-frame intersection - Change _compute_grid_polygon_intersection to process frame-by-frame using NumPy instead of a single broadcast - Make grid_intersections_area optional in compute_density_profile and compute_speed_profile (on-the-fly when omitted) - Simplify compute_profiles to delegate to _compute_density_for_frame and _compute_speed_for_frame per frame with shared intersection - Extract _compute_density_for_frame and _compute_speed_for_frame as single-dispatch helpers; compute_density_profile and compute_speed_profile also delegate here, eliminating duplicated method branches - Move frame-invariant quantities (bounds, grid centers) out of the per-frame loop to avoid redundant recomputation - Update user guide to use the simpler API without compute_grid_cell_polygon_intersection_area
877ab17 to
b23ccd2
Compare
Codecov Report❌ Patch coverage is
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Profile functions (
compute_density_profile,compute_speed_profile,compute_profiles) no longer require pre-computed grid intersections. Whengrid_intersections_areais not provided, intersections are computed per frame internally, avoiding the allocation of the full (grid_cells × pedestrians) matrix._compute_frame_grid_intersectionhelper for single-frame intersection_compute_grid_polygon_intersectionto process frame-by-frame using NumPy instead of a single broadcastgrid_intersections_areaoptional incompute_density_profileandcompute_speed_profile(on-the-fly when omitted)compute_profilesto delegate tocompute_density_profileandcompute_speed_profileper frame with shared intersectioncompute_grid_cell_polygon_intersection_area