Repository navigation
SILo: size the localization pool for the largest trial, not the first - #51
Merged
Merged
Conversation
SILo budgeted 9x one channel of the first valid trial's registered movie (plus 1 GB) per localizing worker. The first trial of a SLAP2 recording is often partial: in multi-ROI exports it had 1064 of 2354 frames (828409 2025-11-11) or only a few frames (828409 2025-11-20, estimated at 1.2 and 1.3 GB per trial against >=20 GB measured), and sessions were killed for memory during localization. localizationTrialBytes sizes every kept trial's movie (h5 by its data, tif by its file) and budgets for the largest. The 9x factor stays: one 780125 trial (3.04 GiB per channel) peaks at 26.0 GB, 8.3x plus the 0.75 GB process, at the s.d. in localizeSources_vIM, where the worker holds eight movie-sized arrays of the activity channel. SILo also prints which trial the pool was sized for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change to size localization workers using the largest kept trial.
No open issues 🎉
What changed in this PR
SILo now sizes its localization worker pool using the largest kept trial for each imaging path, rather than the first valid trial. This prevents a partial first trial from understating memory needs while preserving the existing 9× per-channel estimate plus 1 GB.
Changes:
- Adds a helper that sizes all kept movies using HDF5 dataset dimensions or TIFF file sizes.
- Updates SILo to use the largest estimate and report the trial used for sizing.
- Adds unit and integration coverage for largest-trial selection, movie sizing, and missing-file errors.
| File | Description |
|---|---|
| tests/unit/source_extraction/TestSILo.m | Adds a regression test with a partial first trial and verifies the sizing report. |
| tests/unit/dependencies/extraction/TestLocalizationTrialBytes.m | Tests largest-trial selection, HDF5 and TIFF sizing, and missing-file errors. |
| source_extraction/SILo.m | Uses the largest kept trial’s memory estimate and logs sizing details. |
| dependencies/extraction/activityImage/localizationTrialBytes.m | Adds the shared helper for estimating localization memory across trials. |
Review effort: Balanced
KasparP
added a commit
that referenced
this pull request
Nov 22, 2026
…e-memory SILo localization: stop copying the movie; budget 6x per trial (stacked on #51)
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.
Problem
SILo localizes as many trials at once as fit in memory. It budgets 9× one channel of a trial's registered movie plus 1 GB per trial. It took that movie from the first valid trial of each imaging path, and the first trial of a SLAP2 recording is often partial.
Evidence from 23 multi-ROI SLAP2 sessions exported with GIAnT 9695d27 on a 246 GB machine:
What dominates localization memory
I measured one 780125 trial with memory probes in a fresh MATLAB process. The trial is multi-ROI SLAP2, two channels, 80 Hz, 3.04 GiB per channel (
E1T1DMD2).The peak is 26.0 GB: 8.3× one channel plus the 0.75 GB process. It comes at the s.d. line of
localizeSources_vIM(stdIM = sqrt(max(0,Vk.*IMb.*vIM)+Vb)). At that line the worker holds eight movie-sized single arrays of the activity channel, plus its NaN mask (¼ of a movie):IMandvIM(variance factors), still referenced byloadAndProcessTrialAsynclocalizeSources_vIMmakes of both (copy-on-write, because the caller still holds them)IMs(smoothed, never cleared),IMb(baseline),stdIMLoading both channels peaks at 13.1 GB (4.3×), and the DoG and peak-finding stages at 17.6 GB, both below the localization peak.
Memory scales with rows × cols × frames of the registered movie. For multi-ROI recordings the movie spans the bounding box of all ROIs plus 2×maxshift, and is NaN between ROIs. Memory does not depend on the number of ROIs or sources.
The 9× factor therefore holds: 8.3× on Windows, and the exports' Linux peaks give at least 5.7–6.7× (table below). The bug was which trial it was applied to.
Change
localizationTrialBytes(mocoDr, fns, numChannels)sizes every kept trial's registered movie and returns 9× one channel of the largest, plus 1 GB.h5infocall per trial.Before / after, per trial
"After" applies the new sizing to the logged first-trial estimate, scaled by frames to the longest trial. With online compensation, every trial of a path has the same raster crop, so frames are the only difference.
"Measured" is the localization stage's total memory peak above the pre-localization baseline, divided by the number of workers. It is a lower bound on one worker's peak.
Pool check on 780125 (local, R2024b, Windows). Four trials of Path 2 were localized at once by 4
parforworkers:So the "measured" totals from the exports understate a worker's peak by about 10%. On this evidence, Linux workers peak at roughly 6.5–7.5×, still under 9×.
Tests
runtestsonTestLocalizationTrialBytesandTestSILo: 25 passed, 0 failed (R2024b, Windows).TestLocalizationTrialByteschecks four things:TestSILo/testSizesLocalizationForLargestTrialruns SILo with 2 workers on a dataset with a partial first trial. It uses the existing no-poolextractionPooldouble, so the sizing code runs but localization stays in the client. The test checks that SILo reports sizing for trial 2.Not in this PR
Peak memory could drop from about 8.3× to about 5× one channel:
loadAndProcessTrialAsync, passIMandvIMtolocalizeSources_vIMwithout keeping references, so it can mask them in place;IMsaftervarIM;stdIMafter use.That would localize more trials at once, but it changes the localization code rather than the estimate, so it is left for a separate PR.
🤖 Generated with Claude Code