Skip to content

Sequential per-state refinement of multi-state projects (state sweep)

Status, 2026-11-28: implemented by the autonomous run state_sweep (Phases 0-4 done, see Progress and refine3D_state_sweep_report.md); awaiting the maintainer's review, so the note stays in planned/. Status, 2026-11-27: planned; rewritten the same day after Hans's ruling 3, which replaces the revision reviewed in refine3D_state_sweep_review.md. Base: d110e7c27 (this note is committed on top of it; Phase 0 records the commit the run gets). Supersedes: none. Depends on: the state=X work-project path of refine3D_auto and refine3D_local (validated: yes, flex_pca_blobs refines each state directly, hard and weighted) and the frozen state weight set of flex_pca (validated: yes). Source line numbers are at the base.

1. Why

A multi-state project is refined one state at a time, by hand. refine3D_auto|local state=X builds a single-state work project, refines it and leaves the result there; the parent is never written (refine3D_policy.md, "Per-state M-estimation"). Nothing folds the states back into one project. So a follow-up run, such as refine3D_local after refine3D_auto, cannot start from the parent. The sweep runs the existing single-state workflow once per state and merges the results into one project.

2. Contract

  • Off-state invariant. With state= given, or with at most one state to refine (decision 4), refine3D_auto and refine3D_local take the existing path. Not one line of the sweep runs on that path.
  • Children are ordinary runs. Child s is exec_refine3D_workflow called with the user's command line plus state=s. That is the same workflow, defaults, work-project preparation, parallelization (nthr, nparts) and M-estimation as a direct state=s run. The sweep adds no scientific behaviour: nothing is shared between states.
  • Merge once, at the end. No project is merged or written while children run. After the last child returns, the sweep reads its copy of the parent, merges every work project into it, and writes it once, atomically.
  • Labels and identity are the parent's. The sweep never changes a ptcl3D state label, a row's stack, its index in the stack or its half. Under m_estimator=flex the weights stay frozen, as today.
  • The input is never written. The project given on the command line and its registered files are unchanged.
  • The merged parent is a valid source. refine3D_local, by sweep or with state=X, starts from it without a provenance refusal.

3. Decisions and rulings

  1. (2026-11-27, Hans) Sequential, not a joint engine. States run one after another. Each child gets the command line's full nthr/nparts, parallelized as a single-state job. There is no concurrency between states.
  2. (2026-11-27, Hans) Both hard assignment and m_estimator=flex, in refine3D_auto and refine3D_local. refine3D_states keeps refusing flex; its message points to the sweep instead of refine3D_auto state=X.
  3. (2026-11-27, Hans) Simple and built from what exists. The sweep is a sequential loop over the existing state=X workflow, followed by one merge after all children have completed. No pose sidecar, no new command-line key, no change to the CLI's job-description write and no fault-injection machinery.
  4. Trigger. refine3D_auto|local without state= sweeps when the project has more than one state to refine.
  5. Hard mode: every positive ptcl3D label with a population above 0.
  6. Flex mode: every state of the weight set with positive applied weight on some row, as selected by select_refine3D_state_rows (simple_refine3D_strategy.f90:202).

States run in ascending order. vol1 with a sweep is refused, because it is one state's map. With one state to refine, the existing path runs; that includes the existing refusal of flex without state=. 5. Dispatch in the thin commanders. exec_refine3D_auto and exec_refine3D_local (lines 56-68) evaluate decision 4 on the command as received. When it holds, they call a private run_refine3D_state_sweep(cline, l_local) in simple_commanders_refine3D.f90; otherwise they call exec_refine3D_workflow, unchanged. The sweep dispatches before the workflow mutates the command, so no command snapshot is needed. Children call exec_refine3D_workflow directly, so there is no recursion, no new type and no new module. 6. The sweep, step by step. 1. Resolve the source project: projfile, or discovery as in preflight_cont_startup. Before saving the child template or changing directories, resolve relative input-file arguments (such as pcg_mskfile) against the entry directory using the existing path helpers. Children retain those absolute input paths. 2. Keep a child template: a copy of the command after the commander's autoscale default (lines 59 and 66) and the input-path resolution above. Children bypass the commander, so the template carries that default. 3. Build params once with mkdir=yes. This creates the sweep's numbered directory and its copy of the parent, and leaves cline's projfile pointing at that copy, so the CLI later appends its job entry there, as for any program. 4. For each state s, make a fresh copy of the template and set projfile to the copy's absolute path, state=s and mkdir=yes. Delete outdir/dir_exec. Call exec_refine3D_workflow(cline_s, l_local). The child makes its own numbered directory inside the sweep's directory, as a direct run does. 5. After each child, return to the sweep's directory with simple_chdir and reset CWD_GLOB. Record the child's directory and work project. 6. After the last child, merge (decision 7), register maps (decision 8), rebind references (decision 9) and write the parent once with write(..., tempfile=.true.).

Revised in implementation (Phase 2, 2026-11-27, after review): - The sweep builds its parameters once, from a minimal command: the program, the pinned projfile (discovery included), mkdir=yes, and the user's outdir/dir_exec if given. That makes its directory and its copy of the parent. Built from the full command, it refused valid commands (for example refine3D_local refine=prob_neigh cont_view=lm, or automsk=nu without filt_mode), whose defaults only the workflow sets. - The command line's projfile is then set to the copy. - The child template is the command as given, without outdir/dir_exec. - Each child starts where a direct run starts, the entry directory, with outdir set to its directory inside the sweep's (<sweep directory>/<k>_<program>). Its own parameter build therefore resolves relative input files against the entry directory, exactly as a direct run's does; steps 1 and 2's path resolution is not copied. - After each child, the sweep returns to its own directory. 7. Merge. This is a new sp_project routine. For state s, compute the parent rows with select_refine3D_state_rows on the sweep's unchanged copy. That gives the same rows the child selected, because the child prepared its work project from the same bytes. Verify work row i against parent row parent_rows(i) with the stack/index check of prepare_refine3D_state_work_project (lines 470-481), extracted into an sp_project routine that both use (Phase 1). - Rows whose parent label is s take the child's ptcl3D row. In hard mode that is every selected row; in flex mode, the hard-labelled rows. - The parent's identity keys are then restored: state, stkind, and every other key Phase 0 lists as identity. - The child's stkind is never kept, because pruning renumbers stacks. - A row whose half or observation fields differ from the parent's is an error, not a relabelling. - Flex rows labelled with another state keep the parent's values.

As implemented (Phase 2): merge_state_rows in simple_sp_project_ptcl.f90. The rows each state selects are computed once, from the input project read before the sweep's directory exists. That input has the same bytes as the copy and as each child's copy. 8. Out segment. Each child's state-1 vol and fsc entries, with their pop/mass/ess fields, replace state s's entries in the merged parent. Use remove_state_artifacts_from_osout and the existing add_vol2os_out/add_fsc2os_out, which store absolute paths. The single vol_msk entry keeps the last state's mask. The weight-set registration is the parent's, unchanged. As implemented (Phase 2): import_state_artifacts in simple_sp_project_out.f90. The mask entry carries the parent state it was made for. 9. References rebound. Each child's reference record is valid against its work project, not against the merged parent, and preflight_cont_startup checks the whole project's layout and the producer state (lines 266-281). A new routine in simple_refine3D_provenance.f90 rebinds a child's record: - it reads and validates the record; - it keeps the record's constituents, settings digest, map geometry and align_lp; - it recomputes particle identity on the merged parent and sets the producer state to s; - it copies the child's recorded state-01 masks (automask, NU envelope, order) to their state-s names beside the map, and names those copies in the record. There is no copy for s=1.

