Skip to content

Run pydeseq2 in one process - #135

Merged
shanikawm merged 2 commits into
mainfrom
fix/deseq2-one-worker
Sep 18, 2026
Merged

shanikawm merged 2 commits into
mainfrom
fix/deseq2-one-worker

Conversation

@shanikawm

Copy link
Copy Markdown
Contributor

What this does

find_markers(test_use="deseq2") left pydeseq2 at its default of one joblib worker process per CPU core. That happens twice: once in its DeseqDataSet and again in its DeseqStats. The workers outlive the call. Re-measuring the performance report (#134) found them:

  • taking the process tree from under 1 GB to 5.2 GB on PBMC 3k's DE bench, to save 1.5 s;
  • doubling the out-of-core tutorial's peak to 11.5 GB.

The number of processes grows with the core count, so on a 64-core server it would be 64. multiprocessing.cpu_count() sets it, so no environment variable can cap it.

DESeq2 runs in one R process, and the answer doesn't depend on the worker count. Both pydeseq2 objects now share one DefaultInference(n_cpus=1).

Test: tests/test_deseq2_seurat_parity.py::test_the_fit_runs_in_one_process records every parallel section pydeseq2 opens and requires n_jobs == 1. It also fails if no parallel section opened at all, so it can't pass by checking nothing.

Measured

Same machine as #134 (Apple M5 Pro, 18 cores), both arms re-run:

before after Seurat
de_DESeq2, PBMC 3k clusters 0 v 1 2.50 s, 5.2 GB 4.00 s, 1.2 GB 10.01 s, 2.4 GB
DE tutorial, Python side 108.7 s, 7.2 GB 121.0 s, 3.1 GB —
out-of-core tutorial, Python side 139.0 s, 11.5 GB 165.4 s, 5.6 GB —
  • Output: identical. Measured separately, the DE call's result compared equal (DataFrame.equals) with 18 workers and with one.
  • Tally: unchanged at 45 faster / 22 slower / 1 within 5 %.
  • Docs: PERFORMANCE.md's DE table and tutorial-scripts table are regenerated by make_report.py. Section 5 tells the history, and section 8 strikes the item. The CHANGELOG gains the fix and corrects Re-measure the performance report for 2.0.0 #134's entry.

Verification

  • All 19 DESeq2 tests pass, the new one included.
  • Mutation testing:
    • removing inference= from both objects fails the new test;
    • removing it from DeseqStats alone also fails it, because wald_test opens its own parallel section.
  • tests/test_docs.py passes, including the strict site build.
  • Full tutorial smoke suite: 29 passed. It was run on main, with the fix applied part way through; the fix changes no output, as the equality check above shows.
  • The re-run changed no committed figure (R ran under a UTF-8 locale this time).

🤖 Generated with Claude Code

shanikawm and others added 2 commits September 18, 2026 18:53
find_markers(test_use="deseq2") left pydeseq2 at its default of one joblib
worker per CPU core, for both its DeseqDataSet and its DeseqStats, and the
workers outlive the call. On the benchmark's PBMC 3k DE call they took the
process tree from under 1 GB to 5.1 GB to save 1.6 s; the out-of-core
tutorial's peak doubled to 11.5 GB. DESeq2 runs in one R process, and the
answer does not depend on the worker count, so both objects now share one
DefaultInference(n_cpus=1). tests/test_deseq2_seurat_parity.py records every
parallel section pydeseq2 opens and requires one job; dropping the inference
from either object fails it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The DE bench and the DE and out-of-core tutorial scripts re-run with the fix:
DESeq2 is 4.00 s against Seurat's 10.01 s and peaks at 1.2 GB against 2.4 GB;
the DE tutorial's Python peak falls from 7.2 GB to 3.1 GB and the out-of-core
tutorial's from 11.5 GB to 5.6 GB. The tally is unchanged at 45/22/1. The
report tells the history in section 5 and strikes the item from section 8;
the changelog gains the fix and corrects the benchmark entry.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@shanikawm
shanikawm merged commit 668aa76 into main Sep 18, 2026
8 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.

1 participant