Repository navigation
Refuse loader inputs that are read silently or refused without naming the argument — Closes #23 - #26
Draft
conradbzura wants to merge 7 commits into
Draft
conradbzura wants to merge 7 commits into
conradbzura wants to merge 7 commits into
Conversation
conradbzura
force-pushed
the
23-refuse-unhonoured-loader-inputs
branch
3 times, most recently
from
November 19, 2026 19:54
fb3881c to
ca52bce
Compare
The integer rule, any numbers.Integral but a bool, was written inline in require_index and again in the Jitter, Exclusion and Aggregate field checks. It now lives once in quadrat._engine, the lowest layer, so require_index, those fields, and the sampler and loader arguments that follow all refuse the same values in the same words. A plain int is answered before the ABC test, which costs several times the call on the per-draw epoch path; bool is a subclass and fails it. as_jitter and validate_signal_groups keep their own checks, whose messages name what require_integer cannot: the Jitter alternative, and the whole group specification.
PeakNegativeMixSampler(True, True) built a sampler over one peak and one negative, set_epoch(True) set epoch 1, RechunkedLoader read True as a batch of one, and in_window=True built one-base windows, because each normalised through int() or not at all, which admits a bool and truncates a float. Every integer argument of both samplers and their validate_arguments, RechunkedLoader, auto_fetch_size and build_training_loader, and the window widths load_windows and LocusDataset take, now goes through require_integer and raises TypeError naming the argument. build_training_loader makes these refusals before anything is read; a float fetch_size is now a TypeError where it was a ValueError. Both validate_arguments answer the values they normalised, and auto_fetch_size still takes the prefetch_factor of None a loader without workers holds. require_index now always takes the row count; the one caller that used it as a bare integer check, the dataset's epoch, calls require_integer.
LocusDataset bounded a draw by its two window frames and never by the cache it reads, so a cache over more windows answered another window's signal for every draw, and one over fewer failed only at the first read past its end. WindowSignalCache now answers n_windows from the counts array_meta recorded, or counts its arrays where it has none, and the dataset refuses a missing signal cache, and a signal or control cache whose count is not the frames' rows combined, as it already refuses a sampler of the wrong size. The caches and widths are read-only attributes, so nothing checked at construction can be bypassed by assigning another. A cache over other windows of the same count still passes; no count can tell it apart.
load_windows raised FileNotFoundError for a missing reference, while SequenceStore, and so extract_sequences and extract_loci, raised pyfaidx's FastaNotFoundError, and chrom_lengths fell through to a scan that failed in the engine's words. Both types are OSError, but a caller handling one missed the other. The refusal now lives in reference.require_reference, which chrom_lengths and SequenceStore call before opening the file, so every entry point, the pileups included, raises FileNotFoundError in the same words. A path running through a file counts as missing; one that cannot be examined raises OSError, and a reference that exists but cannot be opened still raises pyfaidx's error. chrom_lengths is where the published docs state this, and every other reader points there.
A bigWig or any other file given as a track passed require_complete, track_frame, track_contigs and TrackStore, and failed later in polars' words, naming no file. The port had dropped upstream's suffix test on purpose, since a single-file table need carry no suffix. track_signal, the one verifier of a track, now reads the four bytes every Parquet file begins with and refuses a file without them with a ValueError naming the path and saying what a track is; track_frame and track_contigs consult it for a single file as for a directory. A directory neither named as a track nor holding any Parquet is refused in the same words, rather than told to pile up again. Each entry point's refusal of a missing track is unchanged.
extract_loci(signals=[]) answered zero-channel signal tensors, and its default target_idx of 0 then named no track without raising. An empty signals or controls list is now refused with a ValueError saying to pass None to read none; zero channels mean nothing to either.
Exclusion(Exclusion(...)) was refused with a message saying to list both, but Exclusion([Exclusion(...), "b.bed"]) passed construction and failed later when the regions were read. An Exclusion anywhere in a list or tuple of regions now gets the top-level refusal.
conradbzura
force-pushed
the
23-refuse-unhonoured-loader-inputs
branch
from
November 19, 2026 21:45
ca52bce to
3e4f3cf
Compare
This was referenced Nov 23, 2026
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
Six inputs on the training path were either accepted though they could not be honoured, or refused in words that named neither the argument nor the file. This PR moves each refusal to the layer where the input is first given and words it in quadrat's terms.
LocusDatasetraisesValueErrornaming the cache and both countsTrueor2.0as a count, seed, epoch, batch size, window width or worker count1, or truncated to2TypeErrornaming the argumentFileNotFoundErrorfromload_windows, pyfaidx'sFastaNotFoundErrorfrom the extractors, an engine error fromchrom_lengthsFileNotFoundError, in the same words, from every entry pointrequire_completeand failed later in polars' words, naming no fileValueErrornaming the path, from every reader that opens itextract_loci(signals=[])target_idxnamed no track and raised nothingValueError, saying to passNoneExclusion([Exclusion(...), "b.bed"])The one remaining hole is documented: a cache built over different windows of the same count passes, because no count can tell it apart.
Closes #23
Proposed changes
Window count (
quadrat.cache,quadrat.dataset)WindowSignalCachegains a publicn_windows, answered from the countsarray_metaalready records, so nothing is mapped to read it.LocusDataset.__init__refuses a signal or control cache whosen_windowsis not the two frames' rows combined, beside the check it already makes of a sampler's size. A cache constructed directly with no record is counted from its arrays.n_windowsbecomes part of the reader protocolsignal_cacheandcontrol_cachedocument. A missingsignal_cacheis refused by name, and the two caches and the two widths become read-only attributes, so nothing checked at construction can be bypassed by assigning another.One integer rule (
quadrat._engine,quadrat.rules,quadrat.sampling,quadrat.loader,quadrat.loci,quadrat.dataset)quadrat._engine.require_integer(label, value)holds the rulerequire_indexused inline: anynumbers.Integral, numpy's included, except abool. It sits in the lowest layer so every module can share it.require_index, which now always takes a row count, and theJitter,ExclusionandAggregatefield checks now call it, and so do:PeakNegativeMixSampler:n_peaks,n_negatives,random_state,set_epochandplan, andn_negativesinvalidate_arguments, which now answers the normalised count.ShardedEpochSampler:n,set_epoch, andbatch_size,rankandworld_sizeinvalidate_arguments. That method now raisesTypeErroras well, and answers the normalised values.RechunkedLoader:batch_size, and the wrapped loader'sbatch_size.auto_fetch_size: every argument, withprefetch_factor=Nonestill taken as torch's default, as a loader without workers holds it.build_training_loader:in_window,out_window,num_workers,max_fetch_bytes,fetch_sizeandrandom_state, all refused before anything is read.load_windowsandLocusDataset: the two window widths.A plain
intis answered before the ABC test, so the check costs nothing measurable on the per-draw epoch path. A float is refused whereint(...)used to truncate it, so a floatfetch_sizeis now aTypeErrorwhere it was aValueError.as_jitterandvalidate_signal_groupskeep their own checks, which already refusebool, because their messages name what the shared one cannot: theJitteralternative, and the whole group specification.Missing reference (
quadrat.reference,quadrat.loci,quadrat.stores)reference.require_reference(path)raisesFileNotFoundError("<path> is not a reference; …"). Two readers call it before they open the file:chrom_lengths, soload_windowsdrops its own inline copy of the check.SequenceStore, soextract_sequencesandextract_lociraise the same error.A path running through a file counts as missing too. A path that cannot be examined, e.g. inside a directory that cannot be searched, raises
OSError, and a reference that exists but cannot be opened still raises pyfaidx's error, which is anOSErrorand names the path.chrom_lengthsis where the published reference states all of this;pileup_alignments,pileup_manyand every other reader point there.A track that is no track (
quadrat.tables,quadrat.stores)tables.track_signal, the one verifier of a track behindrequire_complete, now reads the four bytes every Parquet file begins with (PAR1). A single file without them is refused with aValueErrornaming the path and saying what a track is. The check reads the file's content rather than its suffix, because a single-file table need carry no suffix, which is why the port dropped upstream's suffix test.require_completeandTrackStorereach the check throughtrack_signal, andtrack_frameandtrack_contigsnow consult it for a single file as they already did for a directory. A directory neither named as a track nor holding any Parquet, a folder of bigWigs say, is refused in the same words rather than told to pile up again. Each entry point's refusal of a missing track is unchanged, and the readers now document theOSErroran unreadable file raises.Empty track lists (
quadrat.loci)extract_locirefuses an emptysignalsorcontrolslist. Zero channels mean nothing to either, andNoneis how a caller asks for none.extract_signal(windows, [])is unchanged: it is a plain reader, and a zero-channel answer is consistent there.Nested
Exclusion(quadrat.rules)Exclusion.__post_init__refuses anExclusionanywhere in alistortupleof regions with the message it gives at the top level.Test cases
test_cacheTrue, a numpybool,1.0,"1"TypeErrornaming the labeltest_cacheint64orint32(Hypothesis)intTestWindowSignalCachen_windowsis readTestLocusDatasetValueErrornamingsignal_cacheand both countsTestLocusDatasetValueErrornamingcontrol_cacheTestLocusDatasetboolwidth, is assigned tosignal_cache,control_cache,in_windoworout_windowAttributeErrorTestLocusDatasetNoneas the signal cacheValueErrornamingsignal_cacheTestLocusDatasetTrueasin_windoworout_windowTypeErrornaming the widthTestPeakNegativeMixSamplerTrueor2.0asn_peaks,n_negativesorrandom_stateTypeErrornaming the argumentTestPeakNegativeMixSamplerintcounts and plans what plain integers planTestPeakNegativeMixSamplerTrueor1.0as the epoch, or epochTruetoplanset_epochorplanis calledTypeErrornamingepoch, leaving the epoch at zeroTestShardedEpochSamplerTrueor2.0asbatch_size,rankorworld_sizevalidate_argumentsis calledTypeErrornaming itTestShardedEpochSampler,TestPeakNegativeMixSamplervalidate_arguments, orTrueor2.0asn_negativesvalidate_argumentsis calledint, or raisesTypeErrornamingn_negativesTestShardedEpochSamplerTrueor4.0asn, or epochTrue, or numpy integers for every argumentset_epochis calledTypeErrornaming the argument, or holds each as a plainintn,set_epochand normalisationTestRechunkedLoaderTrueor4.0as the batch, a wrapped loader whosebatch_sizeisTrue, or numpy integers for bothTypeErrornaming whichbatch_size, or holds both as plaininttest_loaderTrueor a float as any offetch_size,batch_size,rank,world_size,random_state,in_window,out_window,num_workersormax_fetch_bytes, among missing filesbuild_training_loaderis calledTypeErrorbefore anything is read or keyedtest_loaderTrueas any argument, a loader's ownprefetch_factor, orprefetch_factor=Noneon an epoch whose fetch depends on the depthauto_fetch_sizeis calledTypeErrornaming it, or answers what a depth of2answers and not what1doestest_lociTrueor a float as a window widthload_windowsis calledTypeErrornaming the widthtest_reference,test_track,test_run,test_loaderchrom_lengths,pileup_alignments,pileup_manyorbuild_training_loaderis calledFileNotFoundErrorsaying it is not a reference, with no scan warning and no cache entrytest_referencerequire_referenceorchrom_lengthsis calledFileNotFoundErrorfor the first two, passes the third, and raises anOSErrorthat is notFileNotFoundErrorfor the lastTestSequenceStoreFileNotFoundErrorsaying it is not a referencetest_lociextract_sequencesorextract_lociis calledFileNotFoundErrorsaying it is not a referencetest_tablesrequire_completeortrack_contigsis calledValueErrornaming the path and saying what a track istest_tablesrequire_completeortrack_signalis calledValueErrorsaying it cannot be verified complete, not that it is no tracktest_tables.parquetrequire_completeis calledtest_stores,test_loci,test_loadertrack_frame,extract_lociorbuild_training_loaderis calledValueErrornaming the path,extract_locibefore indexing the referenceTestTrackStoreValueErrornaming the pathTestTrackStoretest_locisignalsor ascontrolsextract_lociis calledValueErrorsaying to passNoneTestExclusionExclusion, or anExclusionas the regionsExclusionis constructed over themTypeErrorwith one message telling the caller to pass the rules side by side