ensembl.vep.bench package#
Benchmarking: the conformance gate, timing, the strategy matrix, sweeps, results and the Perl oracle.
Measurement only. The corpus a benchmark runs over is ensembl.vep.corpus’s, not something this
package owns; the runners in ensembl.vep.runner.bench are the command line on top.
Submodules#
ensembl.vep.bench.baseline module#
Benchmark results on disk, and comparing a run against an earlier one.
A number without its context is not comparable, so a results file carries what produced it: the corpus spec and its parameter hash, the git revision and whether the tree was dirty, the machine, and the timing policy. A comparison across two different corpora is refused rather than reported.
Timings regress past a threshold. The declared cost per overlap is deterministic, so any change in it is a change in behaviour – reported as such, and not held to a threshold.
- class ensembl.vep.bench.baseline.BenchResults(*, info, rows=())[source]#
Bases:
objectA run’s rows and what produced them.
- Variables:
info (RunInfo) – The run’s context.
rows (tuple[dict[str, object], ...]) – One row per measurement, each with
corpusandconfigurationkeys plus its metrics.
- classmethod from_json(text)[source]#
Read results back.
- Raises:
ValueError – If the file was written in a different format version.
- Return type:
- rows: tuple[dict[str, object], ...]#
- class ensembl.vep.bench.baseline.Comparison(*, corpus_changed=False, regressions=(), cost_changes=(), unmatched=())[source]#
Bases:
objectA run compared against a baseline.
- Variables:
corpus_changed (bool) – The two were run over different corpora, so nothing else is meaningful.
regressions (tuple[Regression, ...]) – Timings past the threshold.
cost_changes (tuple[str, ...]) – Configurations whose declared cost per overlap moved.
unmatched (tuple[str, ...]) – Rows of the current run the baseline has no counterpart for.
- corpus_changed: bool#
- cost_changes: tuple[str, ...]#
- property ok: bool#
Return whether the run is comparable and no timing regressed.
- regressions: tuple[Regression, ...]#
- unmatched: tuple[str, ...]#
- class ensembl.vep.bench.baseline.Regression(*, corpus, configuration, metric, baseline, current)[source]#
Bases:
objectA timing that got slower than the threshold allows.
- Variables:
corpus (str) – The corpus.
configuration (str) – The configuration.
metric (str) – The metric that regressed.
baseline (float) – Its value in the baseline.
current (float) – Its value now.
- baseline: float#
- property change: float#
Return the fractional change, where 0.1 is ten percent slower.
- configuration: str#
- corpus: str#
- current: float#
- metric: str#
- class ensembl.vep.bench.baseline.RunInfo(*, verb, corpus=dict(), corpus_parameters='', git=dict(), machine=dict(), timestamp='', repeats=0, warmup=0)[source]#
Bases:
objectWhat produced a set of results.
- Variables:
verb (str) – The bench verb that ran.
corpus (dict[str, object]) – The corpus spec.
corpus_parameters (str) – The spec’s parameter hash.
git (dict[str, object]) – Revision and dirtiness.
machine (dict[str, object]) – See machine_info.
timestamp (str) – When the run finished.
repeats (int) – Timed samples per measurement.
warmup (int) – Untimed passes per measurement.
- corpus: dict[str, object]#
- corpus_parameters: str#
- git: dict[str, object]#
- machine: dict[str, object]#
- repeats: int#
- timestamp: str#
- verb: str#
- warmup: int#
- ensembl.vep.bench.baseline.TIMING_METRICS = ('ms_per_1k', 'batch_ms_per_1k', 'ns_per_case')#
The metrics a regression is judged on. Lower is better for all of them.
- ensembl.vep.bench.baseline.compare_results(baseline, current, *, threshold)[source]#
Compare a run against a baseline, row by row.
- Parameters:
baseline (
BenchResults) – The earlier run.current (
BenchResults) – This run.threshold (
float) – Fractional slowdown that counts as a regression.
- Returns:
What changed.
- Return type:
- ensembl.vep.bench.baseline.git_state()[source]#
Return the git revision and whether the tree is dirty, or Nones outside a repository.
- Return type:
dict[str,object]
ensembl.vep.bench.endtoend module#
Timing whole runs of the command line, one configuration at a time.
bench matrix times an annotator over overlaps that are already built. This times what a user
runs: reading the VCF, loading transcripts from the indexed GFF3, fetching sequence, annotating,
and writing the output. The difference between the two is the point – a strategy that wins several
times over in isolation moves the end-to-end number by whatever share of the run annotation is.
Each run is a fresh process, so no configuration is timed against another’s warmed module state,
and the process cost a real run pays is counted rather than amortised away. The child is given this
tree on PYTHONPATH, so the benchmark measures the working copy it was started from and never an
ensembl-vep installed elsewhere.
- class ensembl.vep.bench.endtoend.EndToEndRow(*, corpus, configuration, processes, variants, seconds, ms_per_1k, variants_per_second, peak_rss_bytes=0)[source]#
Bases:
objectOne configuration’s measurements over one corpus.
- Variables:
corpus (str) – The corpus kind annotated.
configuration (str) – The configuration’s label, as
bench matrixspells it.processes (int) – Worker processes the run was given.
variants (int) – Variants in the input.
seconds (float) – Median wall clock over the timed repeats.
ms_per_1k (float) – Median wall clock per thousand variants.
variants_per_second (float) – Throughput at the median.
peak_rss_bytes (int) – Largest peak seen over the timed repeats.
- configuration: str#
- corpus: str#
- ms_per_1k: float#
- peak_rss_bytes: int#
- processes: int#
- seconds: float#
- variants: int#
- variants_per_second: float#
- ensembl.vep.bench.endtoend.MISMATCH_LIMIT = 20#
Output mismatches collected before the gate stops, so one broken configuration cannot flood it.
- class ensembl.vep.bench.endtoend.RunOutcome(*, seconds, peak_rss_bytes)[source]#
Bases:
objectWhat one run of the command line cost.
- Variables:
seconds (float) – Wall clock of the whole process.
peak_rss_bytes (int) – The high-water mark of the largest process in the tree – not the sum across workers, which is what a sampling profiler would report instead.
- peak_rss_bytes: int#
- seconds: float#
- ensembl.vep.bench.endtoend.consequence_sets(output)[source]#
Return each variant’s consequence terms, keyed by the variant it was called on.
Terms are compared as a set per variant rather than as file bytes: entry order can legitimately follow the worker count and the buffering, and neither of those is a wrong answer.
- Parameters:
output (
Path) – An annotated VCF.- Returns:
Terms by
(region, position, reference, alternates).- Return type:
dict[tuple[str,str,str,str],frozenset[str]]
- ensembl.vep.bench.endtoend.output_mismatches(reference, candidate)[source]#
Return how a candidate’s output differs from the reference’s, up to
MISMATCH_LIMIT.- Parameters:
reference (
Path) – The reference configuration’s annotated VCF.candidate (
Path) – The configuration being checked.
- Returns:
One description per differing variant; empty when the two agree.
- Return type:
list[str]
- ensembl.vep.bench.endtoend.repository_path()[source]#
Return the directory holding the
ensemblpackage this process imported.What makes the benchmark measure the working copy it runs from: the child gets this on
PYTHONPATH, which takes precedence over anything installed into the interpreter.- Return type:
Path
- ensembl.vep.bench.endtoend.run_command(configuration, *, processes, workspace, output)[source]#
Return the command line for one run of one configuration.
- Parameters:
configuration (
Configuration) – The strategy and caches to run with.processes (
int) – Worker processes for the run.workspace (
Workspace) – The corpus the run annotates.output (
Path) – Where the run writes its annotated VCF.
- Returns:
The argv, invoking this tree’s CLI module rather than an installed entry point.
- Return type:
list[str]
- ensembl.vep.bench.endtoend.run_once(command, *, log_path)[source]#
Run one command to completion, timing it and reading its resource usage.
Stderr goes to a file rather than a pipe: the run is waited for with
os.wait4, which cannot drain a pipe, and a chatty run would otherwise fill it and deadlock.- Parameters:
command (
list[str]) – The argv to run.log_path (
Path) – Where the run’s stderr is written.
- Returns:
The wall clock and peak resident size.
- Return type:
- Raises:
subprocess.CalledProcessError – If the run fails, carrying its log as output.
- ensembl.vep.bench.endtoend.time_runs(command, *, log_path, repeats, warmup)[source]#
Run a command untimed
warmuptimes, then return the outcome ofrepeatstimed runs.- Raises:
subprocess.CalledProcessError – If any run fails.
- Return type:
list[RunOutcome]
ensembl.vep.bench.harness module#
Measuring an annotator: the conformance gate that runs before any timing, and the timing itself.
The gate comes first on purpose. A strategy that is fast because it is wrong is not a result, so a benchmark refuses to time anything until every candidate agrees with the reference on every overlap. The gate returns a report rather than exiting: the runner decides what a mismatch means for the process.
- class ensembl.vep.bench.harness.GateReport(*, reference, candidates, overlaps, mismatches=(), truncated=False)[source]#
Bases:
objectWhat the conformance gate found.
- Variables:
reference (str) – The strategy the candidates were checked against.
candidates (tuple[str, ...]) – The strategies checked.
overlaps (int) – Overlaps checked.
mismatches (tuple[str, ...]) – One line per disagreement found, at most
MISMATCH_LIMIT.truncated (bool) – Whether the gate stopped early at the limit.
- candidates: tuple[str, ...]#
- mismatches: tuple[str, ...]#
- property ok: bool#
Return whether every candidate agreed on every overlap.
- overlaps: int#
- reference: str#
- truncated: bool#
- ensembl.vep.bench.harness.KERNELS_STRATEGY = 'consequence.columnar-kernels'#
The strategy that needs the compiled extension.
- ensembl.vep.bench.harness.MISMATCH_LIMIT = 20#
Mismatches collected before the gate stops, so one broken strategy cannot flood the report.
- ensembl.vep.bench.harness.REFERENCE_STRATEGY = 'consequence.linear'#
The strategy every other one must agree with.
- class ensembl.vep.bench.harness.Timing(*, samples, warmup=0)[source]#
Bases:
objectThe samples one measurement took.
- Variables:
samples (tuple[float, ...]) – Elapsed seconds per timed pass.
warmup (int) – Untimed passes that preceded them.
- property best: float#
Return the fastest sample in seconds.
- ms_per_thousand(contexts)[source]#
Return the best sample as milliseconds per thousand contexts.
- Return type:
float
- samples: tuple[float, ...]#
- warmup: int#
- class ensembl.vep.bench.harness.TimingPolicy(*, repeats=3, warmup=1)[source]#
Bases:
objectHow a measurement is taken.
- Variables:
repeats (int) – Timed samples; the best is reported, as the least noisy.
warmup (int) – Untimed passes first, so the timed ones do not include warming caches.
- repeats: int#
- warmup: int#
- ensembl.vep.bench.harness.annotator_extras(annotator)[source]#
Return whatever instrumentation an annotator and its caches expose, labelled.
The counters live where the work is done: the staged strategies count on the annotator, while the zone map, codon and mapper caches count on themselves, reached through the annotator’s context.
- Return type:
dict[str,object]
- ensembl.vep.bench.harness.conformance_gate(overlaps, *, reference, candidates, reference_name='consequence.linear', limit=20)[source]#
Check every candidate against the reference, overlap by overlap.
- Parameters:
overlaps (
Sequence[TranscriptVariationAllele]) – The overlaps to check.reference (
Annotator[OverlapConsequence]) – The annotator whose terms are right by definition.candidates (
Mapping[str,Annotator[OverlapConsequence]]) – Name -> annotator to check.reference_name (
str, default:'consequence.linear') – The reference’s name, for the report.limit (
int, default:20) – Stop after this many mismatches.
- Returns:
What was found.
- Return type:
- ensembl.vep.bench.harness.consequence_strategies()[source]#
Return every registered
consequence.*strategy, the reference first.- Return type:
list[str]
- ensembl.vep.bench.harness.fact_cost(annotator, overlaps)[source]#
Return facts computed and declared cost charged, each per context, over one pass.
Instruments every fact process-wide for the pass; see
stats.profile.count_fact_computations.- Return type:
tuple[float,float]
- ensembl.vep.bench.harness.native_kernels_available()[source]#
Return whether the strategy that needs the compiled extension is registered.
- Return type:
bool
ensembl.vep.bench.oracle module#
The Perl oracle: the same cases through our annotators and through VariationEffect.pm.
The oracle is the external reference – the whole point is that it is not us – so a disagreement is reported, never gated on. The Perl script tests only the coding, intronic, upstream and downstream categories, so the comparison asks whether our terms cover the Perl ones, not whether they are equal.
Coverage is counted twice, because the direct count undercounts agreement. The Perl script reports
raw predicates, while our annotators emit terms after subsumption: an intronic variant in the
polypyrimidine tract emits splice_polypyrimidine_tract_variant, which suppresses the
intron_variant the Perl side reports. Counting the terms our emitted ones suppress, through the
catalogue’s subsumes chains, separates that from a real disagreement.
The case list here and build_cases in bench/variation_effect.pl must stay aligned by name
and order; CASE_NAMES is what a test pins against the Perl file. The transcript is built with
the corpus’s own build_transcript, so its translation is derived exactly as the suite’s is –
the hand-rolled builder this replaces had fallen out of step with the model and no longer ran.
- ensembl.vep.bench.oracle.CASE_NAMES = ('coding_exact', 'coding_near_boundary', 'intron_primary', 'intron_secondary', 'upstream_near', 'upstream_far', 'downstream_near', 'downstream_far', 'no_hit')#
The cases, in the order the Perl script builds and reports them.
- class ensembl.vep.bench.oracle.OracleCase(*, name, overlap)[source]#
Bases:
objectA named overlap, paired with the Perl case of the same name.
- Variables:
name (str) – The case name, shared with the Perl script.
overlap (TranscriptVariationAllele) – The overlap to annotate.
- name: str#
- overlap: TranscriptVariationAllele#
- ensembl.vep.bench.oracle.covered_cases(perl, ours)[source]#
Return how many cases our terms cover every Perl-reported term of.
- Return type:
int
- ensembl.vep.bench.oracle.covered_through_subsumption(perl, ours, subsumes)[source]#
Return how many cases our terms cover, counting the terms they suppress as covered.
- Parameters:
perl (
Sequence[Sequence[str]]) – The Perl-reported terms, per case.ours (
Sequence[Sequence[str]]) – Our emitted terms, per case.subsumes (
Mapping[str,Sequence[str]]) – Term -> the terms it directly suppresses.
- Returns:
Cases whose every Perl-reported term is emitted by us or suppressed by a term we emit.
- Return type:
int
- ensembl.vep.bench.oracle.oracle_cases()[source]#
Return the cases, named and ordered as the Perl script’s.
- Return type:
tuple[OracleCase,...]
- ensembl.vep.bench.oracle.oracle_transcript()[source]#
Return a small forward-strand coding transcript: two exons around one intron, all of both coding.
Exon 1 is 1000-1029 and exon 2 1050-1088, so the CDS is 69 bases – 23 codons, a multiple of three, so no partial-codon edge leaks into a case that is not about one. The background is a plain
Arepeat: the comparison needs only the category a variant lands in to be unambiguous, not a realistic open reading frame.- Return type:
- ensembl.vep.bench.oracle.perl_seconds(perl_modules, script, *, number, repeats)[source]#
Return the elapsed seconds of each timed oracle run of
numberworkload executions.Each run is a whole process, so the figure includes Perl’s start-up; the per-case number it yields is an upper bound, and says so wherever it is reported.
- Return type:
list[float]
- ensembl.vep.bench.oracle.perl_terms(perl_modules, script, case_count)[source]#
Run the oracle for its terms, one tuple per case in its own order.
- Raises:
ValueError – If the oracle reports a different number of cases, meaning the two case lists have drifted apart.
subprocess.CalledProcessError – If the script fails.
- Return type:
tuple[tuple[str,...],...]
Return why the Perl oracle cannot run here, or None if it can.
- Return type:
str|None
- ensembl.vep.bench.oracle.python_seconds(annotator, cases, *, number, repeats)[source]#
Return the elapsed seconds of each timed run of
numberworkload executions.- Return type:
list[float]
ensembl.vep.bench.suites module#
The strategy x cache matrix: every configuration worth timing, and timing them.
A registered name is a strategy; the caches are orthogonal to it. Timing only registered names would leave the configurations people actually run unmeasured, so a configuration is a strategy plus a cache set, and the set is chosen on the command line rather than hardcoded.
- ensembl.vep.bench.suites.CACHES = ('zonemap', 'codon', 'mapper')#
The caches a configuration can switch on, in the order a label names them.
- class ensembl.vep.bench.suites.Configuration(*, strategy, caches=frozenset(), batch_size=256)[source]#
Bases:
objectOne strategy with one set of caches.
- Variables:
strategy (str) – The registered strategy.
caches (frozenset[str]) – The caches switched on.
batch_size (int) – Chunk size, for the strategies that batch.
- batch_size: int#
- build()[source]#
Return a fresh annotator with fresh caches, so no configuration is timed warm from another.
- Return type:
- caches: frozenset[str]#
- property label: str#
the strategy, then its caches.
- Type:
Return the configuration’s table label
- strategy: str#
- class ensembl.vep.bench.suites.MatrixRow(*, corpus, configuration, contexts, ms_per_1k, batch_ms_per_1k, facts_per_context, cost_per_context, extras=dict())[source]#
Bases:
objectOne configuration’s measurements over one corpus.
- Variables:
corpus (str) – The corpus measured over.
configuration (str) – The configuration’s label.
contexts (int) – Overlaps in the corpus.
ms_per_1k (float) – Best wall clock per thousand overlaps, one overlap at a time.
batch_ms_per_1k (float) – The same, in chunks of the configuration’s batch size.
facts_per_context (float) – Facts computed per overlap.
cost_per_context (float) – Declared cost charged per overlap – the number that survives a port to another language, where wall clock does not.
extras (dict[str, object]) – Whatever instrumentation the annotator and caches expose.
- batch_ms_per_1k: float#
- configuration: str#
- contexts: int#
- corpus: str#
- cost_per_context: float#
- extras: dict[str, object]#
- facts_per_context: float#
- ms_per_1k: float#
- ensembl.vep.bench.suites.build_configurations(strategies, cache_sets, batch_size)[source]#
Cross strategies with cache sets, strategies outermost, without repeats.
- Raises:
ValueError – If a cache set does not parse.
- Return type:
list[Configuration]
- ensembl.vep.bench.suites.parse_cache_set(text)[source]#
Parse
noneor a+-joined set of cache names.- Raises:
ValueError – If a name is not one of
CACHES.- Return type:
frozenset[str]
- ensembl.vep.bench.suites.run_matrix(corpus, overlaps, configurations, policy)[source]#
Measure every configuration over one corpus.
Each measurement builds its own annotator: one for the single-overlap timing, a clean one for the fact count (instrumenting needs its own pass), and one for the batch timing.
- Return type:
list[MatrixRow]
ensembl.vep.bench.sweep module#
Sweeping one numeric annotation setting and timing each value.
Every value is sanity-checked against the reference strategy before it is timed: a setting that
changes the answer is a bug, not a speed-up. The chunking follows the strategy. A Python batch
strategy chunks internally by its own batch_size, so it is handed the whole corpus at once; the
native kernels chunk nowhere else, so for them the swept batch size is the chunk handed over.
- ensembl.vep.bench.sweep.SANITY_CHECK_COUNT = 64#
Overlaps each swept value is checked on before it is timed.
- class ensembl.vep.bench.sweep.Sweep(*, knob, values=())[source]#
Bases:
objectA setting and the values to try.
- Variables:
knob (str) – One of
SWEEPABLE_KNOBS.values (tuple[int, ...]) – The values, in order.
- knob: str#
- values: tuple[int, ...]#
- class ensembl.vep.bench.sweep.SweepPoint(*, corpus, strategy, knob, value, ms_per_1k)[source]#
Bases:
objectOne strategy at one value of the swept setting.
- Variables:
corpus (str) – The corpus measured over.
strategy (str) – The strategy.
knob (str) – The swept setting.
value (int) – Its value for this point.
ms_per_1k (float) – Best wall clock per thousand overlaps.
- property configuration: str#
Return the point’s name in a results file.
- corpus: str#
- knob: str#
- ms_per_1k: float#
- strategy: str#
- value: int#
- ensembl.vep.bench.sweep.sweep_strategy(corpus, strategy, overlaps, sweep, policy)[source]#
Time one strategy at every value of a setting, checking each value first.
- Parameters:
corpus (
str) – The corpus’s label.strategy (
str) – The strategy to sweep.overlaps (
Sequence[TranscriptVariationAllele]) – The corpus.sweep (
Sweep) – The setting and its values.policy (
TimingPolicy) – How to time.
- Returns:
- The timed points, and one line per value that changed
the answer – which is not timed.
- Return type:
tuple[list[SweepPoint],list[str]]
ensembl.vep.bench.workspace module#
The corpus on disk: written, indexed, annotated against, and removed again.
An end-to-end benchmark needs what a real run needs – a VCF, a bgzip-compressed and tabix-indexed
GFF3, and a FASTA with a .fai beside it – because an unindexed source takes a different code
path, and timing that path would answer a different question.
Everything this module writes is recorded as it is written, so clean() can remove exactly what
this invocation created and nothing else. A corpus already in the directory is reused and left
alone, which is what makes --corpus_dir safe to point at a corpus worth keeping.
- ensembl.vep.bench.workspace.INDEXING_TOOLS = ('bgzip', 'tabix')#
The htslib executables the corpus has to be indexed with.
- exception ensembl.vep.bench.workspace.MissingTool[source]#
Bases:
RuntimeErrorAn external executable the benchmark cannot run without is not on PATH.
- class ensembl.vep.bench.workspace.Workspace(*, directory, clean=True)[source]#
Bases:
objectA directory holding the corpus, its indexes and the benchmark’s own output files.
- Variables:
directory (Path) – Where everything lives.
clean (bool) – Remove what this invocation created when
closeis called.created (list[Path]) – Files this invocation wrote, in creation order.
created_directory (bool) – Whether
directoryitself was created here.
- clean: bool#
- created: list[Path]#
- created_directory: bool#
- directory: Path#
- property fasta_path: Path#
Return the corpus FASTA path.
- property gff3_path: Path#
Return the uncompressed, unsorted corpus GFF3 path.
- index()[source]#
Write the FASTA index, then the sorted, compressed and tabix-indexed GFF3.
- Raises:
MissingTool – If bgzip or tabix is not on PATH.
subprocess.CalledProcessError – If either of them fails.
- property indexed_gff3_path: Path#
Return the compressed, sorted, tabix-indexed GFF3 path.
- materialise(corpus)[source]#
Write the corpus as files, or leave a corpus already in the directory alone.
- Parameters:
corpus (
Corpus) – The corpus to write.
- property vcf_path: Path#
Return the corpus VCF input path.