Skip to content

Commit b3b6e82

Browse files
authored
Merge pull request #679 from blooop/feature/ty
Feature/ty
2 parents 61917e2 + 45c9477 commit b3b6e82

47 files changed

Lines changed: 368 additions & 278 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,7 @@ docs/jupyter_execute*
187187
thumbnails/
188188
docs/autoapi/*
189189
.qodo
190+
191+
# Auto-generated documentation excluded from type checking
192+
docs/reference/
190193
.devpod/

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ repos:
4848
# Run the formatter.
4949
- id: ruff-format
5050
types_or: [ python, pyi ]
51+
5152
# Checks for spelling mistakes
5253
- repo: https://github.com/codespell-project/codespell
53-
rev: v2.3.0
54+
rev: v2.3.0
5455
hooks:
5556
- id: codespell
5657
args: ['--write-changes','--skip=index.html',"--ignore-words=./codespell-ignore.txt"]

.tyignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
docs/
2+
*.ipynb

bencher/bench_plot_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def load_data_from_cache(self, bench_name: str) -> Tuple[BenchCfg, List[pn.panel
7979
)
8080

8181
def serve(
82-
self, bench_name: str, plots_instance: List[pn.panel], port: int = None, show: bool = True
82+
self,
83+
bench_name: str,
84+
plots_instance: List[pn.panel],
85+
port: int | None = None,
86+
show: bool = True,
8387
) -> Thread:
8488
"""Launch a panel server to view results
8589

bencher/bench_report.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GithubPagesCfg:
2323
class BenchReport(BenchPlotServer):
2424
def __init__(
2525
self,
26-
bench_name: str = None,
26+
bench_name: str | None = None,
2727
) -> None:
2828
self.bench_name = bench_name
2929
self.pane = pn.Tabs(tabs_location="left", name=self.bench_name)
@@ -33,22 +33,24 @@ def append_title(self, title: str, new_tab: bool = True):
3333
return self.append_tab(pn.pane.Markdown(f"# {title}", name=title), title)
3434
return self.append_markdown(f"# {title}", title)
3535

36-
def append_markdown(self, markdown: str, name=None, width=800, **kwargs) -> pn.pane.Markdown:
36+
def append_markdown(
37+
self, markdown: str, name: str | None = None, width: int = 800, **kwargs
38+
) -> pn.pane.Markdown:
3739
if name is None:
3840
name = markdown
3941
md = pn.pane.Markdown(markdown, name=name, width=width, **kwargs)
4042
self.append(md, name)
4143
return md
4244

43-
def append(self, pane: pn.panel, name: str = None) -> None:
45+
def append(self, pane: pn.panel, name: str | None = None) -> None:
4446
if len(self.pane) == 0:
4547
if name is None:
4648
name = pane.name
4749
self.append_tab(pane, name)
4850
else:
4951
self.pane[-1].append(pane)
5052

51-
def append_col(self, pane: pn.panel, name: str = None) -> None:
53+
def append_col(self, pane: pn.panel, name: str | None = None) -> None:
5254
if name is not None:
5355
col = pn.Column(pane, name=name)
5456
else:
@@ -58,13 +60,13 @@ def append_col(self, pane: pn.panel, name: str = None) -> None:
5860
def append_result(self, bench_res: BenchResult) -> None:
5961
self.append_tab(bench_res.plot(), bench_res.bench_cfg.title)
6062

61-
def append_tab(self, pane: pn.panel, name: str = None) -> None:
63+
def append_tab(self, pane: pn.panel, name: str | None = None) -> None:
6264
if pane is not None:
6365
if name is None:
6466
name = pane.name
6567
self.pane.append(pn.Column(pane, name=name))
6668

67-
def save_index(self, directory="", filename="index.html") -> Path:
69+
def save_index(self, directory: str = "", filename: str = "index.html") -> Path:
6870
"""Saves the result to index.html in the root folder so that it can be displayed by github pages.
6971
7072
Returns:
@@ -75,7 +77,7 @@ def save_index(self, directory="", filename="index.html") -> Path:
7577
def save(
7678
self,
7779
directory: str | Path = "cachedir",
78-
filename: str = None,
80+
filename: str | None = None,
7981
in_html_folder: bool = True,
8082
**kwargs,
8183
) -> Path:
@@ -108,7 +110,7 @@ def save(
108110
self.pane.save(filename=base_path, progress=True, embed=True, **kwargs)
109111
return base_path
110112

111-
def show(self, run_cfg: BenchRunCfg = None) -> Thread: # pragma: no cover
113+
def show(self, run_cfg: BenchRunCfg | None = None) -> Thread: # pragma: no cover
112114
"""Launches a webserver with plots of the benchmark results, blocking
113115
114116
Args:
@@ -118,7 +120,8 @@ def show(self, run_cfg: BenchRunCfg = None) -> Thread: # pragma: no cover
118120
if run_cfg is None:
119121
run_cfg = BenchRunCfg()
120122

121-
return BenchPlotServer().plot_server(self.bench_name, run_cfg, self.pane)
123+
bench_name = self.bench_name or ""
124+
return BenchPlotServer().plot_server(bench_name, run_cfg, self.pane)
122125

123126
def publish_gh_pages(
124127
self,
@@ -154,7 +157,7 @@ def publish_gh_pages(
154157
return publish_url
155158

156159
def publish(
157-
self, remote_callback: Callable, branch_name: str = None, debug: bool = False
160+
self, remote_callback: Callable, branch_name: str | None = None, debug: bool = False
158161
) -> str: # pragma: no cover
159162
"""Publish the results as an html file by committing it to the bench_results branch in the current repo. If you have set up your repo with github pages or equivalent then the html file will be served as a viewable webpage. This is an example of a callable to publish on github pages:
160163

bencher/bench_runner.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class BenchRunner:
4242

4343
def __init__(
4444
self,
45-
name: str | Benchable = None,
46-
bench_class: ParametrizedSweep = None,
45+
name: str | Benchable | None = None,
46+
bench_class: ParametrizedSweep | None = None,
4747
run_cfg: BenchRunCfg | None = None,
48-
publisher: Callable = None,
49-
run_tag: str = None,
48+
publisher: Callable | None = None,
49+
run_tag: str | None = None,
5050
) -> None:
5151
"""Initialize a BenchRunner instance.
5252
@@ -242,13 +242,13 @@ def run(
242242
# New unified parameters (level and repeats are starting values)
243243
level: int = 2,
244244
repeats: int = 1,
245-
max_level: int = None,
246-
max_repeats: int = None,
245+
max_level: int | None = None,
246+
max_repeats: int | None = None,
247247
# Legacy parameters for backward compatibility (deprecated)
248-
min_level: int = None,
249-
start_repeats: int = None,
248+
min_level: int | None = None,
249+
start_repeats: int | None = None,
250250
# Other parameters
251-
run_cfg: BenchRunCfg = None,
251+
run_cfg: BenchRunCfg | None = None,
252252
publish: bool = False,
253253
debug: bool = False,
254254
show: bool = False,
@@ -358,6 +358,7 @@ def run(
358358
self.show_publish(report_to_publish, show, publish, save, debug)
359359
self.results.append(res)
360360
if grouped:
361+
assert report_level is not None
361362
self.show_publish(report_level, show, publish, save, debug)
362363
return self.results
363364

@@ -388,7 +389,7 @@ def show_publish(
388389

389390
def show(
390391
self,
391-
report: BenchReport = None,
392+
report: BenchReport | None = None,
392393
show: bool = True,
393394
publish: bool = False,
394395
save: bool = False,

bencher/bencher.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
class Bench(BenchPlotServer):
4747
def __init__(
4848
self,
49-
bench_name: str = None,
50-
worker: Callable | ParametrizedSweep = None,
51-
worker_input_cfg: ParametrizedSweep = None,
52-
run_cfg: BenchRunCfg = None,
53-
report: BenchReport = None,
49+
bench_name: str | None = None,
50+
worker: Callable | ParametrizedSweep | None = None,
51+
worker_input_cfg: ParametrizedSweep | None = None,
52+
run_cfg: BenchRunCfg | None = None,
53+
report: BenchReport | None = None,
5454
) -> None:
5555
"""Create a new Bench object for benchmarking a worker function with parametrized inputs.
5656
@@ -146,7 +146,9 @@ def add_plot_callback(self, callback: Callable[[BenchResult], pn.panel], **kwarg
146146
self.plot_callbacks.append(partial(callback, **kwargs))
147147

148148
def set_worker(
149-
self, worker: Callable | ParametrizedSweep, worker_input_cfg: ParametrizedSweep = None
149+
self,
150+
worker: Callable | ParametrizedSweep,
151+
worker_input_cfg: ParametrizedSweep | None = None,
150152
) -> None:
151153
"""Set the benchmark worker function and its input configuration.
152154
@@ -174,15 +176,15 @@ def set_worker(
174176
def sweep_sequential(
175177
self,
176178
title: str = "",
177-
input_vars: List[ParametrizedSweep] = None,
178-
result_vars: List[ParametrizedSweep] = None,
179-
const_vars: List[ParametrizedSweep] = None,
180-
optimise_var: ParametrizedSweep = None,
181-
run_cfg: BenchRunCfg = None,
179+
input_vars: List[ParametrizedSweep] | None = None,
180+
result_vars: List[ParametrizedSweep] | None = None,
181+
const_vars: List[ParametrizedSweep] | None = None,
182+
optimise_var: ParametrizedSweep | None = None,
183+
run_cfg: BenchRunCfg | None = None,
182184
group_size: int = 1,
183185
iterations: int = 1,
184-
relationship_cb: Callable = None,
185-
plot_callbacks: List[Callable] | bool = None,
186+
relationship_cb: Callable | None = None,
187+
plot_callbacks: List[Callable] | bool | None = None,
186188
) -> List[BenchResult]:
187189
"""Run a sequence of benchmarks by sweeping through groups of input variables.
188190
@@ -234,17 +236,17 @@ def sweep_sequential(
234236

235237
def plot_sweep(
236238
self,
237-
title: str = None,
238-
input_vars: List[ParametrizedSweep] = None,
239-
result_vars: List[ParametrizedSweep] = None,
240-
const_vars: List[ParametrizedSweep] = None,
241-
time_src: datetime = None,
242-
description: str = None,
243-
post_description: str = None,
239+
title: str | None = None,
240+
input_vars: List[ParametrizedSweep] | None = None,
241+
result_vars: List[ParametrizedSweep] | None = None,
242+
const_vars: List[ParametrizedSweep] | None = None,
243+
time_src: datetime | None = None,
244+
description: str | None = None,
245+
post_description: str | None = None,
244246
pass_repeat: bool = False,
245247
tag: str = "",
246-
run_cfg: BenchRunCfg = None,
247-
plot_callbacks: List[Callable] | bool = None,
248+
run_cfg: BenchRunCfg | None = None,
249+
plot_callbacks: List[Callable] | bool | None = None,
248250
sample_order: SampleOrder = SampleOrder.INORDER,
249251
) -> BenchResult:
250252
"""The all-in-one function for benchmarking and results plotting.
@@ -439,7 +441,7 @@ def run_sweep(
439441
self,
440442
bench_cfg: BenchCfg,
441443
run_cfg: BenchRunCfg,
442-
time_src: datetime = None,
444+
time_src: datetime | None = None,
443445
sample_order: SampleOrder = SampleOrder.INORDER,
444446
) -> BenchResult:
445447
"""Execute a benchmark sweep based on the provided configuration.
@@ -538,7 +540,7 @@ def cache_results(self, bench_res: BenchResult, bench_cfg_hash: str) -> None:
538540
"""Cache benchmark results to disk using the config hash as key."""
539541
self._collector.cache_results(bench_res, bench_cfg_hash, self.bench_cfg_hashes)
540542

541-
# def show(self, run_cfg: BenchRunCfg = None, pane: pn.panel = None) -> None:
543+
# def show(self, run_cfg: BenchRunCfg | None = None, pane: pn.panel = None) -> None:
542544
# """Launch a web server with plots of the benchmark results.
543545
#
544546
# This method starts a Panel web server to display the benchmark results interactively.

bencher/example/example_holosweep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def plot_holo(self, plot=True) -> hv.core.ViewableElement:
6969
return None
7070

7171

72-
def example_holosweep(run_cfg: bch.BenchRunCfg = None) -> bch.Bench:
72+
def example_holosweep(run_cfg: bch.BenchRunCfg | None = None) -> bch.Bench:
7373
"""Example using the new one-arg bench signature: bench(run_cfg).
7474
7575
A report is created internally by Bench when not provided.

bencher/example/example_image_vid.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import bencher as bch
33

44

5-
def example_image_vid(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
5+
def example_image_vid(
6+
run_cfg: bch.BenchRunCfg | None = None, report: bch.BenchReport | None = None
7+
) -> bch.Bench:
68
bench = BenchPolygons().to_bench(run_cfg, report)
79
bench.add_plot_callback(bch.BenchResult.to_sweep_summary)
810
bench.add_plot_callback(
@@ -33,8 +35,10 @@ def example_image_vid(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport =
3335

3436
if __name__ == "__main__":
3537

36-
def simple(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench: # pylint: disable=unused-argument
37-
bench = BenchPolygons().to_bench(bch.BenchRunCfg(level=4), report=report)
38+
def simple(
39+
run_cfg: bch.BenchRunCfg | None = None, report: bch.BenchReport | None = None
40+
) -> bch.Bench:
41+
bench = BenchPolygons().to_bench(run_cfg or bch.BenchRunCfg(level=4), report=report)
3842
bench.plot_sweep(input_vars=["sides"])
3943
bench.plot_sweep(input_vars=["sides", "color"])
4044

@@ -45,7 +49,7 @@ def simple(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> b
4549
return bench
4650

4751
def example_image_vid_sequential(
48-
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
52+
run_cfg: bch.BenchRunCfg | None = None, report: bch.BenchReport | None = None
4953
) -> bch.Bench:
5054
bench = BenchPolygons().to_bench(run_cfg, report)
5155
bench.add_plot_callback(bch.BenchResult.to_title)

bencher/example/example_workflow.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def __call__(self, **kwargs):
5858
surf_y_max = -0.2
5959

6060

61-
def example_floats2D_workflow(run_cfg: bch.BenchRunCfg, bench: bch.Bench = None) -> bch.Bench:
61+
def example_floats2D_workflow(
62+
run_cfg: bch.BenchRunCfg, bench: bch.Bench | None = None
63+
) -> bch.Bench:
6264
"""Example of how to perform a 3D floating point parameter sweep
6365
6466
Args:
@@ -93,7 +95,9 @@ def example_floats2D_workflow(run_cfg: bch.BenchRunCfg, bench: bch.Bench = None)
9395
return bench
9496

9597

96-
def example_floats3D_workflow(run_cfg: bch.BenchRunCfg, bench: bch.Bench = None) -> bch.Bench:
98+
def example_floats3D_workflow(
99+
run_cfg: bch.BenchRunCfg, bench: bch.Bench | None = None
100+
) -> bch.Bench:
97101
"""Example of how to perform a 3D floating point parameter sweep
98102
99103
Args:

0 commit comments

Comments
 (0)