Skip to content

MC-2: default the controls to the experiment description of a MorphoFeature export - #630

Merged
guijacquemet merged 4 commits into
mainfrom
claude/stage2-mc2
Nov 12, 2026
Merged

guijacquemet merged 4 commits into
mainfrom
claude/stage2-mc2

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Stage 2 step MC-2: MorphoCoverage reads the experiment block that MorphoFeature's MF-5b (CellMigrationLab/MorphoFeature#215, merged aafeaff) writes into each exported coverage.json (schema_version 3). The controls now default to the description's references. The target suggestions are used only after the user confirms them. Every refusal in §4 of the design note is applied.

Sources: MorphoFeature design note docs/restart/designs/coverage-experiment-block-2026-11-12.md (branch claude/restart-doc, 1b429d7), §2, §4 and §5. Stage 2 plan stage2-plan-2026-11-09.md, rows MC-0, MC-1 and MC-2.

What MC-2 does

New public module morphocoverage.described, with its shape checks in the private _described_shape.py:

  • read_experiment(coverage, fovs) reads the coverage.json of every export in one analysis (a path, an export folder, a CoverageRecord, or a list of them) beside the FOV table. It returns a DescribedExperiment.

  • Default controls = the references graph (plan MC-2, owner answer 1). There are two shapes:

    • If every other condition with fields references one condition X, the default is {"condition": X}. For v03, v27, v30 and v33 this gives exactly what a user would get by declaring that control, and the test asserts the contrast tables are equal.
    • Otherwise there is one own_control row per (condition, reference). A chain is therefore compared as a chain (v10: VEC_SiCol6a1 vs VEC_SiNC, VEC_SiNC vs VEC, and the same for THBS5). No condition is compared with a root it does not reference.
  • The default is not an error in these cases (note §4, "Not a refusal"), and each is stated in the declaration:

    • a condition whose reference has no field: "not compared: its control X has no field in this export";
    • a condition that shares no repeat with its reference: W_REFERENCE_UNPAIRED;
    • a condition with no reference.

    None of these conditions is ever compared with another control.

  • workflows.described_setup(experiment, **Setup fields) applies the default. scan_design(..., description=experiment) passes it to DesignScan.setup().

    • A control the user declares (control, contrasts, control_parents or master_control) overrides the default. Setup.described records the override, and the declaration, which the report prints first, says: "Controls: chosen by the user, overriding the experiment description (description bd5099bfe78b): the description gives DrugA vs CTRL; the user chose DrugB."
    • When the user declares exactly the reference, it is not counted as an override.
  • Suggestions. experiment.target_suggestions is deliberately not a mapping.

    • Setup(targets=suggestions) is refused with suggestion_not_confirmed.
    • suggestions.confirm(), or confirm({"DrugB": "SRC"}) with edits, returns a plain copy. That copy is the only grouping the condition contrast reads, as the working FOV table's target column.
    • Values are grouped exactly as written: in v27, SRC and src are two targets.
    • Editing the description later, or the dict passed in, changes no confirmed grouping.
  • The scan, given a description:

    • it suggests the description's control and never a name it reads as a control;
    • it computes no reagent groups from the names;
    • it skips the control question when a default exists;
    • it states the source of the controls as a finding;
    • it lists the target suggestions under "Columns that would say more".

Refusals (DescriptionRefused.code), note §4

§4 Code Test
1 coverage_version_unknown (schema_version above 3, below 1, not an integer, or a bool), description_version_unknown (checked before the shape), coverage_set_not_exported test_an_unknown_*, test_an_unexported_set_is_refused
2 experiment_block_missing: a described FOV table (condition_id) whose export is v2 or has no block. Only the default is refused. Controls declared by ID are accepted and stated, and the scan guesses no control and no reagents from the names (owner decision, 12 Nov). An export with the block beside one without it also defaults nothing. test_without_the_block_*, test_one_export_without_the_block_*
3 experiment_block_malformed: 21 mutations (missing or extra key at each level; SHA-256 or digest not 64 lower-case hex; wrong types; a reference or member that is not a condition, including a case variant ctrl/CTRL; a condition missing from references or suggestions; a self-reference), a block in a v2 record, and invalid JSON test_a_malformed_block_is_refused[*]
4 experiment_block_disagrees_with_fovs: condition ≠ source_folder of its ID; unknown condition_id; unknown repeat_group; biological_repeat ≠ source_repeat; a block beside a FOV table without IDs. The check runs again in every workflow (paired_inputs), so a report given another FOV table is refused. test_a_block_that_disagrees_*, test_a_workflow_reading_another_fov_table_*
5 experiment_descriptions_differ (owner decision, 12 Nov) test_exports_of_two_descriptions_are_refused
6 suggestion_not_confirmed test_v27_unconfirmed_suggestions_*
7 MC-1's condition_named_by_folder_label, also for an override and for target keys test_the_override_by_folder_label_*, test_confirmed_targets_name_conditions_by_id

