Repository navigation
(osw): Speed up OpenSwathWorkflow for Large Libraries - #9190
Conversation
…n and scoring diagnostics
…onst reference in prepareScoredFeatureOutput_
…roved scoring management
…n handling in performExtraction method
…nters for feature finders and transition group pickers
…ce extraction process with new scoring management
…scoring efficiency
- Updated the handling of RUN.ID to ensure it is stored as INTEGER instead of BLOB, addressing a type mismatch that caused JOIN queries to return 0 rows. - Refactored the regression test to insert a minimal FEATURE row using the prepared-row writer path instead of direct SQL statements, improving test clarity and maintainability. - Added verification for the type of RUN_ID in the FEATURE table to ensure it is correctly stored as INTEGER.
…structure for improved efficiency
…g job management - Introduced a new lambda function `finalize_context` to handle the finalization of scoring contexts. - Added `remaining_score_jobs` and `finalized` flags to track the state of scoring jobs within each context. - Updated the scoring job processing loop to finalize contexts when all jobs are completed. - Improved thread safety with OpenMP critical sections around context finalization and OSW writing. - Simplified the handling of OSW output and feature writing by consolidating logic into the new finalization function.
… and improved score value management
…ve scoring timing management
…oss-platform memory info handling
…emory management and performance profiling
…e flush trigger for improved memory management
…mination for improved performance
…tion for improved efficiency
…by simplifying calculation
…tion with improved thread handling
…ring rows for OSWData
…racking and flush trigger logic
…eredWriter for better buffer management
…riter for improved buffer management
… feature scoring logic
…to enhance performance
…ragine isotope distributions to improve performance
…ce performance during workflow execution
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp`:
- Around line 301-304: performExtraction() sets the global
suppress_resampling_spacing_warning flag to true and never restores it, which
silences resampling warnings for the entire process; change performExtraction()
to save the previous value of suppress_resampling_spacing_warning, set it to
true for the extraction, and then restore the saved value on all exit paths
(normal return or exceptions). Implement this by adding a small RAII guard
(e.g., ScopedBoolGuard) or by using a try/finally pattern inside
performExtraction(): read old = suppress_resampling_spacing_warning.load(),
store(true), and ensure suppress_resampling_spacing_warning.store(old) in the
guard's destructor or finally block so LinearResamplerAlign warnings are only
suppressed during the extraction scope. Ensure you reference
suppress_resampling_spacing_warning and performExtraction() when adding the
guard.
- Around line 1519-1524: The call to OpenSwath::LightCompound() and nullptr
loses assay/transition context; replace those placeholders in the
prepareRowsInto(...) call so it receives the actual assay compound and the
detection transition pointer you used earlier (e.g., pass the assay's compound
object instead of OpenSwath::LightCompound() and pass a pointer/reference to the
transition/filter instead of nullptr), keeping the other arguments
(to_osw_output, output, id) unchanged so prepareRowsInto(id, to_osw_output,
<assay_compound>, <transition_ptr>, output) preserves OSW row context.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 91eefa96-4eca-4692-a5b5-5719428de6f7
📒 Files selected for processing (4)
src/openms/include/OpenMS/PROCESSING/RESAMPLING/LinearResamplerAlign.hsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cppsrc/topp/OpenSwathWorkflow.cpp
| // Compound and transition are currently unused by the OSW row writer. | ||
| osw_writer.prepareRowsInto(to_osw_output, | ||
| OpenSwath::LightCompound(), | ||
| nullptr, | ||
| output, | ||
| id); |
There was a problem hiding this comment.
Pass the assay compound and detection transition into OSW row preparation.
prepareRowsInto() is documented to receive the compound and optional transition filter; passing an empty LightCompound and nullptr can drop or mis-associate OSW row context, especially for transition/IPF-related output.
🐛 Preserve OSW row context
- // Compound and transition are currently unused by the OSW row writer.
+ const OpenSwath::LightCompound& compound =
+ transition_exp.getCompounds()[assay_peptide_map[id]];
osw_writer.prepareRowsInto(to_osw_output,
- OpenSwath::LightCompound(),
- nullptr,
+ compound,
+ detection_assay_it,
output,
id);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openms/source/ANALYSIS/OPENSWATH/OpenSwathWorkflow.cpp` around lines 1519
- 1524, The call to OpenSwath::LightCompound() and nullptr loses
assay/transition context; replace those placeholders in the prepareRowsInto(...)
call so it receives the actual assay compound and the detection transition
pointer you used earlier (e.g., pass the assay's compound object instead of
OpenSwath::LightCompound() and pass a pointer/reference to the transition/filter
instead of nullptr), keeping the other arguments (to_osw_output, output, id)
unchanged so prepareRowsInto(id, to_osw_output, <assay_compound>,
<transition_ptr>, output) preserves OSW row context.
|
Did a multi-agent review pass on this and want to sanity-check 4 concrete blockers + 2 reframings with you before they harden into review demands. Most of the original "critical regression" findings melted under empirical inspection — but a few items still look real. Could you confirm/push back on each? Blockers (would like verification)B1 — featureXML byte-determinism. B2 — B3 — Memory budget undercounts ~3×. Astral 41.3 → 126.6 GB peak isn't fully explained by "wave scheduler keeps multiple SWATHs resident". The dominant unaccounted item is Two findings I'd like to confirm aren't actually regressionsR1 — IM/resample merge change. R2 — Multi-gene PQP dedup. Removing the raw |
| std::shared_ptr<FeatureWrapperList_> features_; | ||
| std::shared_ptr<FeatureWrapperList_> precursor_features_; | ||
| const std::vector<Feature>* direct_features_ = nullptr; | ||
| FeaturePointerList_ feature_ptrs_; | ||
| FeaturePointerList_ precursor_feature_ptrs_; | ||
| FeatureIndexList_ feature_index_; | ||
| FeatureIndexList_ precursor_feature_index_; | ||
| std::vector<std::string> feature_ids_storage_; | ||
| std::vector<std::string> precursor_feature_ids_storage_; | ||
| const std::vector<std::string>* feature_ids_ = nullptr; | ||
| const std::vector<std::string>* precursor_feature_ids_ = nullptr; |
There was a problem hiding this comment.
this class get's quite chubby ;)
I think some generate comments that put all those new members into context would help.
| Stores precomputed theoretical m/z and intensity arrays plus rescaling | ||
| bounds for repeated scoring of the same transition group. | ||
| */ | ||
| struct OPENMS_DLLAPI PreparedSpectrum |
There was a problem hiding this comment.
don't 100% like the name. maybe something more telling? TransitionGroupTheoreticalSpectrum ? not a beauty though...
| @param[in] lt Library transitions for the transition group | ||
| @param[out] prepared Precomputed theoretical spectrum | ||
| */ | ||
| void prepare(const std::vector<OpenSwath::LightTransition>& lt, |
There was a problem hiding this comment.
the name "prepare" could potentially be replaced...
| PreparedSpectrum& prepared) const; | ||
|
|
||
| /** | ||
| @brief Score an observed spectrum against a precomputed theoretical DIA spectrum. |
There was a problem hiding this comment.
improve description:
it should be clear that it considers multiple spectra. (are those MS2 windows / frames?)
| /** @brief Return pooled normalized library intensities (uses internal pool) | ||
| * | ||
| * Fills and returns a reference to an internal thread-local buffer. Callers | ||
| * that want to avoid per-call allocations can use this to obtain a | ||
| * reference to pooled normalized intensities. |
There was a problem hiding this comment.
hmm this sounds a bit complex... is there a simpler design?
…roved performance and clarity
… and intensity retrieval
…ions and streamline scoring logic
…to anonymous namespace for better encapsulation
…reticalSpectrumCache and update related methods for clarity
…ter warning management during processing B1: performExtraction() now sorts the accumulated FeatureMap once at the end of feature-producing paths, including the wave-scheduler branch before buffered OSW finalization, so feature-based output order is deterministic after parallel accumulation. B2: the resampling warning suppression is now scoped with an RAII guard instead of being left enabled process-wide. I wired that into both the library workflow path and the TOPP tool entrypoint. R1: kept the current IM/resample merge behavior and added a code comment explaining that concatenation is intentional because IM scoring needs drift-time arrays preserved. R2: kept the aggregated PQP gene join and strengthened the inline comment to state that the raw join duplicates transition rows and later breaks transition-group construction.
… to extern for shared process-wide access
…inistic output after parallel scoring fix(TransitionPQPFile_test): update test to check for transition existence and correct size
|
@timosachsenberg , I think I've addressed most/all the comments. The pyopenms wheel for MacOS seems to be failing though because it can't find a suitable arrow version? |
Add CHANGELOG entries for OpenSwathWorkflow speed-up for large libraries (PR #9190): - TOPP: document new wave scheduler parameters (batchSize=0 auto, innerBatchSize, maxConcurrentSwaths, outer_loop_threads) and memory-aware buffered OSW writer - TOPP: document RUN.ID INTEGER fix - Library: document SysInfo::getFreeSystemMemory(), new OpenSwathWorkflowScheduler class, and OpenSwathOSWWriter additions Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
- Add OpenSwathWorkflow SWATH wave scheduler performance improvement and new parameters (innerBatchSize, maxConcurrentSwaths, batchSize=0 default) - Add Fix for RUN.ID stored as BLOB instead of INTEGER in OSW output (fixes downstream PyProphet JOIN queries returning 0 rows) Both entries reference #9190. Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: timosachsenberg <[email protected]>
Description
This PR improves
OpenSwathWorkflowperformance for large transition libraries and high-SWATH-count DIA data. The main changes are:batchSize,innerBatchSize,maxConcurrentSwaths, andouter_loop_threads.The default
batchSizeis now0, which enables automatic scheduling. With in-memory reads, this uses the SWATH wave scheduler; positivebatchSizevalues still force the legacy per-SWATH batch path.Main Changes
PQP loading
Extraction and scoring
innerBatchSizeandmaxConcurrentSwathscontrols.batchSize.Output writing
Allocation and scoring hot paths
MRMScoring,OpenSwathScoring, DIA scoring, ion mobility scoring, and IPF/identification transition scoring.Multi-run memory lifetime
Benchmarks
Benchmarks were run on the
profile/oswbranch and compared againstdevelopbefore these optimizations on a fairly idle machine with 186Gb of Ram and 36 threads.Initial profiling diagnostics
The first diagnostic runs used temporary
-Debugging:profileinstrumentation with-threads 34and-readOptions cacheWorkingInMemoryon the HeLa Evosep diaPASEF dataset. The profiling output reported both wall time and summed worker phase time. The summed worker time is useful for attribution across threads, but is not expected to equal wall time.Input summary for the focused diagnostic run: 24 SWATH windows, 129,754 compounds, 778,524 scored transitions, 519,016 MS1 chromatograms, and 778,524 MS2 chromatograms.
A representative phase breakdown from the temporary profiler showed why the work focused on scoring and output materialization rather than raw extraction:
picker+score_peakgroupsdia+chromscore_output+osw_prepareosw_writeThese diagnostics drove the main implementation choices in this PR: memory-aware wave scheduling for better CPU utilization, pooled temporary buffers in picker/scoring hot paths,
ScoreValueListand OSW row-buffer changes for output preparation, and run-local cleanup for multi-run workflows.HeLa Evosep diaPASEF DDA empirical library, 24 SWATH windows, 1 run
Input summary: 14,216 proteins, 146,788 compounds with 880,728 transitions.
Values are means from running the same OpenSwathWorkflow Command 20 times.
Astral predicted library, 300 SWATH windows, 2 runs
Input summary: 40,787 proteins, 5,550,339 compounds, 33,302,034 transitions loaded. The run-specific evidence filter retained 37,914 target precursors for run 1 and 57,564 target precursors for run 2.
This is a 15.8x end-to-end wall-clock speedup for the two-run Astral benchmark. Extraction/scoring improved by 18.3x for run 1 and 15.2x for run 2.
The optimized Astral path intentionally uses more memory because the wave scheduler keeps multiple SWATH windows resident to improve CPU utilization. The scheduler now accounts for memory budget and
maxConcurrentSwathscan be used to cap concurrency on smaller machines.This PR should not change scoring semantics. The changes are intended to reduce I/O overhead, allocation overhead, scheduling imbalance, and retained run-local memory.
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Improvements
Bug Fixes