The record format is unchanged. A child with no record keeps the legacy route. A pending or invalid record fails the sweep. A rebound child work project stops being a continuation source; continuation is from the merged parent.

Local staging already copies recorded automasks and NU envelopes from producer state s to state 01. Extend the same stage_reference_derivatives routine in simple_refine3D_strategy.f90 to do this for ORDER_ENVMASK_FBODY too, following the existing cleanup of a stale destination when the mask is unrecorded. 10. Stores and trailing chains. The sweep does not copy or register the children's sigma2 stores or trailing chains in the parent. A later local run validates the parent's sigma2 store as today. Its existing chain validator checks any chain beside the source map against the selected child work project, not the full merged parent. Reuse a compatible chain; when fractional trailing is active and the chain is absent or incompatible, use the existing full-first-update fallback. A hard local→local sweep can recreate a compatible work project, so rejection is not guaranteed. No sweep-specific chain reset or change to the validator is needed. 11. Halves. The sweep refuses a project in which a row it would refine has no half, and names the reason. Children must not each label their own subset. As implemented (Phase 2, after review): halves are made by one maker, eo_transaction (simple_eo_partition), which never changes a labelled row and adopts the labels of earlier releases. - Before any directory exists, the sweep runs it on a copy of the input in memory and counts the rows to refine whose half it would change. A child would make those halves itself. - It refuses when that count is above zero, and names the count. - A complete partition, or one an earlier release labelled without records, passes, as it does for a direct run. - The merge's identity check, which includes the half, stays as a backstop. 12. Interruption. The merged parent appears only through the final rename. An interrupted sweep leaves the sweep's unchanged parent copy and child directories. Rerun from the original input; there is no resume. 13. (2026-11-27, recommended at launch preparation; Hans may veto) Each child draws what a direct run draws. Under SIMPLE_SEED, every seed_rnd call (one per parameter build) advances the fixed seed by 7919 since the last seed_rnd_fixed (simple_rnd.f90). The sweep's own parameter build and each earlier child would therefore shift child s's draws away from those of a direct state=s run. Before each child, when a fixed seed is set, the sweep restores the generator state a direct run's process starts from (the call count and the cached run seed), so the identity check of section 6 can hold for every state. Without SIMPLE_SEED nothing is restored. Mechanism revised in Phase 2 (2026-11-27), from Phase 0's finding: without SIMPLE_SEED, child 1's refine3D draws a run seed and exports it into the process environment, so "nothing restored" would run children 2 to n under child 1's seed. As implemented, the sweep reads the seed state once, at its entry, and acts before each child: - if SIMPLE_SEED was set, seed_rnd_fixed(entry seed, propagate=.true.) sets the count to zero and exports and caches the run seed, the start the test's set_fixed_seed gives a direct run; - if it was not set, the new unset_run_seed (simple_rnd.f90) unsets SIMPLE_SEED, drops the cached run seed and sets the count to zero, so the child draws its own seed as a fresh process does.

The outcome is unchanged.

Defaults taken without a question:

  • a log line per state: state, rows, applied mass and effective sample size under flex, run directory, seconds;
  • a table refine3D_state_sweep.txt in the sweep's directory (state, child directory, work project), named in simple_refine3D_fnames.f90;
  • ascending state order.