tests/test_described.py has 67 tests. They all fail on main: the module does not exist there, so collection fails.

Plan acceptance tests (MC-2 row)

  • v27: an unconfirmed prefill is refused for analysis, the confirmed grouping is used, and editing target changes no confirmed grouping. Three tests.
  • Chain v10 is compared as a chain: test_v10_the_chain_is_compared_as_a_chain. There is no golden export for v10, so the test builds the tables and the block from the vendored TOML, following note §2.3.

Golden exports (re-made from MorphoFeature main)

The exports were re-made with make_exports.py from MorphoFeature main d33c6284e4a860eff08cbdfcc098c8069e963234 (after CellMigrationLab/MorphoFeature#215 and CellMigrationLab/MorphoFeature#216), in a fresh venv with its pinned core: preprocessing 0.5.1, CellPatcher 0.4.0, normalization 0.4.0, numpy 2.5.4, pandas 3.1.1, Python 3.13.18. Two runs gave byte-identical files.

Only coverage.json changes in each export. fovs.csv, objects.csv, applicability.csv and tables/shape.csv are byte-identical. provenance.json records the new commit and package versions.

 tests/morphofeature_exports/v03/coverage.json   | 52 +++++++++++++++-
 tests/morphofeature_exports/v27/coverage.json   | 80 ++++++++++++++++++++++++-
 tests/morphofeature_exports/v30/coverage.json   | 52 +++++++++++++++-
 tests/morphofeature_exports/v33/coverage.json   | 52 +++++++++++++++-
 tests/morphofeature_exports/v*/provenance.json  | 4 x 10 +++--

In each coverage.json, "schema_version": 2 becomes 3, and "experiment": {...} is added as the last key. The v03 and v33 description_sha256 values equal the note's §5 "with the Cells mask" values (bd5099bf…, 20aded4a…). A test asserts this.

make_exports.py had to follow MorphoFeature main's run file. It now names no channels or shared_channel_layout, because MF-2 takes the channels from the description and refuses the sorted used_ids order. It also names the mask by its ID, Cells, because MF-3 refuses cells: present in 0 of 33. The README records this.

Before/after: analyses without the block are byte-identical

I wrote a script that runs, on each of v03, v27, v30 and v33:

  • scan_design (full summary and repr(design));
  • report with the declared control (full summary and declaration);
  • the contrast table;
  • html_report (page and every figure file).

I ran it on a main worktree (ba44bf7) and on this branch, with SOURCE_DATE_EPOCH=0 for the PDFs and the page's "Generated " masked. Result: 44 files, 44 identical SHA-256 (diff empty). Two runs on main also matched each other.

Gate

Run on head a4cf9a4 (Python 3.13.18, in a venv that also holds MorphoFeature main and its core):

  • 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.
  • python -m ruff check src tests data: all checks passed. python -m ruff format --check src tests data: 532 files already formatted.
  • Whole suite (pytest -n 4): 4616 passed, 2 skipped, 6 xfailed, 0 failed (11 min).
    • The 2 skips are tests/test_morphobricks_constants.py:31: "morphobricks-preprocessing 0.5.1 is installed; the check needs 0.3.4". This is the venv's MorphoFeature core, not this change.
    • The first full run, on 553cbdd, had 1 failure, test_contracts.py::test_agents_section_7_lists_every_module. AGENTS.md §7 did not list the new modules, and a4cf9a4 fixes it.
  • CI on a4cf9a4: check success, spec-pin success.

Owner questions (recommendation first)

  1. DataFrames from a described run, passed without their coverage.json, still get the scan's name-based control suggestion ("ctrl (named like a control; not declared)"), as on main. The note's §1 says a name guess is what §3.4 forbids once a description exists. Recommend: a small follow-up that suppresses control_guess and reagent_groups whenever the FOV table has condition_id. That changes the scan text of the four fixtures, so I left it out to keep this PR's before/after byte-identical. scan.setup() already refuses a guessed control on main, so no analysis uses the guess.
  2. The guided session (guide()) does not take a description yet. Recommend: a follow-up that gives guide() the coverage.json, so it skips the control question when a default exists and asks the user to confirm the target suggestions.
  3. An export with the block beside one without it (for example an object set at v3 and a patch set at v2) is not in the note. Recommend: as implemented, nothing is defaulted (experiment_block_missing) and declared controls are accepted, the same as refusal 2.
  4. Checks beyond §4.3: a self-reference is refused as malformed, and object keys out of code-point order are not refused (the note says how they are written, not that MorphoCoverage must refuse them). Recommend: keep both as implemented.
  5. New public names (AGENTS §15): the module morphocoverage.described, morphocoverage.workflows.described_setup (added to workflows.__all__), and the Setup fields described and targets. The top-level morphocoverage.__all__ is unchanged. Recommend: accept them as MC-2's interface.
  6. v10 golden. Recommend: add v10 to make_exports.py at the next golden refresh, so the chain test reads a real MorphoFeature export instead of a block built from the TOML.

Related: filed CellMigrationLab/MorphoFeature#217 (patch-only runs record only cellpatcher_version; add core, as CellMigrationLab/MorphoFeature#216 did).

🤖 Generated with Claude Code

https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc

The exports of v03, v27, v30 and v33 come from MorphoFeature main d33c628
(after #215, MF-5b, and #216), with its pinned core (preprocessing v0.5.1,
CellPatcher v0.4.0, normalization v0.4.0). Only coverage.json changes in
each export: schema_version 2 -> 3 and the experiment block as its last
key; fovs.csv, objects.csv, applicability.csv and tables/shape.csv are
byte-identical. provenance.json records the new commit and versions.

make_exports.py follows MorphoFeature main's run file: the channels are the
description's (no `channels`, no `shared_channel_layout`), and the mask is
named by its ID, `Cells`. Two runs give byte-identical files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
… export (MC-2)

morphocoverage.described reads the experiment block of MorphoFeature's
coverage.json (MF-5b, schema_version 3; MorphoFeature design note
coverage-experiment-block-2026-11-12, sections 2 and 4) beside the FOV table:

- read_experiment(coverage, fovs) checks every export of the analysis and
  gives the description's default controls: one control when every other
  condition references it, else one own_control row per condition and its
  reference, so a chain (v10) is compared as a chain. A condition whose
  control has no field, or that shares no repeat with it
  (W_REFERENCE_UNPAIRED), is not compared, and said.
- workflows.described_setup(experiment, ...) and scan_design(...,
  description=experiment) use that default; a control the user declares
  overrides it, and the declaration (printed first by the report) names
  the description's reference beside the user's choice.
- Setup(targets=...) takes the reagent grouping the user confirmed
  (TargetSuggestions.confirm()), a copy; the description's suggestions
  themselves are refused until confirmed.

Refused (DescriptionRefused.code): unknown coverage.json or description
versions, an unexported set, a malformed block, a block that disagrees
with the FOV table (also when a workflow reads another FOV table), exports
of two descriptions, unconfirmed suggestions. A described FOV table whose
export has no block defaults no control and guesses none from the names;
controls declared by ID are accepted (owner decision, 12 Nov 2026).

Analyses that do not pass a description are unchanged: the report, its
HTML page, the contrast table and the scan of v03, v27, v30 and v33 are
byte-identical to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
described.py, _described_shape.py, workflows/_described.py and
workflows/_scan_names.py join the package map
(test_agents_section_7_lists_every_module).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
…rols (MC-2 review)

The notes of a described export ("DrugA: not compared: the description declares no
reference for it", "its control CTRL has no field", W_REFERENCE_UNPAIRED) say what the
description's references alone compare. When the user declares other controls, the report
may compare those very conditions (DrugA vs CTRL), yet the declaration still printed
"DrugA: not compared", which is false of the report. Under an override each note now reads
"By the description's references alone, ..."; without one they are unchanged.

Regression test: test_an_override_never_says_a_compared_condition_is_not_compared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc

Copy link
Copy Markdown
Contributor Author

Independent review of MC-2: merge, with one fix (df09a99)

I checked this PR against the design note (MorphoFeature claude/restart-doc 1b429d7, §2, §4 and §5), the MC-2 plan row and the owner decisions of 12 Nov.

Fix (its own commit, df09a99, with a regression test that fails before it)

When the user overrides the controls, the declaration still printed the description's notes word for word. Example: DrugA: not compared: the description declares no reference for it. But the report did compare DrugA with the user's control: the contrast table had DrugA vs CTRL. So the report contradicted itself. Under an override, each note now reads By the description's references alone, .... Without an override, the notes are unchanged. Test: test_an_override_never_says_a_compared_condition_is_not_compared.

Evidence

  • Goldens: I re-made them from MorphoFeature d33c628 in a fresh venv (preprocessing 0.5.1, CellPatcher 0.4.0, normalization 0.4.0, numpy 2.5.4, pandas 3.1.1). diff -r against tests/morphofeature_exports is empty: byte-identical, tables/ included.
    • The old make_exports.py is refused by MorphoFeature main ("the run file's channels ['ACTIN', 'DNA'] differ from the published description's ..."). That is why the run file no longer names channels.
    • fovs.csv, objects.csv, applicability.csv and shape.csv are unchanged, so the goldens mean what they meant before.
    • The v03/v33 blocks (SHA-256s, digests, IDs, references, repeat groups, suggestions) equal note §5. The v30 conditions digest equals v03's, and its repeat groups match §5.3.
  • Before/after: I ran this on main ba44bf7 and on this branch, with no description, for v03, v27, v30 and v33. The text outputs were the scan summary, findings, questions, suggestions and design, plus the short and full summaries, declaration and contrast CSV, each for a declared Setup and for a scan.setup Setup. All 52 are byte-identical. The HTML report pages and embedded files are identical once the "Generated" time is masked, and so are the PDFs once their dates are masked.
  • "Not a refusal" cases (no field for the control, W_REFERENCE_UNPAIRED, no reference): each is in the short text, the full text and report.html, and none is compared with another control (no contrast rows). There is no separate JSON report format; the HTML's embedded data is the only JSON output.
  • §4 refusals: each matches the note's conditions. A self-reference is also refused, which goes beyond the note. check_described runs in paired_inputs, and every Setup-reading public workflow goes through it. live_session reads no controls.
  • Folder names: with a description given, no folder label or name guess reaches a control or a target. The scan's control guess and reagent groups are overwritten, the targets map onto condition IDs (checked on v33's ctrl/control), and a control named by its folder label is refused.
  • Gate on df09a99: 4617 passed, 2 skipped, 6 xfailed. Both skips are test_morphobricks_constants.py: preprocessing is not installed in the MorphoCoverage venv. Guards: 102 passed. Audit: baselines only tightened. Ruff is clean. CI: check and spec-pin succeeded.

Owner questions (recommendation first)

  1. Name-based control guess when DataFrames come without coverage.json: suppress the guess whenever the FOV table has condition_id, in a follow-up. It is a suggestion only; scan.setup() never uses it.
  2. guide() takes no description: add one in a follow-up.
  3. Mixed exports, with and without the block: keep it as implemented. Nothing is defaulted, and declared controls are accepted.
  4. Keys out of code-point order are not refused: keep that. Related: JSON duplicate keys are silently last-wins, and reference cycles (A→B→A) are not refused. Both are outside the note's list. I recommend refusing cycles as malformed in a follow-up if the owner agrees.
  5. New public names (morphocoverage.described, workflows.described_setup, Setup.described, Setup.targets): accept them.
  6. No v10 golden: add v10 to make_exports.py at the next refresh.

Generated by Claude Code

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.

2 participants