Repository navigation
Let callers choose the jitter and exclusion rules, defaulting to upstream cherimoya main — Closes #21 - #22
Merged
Conversation
A training set is drawn under two rules that were hardcoded: how far a peak's draw may shift from its locus's centre, and which windows an excluded region removes. Each becomes a frozen value a caller can state: Jitter(low, high) as inclusive shift bounds with the margin a window needs, and Exclusion(regions, bin_width, end_padding) as the bin grid and how an interval's end is snapped to it. as_jitter and as_exclusions resolve the shorthand the loader already accepts. The module imports neither torch nor the pileup extra, so the locus filters and the sampler can both read it.
The default exclusion rule is tangermeme 1.6's, and the parity test of extract_loci against tangermeme's own reader holds only from 1.6.
Upstream cherimoya changed both rules after the commit quadrat was ported from. jmschrei/cherimoya#92 widened the jitter draw so a window may start at either end of the widened peak, and tangermeme 1.6 snaps a half-open interval to the bins it overlaps rather than also reaching the bin its exclusive end falls in, and skips empty regions. The sampler, the window loader, the locus filters, the loader and the cache key now take a Jitter for max_jitter and Exclusion values for exclusion_lists, and their defaults are upstream main's rules: an integer m means Jitter(-m, m), and a bare region set means Exclusion(regions). The jitter rule never moves the window cache key, since the margin is unchanged; an exclusion's rule does. The golden digests are re-recorded from upstream's own sampler and PeakGenerator at 5729b57, and the previous ones, recorded at abb4d7b, stay pinned under the pre-#92 rule. BREAKING CHANGE: every seeded stream with a positive max_jitter draws differently. Under the default exclusion rule an interval ending on a 100-base edge no longer reaches the bin beginning there, and an empty region or window no longer covers the bin holding it. Pass Jitter(-m, m - 1) for m > 0 and Exclusion(regions, end_padding=1) to reproduce earlier runs for every region whose end is not before its start.
conradbzura
force-pushed
the
21-jitter-and-exclusion-rules
branch
from
November 17, 2026 16:38
db60e69 to
776f4bd
Compare
This was referenced Nov 17, 2026
conradbzura
marked this pull request as ready for review
November 17, 2026 17:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the two rules a training set is drawn under values the caller states, and default them to upstream cherimoya
main.Jitter(low, high)is the shifts a peak's draw may take from its locus's centre, both bounds inclusive;Exclusion(regions, bin_width=100, end_padding=0)is the bin grid an exclusion is tested on and how an interval's end is snapped to it. The sampler, the window loader, the locus filters, the loader and the window-cache key take them through the existingmax_jitterandexclusion_listsarguments, where an integermstill works and meansJitter(-m, m), and a bare region set meansExclusion(regions).The js031 run measured quadrat byte-identical to upstream
abb4d7band divergent from upstreammain(5729b57) in the jitter draw: jmschrei/cherimoya#92 widened it to include both ends of the widened peak. The exclusion rule differs too, found in upstream's code rather than measured, since the run's exclusions never reach the difference: tangermeme 1.6 snaps[start, end)to the bins it overlaps and skips empty regions. Both now default tomain's, apart from an empty window, which covers no bin where tangermeme 1.6 gives it one, and both old rules stay one argument away, so a run seeded before #92 reproduces without pinning an old quadrat.Each rule is expressed by its input rather than a flag, following the API guide's "compose, don't configure": the pre-#92 jitter is
Jitter(-m, m - 1), and tangermeme 1.5's exclusion rule isend_padding=1, which reproduces its closed end and its marking of an empty region for every region whose end is not before its start.Closes #21
Usage
Proposed changes
quadrat.rules(new)A data-only module holding
Jitter,Exclusion,as_jitter,as_exclusionsandEXCLUSION_BIN_WIDTH. It imports neithertorchnor thepileupextra, which is why the values live here and not inquadrat.sampling:quadrat.locimust not importtorch, and both modules read them.Jitteris a frozen dataclass of twoints, compared, hashed and pickled by value. Itsmargin,max(-low, high, 0), is what a window is widened by on each side; a draw's offset into the widened window runs fromlow + marginthroughhigh + margin. A lopsided rule pays for its longer side on both, which its docstring states.Exclusionis frozen and compared by identity, since its regions may be frames. An interval, region or window alike, covers binsstart // bin_widththrough(end + end_padding - 1) // bin_width, and none whenend + end_padding <= start.Aggregatecannot: every reader trusts their fields as validated.as_exclusionsgathers every bare locus set in a list into one defaultExclusion, after the explicit ones, soexclusion_lists=[a, b]still means one set of regions.The sampler
PeakNegativeMixSamplerholds aJitterasjitterand drawsrandint(low + margin, high + margin + 1), made exactly when the margin is positive, the branch condition it already had. The sequence of generator calls is unchanged, so forJitter(-m, m)the draw is upstream'srandint(0, 2m + 1)and forJitter(-m, m - 1)it is the previousrandint(0, 2m), bit for bit.LocusDraw.jitterkeeps meaning the offset into the widened window, soLocusDatasetis untouched.max_jitteras an attribute is gone;jitterreplaces it.Windows and exclusions
load_windowswidens byas_jitter(max_jitter).margin.exclusion_maskresolves its argument withas_exclusionsand runs the existing bin-table interval join once per rule, binning both sides by that rule and ORing the results. Every rule's regions are read before the first join, so a bad one is refused whatever an earlier rule flagged. Intervals that cover no bin are left out of the join on both sides.The loader and the cache key
build_training_loaderresolvesmax_jitteronce and passes theJitterto the peak windows and the sampler; negatives are still not jittered.window_cache_keykeys the jitter by its margin alone, so the two jitter rules share an entry, and keys eachExclusionby itsbin_width, itsend_paddingand its files. Keys without exclusions are unchanged; keys with them all change, which they must, since an entry built under the old default rule must not be hit under the new one.Golden digests
The plan and batch digests are re-recorded from upstream's own code:
PeakNegativeSampler._prepare_epochandPeakGeneratorat5729b57, over the same arithmetic corpus and the same six sampler configurations, by a recorder that first reproduced every existing literal fromabb4d7b. The existing literals stay, asGOLDEN_PLANS_BEFORE_92andGOLDEN_BATCHES_BEFORE_92, pinned underJitter(-m, m - 1).no_jitteris the same in both, as it should be.Breaking
Every seeded stream with a positive
max_jitterdraws differently. Under the default exclusion rule, an interval ending exactly on a 100-base edge no longer reaches the bin beginning there, whether it is a region or a window, and an empty region or window no longer covers the bin holding it.Jitter(-m, m - 1)form > 0andExclusion(regions, end_padding=1)reproduce earlier runs for every region whose end is not before its start. Thetangermemefloor rises to 1.6.0, whose exclusion rule is now the default and which the parity test against tangermeme's ownextract_lociassumes.Decisions for the owner
inclusive=andclosed_end=became inputs: an inclusive bound pair and an end padding. The padding also expresses a base-overlap exclusion (bin_width=1) at no extra surface.max_jittertakes aJitterandexclusion_liststakes anExclusion, as the issue specified, though a range is not a maximum and one rule is not a list. Rename tojitter=andexclusions=, with the old names as shorthand, when the loader is published; ledgered with renamingLocusDraw.jittertooffset.quadrat.rulesrather than the sampler, for the import constraint above.quadratyet.end_padding=1it flags nothing. No well-formed input changes.Review
Four passes, one reviewer per role, each pass's findings remediated:
exclusion_maskrebuilt its window frame per rule through Python strings (1.6× at a million windows); the tangermeme floor admitted 1.5LocusDraw.jittermisdescribed a negative's offset;TypeErrorundocumented; the PR body cited a deleted test and overstated the js031 run; the empty-interval filter andbin_widthwere pinned only by Hypothesis drawsTwo independent checks ran alongside: a reimplementation of upstream's
_prepare_epochreproduced both golden plan sets, and a 400-trial differential against tangermeme 1.6's own binning found no mismatch over non-empty windows. The last pass's fixes were verified by the suite and the mutation harness, not another review pass. Deferred and incidental findings are ledgered.Test cases
TestPeakNegativeMixSampler5729b57'sTestPeakNegativeMixSamplerJitter(-m, m - 1)abb4d7b'sbuild_training_loader5729b57'sPeakGeneratorbuild_training_loaderJitter(-m, m - 1)abb4d7b'sTestPeakNegativeMixSamplerJitterin a small range[low + margin, high + margin]and every negative's is0TestPeakNegativeMixSamplerJitter(-2, 1),Jitter(-2, 2)and the lopsidedJitter(0, 3)[0, 3],[0, 4]and[3, 6]exclusion_maskexclusion_maskexclusion_maskexclusion_maskExclusions each flagging one window; a list of two bare framesexclusion_maskTypeErrorwindow_cache_keymax_jitter=500,Jitter(-500, 499),Jitter(-500, 500)window_cache_keyExclusion(path)build_training_loadermax_jitter=Truewith missing inputsTypeError, nothing indexed and nothing cachedTestJitterlow > highand non-integers are refused, and the margin contains every shiftTestExclusionExclusionas_jitterandas_exclusionsNone, paths, and lists mixing rules and bare sets