Skip to content

Commit ab04a84

Browse files
committed
fix: pre-commit errors
1 parent 1a20853 commit ab04a84

11 files changed

+39
-158
lines changed

src/calibrationtools/async_runner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import asyncio
99
import threading
10-
from typing import Any, Callable
10+
from typing import Any, Callable, NoReturn
1111

1212

1313
def run_coroutine_from_sync(coroutine_factory: Callable[[], Any]) -> Any:
@@ -39,9 +39,12 @@ def runner() -> None:
3939
except BaseException as exc: # pragma: no cover - passthrough
4040
error["value"] = exc
4141

42+
def raise_worker_error(exc: BaseException) -> NoReturn:
43+
raise exc
44+
4245
thread = threading.Thread(target=runner, daemon=True)
4346
thread.start()
4447
thread.join()
4548
if "value" in error:
46-
raise error["value"]
49+
raise_worker_error(error["value"])
4750
return result["value"]

src/calibrationtools/batch_generation_runner.py

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import asyncio
99
import time
10-
from concurrent.futures import ThreadPoolExecutor
1110
from dataclasses import dataclass
1211
from functools import partial
1312
from typing import Any, Callable
@@ -28,7 +27,7 @@ class BatchGenerationConfig:
2827
stable across batched generations so the runner constructor stays small
2928
and execution methods operate on named fields.
3029
31-
Args:
30+
Attributes:
3231
generation_particle_count (int): Number of accepted particles required
3332
to complete a generation.
3433
tolerance_values (list[float]): Acceptance tolerance for each
@@ -45,9 +44,6 @@ class BatchGenerationConfig:
4544
Callback that stores the finalized population on the sampler.
4645
reporter (SamplerReporter): Reporter used for progress and summary
4746
output.
48-
49-
Returns:
50-
None
5147
"""
5248

5349
generation_particle_count: int
@@ -68,13 +64,10 @@ class BatchGenerationState:
6864
helper methods can share batch-generation state without long parameter
6965
lists.
7066
71-
Args:
67+
Attributes:
7268
proposed_population (ParticlePopulation): Population being filled for
7369
the active generation.
7470
attempts (int): Total proposal attempts consumed so far.
75-
76-
Returns:
77-
None
7871
"""
7972

