Skip to content

Fix embedding-only populations (#649) and pickling of described Setups (#650) - #651

Merged
guijacquemet merged 1 commit into
mainfrom
claude/fix-649-650
Nov 27, 2026
Merged

guijacquemet merged 1 commit into
mainfrom
claude/fix-649-650

Conversation

@guijacquemet

Copy link
Copy Markdown
Contributor

Fixes #649
Fixes #650

#649: embedding-only reports crash in populations_in_report

Cause. populations_in_report validated the observations with feature_cols=setup.columns. Those are the explainable features, and an embedding-only Setup has none, so validate_input_tables refused every such report in which a group was found. The existing embedding-only tests found no groups and returned early, so they never reached the validation.

Fix. workflows/_populations.py now validates with list(setup.columns) or table_columns(setup). In embedding-only mode that is every column of the other tables. embedding_report already passes the same list to check_tables, and _population_spaces and _one_per_field follow the same pattern. I chose the strict option: all of the table's columns are checked, not just the first. Validation keeps NaN and drops no rows, so the set of marked cells is unchanged. A Setup with explainable features validates exactly as before.

Test. tests/test_populations.py::test_an_embedding_only_report_finds_and_tests_the_populations_of_its_table uses the _screen data with its 3 features passed as a non-explainable table, with no readout. Before the fix it failed with the ValueError from the issue. Now it shows that:

  • the planted mitoses form a group (>90% mitotic);
  • every cell is marked;
  • result.enrichment is identical (assert_frame_equal) to enrichment_tests run directly on the marks, so the report is correct, not just non-crashing;
  • arrest is higher than siCTRL in that group.

#650: described Setup with n_jobs != 1 fails with "cannot pickle 'mappingproxy'"

Cause. In described.py, ExperimentBlock is frozen with MappingProxyType: its fields and each of its repeat_groups. TargetSuggestions.suggested and .treatment_keys are frozen the same way. Setup.described (a ControlSource) carries the block, and the Setup is pickled to worker processes.

Fix. ExperimentBlock.__reduce__ pickles the block as plain dicts and rebuilds it through _frozen_block, so it is read-only again at every level. TargetSuggestions.__reduce__ does the same. Types, equality and read-only behaviour are unchanged.

Tests (tests/test_described.py):

  • test_a_described_setup_pickles_with_its_description_unchanged_and_read_only (v10, the reference chain): the round trip gives equal objects, and they are still read-only, nested mappings included.
  • test_a_described_report_in_worker_processes_is_the_serial_report (v03): n_jobs=2 gives a full summary text, contrast table and discovery tests/ranking identical to n_jobs=1.

Both failed before the fix with TypeError: cannot pickle 'mappingproxy' object.

Same class of bug elsewhere. MappingProxyType is used only in described.py. For every golden export (v03, v10, v27, v30, v33), I pickled the described experiment, the Setup after report and every entry of report.results, and all succeeded. The full summary with n_jobs=2 was identical to n_jobs=1 for all five (an ad hoc script, not committed).

Scientific behaviour

  • No result changes for reports that worked before.
  • Embedding-only reports whose populations used to crash now produce them.
  • Described Setups now run in parallel with the serial results.
  • No notebook cell was changed.

Gate (local; Actions are blocked)

Run on head 0f18c19d1014fea313ace6166bbf804939d9452f in a fresh venv (pip install --no-cache-dir -e ".[dev]", Python 3.13), with no PYTEST_ADDOPTS:

  • python -m ruff check src tests data: All checks passed
  • python -m ruff format --check src tests data: 536 files already formatted
  • pytest -n 0 tests/test_guards.py tests/test_function_guards.py tests/test_function_tools.py: 102 passed
  • python tools/audit.py --check-against origin/main: baselines only tightened against origin/main
  • pytest (whole suite, xdist): 4785 passed, 2 skipped, 6 xfailed, 0 failed

Generated by Claude Code

#650)

#649: populations_in_report validated the observations with the explainable
features only, empty for an embedding-only Setup, so every such report with a
group found was refused. It now validates with the other tables' columns when
there is no explainable feature, as the report's data check does.

#650: ExperimentBlock and TargetSuggestions hold MappingProxyType mappings,
which cannot be pickled to worker processes (n_jobs != 1). Both now pickle as
plain dicts through __reduce__ and are frozen again on load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VbytvF3Gsa85ix8Ne2yMDW
@guijacquemet
guijacquemet merged commit 9fa2402 into main Nov 27, 2026
2 checks passed
@guijacquemet
guijacquemet deleted the claude/fix-649-650 branch November 27, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants