Repository navigation
Find the draw prefix of _fovs_until chunk by chunk (2x, same draws; refs #646, #501) - #653
Conversation
_fovs_until drew one batch of about twice the fields a draw needs, then gathered, summed and searched the whole batch. It now finds the prefix that reaches n in chunks of 16384 integer prefix sums and never touches the unused tail, keeping the same random numbers, the same batch, the same one-call float sum and the generator's state afterwards, so every output is equal bit for bit. About 2x faster at small scale. This does not fix issue 646: there the rule asks for about 25 million objects, the work is linear in that number, and the random draws that must be kept for identical results set the floor. Refs 646, 501. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reference_compare removed /CreationDate (D:...Z) only. On a machine off UTC, matplotlib writes D:20261128205345+03'00', so every PDF and every page carrying one was reported as changed (382 false differences on the 646 change; 0 once fixed). Tested with Z, two offsets and no zone, in a PDF and inside a page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Whole suite run locally after merge, on The one failure has nothing to do with these changes. It is about the machine: GitHub Actions also ran on both PRs: 🤖 Generated with Claude Code |
Definitive timing (quiet machine, 2026-11-29)One process pinned to one core,
Draw helper alone, best of 5 (5 fields of 2 objects, one outlier sum):
The identical-output change alone takes the 646 case from 33 to 19 minutes. The draw limit is what brings it down to under half a second. |
Refs #646 (partly: this does not fix it) and #501.
What
object_rules._fovs_untildrew a batch of about twice the fields a draw needs, then gathered, cumulated, searched and summed the whole batch, and gathered the chosen prefix twice more. It now finds the prefix that reaches the rule'snobjects chunk by chunk (16,384 integer prefix sums at a time,_prefix_reaching) and never touches the unused tail.Kept exactly: the random numbers (same
rng.integerscall, same batch size, unused tail still discarded), the onesums[chosen].sum()call per batch (same float rounding), and the generator's state afterwards. Every output is equal bit for bit.Why this does not close #646
The 15-minute hang is not a loop that re-scans or re-sorts. On the v27 export the
xcontrol mean of repeat rep1 is 0.25; a DrugA field raised by 100, read relative to that mean, makes the rule ask for 11 and 45 million cells (targets 5% and 2.5%). Each of the 4,000 draws then picks millions of fields of 2 cells: the work is linear inn. Generating those random numbers alone is about 30% of the time and must stay for identical results, so an identical swap is capped at about 3×. Fixing #646 needs a behaviour change; one is prepared onclaude/rule-draw-limit(not opened as a PR), awaiting the owner's decision and limit.Equivalence
tests/test_object_rules.py::test_fovs_until_draws_exactly_as_before_646: the former function is kept in the test as the reference; 24 seeded random field sets (empty fields, one outlier field,nfrom 1 to 5 × 16,384 × 3, mostly-empty sets whose draws need a second batch).np.testing.assert_array_equalon means, objects and fields of every draw, and equalbit_generator.stateafterwards. A spy run confirmed the cases include prefixes that cross a chunk boundary (6) and batches that fall short ofn(35).Timing (small scale only)
5 fields of 2 objects, one outlier sum, single thread, best of 3, NumPy 2.5.5, on a shared machine with another heavy job running:
These time the helper alone, not
object_rule_checkorreport. The definitive timing waits for a quiet window on the machine.Local gate (on 4c1c83c)
Also run:
tests/test_reference.py(20 passed),ruff checkandruff format --checkonsrc tests data(clean);tests/test_object_rules.py,test_sampling_unit.py,test_morphofeature_exports.py,test_one_per_field.py,test_repeat_groups.py,test_biological_repeat.py,test_acquisition_identity.py(271 passed, 4 workers).Reference check (behaviour unchanged): 0 differences
data/reference/reference.py runonorigin/mainand on this change (--parallel 2 --skip idr: the 50 scenarios, 3 lab datasets, synthetic and fiberfeatures, 55 jobs, all exit 0), thencompare: 0 differences. The IDR job was skipped because it uses every CPU.The first compare reported 382 differences (335 PDFs and 47 pages). Every one was a PDF
/CreationDatewritten with this machine's offset (D:20261128205345+03'00'); the comparer removed only UTC dates (D:...Z). The second commit fixesreference_compare.PDF_STAMPto accept an offset or no zone, with a test (Z,+03'00',-05'30', none; in a PDF and inside a page). The same two trees then compare with 0 differences.Not run: the whole suite (
pyteston every CPU). It was held back because of the machine's resource limit while another session runs a large end-to-end gate; it needs running before merge.🤖 Generated with Claude Code