8073
proposed_population: ParticlePopulation
@@ -93,32 +86,13 @@ class BatchGenerationRunner:
9386
across batched generations.
9487
run_state (SamplerRunState): Mutable bookkeeping for the active sampler
9588
run.
96-
97-
Returns:
98-
None
9989
"""
10090

10191
def __init__(
10292
self,
10393
config: BatchGenerationConfig,
10494
run_state: SamplerRunState,
10595
) -> None:
106-
"""Store the collaborators needed to execute batched generations.
107-
108-
This constructor keeps the runner lightweight by receiving a grouped
109-
configuration object for stable dependencies and a separate run-state
110-
object for per-run bookkeeping.
111-
112-
Args:
113-
config (BatchGenerationConfig): Static settings and callbacks for
114-
batched generation execution.
115-
run_state (SamplerRunState): Mutable bookkeeping for the active
116-
sampler run.
117-
118-
Returns:
119-
None: This constructor does not return a value.
120-
"""
121-
12296
self.config = config
12397
self.run_state = run_state
12498

@@ -155,7 +129,9 @@ def resolve_settings(
155129
raise ValueError("batchsize must be positive")
156130
return batchsize, False
157131

158-
def run_generation(self, request: BatchGenerationRequest) -> GenerationStats:
132+
def run_generation(
133+
self, request: BatchGenerationRequest
134+
) -> GenerationStats:
159135
"""Execute one batched generation and store its final population.
160136
161137
This method coordinates adaptive proposal sizing, batch evaluation,
@@ -466,7 +442,10 @@ def _accept_particle_batch(
466442

467443
considered = 0
468444
for err, proposed_particle in zip(errs, proposed_particles):
469-
if proposed_population.size >= self.config.generation_particle_count:
445+
if (
446+
proposed_population.size
447+
>= self.config.generation_particle_count
448+
):
470449
break
471450

472451
considered += 1

src/calibrationtools/particle_evaluator.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,21 @@ class ParticleEvaluator:
2020
boundary.
2121
2222
Args:
23-
particles_to_params (Callable[[Particle], dict]): Function mapping a
23+
particles_to_params (Callable[..., dict]): Function mapping a
2424
particle to model parameters.
2525
outputs_to_distance (Callable[..., float]): Function scoring simulated
2626
outputs against target data.
2727
target_data (Any): Observed data used for distance evaluation.
2828
model_runner (MRPModel): Model runner used to simulate outputs.
29-
30-
Returns:
31-
None
3229
"""
3330

3431
def __init__(
3532
self,
36-
particles_to_params: Callable[[Particle], dict],
33+
particles_to_params: Callable[..., dict],
3734
outputs_to_distance: Callable[..., float],
3835
target_data: Any,
3936
model_runner: MRPModel,
4037
) -> None:
41-
"""Store the collaborators needed to score one proposed particle.
42-
43-
This constructor keeps the particle-evaluation boundary explicit by
44-
grouping the user-supplied mapping function, scoring function, target
45-
data, and model runner in one object.
46-
47-
Args:
48-
particles_to_params (Callable[[Particle], dict]): Function mapping
49-
a particle to model parameters.
50-
outputs_to_distance (Callable[..., float]): Function scoring
51-
simulated outputs against target data.
52-
target_data (Any): Observed data used for distance evaluation.
53-
model_runner (MRPModel): Model runner used to simulate outputs.
54-
55-
Returns:
56-
None
57-
"""
58-
5938
self.particles_to_params = particles_to_params
6039
self.outputs_to_distance = outputs_to_distance
6140
self.target_data = target_data

src/calibrationtools/particlewise_generation_runner.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ParticlewiseGenerationConfig:
3131
execution methods can depend on named fields instead of long parameter
3232
lists.
3333
34-
Args:
34+
Attributes:
3535
generation_particle_count (int): Number of accepted particles required
3636
to complete a generation.
3737
tolerance_values (list[float]): Acceptance tolerance for each
@@ -52,9 +52,6 @@ class ParticlewiseGenerationConfig:
5252
Callback that stores the finalized population on the sampler.
5353
reporter (SamplerReporter): Reporter used for progress and summary
5454
output.
55-
56-
Returns:
57-
None
5855
"""
5956

6057
generation_particle_count: int
@@ -77,7 +74,7 @@ class ParticlewiseGenerationRequest:
7774
across sampler iterations, including executor access, timing markers, and
7875
keyword arguments forwarded into particle evaluation.
7976
80-
Args:
77+
Attributes:
8178
generation (int): Zero-based generation index to execute.
8279
n_workers (int): Number of workers available to the generation.
8380
parallel_executor (ThreadPoolExecutor | None): Executor used for
@@ -88,9 +85,6 @@ class ParticlewiseGenerationRequest:
8885
generation.
8986
particle_kwargs (dict[str, Any]): Keyword arguments forwarded into
9087
particle evaluation.
91-
92-
Returns:
93-
None
9488
"""
9589

9690
generation: int
@@ -109,16 +103,13 @@ class ParticlewiseGenerationState:
109103
and generation-specific sample method so helper methods can share that data
110104
without long positional argument lists.
111105
112-
Args:
106+
Attributes:
113107
proposed_population (ParticlePopulation): Population being filled for
114108
the active generation.
115109
generator_slots (list[GeneratorSlot]): Proposal slots used to preserve
116110
deterministic ordering across execution modes.
117111
sample_method (Callable[[SeedSequence | None], Particle]): Proposal
118112
function for the active generation.
119-
120-
Returns:
121-
None
122113
"""
123114

124115
proposed_population: ParticlePopulation
@@ -139,32 +130,13 @@ class ParticlewiseGenerationRunner:
139130
used across particlewise generations.
140131
run_state (SamplerRunState): Mutable bookkeeping for the active sampler
141132
run.
142-
143-
Returns:
144-
None
145133
"""
146134

147135
def __init__(
148136
self,
149137
config: ParticlewiseGenerationConfig,
150138
run_state: SamplerRunState,
151139
) -> None:
152-
"""Store the collaborators needed to execute particlewise generations.
153-
154-
This constructor keeps the runner lightweight by receiving a grouped
155-
configuration object for stable dependencies and a separate run-state
156-
object for per-run bookkeeping.
157-
158-
Args:
159-
config (ParticlewiseGenerationConfig): Static settings and callbacks
160-
for particlewise generation execution.
161-
run_state (SamplerRunState): Mutable bookkeeping for the active
162-
sampler run.
163-
164-
Returns:
165-
None: This constructor does not return a value.
166-
"""
167-
168140
self.config = config
169141
self.run_state = run_state
170142

@@ -371,6 +343,10 @@ async def _collect_accepted_particles_async(
371343
Returns:
372344
tuple[list[AcceptedProposal], int]: Accepted proposals for the
373345
generation and the total number of attempts consumed.
346+
347+
Raises:
348+
BaseException: Re-raises any exception raised while collecting
349+
proposals after cancelling the outstanding tasks.
374350
"""
375351

376352
assert request.parallel_executor is not None
@@ -569,6 +545,10 @@ def _finalize_generation(
569545
570546
Returns:
571547
None: This helper does not return a value.
548+
549+
Raises:
550+
UserWarning: Raised when a proposal slot exhausts all attempts
551+
without producing an accepted particle.
572552
"""
573553

574554
with self.config.reporter.create_weight_progress() as progress:

src/calibrationtools/sampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ABCSampler:
4545
generation_particle_count (int): Number of particles to accept per generation for a complete population.
4646
tolerance_values (list[float]): List of tolerance values for each generation for evaluating acceptance criterion.
4747
priors (PriorDistribution | dict | Path): Prior distribution of the parameters being calibrated. Can be provided as a PriorDistribution object, a dictionary, or a path to a JSON file containing a valid priors schema.
48-
particles_to_params (Callable[[Particle], dict]): Function to map particles to model parameters.
48+
particles_to_params (Callable[..., dict]): Function to map particles to model parameters.
4949
outputs_to_distance (Callable[..., float]): Function to compute distance between model outputs and target data.
5050
target_data (Any): Observed data to compare against.
5151
model_runner (MRPModel): Model runner to simulate outputs given parameters.
@@ -92,7 +92,7 @@ def __init__(
9292
generation_particle_count: int,
9393
tolerance_values: list[float],
9494
priors: PriorDistribution | dict | Path,
95-
particles_to_params: Callable[[Particle], dict],
95+
particles_to_params: Callable[..., dict],
9696
outputs_to_distance: Callable[..., float],
9797
target_data: Any,
9898
model_runner: MRPModel,

src/calibrationtools/sampler_reporting.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
from dataclasses import dataclass
8-
from typing import Iterator
98

109
from rich.console import Console
1110
from rich.progress import (
@@ -27,12 +26,9 @@ class ProgressHandle:
2726
This carrier keeps the `Progress` instance and the active task id together
2827
so runners can update progress through a single object.
2928
30-
Args:
29+
Attributes:
3130
progress (Progress): Active Rich progress instance.
3231
task_id (TaskID): Task identifier within that progress instance.
33-
34-
Returns:
35-
None
3632
"""
3733

3834
progress: Progress
@@ -48,30 +44,13 @@ class SamplerReporter:
4844
Args:
4945
verbose (bool): Whether progress and summary output should be visible.
5046
console (Console | None): Optional console override used for tests.
51-
52-
Returns:
53-
None
5447
"""
5548

5649
def __init__(
5750
self,
5851
verbose: bool,
5952
console: Console | None = None,
6053
) -> None:
61-
"""Store the console used for progress and summary output.
62-
63-
This constructor uses a hidden console when `verbose` is false so the
64-
sampler can suppress all Rich output without changing execution flow.
65-
66-
Args:
67-
verbose (bool): Whether progress and summary output should be
68-
visible.
69-
console (Console | None): Optional console override used for tests.
70-
71-
Returns:
72-
None: This constructor does not return a value.
73-
"""
74-
7554
self.console = (
7655
console if console is not None else formatting.get_console(verbose)
7756
)

0 commit comments

Comments
 (0)