Repository navigation
Stream QPX feature Parquet export in batches to bound peak memory - #9698
Conversation
For isobaric labeling there is ~one consensus feature per PSM, so the ConsensusMap feature table can be millions of rows. The old ConsensusMapArrowExport::exportToArrow built the entire Arrow table in memory before a single write, so on large runs peak memory drove the process into swap/OOM and quantms.feature.parquet was never created (it is written first in IsobaricWorkflow, before the PSM/pg exports). Port the streaming approach already used for the PSM export (#9697) to the feature export, serial only: - Refactor the per-row build into an anonymous-namespace range builder buildFeatureTableRange(cmap, id_lut, [begin, end)); hoist the per-map protein-group/gene lookups into buildFeatureIdLookups and the Parquet writer properties into makeFeatureWriterProperties. Each feature row is independent, so any contiguous sub-range yields a self-contained, schema-valid table. - exportToArrow() now delegates over the whole range (output unchanged). - Add exportToParquetStreaming(): build and flush one batch_size-sized range at a time through a persistent parquet::arrow::FileWriter, so peak memory stays bounded by one batch instead of the whole table. - IsobaricWorkflow uses the streaming path for the feature export. Written rows and their order are identical to the one-shot path; only the Parquet row-group layout may differ. A new class-test asserts streaming<->one-shot equivalence (full Table::Equals over combined chunks, order-sensitive via unique RT) across multiple batches, the single-batch and batch_size==0 cases, and the empty-map edge. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01HcY3LMYuUDF2psYat9uUYN
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new ChangesStreaming Parquet Export
Sequence Diagram(s)sequenceDiagram
participant IsobaricWorkflow
participant ConsensusMapArrowExport
participant buildFeatureIdLookups
participant buildFeatureTableRange
participant ParquetFileWriter
IsobaricWorkflow->>ConsensusMapArrowExport: exportToParquetStreaming(cmap, filename, batch_size, config)
ConsensusMapArrowExport->>buildFeatureIdLookups: buildFeatureIdLookups(cmap)
buildFeatureIdLookups-->>ConsensusMapArrowExport: lookup tables
ConsensusMapArrowExport->>ParquetFileWriter: open(filename, schema, writer_props)
loop each batch [b, e)
ConsensusMapArrowExport->>buildFeatureTableRange: buildFeatureTableRange(cmap, id_lut, b, e)
buildFeatureTableRange-->>ConsensusMapArrowExport: Arrow table batch
ConsensusMapArrowExport->>ParquetFileWriter: WriteTable(batch)
end
ConsensusMapArrowExport->>ParquetFileWriter: Close()
ParquetFileWriter-->>ConsensusMapArrowExport: close status
ConsensusMapArrowExport-->>IsobaricWorkflow: ok / failure
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h (1)
90-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
Sizefor the public batch-size parameter.
batch_sizeis a feature count, so the public OpenMS API should useSizeinstead ofsize_t; mirror the same change in the.cppdefinition and helper counters. As per coding guidelines, “Use OpenMS primitive types fromOpenMS/CONCEPT/Types.hinstead of standard C++ types.”Proposed fix
- size_t batch_size = 1000000, + Size batch_size = 1000000,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h` at line 90, The public batch-size API in ConsensusMapArrowExport should use OpenMS::Size instead of size_t. Update the ConsensusMapArrowExport declaration, the matching .cpp definition, and any related helper counters or loop variables that represent feature counts to use Size consistently. Keep the symbol names aligned with the existing export path so the public interface and implementation both follow the OpenMS primitive type guideline from OpenMS/CONCEPT/Types.h.Source: Coding guidelines
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (2)
133-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
Sizefor feature ranges and batch counters.These values index
ConsensusMaprows and represent OpenMS container sizes; useSizeconsistently instead ofsize_t. As per coding guidelines, “Use OpenMS primitive types fromOpenMS/CONCEPT/Types.hinstead of standard C++ types.”Proposed fix
std::shared_ptr<arrow::Table> buildFeatureTableRange( const ConsensusMap& cmap, const FeatureIdLookups& id_lut, - size_t range_begin, - size_t range_end) + Size range_begin, + Size range_end) @@ - for (size_t feat_idx = range_begin; feat_idx < range_end; ++feat_idx) + for (Size feat_idx = range_begin; feat_idx < range_end; ++feat_idx) @@ bool ConsensusMapArrowExport::exportToParquetStreaming( const ConsensusMap& cmap, const std::string& filename, - size_t batch_size, + Size batch_size, const ParquetWriteConfig& config) @@ - const size_t N = cmap.size(); + const Size N = cmap.size(); @@ - for (size_t b = 0; b < N && ok; b += batch_size) + for (Size b = 0; b < N && ok; b += batch_size)Also applies to: 293-293, 339-341, 969-973, 1029-1038
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp` around lines 133 - 137, Use OpenMS Size consistently for feature range indices and batch counters instead of size_t. Update buildFeatureTableRange and the related code paths in ConsensusMapArrowExport to use Size for ConsensusMap row indexing and container-sized values, and ensure any loop counters or range parameters in the referenced export helpers follow the same OpenMS type convention from OpenMS/CONCEPT/Types.h.Source: Coding guidelines
987-988: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid flushing logs with
std::endl.Use
"\n"in the new logging paths to avoid unnecessary flushes. As per coding guidelines, “Avoidstd::endland use\ninstead for performance reasons.”Proposed fix
- OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open " << filename << " for writing: " - << file_result.status().ToString() << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open " << filename << " for writing: " + << file_result.status().ToString() << "\n"; @@ - OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open Parquet writer for " << filename << ": " - << writer_result.status().ToString() << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open Parquet writer for " << filename << ": " + << writer_result.status().ToString() << "\n"; @@ - OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to build feature batch [" << b << ", " << e << ")" << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to build feature batch [" << b << ", " << e << ")" << "\n"; @@ - OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to write feature batch to " << filename << ": " - << st.ToString() << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to write feature batch to " << filename << ": " + << st.ToString() << "\n"; @@ - OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close Parquet writer for " << filename << ": " - << writer_close.ToString() << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close Parquet writer for " << filename << ": " + << writer_close.ToString() << "\n"; @@ - OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close output stream for " << filename << ": " - << outfile_close.ToString() << std::endl; + OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close output stream for " << filename << ": " + << outfile_close.ToString() << "\n";Also applies to: 1000-1001, 1015-1015, 1021-1022, 1046-1047, 1053-1054
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp` around lines 987 - 988, The logging in ConsensusMapArrowExport still uses std::endl in several error paths, which should be replaced with "\n" to avoid unnecessary flushes. Update the affected OPENMS_LOG_ERROR statements in ConsensusMapArrowExport (including the file-open failure path and the other listed logging sites) to end with "\n" instead of std::endl while keeping the existing message text and context intact.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp`:
- Around line 439-509: Replace the boolean assertions in
ConsensusMapArrowExport_test.cpp with the dedicated macros: in the
ConsensusMapArrowExport streaming and empty-map test cases, change every
TEST_EQUAL(..., true) to TEST_TRUE(...) and any TEST_EQUAL(..., false) to
TEST_FALSE(...). Keep the same expressions and surrounding checks, and update
the representative assertions around exportToParquetStreaming, read_combined,
all_eq, File::exists, and Equals so the test follows the project’s boolean
assertion style.
---
Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h`:
- Line 90: The public batch-size API in ConsensusMapArrowExport should use
OpenMS::Size instead of size_t. Update the ConsensusMapArrowExport declaration,
the matching .cpp definition, and any related helper counters or loop variables
that represent feature counts to use Size consistently. Keep the symbol names
aligned with the existing export path so the public interface and implementation
both follow the OpenMS primitive type guideline from OpenMS/CONCEPT/Types.h.
In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp`:
- Around line 133-137: Use OpenMS Size consistently for feature range indices
and batch counters instead of size_t. Update buildFeatureTableRange and the
related code paths in ConsensusMapArrowExport to use Size for ConsensusMap row
indexing and container-sized values, and ensure any loop counters or range
parameters in the referenced export helpers follow the same OpenMS type
convention from OpenMS/CONCEPT/Types.h.
- Around line 987-988: The logging in ConsensusMapArrowExport still uses
std::endl in several error paths, which should be replaced with "\n" to avoid
unnecessary flushes. Update the affected OPENMS_LOG_ERROR statements in
ConsensusMapArrowExport (including the file-open failure path and the other
listed logging sites) to end with "\n" instead of std::endl while keeping the
existing message text and context intact.
🪄 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: c8c7f691-29fe-41ba-839c-a222ea3774e8
📒 Files selected for processing (4)
src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.hsrc/openms/source/FORMAT/ConsensusMapArrowExport.cppsrc/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cppsrc/topp/IsobaricWorkflow.cpp
…st.cpp Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Three recently merged PRs landed on develop without changelog coverage: the PeptideIdentification::base_name removal (breaking API change routed through the run-level primary MS run path) and the two QPX Parquet streaming-export performance fixes (PSM export in #9697, feature export in #9698) that bound peak memory for large isobaric-labeling runs. Claude-Session: https://claude.ai/code/session_0167xb6udbdqvWLcUsNeZf4r Co-authored-by: Claude <[email protected]>
Routine changelog sweep found three merged develop PRs without changelog coverage: FileInfo progress-logging restoration (#9707), a pyOpenMS enum binding completeness fix (#9705), and OpenMP parallelization of the QPX feature Parquet export (#9699, extending #9698). Also updated the #9698 entry's now-inaccurate "Serial only" note to point at #9699. Claude-Session: https://claude.ai/code/session_014CUTttkkvRtTRtiV8ctAM6 Co-authored-by: Claude <[email protected]>
Three recently merged PRs landed on develop without changelog coverage: the OpenMP parallelization of the QPX feature Parquet export (#9699, follow-up to #9698), the pyOpenMS enum-binding drift fix restoring several inaccessible NASFragmentType/ProteomicsPkaScale/OSWHierarchy/ LPWrapper::SOLVER enumerators (#9705), and the re-added FileInfo progress logging exposed to pyOpenMS via Options.log_type (#9707). Claude-Session: https://claude.ai/code/session_01YCkM79JUnodCGEHtBKNWSz Co-authored-by: Claude <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Motivation
IsobaricWorkflowwrites three QPX Parquet files in order:quantms.feature.parquet(viaConsensusMapArrowExport), thenquantms.psm.parquet, thenquantms.pg.parquet.For isobaric labeling there is ~one consensus feature per PSM, so the feature table can be millions of rows. The old
ConsensusMapArrowExport::exportToArrowbuilt the entire Arrow table in memory before a single write, so on large runs peak memory drove the process into swap/OOM — and because the feature file is written first,quantms.feature.parquetwas never created at all (the run died before any file hit disk).#9697 already fixed the equivalent problem for the PSM export (
QPXFile::exportToParquetStreaming). This PR ports the same pattern to the feature export, serial only.What this does
buildFeatureTableRange(cmap, id_lut, [begin, end)); hoist the per-map protein-group/gene lookups intobuildFeatureIdLookupsand the Parquet writer-property setup intomakeFeatureWriterProperties. Each feature row is independent (no cross-row state), so any contiguous sub-range yields a self-contained, schema-valid table.exportToArrow()now delegates over the whole range[0, size())— output unchanged.exportToParquetStreaming(cmap, filename, batch_size, config): build and flush onebatch_size-sized range at a time through a persistentparquet::arrow::FileWriter, so peak memory stays bounded by one batch instead of the whole ~N-row table.IsobaricWorkflowuses the streaming path for the feature export.The written rows and their order are identical to the one-shot path; only the Parquet row-group layout may differ.
Scope
pgexport builds one row per indistinguishable protein group (bounded by protein count, not per-PSM), so it is not a memory risk and is intentionally left unchanged.ProForma/modifications/MetaInfoRegistry; an OpenMP parallel build (as in Speed up & bound memory of QPX PSM Parquet export (streaming + parallel build) #9697's PSM path) is deliberately out of scope here and can be a follow-up.Tests
ConsensusMapArrowExport_testextended with a streaming↔one-shot equivalence section: fullTable::Equalsover combined chunks (covers nested/list + lookup-derived columns), made order-sensitive via a unique per-feature RT, across multiple batches, the single-batch andbatch_size == 0cases, and the empty-map edge. AllConsensusMapArrowExportclass tests pass locally.🤖 Generated with Claude Code
https://claude.ai/code/session_01HcY3LMYuUDF2psYat9uUYN
Summary by CodeRabbit
New Features
Bug Fixes
Tests