Skip to content

Improve profile computation memory efficiency#525

Open
schroedtert wants to merge 2 commits into
PedestrianDynamics:mainfrom
schroedtert:improve-large-traj-profiles
Open

Improve profile computation memory efficiency#525
schroedtert wants to merge 2 commits into
PedestrianDynamics:mainfrom
schroedtert:improve-large-traj-profiles

Conversation

@schroedtert
Copy link
Copy Markdown
Collaborator

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_profile and compute_speed_profile per frame with shared intersection
  • Update user guide to use the simpler API without compute_grid_cell_polygon_intersection_area

@schroedtert schroedtert added the profiles Anything related to computing profiles label Mar 28, 2026
@schroedtert schroedtert requested a review from Copilot March 28, 2026 16:00
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

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_intersection and updates profile methods to compute intersections per frame when grid_intersections_area is omitted.
  • Refactors compute_profiles to 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.

Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
@schroedtert schroedtert added the usability Anything increasing the usablity label Mar 28, 2026
@chraibi chraibi requested a review from Copilot April 7, 2026 20:19
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

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.

Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread pedpy/methods/profile_calculator.py Outdated
@chraibi
Copy link
Copy Markdown
Collaborator

chraibi commented Apr 7, 2026

Benchmark results

Ran scripts/bench_profiles.py --frames 300 --peds 150 --repeats 1 (45k rows, 20×20 grid) on main vs this branch:

Metric main this branch
compute_profiles time 24.9s 15.1s
compute_profiles peak memory 1238 MB 7.3 MB
Precomputation time 12.6s 7.7s
density_profile (precomputed) 0.12s 0.10s

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 scripts/bench_profiles.py for reproducibility.

@chraibi chraibi marked this pull request as ready for review April 7, 2026 20:41
@chraibi chraibi requested review from JuleAdrian and Copilot April 7, 2026 20: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

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.

@chraibi chraibi force-pushed the improve-large-traj-profiles branch from ecdceba to a2ca5be Compare April 7, 2026 20:58
@chraibi chraibi removed the request for review from JuleAdrian April 8, 2026 09:43
@schroedtert schroedtert marked this pull request as draft April 9, 2026 06:16
@schroedtert schroedtert added this to the v1.5.0 milestone May 3, 2026
@schroedtert schroedtert force-pushed the improve-large-traj-profiles branch 2 times, most recently from 203a77e to 214d006 Compare May 4, 2026 19:47
Adapt pre-commit config to keep the tags, jupyter and id metadata of the
notebooks.
@schroedtert schroedtert force-pushed the improve-large-traj-profiles branch 2 times, most recently from 79f420b to ebe7a36 Compare May 4, 2026 20:16
@schroedtert schroedtert requested a review from Copilot May 4, 2026 20:18
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

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.

Comment thread pedpy/methods/profile_calculator.py
Comment thread pedpy/methods/profile_calculator.py Outdated
Comment thread notebooks/user_guide.ipynb
Comment thread notebooks/user_guide.ipynb
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

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.

Comment thread notebooks/user_guide.ipynb Outdated
Comment thread pedpy/methods/profile_calculator.py
Comment thread pedpy/methods/profile_calculator.py Outdated
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread notebooks/user_guide.ipynb Outdated
Comment thread pedpy/methods/profile_calculator.py
Comment thread pedpy/methods/profile_calculator.py Outdated
@schroedtert schroedtert force-pushed the improve-large-traj-profiles branch 3 times, most recently from 1993bb7 to 0848ce9 Compare May 8, 2026 20:01
@schroedtert schroedtert requested a review from Copilot May 8, 2026 20:02
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread notebooks/user_guide.ipynb Outdated
Comment thread pedpy/methods/profile_calculator.py
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread pedpy/methods/profile_calculator.py
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
@schroedtert schroedtert force-pushed the improve-large-traj-profiles branch from e20b685 to 877ab17 Compare May 8, 2026 20:20
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 93.16239% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.84%. Comparing base (d362055) to head (877ab17).

Files with missing lines Patch % Lines
pedpy/methods/profile_calculator.py 93.16% 8 Missing ⚠️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@schroedtert schroedtert marked this pull request as ready for review May 8, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiles Anything related to computing profiles usability Anything increasing the usablity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants