Report: sequential per-state refinement of multi-state projects (state sweep)¶
Run state_sweep, dell, 2026-11-27/28. Base 8c42768220ddc61a84fa5dda22be7b41769f668e. Plan:
refine3D_state_sweep.md beside this report. Its Progress section holds the detail, the numbers and the log
paths. Evidence lives under ~/agent_runs/state_sweep/scratch/keep/ (written keep/ below); the driver's diff of
each phase is ~/agent_runs/state_sweep/review/phase_N.diff.
refine3D_auto and refine3D_local without state= now refine a project with several states one state at a
time, as ordinary state=X runs, and merge the results into one project, written once. refine3D_local can
continue every state from that merged project. Before this, a multi-state project was refined by hand, state by
state, and nothing merged the states back.
1. What was learned¶
- A sweep child is the direct run, to the byte. At one thread with a fixed seed, every sweep child equals the
direct
state=Xrun of its state and mode, in every map and binary file of its directory, in every key of its work project's particle records (ptcl3D), and in its output segment. This holds for three states, hard and weighted, on the first and final Phase 2 builds and on the Phase 3 build, auto and local alike (Phase 2 and 3 Progress). Direct runs stayed byte-identical to the base through every phase. - A fixed seed needs the process state restored, and an unseeded run needs the seed removed. Each parameter
build reseeds from
SIMPLE_SEEDplus a counter that only a fixed reseed resets. WithoutSIMPLE_SEED, the first refine3D of a process draws a run seed and exports it into the environment. A second child in the same process would therefore draw differently from a direct run in either case. With the restore, the children equal direct runs, and unseeded children record three different run seeds, as separate processes do. - The test fixture publishes three states, not two. Besides the two planted states,
flex_pcapublishes a third, minor state: 19 particles under hard labels, matched to no truth. The sweep refines it like any other state. Its hard local refinement loses about 0.05 correlation to its auto map, exactly as on the base. - A default local run never stages derived products from a refined map. The final reconstruction records its
map with
filt_mode=noneunlessautomsk=nu. The local refinement runsnonuniform, so their settings digests differ, and the local run rebuilds its products from the half maps (the "base-half fallback"). All twelve direct auto-to-local chains on the base do this. Where staging does happen (automsk=nu), the local run's own automasking rewrites the staged mask in its first iteration. - The command line needs
npartsforrefine3D_autoandrefine3D_local. Anynparts, even 1, makes refine3D distributed. Hand runs and in-test runs are therefore different execution modes and are never byte-compared with each other. - Inherited before this run.
refine3D_autowithoutstate=on a multi-state project failed in its first iteration (previous best state outside boundary). The test registry recorded 3.5 GB of memory and 2.5 GB of disk forflex_pca_blobs, against a measured 8.7 GiB and 3.0 GiB at base. Building the base on dell needs GTK 3 development files that the machine lacks.
2. What changed, phase by phase¶
- Phase 0, baseline (1 file, the plan;
phase_0.diff). Base built in Release and Debug; the fast gate passed 15 of 15 on both.flex_pca_blobsran twice, in 248 s and 229 s, with per-state correlations equal to 2×10⁻⁷. The identity rule was frozen as byte identity at one thread. The chain reference was measured, the behaviour withoutstate=recorded, and the identity keys frozen. - Phase 1, row map (5 files;
phase_1.diff). Newsp_project%ptcl_rows_match: row i of a project is rowrows(i)of its source, by stack file and index in the stack.prepare_refine3D_state_work_projectnow uses it. Aunit_projecttest covers renumbered stacks and sparse indices, and seven refused plants. - Phase 2, sweep (13 files;
phase_2.diff): - the dispatch and trigger in both commanders, and
run_refine3D_state_sweep; sp_project%merge_state_rowsandimport_state_artifacts;unset_run_seedinsimple_rnd;- the sweep table's name, the user-interface help of
stateandm_estimator, andrefine3D_states' refusal, which now points to the sweep; - the merge test, and the sweep cases in
flex_pca_blobs; - the entry's measured memory and disk in the registry.
- Phase 3, references (8 files;
phase_3.diff). Newrebind_reference_setinsimple_refine3D_provenance, called by the sweep before its single write. Local staging now also stages a recorded order mask. Added: the rebinding and order-mask tests, and the chain cases inflex_pca_blobs. - Phase 4, documents (7 files, this report included). The state sweep is described in the refine3D, local, auto and states policies and in the heterogeneous-data guide. The plan has its status line and the Phase 4 Progress entry.
In all, 23 changed or new files (22 modified, the report new), besides the three instruction files that were already modified when the run started (section 8).
3. Decisions taken under delegation¶
- Build environment. The base requires GTK 3 development files, which dell lacks, and the run has no root. A
runtime-only pkg-config file (
keep/gtk3_shim) points at the installed GTK 3.22 libraries. GTK links only into the viewer and the test executable, never into the library. (Phase 0 Progress.) - Hand runs use
nparts=1, the smallest configuration the command line accepts. (Phase 0.) - The truth gates judge only the states that have a truth. The sweep's child-against-direct gate and the chain's local-against-auto gate apply to the two truth-matched states. The third state is reported. If it must be gated, the base already fails the chain rule there. (Phase 0, kept in Phases 2 and 3.)
- The seed restore. With
SIMPLE_SEEDgiven at the sweep's entry,seed_rnd_fixedwith that seed runs before each child. Without it, the newunset_run_seedruns. The plan's "without a seed nothing is restored" would have run children 2 and up under child 1's seed. (Plan's seed decision; Phase 2.) - How the sweep is built:
- Its own parameters come from a minimal command (program, project, directory keys). Built from the full command, they refused valid commands whose defaults only the workflow sets (found in review).
- Each child starts in the entry directory, with
outdirinside the sweep's, so relative inputs resolve as for a direct run. The plan had made input paths absolute itself. - The rows each state selects are read from the input before any directory exists. (Phase 2.)
- The halves check is a dry run of the halves' one maker on a copy in memory. The sweep refuses when a child would have to make halves, and accepts halves an earlier release made without stack records. (Phase 2, after review.)
- The merge's identity keys: the label and stack number are restored from the parent; the half, index in the stack, particle index, optics and group, CTF observation, coordinates and frame must be equal. The copy's project information names itself before the write, and the mask entry carries the state it was made for. (Phases 0 and 2.)
- The chain's mask check reads the records and the copies instead of the local run, for the reasons in section
- The staging itself is unit-tested and shown by a traced
automsk=nuchain. (Phase 3; plan section 6.) - The registry's memory and disk for
flex_pca_blobswere set to the measured 9.0 and 6.0 GB. (Phase 2.)
4. Deviations from the plan¶
- The fixture has three states. "Both states run" became "every state runs", and the four auto and four local children of the cost estimate became six of each. The cost still stays at about half of its limit.
- The plan's input-path resolution was replaced by starting each child in the entry directory; see section 3.
- The seed restore also unsets
SIMPLE_SEED. This needed a test file outside the file table,simple_rnd_tester.f90, added to the table in Phase 2 before it was edited. - The chain's "stages the translated masks, checked by checksum" is checked on the rebound records and the copies; see section 3.
- The rows each state selects are computed on the input, not on the sweep's copy. The bytes are the same.
- The direct hard runs in
flex_pca_blobsnow carry the hard sweep's relativepcg_mskfile. It is inert under the default gridding backend: such a direct run is byte-identical to one without it. - Expected and not seen: none of the sweep's gates moved any existing value beyond 10⁻⁷.
5. Evidence against the baseline¶
- Fast gate: 15 of 15 suites on Release and Debug, after every phase, with no compiler warning added.
- Unit suites, all passing:
unit_project(row map, merge), 3,360 assertions;unit_reconstruction(rebinding), 2,092;unit_cart_align3D(order-mask staging), 1,495;unit_numerics(seed unset), 2,375.
Each new test was shown to fail on a planted fault:
- the row map, with the stack comparison removed and with the index comparison removed (4 assertions each);
- the merge, keeping the child's stack number (9 assertions, then a stop);
- the rebinding, writing back the old producer state (4) and letting a pending record through (3);
- the order-mask staging, with its block removed (2).
- Identity, byte for byte at one thread with SIMPLE_SEED=202610071. Excluded from comparison: run-directory
paths, the project information segment, timestamps and logs.
- Direct refine3D_auto state=X, 3 states × hard/weighted, equal the base on the Phase 1, 2 and 3 builds.
- Sweep children equal the direct runs, on both the first and the final Phase 2 builds and on the Phase 3 build.
- Local sweep children equal direct refine3D_local state=X runs on the same merged project.
- In both cases, from Phase 3, the only extra file is the rebinding's state-X mask copy, which has the bytes of
the child's own mask.
- flex_pca_blobs, every check passing:
| Phase | Wall time | Load at start |
|---|---|---|
| 0 (base), two runs | 248 s, 229 s | 4.2, 4.0 |
| 2 | 354 s, 334 s | 1.8, 0.7 |
| 3 | 354 s, 351 s | 0.9, 1.8 |
The limit is 744 s. Peak memory is 8.7 GiB throughout. The run directory peaks at 5.7 GiB, against 3.0 GiB at base. Pre-existing values are unchanged within 10⁻⁷.
Truth correlations at 8 Å against the gate floors:
| Case | State 1 (A) | State 3 (B) |
|---|---|---|
| Hard sweep child / direct | 0.9893575 / 0.9893576 | 0.9889717 / 0.9889717 |
| Weighted sweep child / direct | 0.9917618 / 0.9917618 | 0.9924111 / 0.9924111 |
| Hard local chain (floor) | 0.9890127 (0.9793575) | 0.9907646 (0.9789717) |
| Weighted local chain (floor) | 0.9929867 (0.9817618) | 0.9946475 (0.9824111) |
| - Reviews: two read-only reviews of the diff by a separate agent, after Phases 2 and 3. | ||
| - The first found that the sweep refused valid commands, refused projects an earlier release had labelled with | ||
| halves, and left the merged project naming the input. It also found two test checks that could not fail. | ||
| All are fixed and re-validated on the final Phase 2 build. | ||
| - The second found no substantive defect; its four minor points are fixed. | ||
- Off-state cases: the entry's direct state=X runs pass with Phase 0's values. cont_refine3D_1jxy passes on |
||
| the Phase 2 and 3 builds with all 114 gate values identical to the base. The input project stays byte-identical in | ||
| every run. |
6. Left open for the maintainer¶
Reported, not gated (in-test runs at 8 threads; Phase 2 and 3 Progress): - Each child's half-map FSC = 0.143 resolution. Sweep: states 1 and 3 at 8.53 Å in both modes; state 2 at 14.22 Å (hard) and 9.14 Å (weighted). Local chain: 8.53 Å; state 2 at 16.0 Å (hard) and 9.14 Å (weighted). - The weighted children's pose divergence on rows two states both selected (median rotation and shift difference):
| States | Rows | Rotation | Shift |
|---|---|---|---|
| 1 and 2 | 835 | 2.96° | 0.28 px |
| 1 and 3 | 665 | 4.28° | 0.50 px |
| 2 and 3 | 1,162 | 2.63° | 0.27 px |
This is the evidence for or against a per-state pose sidecar; the weighted local maps were not worse for it.
- The third state's correlations with the two truths. Hard sweep 0.73 and 0.69, local 0.68 and 0.64; weighted 0.97
and 0.99 in both.
- The sweep table, for example from a hand sweep (keep/p2_final/sweep_no/refine3D_state_sweep.txt):
# state child_directory work_project
1 <sweep>/1_refine3D_auto <sweep>/1_refine3D_auto/refine3D_auto_state01.simple
2 <sweep>/2_refine3D_auto <sweep>/2_refine3D_auto/refine3D_auto_state02.simple
3 <sweep>/3_refine3D_auto <sweep>/3_refine3D_auto/refine3D_auto_state03.simple
To decide:
- Whether the third state should be gated (section 3, item 3).
- Whether a default local run should stage verified products from a refined map. That would mean aligning the final
reconstruction's recorded settings with the local refinement's; it is not part of this plan.
- An inherited edge of local staging: inside a multi-state producer's own directory with mkdir=no, staging can
overwrite that producer's state-01 masks, and the order mask now shares it. It is harmless for rebound sweep
records, whose copies have the same bytes.
- The GTK 3 development files on dell, which the base needs and the machine lacks.
Not measured: real data. The sweep adds no scientific behaviour (each child is the direct run), so no real-data read was planned.
7. Proposed skill lines (not applied)¶
simple-refine3d, under "Working Rules": "refine3D_auto|localwithoutstate=on a multi-state project run a state sweep (run_refine3D_state_sweep): each state is an ordinarystate=Xchild, started in the entry directory with a direct run's generator state; no project is written or merged between children. Afterwardsmerge_state_rows,import_state_artifactsandrebind_reference_setfold the children into the sweep's copy, written once. A child must equal the direct run (refine3D_policy.md, "State sweep")."simple-main-project, under "Rules": "ptcl_rows_matchis the one row map of a pruned selection against its source (stack file and index in the stack);merge_state_rowsfolds a state's work project back, restoring label and stack number and refusing any change of half or observation."simple-main-volume: "rebind_reference_setbinds a sweep child's reference record to the merged project and its state; the record format is unchanged."simple-main-commanders, under "Tests":test=flex_pca_blobscoversrefine3D_states_cavgs, the state sweep and its local chain.
8. Changed and new files¶
git status --porcelain at the end of the run (the first three files were already modified when the run started
and were not touched):
M .github/copilot-instructions.md
M AGENTS.md
M CLAUDE.md
M doc/how2s/how2_process_heterogeneous_datasets.md
M doc/implementation_notes/planned/refine3D_state_sweep.md
M doc/policies/3D/refine3D_auto_policy.md
M doc/policies/3D/refine3D_local_policy.md
M doc/policies/3D/refine3D_policy.md
M doc/policies/heterogeneity/refine3D_states_policy.md
M doc/policies/test_environment_policy.md
M src/defs/simple_refine3D_fnames.f90
M src/main/commanders/simple/simple_commanders_refine3D.f90
M src/main/commanders/test/simple_commanders_test_highlevel_flex.f90
M src/main/commanders/test/simple_test_registry.f90
M src/main/project/simple_sp_project.f90
M src/main/project/simple_sp_project_out.f90
M src/main/project/simple_sp_project_ptcl.f90
M src/main/project/simple_sp_project_tester.f90
M src/main/strategies/parallelization/simple_refine3D_strategy.f90
M src/main/strategies/parallelization/simple_refine3D_strategy_tester.f90
M src/main/ui/simple/simple_ui_refine3D.f90
M src/main/volume/simple_refine3D_provenance.f90
M src/main/volume/simple_refine3D_provenance_tester.f90
M src/utils/math/simple_rnd.f90
M src/utils/math/simple_rnd_tester.f90
?? doc/implementation_notes/planned/refine3D_state_sweep_report.md
9. Commit message¶
refine3D_auto/local: refine multi-state projects state by state (state sweep)
Without state=, refine3D_auto and refine3D_local now refine a project with
more than one state to refine one state at a time, each as the ordinary
state=X run (full nthr/nparts, its own directory, a direct run's generator
state), and merge the results into the sweep's copy of the parent, written
once: the parent's labels, stacks, halves and identity kept, each state's map
and FSC from its child, each child's reference record rebound to the merged
project so that refine3D_local continues every state from it. The input
project is never written; a project without halves is refused.
- sp_project: ptcl_rows_match (the row map, also used by the state work
project), merge_state_rows, import_state_artifacts
- refine3D provenance: rebind_reference_set; local staging stages recorded
order masks
- simple_rnd: unset_run_seed (an unseeded child draws its own run seed)
- refine3D_states' flex refusal points to the sweep; help of state and
m_estimator
- tests: row map, merge, rebinding, order-mask staging and seed units, each
shown to fail on a plant; flex_pca_blobs sweep and chain cases
- docs: refine3D, local, auto and states policies, heterogeneous-data guide,
test policy, registry memory/disk of flex_pca_blobs
Sweep children are byte-identical to direct state=X runs at one thread;
direct runs and cont_refine3D_1jxy are unchanged.