Skip to content

fix main_density_calc to reduce memory usage#47

Merged
shruthivis merged 1 commit intoisblab:mainfrom
omgol411:main
Apr 13, 2026
Merged

fix main_density_calc to reduce memory usage#47
shruthivis merged 1 commit intoisblab:mainfrom
omgol411:main

Conversation

@omgol411
Copy link
Copy Markdown
Contributor

@omgol411 omgol411 commented Apr 13, 2026

Addressing #42

  • pass information about single bead to main_density_calc
  • common BeadDensity instance for all beads

Summary by CodeRabbit

  • Refactor
    • Improved internal efficiency of density calculations in the computation pipeline through streamlined multiprocessing architecture and optimized argument passing.

@omgol411 omgol411 self-assigned this Apr 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

This pull request refactors the multiprocessing architecture in the density calculation pipeline. The changes eliminate functools.partial usage by restructuring worker invocation to pass a single argument tuple per bead instead of partially-applied keyword arguments. Function signatures for main_density_calc and get_bead_spread were modified, and a BeadDensity instance is now pre-instantiated once per run and reused across worker tasks.

Changes

Cohort / File(s) Summary
Multiprocessing Worker Refactoring
src/main.py
Removed functools.partial and restructured argument passing by changing main_density_calc signature from (i, coords, mass, radius, grid, voxel_size, n_breaks) to (coords, mass, radius, bead_density, n_breaks) and get_bead_spread from individual parameters to a single arguments tuple. Pre-instantiate BeadDensity outside worker loop and construct per-bead argument tuples for p.imap. Updated density computation to use full coords array instead of per-bead slices.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • shruthivis

Poem

🐰 Tuples hop in, arguments unite,
Partial functions fade from sight,
Beads spread densely, work once shared,
Multiprocessing, cleaner prepared!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: refactoring main_density_calc to use a shared BeadDensity instance instead of per-bead calculations, which directly reduces memory usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main.py (1)

13-19: Remove commented-out dead code.

Line 14 contains a commented-out line from the previous implementation. Since the BeadDensity instance is now passed in as a parameter, this dead code should be removed for clarity.

Suggested fix
 def main_density_calc(coords, mass, radius, bead_density, n_breaks):
-	# bead_density = BeadDensity(coords.shape[0], grid=grid, voxel_size=voxel_size)
 	# Obtain min-max coords for the bead across all models to construct a kernel.
 	# k1 --> min xyz coords of kernel; k2 --> max xyz coords of kernel.
 	k1, k2 = _get_bounding_box(coords)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main.py` around lines 13 - 19, Remove the dead commented-out
instantiation of BeadDensity in main_density_calc; since a BeadDensity instance
is now passed in, delete the commented line (the line starting with "#
bead_density = BeadDensity...") and keep the existing logic that calls
_get_bounding_box(coords), bead_density.construct_kernel(k1,k2), and
bead_density.return_density_opt(coords, radius, mass, n_breaks).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main.py`:
- Around line 13-19: Remove the dead commented-out instantiation of BeadDensity
in main_density_calc; since a BeadDensity instance is now passed in, delete the
commented line (the line starting with "# bead_density = BeadDensity...") and
keep the existing logic that calls _get_bounding_box(coords),
bead_density.construct_kernel(k1,k2), and
bead_density.return_density_opt(coords, radius, mass, n_breaks).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 37990eb8-19b4-4d92-8209-bc57c4d4f5d0

📥 Commits

Reviewing files that changed from the base of the PR and between a0cedb4 and 253dcc4.

📒 Files selected for processing (1)
  • src/main.py

@omgol411 omgol411 requested a review from shruthivis April 13, 2026 12:45
@shruthivis shruthivis merged commit 9150df4 into isblab:main Apr 13, 2026
2 checks passed
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.

2 participants