feat: parallel slice aggregation with n_jobs#46
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR introduces parallel execution support to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant aggregate as aggregate()
participant helper as _get_n_workers()
participant executor as ThreadPoolExecutor
participant slice as _run_slice()
participant single as _aggregate_single()
User->>aggregate: call with n_jobs=-1
aggregate->>helper: _get_n_workers(n_jobs=-1)
helper-->>aggregate: worker_count=4 (example)
alt worker_count <= 1
aggregate->>single: sequential execution
else worker_count > 1
aggregate->>executor: create ThreadPoolExecutor
executor->>slice: map _run_slice over slices
slice->>single: _aggregate_single(slice_key)
single-->>slice: aggregated result
slice-->>executor: return result
executor-->>aggregate: all results
end
aggregate-->>User: final aggregated DataArray
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
- Add n_jobs parameter to aggregate() - None or 1 = sequential, -1 = all CPUs, N = N workers - Uses ThreadPoolExecutor (no pickling, GIL released during tsam) - Follows joblib convention for negative values - Tests: parallel matches sequential, n_jobs=-1, no-slice ignores Closes #12 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b6805d8 to
ba894dc
Compare
|
Wontfix, as minimal value. |
Summary
Add
n_jobsparameter toaggregate()for parallel slice processing:Implementation
Uses
ThreadPoolExecutor— sklearn releases the GIL during C-level clustering, giving real parallelism with zero overhead (no process spawn, no pickling, no file IO).Benchmarked: 2x speedup on 8760h × 50 vars × 5 scenarios.
We evaluated
ProcessPoolExecutor(like tsam's tuning module) but the ~1.5s process spawn overhead never amortizes for our use case (5-50 slices at ~30-150ms each).API
Noneor1= sequential (default)-1= all CPUs,-2= all minus one (joblib convention)N= exactly N workersCloses #12
Test plan
scripts/benchmark_parallel.py🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Tests
Chores