Coverage for src/python/ensembl/vep/config/sections/common/execution.py: 100%
31 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Options controlling annotation-worker execution."""
16from __future__ import annotations
18from typing import ClassVar
20from attrs import define, field
22from ensembl.vep.common.enums import StartMethod
23from ensembl.vep.config.option_spec import option
24from ensembl.vep.config.sections.base import ConfigSection
26__all__ = ["ExecutionConfig"]
28# Mirrors ensembl.vep.caches.feature_pool.DEFAULT_TRANSCRIPT_POOL_BYTES (the source of truth
29# every other call site imports). Not imported here so this config layer stays free of the
30# domain-layer dependencies caches.feature_pool pulls in transitively (models.genic); kept in
31# sync by test_transcript_pool_bytes_default_matches_the_caches_module.
32_DEFAULT_TRANSCRIPT_POOL_BYTES = 128 * 1024 * 1024
35@define(frozen=True, kw_only=True, auto_attribs=True)
36class ExecutionConfig(ConfigSection):
37 """Configure worker processes and optional independent-track threads.
39 Attributes:
40 processes (int): Number of worker processes. Perl VEP spells it ``--fork``, accepted as a
41 synonym so every layer writes this one field and the highest-precedence layer wins.
42 start_method (StartMethod): Multiprocessing start method, or ``auto``.
43 threads (int): Threads available to independent annotation tracks in one worker.
44 buffer_size (int): Maximum records in one sequence-region input buffer.
45 annotation_window (int): Maximum variations retaining overlap graphs at one time.
46 max_in_flight (int | None): Explicit submitted-buffer cap, or None to match worker count.
47 transcript_pool_bytes (int): Byte budget for the per-worker cross-payload transcript pool.
48 ``0`` disables pooling; every payload then rebuilds its own transcripts, matching
49 behaviour before Stage 4.
50 """
52 section_name: ClassVar[str] = "execution"
54 processes: int = field(default=1, metadata=option("worker process count", synonyms=("fork",)))
55 start_method: StartMethod = field(
56 default=StartMethod.AUTO,
57 metadata=option("multiprocessing start method"),
58 )
59 threads: int = field(default=1, metadata=option("independent annotation-track thread count"))
60 buffer_size: int = field(default=5000, metadata=option("records per input buffer"))
61 annotation_window: int = field(
62 default=1024,
63 metadata=option("variations annotated together within an input buffer"),
64 )
65 max_in_flight: int | None = field(
66 default=None,
67 metadata=option("maximum submitted input buffers"),
68 )
69 transcript_pool_bytes: int = field(
70 default=_DEFAULT_TRANSCRIPT_POOL_BYTES,
71 metadata=option("transcript pool byte budget (0 disables)", metavar="BYTES"),
72 )
74 def __attrs_post_init__(self) -> None:
75 """Reject execution settings that cannot produce a useful worker pool."""
76 if self.processes < 1:
77 raise ValueError("processes must be at least one")
78 if self.threads < 1:
79 raise ValueError("threads must be at least one")
80 if self.buffer_size < 1:
81 raise ValueError("buffer_size must be at least one")
82 if self.annotation_window < 1:
83 raise ValueError("annotation_window must be at least one")
84 if self.max_in_flight is not None and self.max_in_flight < 1:
85 raise ValueError("max_in_flight must be at least one")
86 if self.transcript_pool_bytes < 0:
87 raise ValueError("transcript_pool_bytes must be at least zero")