4. Not in this plan

  • A joint multi-state engine, per-state sigma2 spectra, concurrency between states, and restarting an interrupted sweep.
  • A per-state pose sidecar for flex rows labelled with another state. Today's direct state=X runs seed those rows from the parent's poses, and the sweep does no worse. The report gives the measured divergence (section 6); a sidecar is a later plan only if real data show it matters.
  • Any change to update_job_descriptions_in_project, refine3D_states, refine3D_states_cavgs, flex_pca or solve3D, beyond decision 2's message.
  • The ruling of 2026-11-27 that refine3D_local refine=prob_neigh requires cont_view (unset becomes lm, no refused, the 20,000/500 grid defaults go). It waits for the PorF read of polar_continuous_view_report.md, section 8, and lands with that read, not here.
  • Folders out of bounds: src/main/strategies/search/**, src/main/pftc/**, src/main/cftc/**, src/main/sigma2/**.

5. Change types and gates

Phase Kind Gate
1 identical fast gate; unit_project; direct state=X identity under the Phase 0 rule
2 new path, off-state identical Phase 1's identity; unit_project merge test; sweep cases in flex_pca_blobs
3 new path (rebinding and order-mask staging) provenance and existing strategy testers; local-after-auto sweep cases in flex_pca_blobs
4 docs, report fast gate

6. Acceptance

  • Fixture. flex_pca_blobs (simple_commanders_test_highlevel_flex.f90): two blob states, 2,000 particles, a frozen weight set. run_state_refinements refines each state directly with m_estimator=flex and no (STATE_REFINE_MAXITS = 5). The gate is STATE_REFINE_MARGIN = 0.01, measured on the profile of 2026-10-19.
  • Identity rule (measured, Phase 0). Two direct refine3D_auto state=X runs per mode at nthr=1, fixed seed. If the final maps and the work ptcl3D are byte-identical, identity gates are byte gates. Otherwise the tolerance is twice the largest difference between the two runs, frozen in Phase 0. Exclusions: paths, projinfo, timestamps, logs.
  • Merge (unit_project). The fixture has several stacks, drops a whole earlier stack from one state's selection, and keeps sparse indices in the surviving stack. Checks:
  • copied fields equal the child's;
  • identity keys, labels and halves equal the parent's;
  • rows with other labels are unchanged;
  • every merged row resolves to its original stack file and index;
  • a foreign or reordered work project is refused.

The test must fail if the child's stkind is kept. - Sweep (flex_pca_blobs, Phase 2). Run refine3D_auto without state= on the published project, once with m_estimator=no and once with flex. Checks: - both states run, each in its own directory; - each child's map meets the existing truth gate against the direct run of the same state and mode (corr ≥ direct − STATE_REFINE_MARGIN); - the merged parent's labels equal the input's; - state s's vol/fsc entries name child s's files; - under flex, the weight set still validates; - a relative input-file argument such as pcg_mskfile resolves to the entry directory's file in both children (include it in one existing sweep case; the matching direct run uses the same file); - the command-line project is byte-identical, as the existing check does.

Once, outside the entry, at nthr=1: child s's map and work ptcl3D equal a direct run's under the identity rule. - Chain (flex_pca_blobs, Phase 3). Run refine3D_local without state= on each merged parent. Checks: - it starts without a provenance refusal; - for s ≥ 2 it stages the translated masks, checked by checksum against the child's state-01 originals; - each state's local map correlates with truth at least as well as the auto sweep's map, minus STATE_REFINE_MARGIN.

The margin was measured for direct auto runs; its use here is guessed. So Phase 0 measures direct auto→local per state and mode twice on the base, and stops if the base itself fails this rule.

As implemented (Phase 3, 2026-11-27, decided under delegation): the second check cannot be made as written, for two reasons that predate this run. - A default local run stages no derived products. The record of a refinement's final map is written by the final reconstruction, which runs with filt_mode=none unless automsk=nu. The local refinement runs with nonuniform, so the settings digests differ and the local run rebuilds its products from the half maps. All twelve of Phase 0's direct chains did this ("base-half fallback"). - Where a local run does stage the masks (with automsk=nu), its own automasking rewrites them in the first iteration, so no staged mask survives a run to be checksummed.

The chain case therefore checks the following: - every state's rebound record validates against the merged parent as that state, the condition for starting without a provenance refusal; - for s ≥ 2, the record names the state-s copies of the child's masks, and those copies carry the bytes of the state-01 originals; - the local sweep refines every state; - the truth rule holds, on the truth-matched states (Phase 0's decision).

The staging copy itself is tested in unit_cart_align3D, and shown on a hand-traced automsk=nu chain (Progress). - Rebinding (provenance tester). A record rebound to state 2 validates against the merged project, names the state-02 masks, and keeps the child's settings digest and align_lp. A pending record is refused. - Order-mask staging (existing strategy tester). A recorded state-02 order mask is staged under state 01 with identical bytes; an unrecorded mask is not copied and a stale state-01 destination is removed. - Off-state. The existing direct state=X runs of flex_pca_blobs and the single-state refine3D_local runs of cont_refine3D_1jxy pass unchanged. - Reported, not gated: - each state's FSC (fsc_state01.bin of each child) and the sweep table; - under flex, the median angular and shift difference between the two states' refined poses on the rows that both selected. This is the evidence for or against a later pose sidecar. - Cost. Phase 0 records flex_pca_blobs wall time. The new cases add four auto children and four local children. Stop if the entry exceeds three times its Phase 0 wall time, or 7,200 s; a separate entry is then Hans's call.

7. Common rules and stop conditions

  • No new command-line parameter, no environment knob. No floor, tolerance or assertion relaxed. Fix as you go, with a file-table row first. The fast gate runs at one thread; the high-level entry at its registered count, except the nthr=1 identity runs.
  • Stop if:
  • a child changes a prepared single-state label;
  • the merge would change a parent label, stack, index or half;
  • Phase 0's identity runs disagree by more than STATE_REFINE_MARGIN;
  • rebinding needs a change to the record format;
  • an edit is needed outside the file table or in an out-of-bounds folder;
  • the cost rule above is exceeded.
  • No ruling waives: the fast gate, Phase 1 identity, the merge test, and the sweep and chain cases.

8. Phases

  • Phase 0, baseline. Build Release and Debug, run the fast gate, record the machine and its load. Then:
  • run flex_pca_blobs twice, recording wall time and gate values;
  • run the identity runs and the direct auto→local chain reference of section 6;
  • record what refine3D_auto without state= does today on the fixture's two-state hard project (auto has no refusal for it), so the behaviour change is deliberate;
  • list the ptcl3D keys a child writes, and freeze the identity keys of decision 7;
  • check the fixture's selected rows all carry halves.

Exit: Progress holds the identity verdict or tolerance, the chain reference per state and mode, the wall time, the base behaviour, and the key lists. - Phase 1, row map. The parent-to-work row check becomes one sp_project routine, and prepare_refine3D_state_work_project calls it. Exit: a unit_project test (renumbered stacks and sparse indices accepted; a foreign or reordered stack refused); direct state=X identity. - Phase 2, sweep. Decisions 4-8 and 10-13: - the trigger and the dispatch; - run_refine3D_state_sweep; - the merge and out-entry routines; - decision 2's message.

Exit: the merge test and the sweep cases of section 6; the off-state cases pass. - Phase 3, references. Decision 9, the order-mask extension to existing local staging, and the chain cases. Keep decision 10's existing compatible-chain reuse/fallback behavior. Exit: the rebinding and order-mask staging tests and the chain cases of section 6. - Phase 4, docs and report. Update the living descriptions: refine3D_policy.md ("Per-state M-estimation", a new "State sweep"), refine3D_local_policy.md, refine3D_auto_policy.md, heterogeneity/refine3D_states_policy.md (decision 2) and how2_process_heterogeneous_datasets.md. Write the report refine3D_state_sweep_report.md. Exit: fast gate; every listed policy names the sweep; the report exists.

File table

File What Phases
src/main/commanders/simple/simple_commanders_refine3D.f90 dispatch in the auto/local commanders, input-path resolution before the child template, run_refine3D_state_sweep, row-map call, refine3D_states message 1, 2, 3
src/main/project/simple_sp_project.f90, simple_sp_project_ptcl.f90, simple_sp_project_out.f90 (if needed), simple_sp_project_tester.f90 row map, merge, out-entry relabel; tests 1, 2
src/main/volume/simple_refine3D_provenance.f90, simple_refine3D_provenance_tester.f90 record rebinding with mask translation 3
src/main/strategies/parallelization/simple_refine3D_strategy.f90, simple_refine3D_strategy_tester.f90 extend existing local staging to recorded order masks; recorded/unrecorded mask tests 3
src/defs/simple_refine3D_fnames.f90 sweep table filename 2
src/main/ui/simple/simple_ui_refine3D.f90 help of state and m_estimator 2
src/main/commanders/test/simple_commanders_test_highlevel_flex.f90 sweep and chain cases 2, 3
doc/policies/3D/refine3D_policy.md, refine3D_local_policy.md, refine3D_auto_policy.md, doc/policies/heterogeneity/refine3D_states_policy.md, doc/how2s/how2_process_heterogeneous_datasets.md living descriptions 4
doc/policies/test_environment_policy.md the flex_pca_blobs row names the sweep and chain cases (if needed) 2, 3, 4
src/utils/math/simple_rnd.f90 a public restore of the fixed-seed state for decision 13 (if needed) 2
src/utils/math/simple_rnd_tester.f90 its test (added in Phase 2: the restore must also unset SIMPLE_SEED, Phase 0) 2
src/main/commanders/test/simple_test_registry.f90 flex_pca_blobs's measured mem_gb/disk_gb (if needed); never its deadline or thread counts 2, 3
doc/implementation_notes/planned/refine3D_state_sweep*.md this plan, Progress, report each

Progress

2026-11-27: proposal only; no implementation phase has started. Rewritten after ruling 3 from a 434-line revision that had grown through two reviews. That revision's review is refine3D_state_sweep_review.md.

The rewrite drops:

  • the state pose sidecar with its continuation payload;
  • the change to the CLI job-description write;
  • the fault-injection interruption matrix;
  • the hard/flex × gridding/PCG fractional matrix;
  • the in-memory staging across children;
  • the cont_view default switch, moved to section 4.

Still covered from the earlier reviews:

  • child stack renumbering (decision 7, merge test);
  • re-entry with a normalized command (decision 5: dispatch before mutation);
  • earlier merges changing later seeds (moot: one merge at the end);
  • state-01 masks under relabelling (decision 9);
  • partial publication (one atomic write);
  • prepared-versus-parent labels (Phase 0).

2026-11-27 follow-up: resolve relative input paths before saving the child template; include order-mask staging in the existing strategy routine and file table; leave compatible-chain reuse and the missing/incompatible-chain fallback to the existing validator on the selected work project. The simplified design is unchanged. Documentation only; no implementation, build or runtime tests in this revision.

2026-11-27, launch preparation (run state_sweep on dell): the file table's phase column lists phases one by one (arun's fence reads 1-3 as phases 1 and 3, which would have kept Phase 2 out of the commander), all became each, and three rows marked "if needed" were added: the test policy's flex_pca_blobs row, the entry's measured memory and disk in the test registry, and the seed restore of decision 13 in simple_rnd.f90. refine3D_state_sweep_review.md is not in the repository; the run does not need it. Decision 13 (the seed restore per child) was added as a recommendation: without it, children under a fixed seed do not draw what direct runs draw, and section 6's child-equals-direct check fails for every state.

2026-11-27, Phase 0 (baseline), run state_sweep on dell. Base 8c42768220ddc61a84fa5dda22be7b41769f668e (this plan's commit on top of d110e7c27). Files changed: this plan only. No ruling exists yet. Evidence is under ~/agent_runs/state_sweep/scratch/keep/ (written keep/ below); the build logs are beside the build trees in scratch/.

Machine and builds. dell: Oracle Linux 8.10, Intel Core Ultra 9 285 (24 cores without hyperthreading, 8 performance and 16 efficiency), 62 GB, no GPU; gfortran 15.2.1 (gcc-toolset-15), CMake 3.26.5. Load 0.10 before the first build. Each tree: cmake -S <repo> -B <tree> -DCMAKE_BUILD_TYPE=Release|debug -DBUILD_TESTS=ON -DNICE=OFF -DUSE_ARCHOPT=ON -DFORTLS=OFF -DPython3_EXECUTABLE=/usr/bin/python3.12, make -j20, make install, scripts/run_fast_gate.sh <tree>. ~/src/SIMPLE/.deps was copied into the repository before the first configure; its OpenBLAS cache recipe differed, so OpenBLAS 0.3.34 was rebuilt there. The Release build took 2 min, the Debug build 42 s. The fast gate passed 15 of 15 suites on both, with its source checks (Release 12 s, Debug 40 s). The Release tree scratch/build_release is the base build for every later comparison and is never rebuilt.

GTK 3 (decided under delegation): since 2026-11-24 the configure requires the GTK 3 development files through pkg-config. dell has the GTK 3.22.30 runtime but not the development package, and the run has no root. A runtime-only pkg-config file in keep/gtk3_shim (version 3.22.30, link libraries only, symlinked to the system's runtime libraries) is put on PKG_CONFIG_PATH for configure and make. This is safe because SIMPLE compiles no C against GTK headers (gtk-fortran is a set of Fortran bindings), and GTK is linked only into simple_viewer and simple_test_exec, never into the library. The pinned gtk-fortran archive was fetched; its SHA-256 matches.

flex_pca_blobs, twice, with the CTest entry's command and environment (simple_test_exec test=flex_pca_blobs nthr=4, OMP_NUM_THREADS=8; logs and gate tables in keep/fpb_run1/ and keep/fpb_run2/, fpb.log and metrics.tsv). Both pass every check. Wall time 248.0 s and 229.5 s (load 4.2 and 4.0 at the start, left from the builds and the previous run; nothing else ran). Peak resident memory was 9.1 GB in both, against 3.5 GB in the test registry and "up to 8.7 GiB" in the test policy. The gate values agree between the two runs except for the two shared-against-distributed map correlations (0.9999729 and 0.9999731; 0.9999822 and 0.9999821) and one per-state correlation. Values, the same in both runs: - label accuracy 0.9905 (shared memory) and 0.9920 (distributed), floor 0.60; - leading eigenvolume against the truth difference 0.932 and 0.899; deconvolution noise scale 0.760 and 0.796; - shared/distributed label agreement 0.9905, latent correlation 0.689; - class-average state route: 180 committed sub-averages (floor 90), sub-average state accuracy 0.617 (null median 0.378, 99.9th percentile 0.444), member purity 0.721, particle state accuracy 0.507, median pair pose error 22.3 degrees (0.291 of the pairs within 5 degrees), 3 planted states matched.

The per-state refinements of run_state_refinements (8 threads; map correlation with its truth at 8 Å), run 1 / run 2: - state 1 weighted 0.9917618 / 0.9917618, hard 0.9893575 / 0.9893577; - state 3 weighted 0.9924111 / 0.9924111, hard 0.9889717 / 0.9889717.

The spread at the entry's threads is 2×10⁻⁷, far inside STATE_REFINE_MARGIN (0.01). Frozen for the cost rule (measured): 3 × 248 s = 744 s.

The published project holds three states, not two. Both runs publish three, with the same counts: - state 1: 985 particles of truth A; - state 3: 996 particles of truth B; - state 2: 19 particles (15 of A, 4 of B).

In the state weight set (kernel weights), state 2 has applied mass 343.5 and an effective sample size of 882 over 1,332 rows. The test matches states 1 and 3 to the two truths and refines only those. By decision 4 the sweep therefore runs three children per mode, state 2 included. Its direct runs complete in both modes (below). Section 6's "two blob states", "both states run" and "four auto children and four local children" each become three. With the measured child times (auto 7-27 s, local 2-6 s at 8 threads) the cost stays well under 744 s.

Fixture copy. The shared-memory run's published project was copied while the test ran and restored to its original path after the passing test removed its directory: keep/fpb_run1/test_flex_pca_blobs_162203/shared/phantom.simple (SHA-256 4529c826…). Its particle stack and truth maps are in the base tree's fixture cache (scratch/build_release/test_runs/fixture_cache/blob_B991BCAA9266147F/, absolute paths in the project; backup copy keep/fixture_cache_blob_B991BCAA9266147F_backup). All 100 files are checksummed in keep/fixture_checksums.sha256.

Halves (decision 11): every one of the 2,000 rows carries a half (1,000 even, 1,000 odd), so every row any state selects has one. Rows selected, with even/odd counts:

State Hard rows (even/odd) Weighted rows (even/odd)
1 985 (490/495) 1,333 (672/661)
2 19 (11/8) 1,332 (664/668)
3 996 (499/497) 1,332 (666/666)

The weighted selections reach far into other labels: 1,313 of state 2's 1,332 rows are labelled 1 or 3.

Command line (decided under delegation). The command-line interface requires nparts for refine3D_auto and refine3D_local; the in-process test never sets it. With nparts given, refine3D takes the distributed strategy (a master and worker processes), even at nparts=1. Hand runs use nparts=1. The entry's in-process runs are shared memory: a different execution mode, so hand-run and in-entry numbers are never byte-compared with each other.

Identity rule, frozen: byte gates. Two direct runs per state and mode, each simple_exec prg=refine3D_auto projfile=<fixture parent> mkdir=yes pgrp=c1 mskdiam=100 maxits=5 nthr=1 nparts=1 state=s m_estimator=flex|no in a fresh process, with SIMPLE_SEED=202610071 (the test's STATE_REFINE_SEED). All six pairs (states 1 to 3, weighted and hard) are byte-identical: - every map and binary file of the run directory (31 or 32); - every key of the work project's ptcl3D segment; - the work project's out segment.

Exclusions: the run directory's path in project records, the project info segment, timestamps and logs (the PDF and JPG plots, text reports, BENCH and job files are not compared). A negative control (weighted against hard, state 1) reports differences. The frozen base reference is keep/identity_base/: the SHA-256 of every map and binary file, and the ptcl3D and out dumps, per run. The tool is keep/tools/identity_check.sh.

Chain reference. For each state and mode, twice, at 8 threads with nparts=1 and the same seed: refine3D_auto state=s on the fixture parent, then refine3D_local state=1 in the same mode on that run's work project, the only project the base can continue from. The score is the test's own metric (map correlation with the truth at 8 Å inside the 100 Å mask, compare_to_truth, linked into keep/tools/volcorr). The two repeats agree to 10⁻⁶ (keep/chain_base/results.txt). Auto → local:

State (truth) Weighted Hard
1 (A) 0.991762 → 0.992787 0.989359 → 0.989013
3 (B) 0.992413 → 0.994160 0.988972 → 0.990765
2 (none), against A 0.969702 → 0.968757 0.732124 → 0.685610
2 (none), against B 0.987128 → 0.985513 0.691624 → 0.638088

The base meets section 6's chain rule (local at least auto − 0.01) for states 1 and 3 in both modes and both repeats.

Decided under delegation: the rule judges a state against its truth. The fixture has truths only for its two planted states, and the test's one-to-one matching assigns them to states 1 and 3. State 2 has no truth and is reported. Against either truth, state 2's hard local map loses 0.047 (A) and 0.054 (B) to its auto map (19 particles; the auto map's conical FSC area ratio, cFAR, is 0.008). Weighted, it stays within 0.002. If state 2 must be gated, the base fails the rule there, and Phases 2 and 3 need a ruling on it.

Base behaviour without state= (keep/base_nostate/): - refine3D_auto on the three-state hard project counts all 2,000 particles as active, starts from the parent's state-1 map and reconstructs every particle as one state. Then iteration 1's worker stops with previous best state outside boundary; prep4prob (simple_strategy3D_srch.f90, line 243) and the run fails. The input project is not written. - With m_estimator=flex, it is refused before any work ("give state="). - refine3D_local without state= is refused ("needs state=X for a multistate project").

The sweep replaces the failure and the flex refusal (Phase 2) and the local refusal (Phase 3).

Keys. Rows of each final work project were matched to parent rows by stack file and index in the stack (keep/keys/keys_report.txt). Over all six direct runs, the keys a child holds with values other than its parent row's are: - pose and shift: e1 e2 e3 x y; - search scores and moves: corr dist dist_inpl frac inpl proj mi_proj mi_state shincarg shincr shsig; - sampling counters: updatecnt sampled; - the state's resolution, stamped on its rows: lp lp_est res res05 cfar; - cont_inpl_attempted cont_inpl_improved; - state, set to 1 when the work project is prepared: every selected row in hard mode, the rows labelled another state in weighted mode.

Unchanged in every run: eo indstk stkind pind ogid gid dfx dfy angast phshift xpos ypos frame and the remaining 2D and bookkeeping slots. No child changes ptcl2D.

Identity keys of decision 7, frozen: - restored from the parent: state, and stkind (pruning renumbers stacks; this fixture has a single stack, so the merge test must plant several); - taken from the parent and required to equal the child's row, else an error: eo (the half), indstk (the index in the stack), pind (the particle's original index), ogid and gid (optics group and group), dfx dfy angast phshift (the contrast transfer function, CTF, observation), xpos ypos (coordinates) and frame.

Every other key is the child's.

Decision 13's premise. Every parameter build calls seed_rnd. Under SIMPLE_SEED it seeds the generator with SIMPLE_SEED + 7919 × n, where n counts the calls since the last seed_rnd_fixed; nothing on the refine3D path calls seed_rnd_fixed. A direct run's process starts with n = 0, no cached run seed and gfortran's default generator state, and its first build seeds with SIMPLE_SEED + 0. The test's set_fixed_seed before each run gives the same start. A direct run without SIMPLE_SEED was traced with strace (keep/seedcount/); there every seed_rnd opens /dev/urandom. The master's first 8 parameter builds open it (the workflow's own, the selection program's, then those of the startup programs and refine3D), then refine3D draws the run seed, and no later build opens it. So in a sweep under SIMPLE_SEED, child 2's first build would seed with SIMPLE_SEED + 7919 × n, n ≥ 9 (the sweep's own build and child 1's at least 8), instead of + 0. The premise holds.

Found besides: without SIMPLE_SEED, refine3D's project owner draws a run seed and exports it into the process environment (adopt_run_seed → ensure_run_seed → setenv). From then on the process runs as if the seed had been given: later builds take the fixed-seed path, and later workers inherit the seed. In one sweep process, children 2 to n would run under child 1's seed, while direct runs each draw their own. "Without SIMPLE_SEED nothing is restored" therefore does not give a child what a direct run draws. The restore must also return SIMPLE_SEED to unset, and drop the cached run seed, when the sweep started without it. simple_rnd can set the variable but not unset it, so Phase 2 needs the file-table row for simple_rnd.f90 that is marked "if needed".

Exit, item by item: - identity verdict: byte gates, with the exclusions above; - chain reference per state and mode: the table above; - wall time: 248.0 s and 229.5 s; - base behaviour: recorded above; - key lists: recorded, and the identity keys frozen.

In short: the base builds and passes its gates on dell (with a GTK shim). Direct state=X runs are byte-reproducible at one thread, so later identity gates are byte gates. The chain rule holds on the base for the two truth-matched states. The fixture carries a third, tiny state that the sweep will refine and that has no truth. Decision 13 must also undo the run seed that a child exports when no seed was given.

2026-11-27, Phase 1 (row map), run state_sweep on dell, on the Phase 0 base. No ruling exists yet. Evidence is under ~/agent_runs/state_sweep/scratch/keep/ (written keep/); the Phase 1 build tree is scratch/build_p1, built with Phase 0's recipe (including the GTK shim).

What changed. The check that a state's work project row is the parent row it was selected from is now one sp_project routine, ptcl_rows_match(source, oritype, rows, msg) (simple_sp_project.f90 declares and binds it, simple_sp_project_ptcl.f90 holds it). Row i of the project must resolve, through its stack entry, to the same stack file and the same index in that stack as row rows(i) of the source, for every row and in order. The stack number (stkind) itself may differ, because pruning a selection renumbers stacks. The routine returns false and names the first disagreement in msg: - a row count other than the selection's; - a selected row outside the source; - a row resolving to another file or another image.

prepare_refine3D_state_work_project (simple_commanders_refine3D.f90) now calls it in place of its own loop. The success path computes exactly what the loop did; only the wording of the refusal changes. One side effect of the edit: gfortran's reallocation check raised a new "used uninitialized" warning on parent_rows (the base compiles without Fortran warnings), so parent_rows is now allocated to its size before the pack that fills it, with the same values. Files changed: - src/main/project/simple_sp_project.f90; - src/main/project/simple_sp_project_ptcl.f90; - src/main/project/simple_sp_project_tester.f90; - src/main/commanders/simple/simple_commanders_refine3D.f90; - this plan.

Unit test (test_ptcl_rows_match in simple_sp_project_tester.f90, suite unit_project). The parent has three stacks (3, 3 and 4 images). The work project is made from it as the selection program makes one: rows 4, 6, 7, 9 and 10 are kept and the rest pruned. This drops the whole first stack, renumbers the other two to 1 and 2, and keeps sparse images (1 and 3 of the second stack; 1, 3 and 4 of the third). The test asserts the renumbering and sparse indices, then checks that the selection matches in ptcl3D and in ptcl2D.

Each of these plants is refused with a named disagreement, then removed, and the selection is accepted again: - a stack entry pointing to a foreign file; - the two stack entries swapped; - two rows of one stack swapped; - two rows of different stacks swapped; - an image index moved within its stack; - a selection one row short; - a selection naming a row beyond the source.

The test shows it can fail. Two deliberate code mutations of the routine were built in a separate tree and run. Dropping the stack-file comparison fails exactly the foreign-stack and swapped-stack assertions (4 failures). Dropping the index comparison fails exactly the within-stack swap and the moved-index assertions (4 failures). The source was then restored from a saved copy and verified by SHA-256 (keep/p1_mutation/unit_m1.log, unit_m2.log). unit_project on the Phase 1 build: 24 groups, 3,302 assertions, none failed (keep/p1_mutation/unit_project.log).

Gates. The fast gate passed 15 of 15 suites on the final Phase 1 build (scratch/build_p1.gate2.log). Direct state=X identity was checked against Phase 0's frozen base reference, under the frozen byte rule, on the frozen Phase 1 install. One direct refine3D_auto state=s m_estimator=flex|no run per state and mode, with Phase 0's command (nthr=1 nparts=1, SIMPLE_SEED=202610071) on the unchanged fixture parent (SHA-256 4529c826…).

All six (states 1, 2 and 3, weighted and hard) are byte-identical to the Phase 0 runs: - the SHA-256 of every map and binary file of the run directory (31 or 32 files); - every key of every row of the work project's ptcl3D; - the work project's out segment, with the run directory's path removed.

A negative control (the state 1 weighted run against the state 1 hard reference) reports differences. Evidence: keep/p1_identity/verdict.txt, with the hashes and dumps per run beside it; tool keep/tools/identity_vs_ref.sh.

Besides the gates, flex_pca_blobs was run on the Phase 1 build; its direct per-state refinements run in-process through the new routine. It passes. Its gate table equals the first Phase 0 run's except the two shared-against-distributed map correlations, which equal the second Phase 0 run's exactly (the per-state correlations are 0.9917618, 0.9893575, 0.9924111 and 0.9889717, as in Phase 0). Wall time 268.5 s with load 7.0 at the start, left over from the identity runs, so it is not a timing (keep/p1_fpb/).

Exit, item by item: - unit_project test: renumbered stacks and sparse indices accepted; a foreign stack and reordered stacks or rows refused; each plant shown to fail and removed. - Direct state=X identity: byte-identical in both modes, for all three states.

In short: the row check exists once, in sp_project, where Phase 2's merge will reuse it. It is tested against every planted disagreement, and direct runs are unchanged to the byte.

2026-11-27, Phase 2 (sweep), run state_sweep on dell, on Phase 1's tree. No ruling exists yet. Evidence is under ~/agent_runs/state_sweep/scratch/keep/ (written keep/); the Phase 2 build tree is scratch/build_p2.

What changed. refine3D_auto and refine3D_local without state= now refine a project with several states one state at a time and merge the results: the state sweep. Files changed: - simple_commanders_refine3D.f90: the dispatch in both commanders; refine3D_sweep_states, the trigger of decision 4; run_refine3D_state_sweep; decision 2's message, in which refine3D_states now points to the sweep. - simple_sp_project.f90 with its submodules _ptcl and _out: merge_state_rows (decision 7) and import_state_artifacts (decision 8). simple_sp_project_tester.f90 holds the merge test. - simple_rnd.f90 and simple_rnd_tester.f90: unset_run_seed (decision 13) and its test. The tester row was added to the file table first. - simple_refine3D_fnames.f90: the sweep table's name, refine3D_state_sweep.txt. - simple_ui_refine3D.f90: the help of state and m_estimator. - simple_commanders_test_highlevel_flex.f90: the sweep cases. - simple_test_registry.f90: the measured memory and disk of flex_pca_blobs. - test_environment_policy.md: the flex_pca_blobs row and section. - This plan: the revisions recorded in decisions 6, 8, 11 and 13.

How a sweep runs (as finally implemented, after the review described below). With state= given, the commanders take the existing path without reading anything. Otherwise they read the project and list the states to refine: each positive label with particles, or, with m_estimator=flex, each state of the weight set with a positive applied weight on some row. With fewer than two, the existing path runs, refusals included. With two or more: 1. The sweep refuses vol1 (one state's map) and mkdir=no. 2. From the input project, read only, it records the rows each state selects. 3. It runs the halves' one maker on a copy in memory and refuses when that would change the half of a row to refine. Nothing has been made at this point. 4. It notes whether SIMPLE_SEED is set. 5. It builds its parameters once, from the program, the project and the directory keys. That makes its numbered directory and its copy of the parent. 6. It points the command line's projfile at the copy, so the command-line interface appends its job entry there. 7. For each state in ascending order: - it restores the generator state a direct run starts from; - it returns to the entry directory, where a direct run starts; - it runs exec_refine3D_workflow with the command as given plus state=s and outdir naming the child's directory inside the sweep's; - it returns to its own directory.

The child's own parameter build therefore resolves relative input files against the entry directory, as a direct run's does. 8. One log line per state gives its rows, applied mass and effective sample size (weighted), seconds and directory. 9. After the last child, each work project is merged into the copy. The copy's project information is updated to name itself, and it is written once, through a temporary file and a rename. 10. The table (state, child directory, work project) is written beside it.

The merge first checks the work project's rows against the parent's with ptcl_rows_match (Phase 1). It then checks every selected row on the identity keys frozen in Phase 0 (half, index in the stack, particle index, optics and group, contrast transfer function observation, coordinates, frame) before changing anything. Each row labelled with the state takes the child's record, keeping the parent's label and stack number. Rows labelled with another state keep the parent's record. Each state's map and FSC entries become the child's, with the hard population, and the applied mass and effective sample size when the child is weighted. The single mask entry is the last child's. Sigma2 stores and trailing chains are not copied (decision 10).

Unit tests. test_merge_state_rows (unit_project) uses a parent of three stacks. Its state selection drops the first stack and keeps sparse images of the others. It checks the following: - the copied fields are the child's; - the label, stack number, half and particle index are the parent's; - every merged row resolves to its original stack file and index; - rows with other labels are unchanged, including a weighted selection's row labelled with another state; - a reordered or foreign work project, or a changed half, is refused and leaves the parent unchanged.

Shown to fail when the child's stack number is kept (that line of the merge commented out): 9 assertions fail, then a corrupted row stops the stack map (keep/p2_mutation_stkind_kept.log); the source was restored and verified by SHA-256. test_unset_run_seed (unit_numerics): after the unset no global seed remains, the environment variable, cached seed and reseed count are gone, and the next run draws and exports a seed of its own. unit_project 3,360 assertions, unit_numerics 2,375, none failed. The fast gate passed 15 of 15 suites on the final Phase 2 build (scratch/build_p2.gate6.log) and on the Debug build with the final Phase 2 code (scratch/build_debug.gate_p2b.log). No compiler warning was added.

Review. A read-only review of the diff by a subagent found five problems. All are fixed or answered: - The sweep built its parameters from the full command before the workflow's defaults, so it refused valid commands (for example refine3D_local refine=prob_neigh cont_view=lm, or automsk=nu without filt_mode) and left its directory behind. Fixed: steps 5 and 7 above. - The first halves check refused projects whose halves an earlier release made without records, which direct runs accept, and gave no reason. Fixed: step 3. - The merged parent's project information still named the input. Fixed: step 9. - The test's check of the relative input file read the test's own command line. Fixed (below). - Adding the support file to the direct hard runs might change them. Answered: it is inert, see below.

Hand sweeps on the fixture copy, through the command line, before the entry. Run once on the first build (keep/p2_hand/) and again on the final build (keep/p2_final/). simple_exec prg=refine3D_auto projfile=<fixture parent> mkdir=yes pgrp=c1 mskdiam=100 maxits=5 nthr=1 nparts=1 m_estimator=no|flex, with SIMPLE_SEED=202610071. On the final build the hard sweep also carried pcg_mskfile as a file name relative to its entry directory. - Child equals direct. Both sweeps refined three states each. On both builds, all six children (states 1, 2 and 3, hard and weighted) are byte-identical to the Phase 0 direct state=s runs, under the frozen byte rule: every map and binary file, every ptcl3D key, and the out segment (keep/p2_final/child_vs_direct.txt). That includes the children that ran after another child in the same process, which is decision 13's restore at work. - The relative file reaches every child. In a traced short hard sweep, every child's worker processes were started with the child's command line naming pcg_mskfile as the entry directory's absolute file (keep/p2_final/sweep_no_trace/execve.txt.gz). The file existed nowhere else. - Halves (keep/p2_final/halves/), on two test copies of the fixture made by a scratch tool. With every half removed, the sweep is refused before any directory is made. With the stack partition records removed but the labels kept (an earlier release), it is accepted: every child adopts the same labels and the merge passes. - A command the first implementation refused. refine3D_auto automsk=nu without filt_mode now sweeps all three states (keep/p2_final/sweep_automsk_nu/). - Merged parents. On both builds, the input's labels, stack numbers and identity keys are kept. All 2,000 rows take their child's record apart from label and stack number. Each state's map and FSC entries name its child's files, with population, applied mass and effective sample size. The weight-set entry is the parent's (merged_check.py on dumps in sweep_no/ and sweep_flex/). On the final build the merged parent's project information names the merged copy and its directory. - Unseeded sweep. Without SIMPLE_SEED, a hard sweep with two iterations: the three children recorded three different run seeds in their work projects, so each drew its own, as direct runs do (sweep_unseeded/). - Inert support file. A direct hard state=1 run with a relative pcg_mskfile is byte-identical to Phase 0's run without it: under the gridding default of refine3D_auto the file is only checked for existence. The entry's direct hard runs could therefore take the same file as the hard sweep without changing. - Input unchanged. The fixture parent's SHA-256 is unchanged after all hand runs.

Sweep cases in flex_pca_blobs. refine3D_auto without state= on the shared run's published project, hard and weighted, in-process at the entry's 8 threads with the test's seed. The hard sweep, and the direct hard runs it is compared with, take pcg_mskfile as a file name relative to the run directory: a soft sphere of the mask diameter, written by the test. Gated, and passing in both modes: - every state of the project runs (three, from the test's own reading of the project), each in its own directory beside its work project; - every child resolves the relative pcg_mskfile to the entry directory's file. The file exists only there, not in the sweep's or any child's directory, and a child's parameters stop on a relative file that does not resolve; - the merged parent is written and keeps the input's labels; - each state's map and FSC entries name its child's files; - the weighted merged parent's state weight set validates; - the input project is byte-identical.

Each truth-matched child's map against the direct run of its state and mode (correlation with the truth at 8 Å, gate: at least direct − STATE_REFINE_MARGIN):

State (truth) Hard child / direct Weighted child / direct
1 (A) 0.9893575 / 0.9893576 0.9917618 / 0.9917618
3 (B) 0.9889717 / 0.9889717 0.9924111 / 0.9924111

Reported, not gated: - State 2, matched to no truth: hard 0.7317 (A) and 0.6914 (B), weighted 0.9697 and 0.9871. - Each child's half-map FSC = 0.143 resolution: states 1 and 3 at 8.53 Å in both modes; state 2 at 14.22 Å (hard) and 9.14 Å (weighted). - The weighted children's pose divergence on the rows two states both selected (median rotation and shift difference): states 1 and 2, 835 rows, 2.96° and 0.28 px; 1 and 3, 665 rows, 4.28° and 0.50 px; 2 and 3, 1,162 rows, 2.63° and 0.27 px.

The entry's other values equal Phase 0's second run, except the direct state 1 hard correlation (0.9893576 against 0.9893577), inside Phase 0's spread (keep/p2_fpb/metrics.tsv).

Cost. The entry with the sweep cases passed in 354.1 s on the first build and in 334.4 s on the final build (load 1.8 and 0.7 at the start, nothing else running), against the frozen limit of 744 s (3 × 248 s). The final run's gate table equals the first's except the weighted state 1 child's correlation, 0.9917617 against 0.9917618 (keep/p2_fpb_final/). Peak memory was 8.7 GiB, as at base. The run directory peaks at 5.51 GiB (2.97 GiB at base), measured in two further untimed passing runs (keep/p2_fpb_disk/, keep/p0_fpb_disk/). The registry now records mem_gb=9.0 and disk_gb=6.0 for the entry, in place of 3.5 and 2.5, which were already below base.

Off-state cases. The direct state=X runs of flex_pca_blobs pass with Phase 0's values (above). cont_refine3D_1jxy passes on the first Phase 2 build and on the base, run side by side (424 s and 426 s), and again on the final build. All three 114-row gate tables are identical (keep/p2_cont/).

Phase 1's gates were run again on the final Phase 2 build: the fast gate and unit_project (above), and direct state=X identity. One direct run per state and mode, with Phase 0's command, is byte-identical to the Phase 0 reference for all six, on the final build (keep/p2_identity_verdict.txt).

Left for Phase 3, as planned: refine3D_local already dispatches a sweep, but each child's reference record still describes its work project. Until decision 9 rebinds the records, a local run on a merged parent, with or without state=, is refused by preflight_cont_startup.

Exit, item by item: - merge test: passes, and shown to fail when the child's stack number is kept; - sweep cases of section 6: pass in both modes; - child equals direct at one thread: byte-identical for every state in both modes; - off-state cases: pass, unchanged.

2026-11-28, Phase 3 (references), run state_sweep on dell, on Phase 2's tree. No ruling exists yet. Evidence is under ~/agent_runs/state_sweep/scratch/keep/ (written keep/); the Phase 3 build tree is scratch/build_p3.

What changed. A sweep's merged parent is now a valid source for refine3D_local, through decision 9. Files: - simple_refine3D_provenance.f90: new rebind_reference_set. A child's reference record describes the child's final map against its work project, whose only state is 1. The routine binds that record to the merged parent and to the parent state: - it reads and validates the record, and leaves a missing record (the legacy route) or a pending or invalid one untouched, reporting which; - it keeps the constituents, the settings digest, the map geometry and the matching low-pass of the record; - it recomputes the particle identity on the merged parent (layout, halves, population, poses, observations, lineage) and sets the producer state to s; - for s above 1, it copies the recorded state-01 masks (automask, nonuniform-filter envelope, order mask) to their state-s names beside the map and names the copies instead; - it rewrites the record behind the existing pending marker, so an interrupted rewrite reads as invalid, never as legacy; - it reads the record back and requires it to validate against the merged parent as state s.

The record format is unchanged. - simple_commanders_refine3D.f90, in run_refine3D_state_sweep: after the merges, every state's record is first validated, so a pending or invalid one stops the sweep before anything changes. Then each is rebound, and only then is the merged parent written. - simple_refine3D_strategy.f90, in stage_reference_derivatives: local staging now also copies a recorded order mask of the producer state to state 01, and removes a stale state-01 order mask when none is recorded, as it already did for the automask and the envelope. - Tests: simple_refine3D_provenance_tester.f90, simple_refine3D_strategy_tester.f90, and the chain cases in simple_commanders_test_highlevel_flex.f90. - test_environment_policy.md: the flex_pca_blobs row and section. - This plan: section 6's chain note.

Unit tests, each shown to fail on a plant. - test_rebind_reference_set (unit_reconstruction). A child record of state 1, with all three masks recorded, is rebound to state 2 of a merged project. Gated: - it validates against the merged project as state 2, and not as state 1, nor against the child work project; - it names the state-02 copies of the masks, which carry the state-01 bytes, and no longer the state-01 names; - the child's settings digest and matching low-pass are kept, with the derivatives staged from producer state 2; - a planted change of a half in the merged project is refused; - a rebinding to state 1 copies nothing and keeps the names; - a complete record behind a pending marker is refused and left byte for byte as it was, with nothing copied; - a map without a record keeps the legacy route.

Plants: writing back the old producer state fails 4 assertions; letting a pending record through fails the 3 pending checks (keep/p3_mutation/). - test_order_mask_staging (unit_cart_align3D). A recorded state-02 order mask is staged as state 01 with identical bytes. When unrecorded, it is not copied, and a planted stale state-01 copy is removed. Plant: removing the new block fails both assertions. - All pass: unit_reconstruction 2,092 assertions, unit_cart_align3D 1,495, unit_project 3,360, unit_numerics 2,375. The fast gate passed 15 of 15 suites on the final Phase 3 build (scratch/build_p3.gate5.log) and on the Debug build (scratch/build_debug.gate_p3.log). No compiler warning was added.

Finding: a default local run stages no derived products (decided under delegation; section 6's chain note). The record of a refinement's final map is written by the final reconstruction, which runs with filt_mode=none unless automsk=nu. The local refinement runs with nonuniform, so the settings digests differ and the local run rebuilds its products from the half maps. All twelve of Phase 0's direct chains did this, and the auto and local records of a fresh direct chain both read gridding c1 none ... (keep/p3_hand/settings/). With automsk=nu the record keeps nonuniform and the direct local run stages the verified products. Even then, the local run's own automasking rewrites the staged mask in its first iteration, so no staged mask survives a run to be checksummed. The chain case's mask check is therefore made on the masks a local run would stage (below), and the staging itself is shown by trace.

Hand chains on the fixture copy, through the command line (keep/p3_hand/). They ran on the Phase 3 build from before the review's fixes below, which change only an error message, a comment and tests: - Children still equal direct runs. Auto sweeps, hard and weighted, at nthr=1 nparts=1 with SIMPLE_SEED=202610071. Every file a child produced is byte-identical to Phase 0's direct state=s run, and so are the ptcl3D and out segments. Children 2 and 3 additionally hold the rebinding's state-s mask copy, which has the bytes of the child's own state-01 mask (child_vs_direct.txt). - The local chain starts from the merged parent. refine3D_local without state= on each merged parent, at nthr=1. Every local child verified the rebound record ("verified the source reference set"), then took the default base-half fallback. Each local child is byte-identical to a direct refine3D_local state=s on the same merged parent, again plus the mask copy for states 2 and up (local_child_vs_direct.txt). The merged parents were not written. - Chain truth at one thread (map correlation with the truth at 8 Å, auto child → local child): hard state 1 0.98937 → 0.98901, state 3 0.98897 → 0.99077; weighted state 1 0.99176 → 0.99299, state 3 0.99243 → 0.99466. State 2, which has no truth: hard 0.707 → 0.660 against A, weighted 0.970 → 0.970 (chain_nthr1.txt). The weighted local maps from the merged parent are at least as good as Phase 0's direct chains from the work project (0.99279 and 0.99416). - Staging of translated masks, traced. A hard auto sweep with automsk=nu: the records of children 2 and 3 name automask3D_state02.mrc, automask3D_state03.mrc and nu_envmask3D_state03.mrc, copies with the originals' checksums. The local sweep on its merged parent: every child staged the verified products. strace shows the local children of states 2 and 3 opening exactly those three translated files and writing their own automask3D_state01.mrc (nu_auto/, nu_local/openat.txt.gz).

Chain cases in flex_pca_blobs. After each sweep case, the test runs refine3D_local without state= on its merged parent, at the entry's 8 threads. Gated, and passing in both modes: - every state's rebound record validates against the merged parent as that state; - states 2 and 3 name their copy of the child's mask (one each, the automask), with the original's bytes, and no state-01 name remains; - the local sweep refines every state, and each writes its work project; - the local merged parent keeps the input's labels, and under weighting its weight set validates; - the merged parent the chain starts from is byte-identical afterwards.

Truth rule on the truth-matched states (local map at least auto map − STATE_REFINE_MARGIN):

State (truth) Hard local (floor) Weighted local (floor)
1 (A) 0.9890127 (0.9793575) 0.9929867 (0.9817618)
3 (B) 0.9907646 (0.9789717) 0.9946475 (0.9824111)

Reported, not gated: - State 2 local: hard 0.684 (A) and 0.636 (B), weighted 0.970 and 0.987. - The local children's half-map FSC = 0.143 resolutions: states 1 and 3 at 8.53 Å; state 2 at 16.0 Å (hard) and 9.14 Å (weighted).

The entry's earlier values equal Phase 2's final run to within 10⁻⁷ (keep/p3_fpb/, keep/p3_fpb_final/).

Cost. The entry with sweep and chain cases passed in 354.3 s and, after the review fixes, in 350.6 s (load 0.9 and 1.8 at the start, nothing else running), against the frozen limit of 744 s. Peak memory 8.7 GiB; run directory peak 5.68 GiB (keep/p3_fpb_disk/), inside the registry's disk_gb=6.0, which is unchanged.

Review. A read-only review of the Phase 3 diff found no substantive defect, and four minor points, all fixed: - an empty message on a failed reread; - a comment that understated when an invalid result can follow a rewrite; - the pending-record check could not fail, and there was no state-1 case; - the entry's mask check skipped the state-01 test for a mask that was not renamed.

It also noted an inherited edge: staging inside a multi-state producer's own directory with mkdir=no can overwrite that producer's state-01 masks. The order mask now shares it. It is harmless for rebound sweep records, whose copies have the same bytes, and is left for the maintainer.

Phase 2's gates again, on the final Phase 3 build: - the merge test (unit_project, above); - child equals direct at one thread (above); - the sweep cases in the entry (above, all pass); - direct state=X identity, byte-identical to Phase 0 for all six state/mode cases (keep/p3_identity_verdict.txt); - the off-state cases: the entry's direct runs (above), and cont_refine3D_1jxy, which passes with gate values identical to the base (keep/p2_cont/metrics_p3.tsv).

Exit, item by item: - rebinding test: passes, and shown to fail on two plants; - order-mask staging test: passes, and shown to fail on its plant; - chain cases of section 6: pass in both modes, with the mask check as recorded in section 6; - cost: inside the limit.

In short: a sweep's merged parent is now a source refine3D_local accepts, state by state. A local child equals a direct local run on the same parent. With default settings, local runs rebuild their derived products rather than stage them; that predates this run, and is why the mask check reads the record and the copies rather than the local run.

2026-11-28, Phase 4 (documents and report), run state_sweep on dell. No ruling exists yet. No source file changed.

Living descriptions. - doc/policies/3D/refine3D_policy.md: the introduction names the sweep. "Per-state M-estimation" says what happens without state= (a sweep with more than one state to refine; the old refusal only with one). A new "State sweep" subsection covers the trigger, the checks made before anything is created, the children and the generator state, the merge, the out entries, the record rebinding, what the sweep does not do, and continuation, including why a default local run rebuilds rather than stages its derived products. - refine3D_local_policy.md: a multi-state project is refined with state=X or as a sweep. A sweep's merged parent is a continuation source, and local staging copies recorded masks, the order mask included, when the settings match. - refine3D_auto_policy.md: each refinement is single-state, and a multi-state project is refined as a sweep. - doc/policies/heterogeneity/refine3D_states_policy.md: the weighted refinement of flex_pca's states, one at a time, by sweep or with state=X, and the refusal pointing to the sweep. - doc/how2s/how2_process_heterogeneous_datasets.md: the overview, an alternative in section 6 that refines every state with one command, the merged project and its table, and the weighted route without state=.

The test policy's flex_pca_blobs row and section already name the sweep and chain cases (Phases 2 and 3).

Report. refine3D_state_sweep_report.md, beside this plan, follows doc/how2s/how2write_agent_plans.md section 8: - what was learned; - what changed, phase by phase; - the decisions taken under delegation; - the deviations; - the evidence against the baseline, with the reported-not-gated numbers (per-state FSCs, the sweep table, the weighted pose divergence, the third state's correlations); - what is left open; - proposed skill lines; - the changed files; - a commit message.

The plan's status line says the plan is implemented and awaiting review; the note stays in planned/.

Gates. The fast gate passed 15 of 15 suites on the final Release build (scratch/build_p3.gate_p4.log) and on the Debug build (scratch/build_debug.gate_p4.log). Both trees hold the final source.

Exit, item by item: - fast gate: passes on Release and Debug; - every listed policy and the guide name the sweep; - the report exists.

Files changed in this phase: - doc/policies/3D/refine3D_policy.md, refine3D_local_policy.md, refine3D_auto_policy.md; - doc/policies/heterogeneity/refine3D_states_policy.md; - doc/how2s/how2_process_heterogeneous_datasets.md; - this plan; - the new report.