holobench 1.19.0__py2.py3-none-any.whl → 1.30.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bencher/__init__.py +12 -1
- bencher/bench_report.py +6 -109
- bencher/bench_runner.py +1 -1
- bencher/bencher.py +103 -57
- bencher/example/benchmark_data.py +0 -4
- bencher/example/example_composable_container.py +106 -0
- bencher/example/example_composable_container2.py +160 -0
- bencher/example/example_consts.py +39 -0
- bencher/example/example_custom_sweep2.py +42 -0
- bencher/example/example_dataframe.py +48 -0
- bencher/example/example_image.py +32 -17
- bencher/example/example_image1.py +81 -0
- bencher/example/example_levels2.py +37 -0
- bencher/example/example_simple_float.py +15 -25
- bencher/example/example_simple_float2d.py +29 -0
- bencher/example/example_strings.py +3 -2
- bencher/example/example_video.py +2 -11
- bencher/example/meta/example_meta.py +2 -2
- bencher/example/meta/example_meta_cat.py +2 -2
- bencher/example/meta/example_meta_float.py +1 -1
- bencher/example/meta/example_meta_levels.py +2 -2
- bencher/optuna_conversions.py +3 -2
- bencher/plotting/plt_cnt_cfg.py +1 -0
- bencher/results/bench_result.py +3 -1
- bencher/results/bench_result_base.py +58 -8
- bencher/results/composable_container/composable_container_base.py +25 -12
- bencher/results/composable_container/composable_container_dataframe.py +52 -0
- bencher/results/composable_container/composable_container_panel.py +17 -18
- bencher/results/composable_container/composable_container_video.py +163 -55
- bencher/results/dataset_result.py +227 -0
- bencher/results/holoview_result.py +15 -7
- bencher/results/optuna_result.py +4 -3
- bencher/results/panel_result.py +1 -1
- bencher/results/video_summary.py +104 -99
- bencher/utils.py +28 -2
- bencher/variables/__init__.py +0 -0
- bencher/variables/inputs.py +24 -1
- bencher/variables/parametrised_sweep.py +6 -4
- bencher/variables/results.py +29 -1
- bencher/variables/time.py +22 -0
- bencher/video_writer.py +20 -74
- {holobench-1.19.0.dist-info → holobench-1.30.0.dist-info}/METADATA +77 -35
- {holobench-1.19.0.dist-info → holobench-1.30.0.dist-info}/RECORD +46 -33
- {holobench-1.19.0.dist-info → holobench-1.30.0.dist-info}/WHEEL +1 -1
- holobench-1.30.0.dist-info/licenses/LICENSE +21 -0
- resource/bencher +0 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
from PIL import Image, ImageDraw
|
3
|
+
from bencher.video_writer import VideoWriter
|
4
|
+
|
5
|
+
|
6
|
+
class BenchImageTest(bch.ParametrizedSweep):
|
7
|
+
character = bch.StringSweep(["a", "b", "c", "d", "e", "f"])
|
8
|
+
r = bch.IntSweep(default=255, bounds=[0, 255])
|
9
|
+
g = bch.IntSweep(default=255, bounds=[0, 255])
|
10
|
+
b = bch.IntSweep(default=255, bounds=[0, 255])
|
11
|
+
width = bch.IntSweep(default=100, bounds=[10, 100])
|
12
|
+
height = bch.IntSweep(default=100, bounds=[10, 100])
|
13
|
+
|
14
|
+
image = bch.ResultImage()
|
15
|
+
|
16
|
+
def __call__(self, **kwargs):
|
17
|
+
self.update_params_from_kwargs(**kwargs)
|
18
|
+
|
19
|
+
img = Image.new("RGB", (self.width, self.height), color=(self.r, self.g, self.b))
|
20
|
+
ImageDraw.Draw(img).text(
|
21
|
+
(self.width / 2.0, self.height / 2.0),
|
22
|
+
self.character,
|
23
|
+
(0, 0, 0),
|
24
|
+
anchor="mm",
|
25
|
+
font_size=self.height,
|
26
|
+
)
|
27
|
+
self.image = bch.gen_image_path()
|
28
|
+
img.save(self.image)
|
29
|
+
return super().__call__(**kwargs)
|
30
|
+
|
31
|
+
|
32
|
+
def bench_image(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
|
33
|
+
bench = BenchImageTest().to_bench(run_cfg, report)
|
34
|
+
bench.sweep_sequential(group_size=1)
|
35
|
+
return bench
|
36
|
+
|
37
|
+
|
38
|
+
class BenchComposableContainerImage(BenchImageTest):
|
39
|
+
compose_method = bch.EnumSweep(bch.ComposeType)
|
40
|
+
labels = bch.BoolSweep()
|
41
|
+
# num_frames = bch.IntSweep(default=5, bounds=[1, 10])
|
42
|
+
# character = bch.StringSweep(["a", "b"])
|
43
|
+
|
44
|
+
text_vid = bch.ResultVideo()
|
45
|
+
frame_width = bch.ResultVar("pixels")
|
46
|
+
frame_height = bch.ResultVar("pixels")
|
47
|
+
duration = bch.ResultVar("S")
|
48
|
+
|
49
|
+
def __call__(self, **kwargs):
|
50
|
+
self.update_params_from_kwargs(**kwargs)
|
51
|
+
# if self.labels:
|
52
|
+
# var_name = "sides"
|
53
|
+
# var_value = self.sides
|
54
|
+
vr = bch.ComposableContainerVideo()
|
55
|
+
|
56
|
+
for c in ["a", "b"]:
|
57
|
+
res = super().__call__(character=c)
|
58
|
+
vr.append(res["image"])
|
59
|
+
|
60
|
+
vid = vr.render(
|
61
|
+
bch.RenderCfg(
|
62
|
+
compose_method=self.compose_method,
|
63
|
+
# var_name=var_name,
|
64
|
+
# var_value=var_value,
|
65
|
+
max_frame_duration=2.0,
|
66
|
+
# max_frame_duration=1.,
|
67
|
+
# duration=1.
|
68
|
+
)
|
69
|
+
)
|
70
|
+
|
71
|
+
self.frame_width, self.frame_height = vid.size
|
72
|
+
self.duration = vid.duration
|
73
|
+
print("RES", self.frame_width, self.frame_height, self.duration)
|
74
|
+
|
75
|
+
self.text_vid = VideoWriter().write_video_raw(vid)
|
76
|
+
return self.get_results_values_as_dict()
|
77
|
+
|
78
|
+
|
79
|
+
# class BenchComposableContainerVideo(bch.ParametrizedSweep):
|
80
|
+
# unequal_length = bch.BoolSweep()
|
81
|
+
# compose_method = bch.EnumSweep(bch.ComposeType)
|
82
|
+
# labels = bch.BoolSweep()
|
83
|
+
# polygon_vid = bch.ResultVideo()
|
84
|
+
|
85
|
+
# def __call__(self, **kwargs):
|
86
|
+
# self.update_params_from_kwargs(**kwargs)
|
87
|
+
# vr = bch.ComposableContainerVideo()
|
88
|
+
# for i in range(3, 5):
|
89
|
+
# num_frames = i * 10 if self.unequal_length else 5
|
90
|
+
# res = BenchComposableContainerImage().__call__(
|
91
|
+
# compose_method=bch.ComposeType.sequence, sides=i, num_frames=num_frames
|
92
|
+
# )
|
93
|
+
# vr.append(res["polygon_vid"])
|
94
|
+
|
95
|
+
# self.polygon_vid = vr.to_video(bch.RenderCfg(compose_method=kwargs.get("compose_method")))
|
96
|
+
# return self.get_results_values_as_dict()
|
97
|
+
|
98
|
+
|
99
|
+
def example_composable_container_image(
|
100
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
101
|
+
) -> bch.Bench:
|
102
|
+
bench = BenchComposableContainerImage().to_bench(run_cfg, report)
|
103
|
+
bench.result_vars = ["text_vid", "duration"]
|
104
|
+
# bench.result_vars = ["duration"]
|
105
|
+
# bench.add_plot_callback(bch.BenchResult.to_panes)
|
106
|
+
# bench.add_plot_callback(bch.BenchResult.to_table)
|
107
|
+
|
108
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, result_types=(bch.ResultVideo))
|
109
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_summary, result_types=(bch.ResultVideo))
|
110
|
+
# bench.plot_sweep(input_vars=["compose_method", "labels"])
|
111
|
+
|
112
|
+
bench.plot_sweep(input_vars=["compose_method"])
|
113
|
+
|
114
|
+
# bench.compose_
|
115
|
+
# bench.plot_sweep(
|
116
|
+
# input_vars=[bch.p("num_frames", [2, 8, 20])],
|
117
|
+
# const_vars=dict(compose_method=bch.ComposeType.sequence),
|
118
|
+
# )
|
119
|
+
|
120
|
+
return bench
|
121
|
+
|
122
|
+
|
123
|
+
# def example_composable_container_video(
|
124
|
+
# run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
125
|
+
# ) -> bch.Bench:
|
126
|
+
# bench = BenchComposableContainerVideo().to_bench(run_cfg, report)
|
127
|
+
|
128
|
+
# bench.result_vars = ["polygon_vid"]
|
129
|
+
# bench.add_plot_callback(bch.BenchResult.to_panes)
|
130
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, result_types=(bch.ResultVideo))
|
131
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_summary, result_types=(bch.ResultVideo))
|
132
|
+
# bench.plot_sweep(input_vars=["compose_method", "labels"], const_vars=dict(unequal_length=True))
|
133
|
+
|
134
|
+
# res = bench.plot_sweep(
|
135
|
+
# input_vars=[],
|
136
|
+
# const_vars=dict(unequal_length=False, compose_method=bch.ComposeType.sequence),
|
137
|
+
# plot_callbacks=False,
|
138
|
+
# )
|
139
|
+
|
140
|
+
# bench.report.append(res.to_video_grid())
|
141
|
+
|
142
|
+
# return bench
|
143
|
+
|
144
|
+
|
145
|
+
# if __name__ == "__main__":
|
146
|
+
# ex_run_cfg = bch.BenchRunCfg()
|
147
|
+
# ex_run_cfg.use_sample_cache = False
|
148
|
+
# # ex_run_cfg.level = 2
|
149
|
+
# ex_report = bch.BenchReport()
|
150
|
+
# example_composable_container_image(ex_run_cfg, report=ex_report)
|
151
|
+
# # example_composable_container_video(ex_run_cfg, report=ex_report)
|
152
|
+
# ex_report.show()
|
153
|
+
|
154
|
+
|
155
|
+
if __name__ == "__main__":
|
156
|
+
bench_runner = bch.BenchRunner("ImageChar")
|
157
|
+
# bench_runner.add_run(bench_image)
|
158
|
+
bench_runner.add_run(example_composable_container_image)
|
159
|
+
|
160
|
+
bench_runner.run(level=6, show=True, use_cache=False)
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"""This file contains examples for how to perform basic 2D benchmarking parameter sweeps"""
|
2
|
+
|
3
|
+
import math
|
4
|
+
import bencher as bch
|
5
|
+
|
6
|
+
|
7
|
+
class SimpleFloat(bch.ParametrizedSweep):
|
8
|
+
theta = bch.FloatSweep(
|
9
|
+
default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30
|
10
|
+
)
|
11
|
+
offset = bch.FloatSweep(default=0, bounds=[0, 1], doc="Input angle offset", units="rad")
|
12
|
+
noise = bch.FloatSweep(default=0, bounds=[0, 1], doc="noise", units="rad")
|
13
|
+
out_sin = bch.ResultVar(units="v", doc="sin of theta")
|
14
|
+
|
15
|
+
def __call__(self, **kwargs):
|
16
|
+
self.update_params_from_kwargs(**kwargs)
|
17
|
+
self.out_sin = math.sin(self.theta) + self.offset + self.noise
|
18
|
+
return super().__call__(**kwargs)
|
19
|
+
|
20
|
+
|
21
|
+
def example_2D_float_const(
|
22
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
23
|
+
) -> bch.Bench:
|
24
|
+
"""This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
|
25
|
+
|
26
|
+
bench = SimpleFloat().to_bench(run_cfg, report)
|
27
|
+
const_vars = SimpleFloat().get_input_defaults_override(offset=0.5)
|
28
|
+
bench.plot_sweep(input_vars=["theta"], const_vars=const_vars)
|
29
|
+
|
30
|
+
const_vars = SimpleFloat().get_input_defaults_override(noise=0.2)
|
31
|
+
bench.plot_sweep(input_vars=["theta"], const_vars=const_vars)
|
32
|
+
|
33
|
+
bench.plot_sweep(input_vars=["theta"], const_vars=dict(offset=0.3))
|
34
|
+
|
35
|
+
return bench
|
36
|
+
|
37
|
+
|
38
|
+
if __name__ == "__main__":
|
39
|
+
example_2D_float_const().report.show()
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
|
3
|
+
|
4
|
+
class Square(bch.ParametrizedSweep):
|
5
|
+
"""An example of a datatype with an integer and float parameter"""
|
6
|
+
|
7
|
+
x = bch.FloatSweep(default=0, bounds=[0, 6])
|
8
|
+
|
9
|
+
result = bch.ResultVar("ul", doc="Square of x")
|
10
|
+
|
11
|
+
def __call__(self, **kwargs) -> dict:
|
12
|
+
self.update_params_from_kwargs(**kwargs)
|
13
|
+
self.result = self.x * self.x
|
14
|
+
return self.get_results_values_as_dict()
|
15
|
+
|
16
|
+
|
17
|
+
def example_custom_sweep2(
|
18
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
19
|
+
) -> bch.Bench:
|
20
|
+
"""This example shows how to define a custom set of value to sample from intead of a uniform sweep
|
21
|
+
|
22
|
+
Args:
|
23
|
+
run_cfg (BenchRunCfg): configuration of how to perform the param sweep
|
24
|
+
|
25
|
+
Returns:
|
26
|
+
Bench: results of the parameter sweep
|
27
|
+
"""
|
28
|
+
|
29
|
+
bench = Square().to_bench(run_cfg=run_cfg, report=report)
|
30
|
+
|
31
|
+
# These are all equivalent
|
32
|
+
bench.plot_sweep(input_vars=[Square.param.x.with_sample_values([0, 1, 2])])
|
33
|
+
bench.plot_sweep(input_vars=[bch.p("x", [4, 5, 6])])
|
34
|
+
|
35
|
+
bench.plot_sweep(input_vars=[bch.p("x", samples=5)])
|
36
|
+
bench.plot_sweep(input_vars=[bch.p("x", samples=6)])
|
37
|
+
|
38
|
+
return bench
|
39
|
+
|
40
|
+
|
41
|
+
if __name__ == "__main__":
|
42
|
+
example_custom_sweep2().report.show()
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
|
3
|
+
import xarray as xr
|
4
|
+
import numpy as np
|
5
|
+
import holoviews as hv
|
6
|
+
|
7
|
+
|
8
|
+
class ExampleMergeDataset(bch.ParametrizedSweep):
|
9
|
+
|
10
|
+
value = bch.FloatSweep(default=0, bounds=[0, 10])
|
11
|
+
repeats_x = bch.IntSweep(default=2, bounds=[2, 4])
|
12
|
+
# repeats_y = bch.IntSweep(default=2, bounds=[2, 4])
|
13
|
+
|
14
|
+
result_df = bch.ResultDataSet()
|
15
|
+
|
16
|
+
def __call__(self, **kwargs):
|
17
|
+
self.update_params_from_kwargs(**kwargs)
|
18
|
+
# First, create a DataArray from the vector
|
19
|
+
vector = [v + self.value for v in range(1, self.repeats_x)]
|
20
|
+
data_array = xr.DataArray(vector, dims=["index"], coords={"index": np.arange(len(vector))})
|
21
|
+
# Convert the DataArray to a Dataset
|
22
|
+
result_df = xr.Dataset({"result_df": data_array})
|
23
|
+
self.result_df = bch.ResultDataSet(result_df.to_pandas())
|
24
|
+
return super().__call__(**kwargs)
|
25
|
+
|
26
|
+
|
27
|
+
def example_dataset(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None):
|
28
|
+
bench = ExampleMergeDataset().to_bench(run_cfg, report)
|
29
|
+
res = bench.plot_sweep(input_vars=["value"], const_vars=dict(repeats_x=4))
|
30
|
+
# bench.report.append(res.to_panes(target_dimension=1))
|
31
|
+
# bench.report.append(res.to_panes(target_dimension=2))
|
32
|
+
# bench.reprt.append(res.to_video_grid
|
33
|
+
# # bch.BenchResult.to_video_grid,
|
34
|
+
# target_duration=0.06,
|
35
|
+
# compose_method_list=[
|
36
|
+
# bch.ComposeType.right,
|
37
|
+
# bch.ComposeType.right,
|
38
|
+
# bch.ComposeType.sequence,
|
39
|
+
# ],
|
40
|
+
# )
|
41
|
+
# bench.report.append(res.to_panes(container=hv.Bars,target_dimension=1))
|
42
|
+
# bench.report.append(res.to_panes(container=hv.Curve))
|
43
|
+
bench.report.append(res.to_dataset1(container=hv.Curve))
|
44
|
+
return bench
|
45
|
+
|
46
|
+
|
47
|
+
if __name__ == "__main__":
|
48
|
+
example_dataset().report.show()
|
bencher/example/example_image.py
CHANGED
@@ -4,10 +4,11 @@ import math
|
|
4
4
|
import matplotlib.pyplot as plt
|
5
5
|
|
6
6
|
|
7
|
-
def polygon_points(radius: float, sides: int):
|
7
|
+
def polygon_points(radius: float, sides: int, start_angle: float):
|
8
8
|
points = []
|
9
|
-
for ang in np.linspace(0,
|
10
|
-
|
9
|
+
for ang in np.linspace(0, 360, sides + 1):
|
10
|
+
angle = math.radians(start_angle + ang)
|
11
|
+
points.append(([math.sin(angle) * radius, math.cos(angle) * radius]))
|
11
12
|
return points
|
12
13
|
|
13
14
|
|
@@ -17,16 +18,16 @@ class BenchPolygons(bch.ParametrizedSweep):
|
|
17
18
|
linewidth = bch.FloatSweep(default=1, bounds=(1, 10))
|
18
19
|
linestyle = bch.StringSweep(["solid", "dashed", "dotted"])
|
19
20
|
color = bch.StringSweep(["red", "green", "blue"])
|
21
|
+
start_angle = bch.FloatSweep(default=0, bounds=[0, 360])
|
20
22
|
polygon = bch.ResultImage()
|
21
23
|
area = bch.ResultVar()
|
22
24
|
side_length = bch.ResultVar()
|
23
25
|
|
24
26
|
def __call__(self, **kwargs):
|
25
27
|
self.update_params_from_kwargs(**kwargs)
|
26
|
-
points = polygon_points(self.radius, self.sides)
|
28
|
+
points = polygon_points(self.radius, self.sides, self.start_angle)
|
27
29
|
# self.hmap = hv.Curve(points)
|
28
30
|
self.polygon = self.points_to_polygon_png(points, bch.gen_image_path("polygon"))
|
29
|
-
self.area = self.radius * self.sides
|
30
31
|
|
31
32
|
self.side_length = 2 * self.radius * math.sin(math.pi / self.sides)
|
32
33
|
self.area = (self.sides * self.side_length**2) / (4 * math.tan(math.pi / self.sides))
|
@@ -82,15 +83,31 @@ def example_image(
|
|
82
83
|
return bench
|
83
84
|
|
84
85
|
|
85
|
-
def example_image_vid(
|
86
|
-
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
87
|
-
) -> bch.Bench:
|
86
|
+
def example_image_vid(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
|
88
87
|
bench = BenchPolygons().to_bench(run_cfg, report)
|
89
88
|
bench.add_plot_callback(bch.BenchResult.to_sweep_summary)
|
90
|
-
bench.add_plot_callback(
|
91
|
-
|
89
|
+
bench.add_plot_callback(
|
90
|
+
bch.BenchResult.to_video_grid,
|
91
|
+
target_duration=0.06,
|
92
|
+
compose_method_list=[
|
93
|
+
bch.ComposeType.right,
|
94
|
+
bch.ComposeType.right,
|
95
|
+
bch.ComposeType.sequence,
|
96
|
+
],
|
97
|
+
)
|
98
|
+
# from functools import partial
|
99
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_summary)
|
100
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, time_sequence_dimension=0)
|
101
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid)
|
102
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, time_sequence_dimension=2)
|
103
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, time_sequence_dimension=3)
|
104
|
+
|
105
|
+
bench.plot_sweep(input_vars=["radius"])
|
106
|
+
# res = bench.plot_sweep(input_vars=["radius"], plot=False)
|
107
|
+
# bench.report.append(res.to_video_grid(target_duration=0.06))
|
92
108
|
bench.plot_sweep(input_vars=["radius", "sides"])
|
93
|
-
bench.plot_sweep(input_vars=["radius", "sides", "linewidth"])
|
109
|
+
# bench.plot_sweep(input_vars=["radius", "sides", "linewidth"])
|
110
|
+
# bench.plot_sweep(input_vars=["radius", "sides", "linewidth", "color"])
|
94
111
|
|
95
112
|
return bench
|
96
113
|
|
@@ -104,14 +121,12 @@ if __name__ == "__main__":
|
|
104
121
|
|
105
122
|
# res = bench.sweep(input_vars=["sides", "radius"])
|
106
123
|
|
107
|
-
# bench.report.append(res.to_heatmap(target_dimension=3))
|
108
|
-
|
109
124
|
bench.plot_sweep(input_vars=["sides"])
|
110
125
|
bench.plot_sweep(input_vars=["sides", "color"])
|
111
126
|
|
112
|
-
bench.plot_sweep(input_vars=["sides", "radius"])
|
113
|
-
|
114
|
-
|
127
|
+
res = bench.plot_sweep(input_vars=["sides", "radius"])
|
128
|
+
bench.report.append(res.to_heatmap(target_dimension=3))
|
129
|
+
bench.report.append(res.to_line(target_dimension=1))
|
115
130
|
|
116
131
|
return bench
|
117
132
|
|
@@ -131,7 +146,7 @@ if __name__ == "__main__":
|
|
131
146
|
# ex_run_cfg.debug = True
|
132
147
|
# ex_run_cfg.repeats = 2
|
133
148
|
ex_run_cfg.level = 4
|
134
|
-
example_image_vid(ex_run_cfg).report.show()
|
149
|
+
# example_image_vid(ex_run_cfg).report.show()
|
135
150
|
simple().report.show()
|
136
151
|
|
137
152
|
# example_image_vid_sequential(ex_run_cfg).report.show()
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
import numpy as np
|
3
|
+
import math
|
4
|
+
import matplotlib.pyplot as plt
|
5
|
+
|
6
|
+
|
7
|
+
def polygon_points(radius: float, sides: int, start_angle: float):
|
8
|
+
points = []
|
9
|
+
for ang in np.linspace(0, 360, sides + 1):
|
10
|
+
angle = math.radians(start_angle + ang)
|
11
|
+
points.append(([math.sin(angle) * radius, math.cos(angle) * radius]))
|
12
|
+
return points
|
13
|
+
|
14
|
+
|
15
|
+
class BenchPolygons(bch.ParametrizedSweep):
|
16
|
+
sides = bch.IntSweep(default=3, bounds=(3, 7))
|
17
|
+
radius = bch.FloatSweep(default=1, bounds=(0.2, 1))
|
18
|
+
linewidth = bch.FloatSweep(default=1, bounds=(1, 10))
|
19
|
+
linestyle = bch.StringSweep(["solid", "dashed", "dotted"])
|
20
|
+
color = bch.StringSweep(["red", "green", "blue"])
|
21
|
+
start_angle = bch.FloatSweep(default=0, bounds=[0, 360])
|
22
|
+
polygon = bch.ResultImage()
|
23
|
+
polygon_small = bch.ResultImage()
|
24
|
+
|
25
|
+
area = bch.ResultVar()
|
26
|
+
side_length = bch.ResultVar()
|
27
|
+
|
28
|
+
def __call__(self, **kwargs):
|
29
|
+
self.update_params_from_kwargs(**kwargs)
|
30
|
+
points = polygon_points(self.radius, self.sides, self.start_angle)
|
31
|
+
# self.hmap = hv.Curve(points)
|
32
|
+
self.polygon = self.points_to_polygon_png(points, bch.gen_image_path("polygon"), dpi=30)
|
33
|
+
self.polygon_small = self.points_to_polygon_png(
|
34
|
+
points, bch.gen_image_path("polygon"), dpi=10
|
35
|
+
)
|
36
|
+
|
37
|
+
self.side_length = 2 * self.radius * math.sin(math.pi / self.sides)
|
38
|
+
self.area = (self.sides * self.side_length**2) / (4 * math.tan(math.pi / self.sides))
|
39
|
+
return super().__call__()
|
40
|
+
|
41
|
+
def points_to_polygon_png(self, points: list[float], filename: str, dpi):
|
42
|
+
"""Draw a closed polygon and save to png"""
|
43
|
+
fig = plt.figure(frameon=False)
|
44
|
+
ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0], frameon=False)
|
45
|
+
ax.set_axis_off()
|
46
|
+
ax.plot(
|
47
|
+
[p[0] for p in points],
|
48
|
+
[p[1] for p in points],
|
49
|
+
linewidth=self.linewidth,
|
50
|
+
linestyle=self.linestyle,
|
51
|
+
color=self.color,
|
52
|
+
)
|
53
|
+
ax.set_xlim(-1, 1)
|
54
|
+
ax.set_ylim(-1, 1)
|
55
|
+
|
56
|
+
ax.set_aspect("equal")
|
57
|
+
fig.add_axes(ax)
|
58
|
+
fig.savefig(filename, dpi=dpi)
|
59
|
+
|
60
|
+
return filename
|
61
|
+
|
62
|
+
|
63
|
+
def example_image_vid_sequential1(
|
64
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
65
|
+
) -> bch.Bench:
|
66
|
+
bench = BenchPolygons().to_bench(run_cfg, report)
|
67
|
+
res = bench.plot_sweep(input_vars=["sides"])
|
68
|
+
|
69
|
+
bench.report.append(res.to_panes(zip_results=True))
|
70
|
+
|
71
|
+
return bench
|
72
|
+
|
73
|
+
|
74
|
+
if __name__ == "__main__":
|
75
|
+
|
76
|
+
ex_run_cfg = bch.BenchRunCfg()
|
77
|
+
ex_run_cfg.use_sample_cache = True
|
78
|
+
ex_run_cfg.overwrite_sample_cache = True
|
79
|
+
ex_run_cfg.level = 3
|
80
|
+
|
81
|
+
example_image_vid_sequential1(ex_run_cfg).report.show()
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
|
3
|
+
|
4
|
+
class Square(bch.ParametrizedSweep):
|
5
|
+
"""An example of a datatype with an integer and float parameter"""
|
6
|
+
|
7
|
+
x = bch.FloatSweep(default=0, bounds=[0, 6])
|
8
|
+
|
9
|
+
result = bch.ResultVar("ul", doc="Square of x")
|
10
|
+
|
11
|
+
def __call__(self, **kwargs) -> dict:
|
12
|
+
self.update_params_from_kwargs(**kwargs)
|
13
|
+
self.result = self.x * self.x
|
14
|
+
return self.get_results_values_as_dict()
|
15
|
+
|
16
|
+
|
17
|
+
def example_levels2(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
|
18
|
+
"""This example shows how to define a custom set of value to sample from intead of a uniform sweep
|
19
|
+
|
20
|
+
Args:
|
21
|
+
run_cfg (BenchRunCfg): configuration of how to perform the param sweep
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
Bench: results of the parameter sweep
|
25
|
+
"""
|
26
|
+
|
27
|
+
bench = Square().to_bench(run_cfg=run_cfg, report=report)
|
28
|
+
|
29
|
+
# These are all equivalent
|
30
|
+
bench.plot_sweep(input_vars=[Square.param.x.with_level(run_cfg.level, 3)])
|
31
|
+
bench.plot_sweep(input_vars=[bch.p("x", max_level=3)])
|
32
|
+
|
33
|
+
return bench
|
34
|
+
|
35
|
+
|
36
|
+
if __name__ == "__main__":
|
37
|
+
example_levels2(bch.BenchRunCfg(level=4)).report.show()
|
@@ -1,38 +1,28 @@
|
|
1
1
|
"""This file has some examples for how to perform basic benchmarking parameter sweeps"""
|
2
2
|
|
3
|
+
import math
|
3
4
|
import bencher as bch
|
4
5
|
|
5
|
-
# All the examples will be using the data structures and benchmark function defined in this file
|
6
|
-
from bencher.example.benchmark_data import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
|
7
6
|
|
7
|
+
class SimpleFloat(bch.ParametrizedSweep):
|
8
|
+
theta = bch.FloatSweep(
|
9
|
+
default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30
|
10
|
+
)
|
11
|
+
out_sin = bch.ResultVar(units="v", doc="sin of theta")
|
8
12
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
def __call__(self, **kwargs):
|
14
|
+
self.update_params_from_kwargs(**kwargs)
|
15
|
+
self.out_sin = math.sin(self.theta)
|
16
|
+
return super().__call__(**kwargs)
|
13
17
|
|
14
|
-
bench = bch.Bench(
|
15
|
-
"benchmarking_example_float1D",
|
16
|
-
bench_function,
|
17
|
-
ExampleBenchCfgIn,
|
18
|
-
run_cfg=run_cfg,
|
19
|
-
report=report,
|
20
|
-
)
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
title="Example 1D Float",
|
25
|
-
input_vars=[ExampleBenchCfgIn.param.theta],
|
26
|
-
result_vars=[ExampleBenchCfgOut.param.out_sin],
|
27
|
-
description=example_1D_float.__doc__,
|
28
|
-
)
|
19
|
+
def example_1D_float(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
|
20
|
+
"""This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
|
29
21
|
|
22
|
+
bench = SimpleFloat().to_bench(run_cfg, report)
|
23
|
+
bench.plot_sweep()
|
30
24
|
return bench
|
31
25
|
|
32
26
|
|
33
27
|
if __name__ == "__main__":
|
34
|
-
|
35
|
-
ex_run_cfg.repeats = 2
|
36
|
-
# ex_run_cfg.over_time = True
|
37
|
-
|
38
|
-
example_1D_float(ex_run_cfg).report.show()
|
28
|
+
example_1D_float().report.show()
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"""This file contains examples for how to perform basic 2D benchmarking parameter sweeps"""
|
2
|
+
|
3
|
+
import math
|
4
|
+
import bencher as bch
|
5
|
+
|
6
|
+
|
7
|
+
class SimpleFloat(bch.ParametrizedSweep):
|
8
|
+
theta = bch.FloatSweep(
|
9
|
+
default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30
|
10
|
+
)
|
11
|
+
offset = bch.FloatSweep(default=0, bounds=[0, 1], doc="Input angle", units="rad")
|
12
|
+
out_sin = bch.ResultVar(units="v", doc="sin of theta")
|
13
|
+
|
14
|
+
def __call__(self, **kwargs):
|
15
|
+
self.update_params_from_kwargs(**kwargs)
|
16
|
+
self.out_sin = math.sin(self.theta) + self.offset
|
17
|
+
return super().__call__(**kwargs)
|
18
|
+
|
19
|
+
|
20
|
+
def example_2D_float(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
|
21
|
+
"""This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
|
22
|
+
|
23
|
+
bench = SimpleFloat().to_bench(run_cfg, report)
|
24
|
+
bench.plot_sweep()
|
25
|
+
return bench
|
26
|
+
|
27
|
+
|
28
|
+
if __name__ == "__main__":
|
29
|
+
example_2D_float().report.show()
|
@@ -21,6 +21,9 @@ class TestPrinting(bch.ParametrizedSweep):
|
|
21
21
|
self.result += f",{self.c}"
|
22
22
|
if self.d is not None:
|
23
23
|
self.result += f",{self.d}"
|
24
|
+
self.result += "\n\ttab\n\t\ttab2"
|
25
|
+
|
26
|
+
self.result = bch.tabs_in_markdown(self.result)
|
24
27
|
return super().__call__()
|
25
28
|
|
26
29
|
|
@@ -36,8 +39,6 @@ def example_strings(
|
|
36
39
|
[TestPrinting.param.a, TestPrinting.param.b, TestPrinting.param.c, TestPrinting.param.d],
|
37
40
|
]:
|
38
41
|
bench.plot_sweep(f"String Panes {[v.name for v in s]}", input_vars=s)
|
39
|
-
# bench.report.append(res.to_sweep_summary())
|
40
|
-
# bench.report.append(res.to_panes())
|
41
42
|
|
42
43
|
return bench
|
43
44
|
|
bencher/example/example_video.py
CHANGED
@@ -95,24 +95,15 @@ def example_video(
|
|
95
95
|
def example_video_tap(
|
96
96
|
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
97
97
|
) -> bch.Bench: # pragma: no cover
|
98
|
-
|
99
|
-
|
100
|
-
# run_cfg.use_sample_cache = False
|
101
|
-
# run_cfg.use_optuna = True
|
102
|
-
run_cfg.auto_plot = False
|
103
|
-
run_cfg.run_tag = "3"
|
104
|
-
bench = tp.to_bench(run_cfg=run_cfg, report=report)
|
105
|
-
|
98
|
+
bench = TuringPattern().to_bench(run_cfg=run_cfg, report=report)
|
106
99
|
res = bench.plot_sweep(
|
107
|
-
"phase",
|
108
100
|
input_vars=["alpha", "beta"],
|
109
101
|
# result_vars=["video","score"],
|
110
102
|
# result_vars=["score"],
|
111
103
|
run_cfg=run_cfg,
|
112
104
|
)
|
113
105
|
|
114
|
-
bench.report.append(res.
|
115
|
-
bench.report.append(res.to_heatmap())
|
106
|
+
bench.report.append(res.to_video_grid())
|
116
107
|
|
117
108
|
return bench
|
118
109
|
|
@@ -151,9 +151,9 @@ def example_meta(
|
|
151
151
|
description="""## All Combinations of Variable Sweeps and Resulting Plots
|
152
152
|
This uses bencher to display all the combinatios of plots bencher is able to produce""",
|
153
153
|
input_vars=[
|
154
|
-
|
154
|
+
bch.p("float_vars", [0, 1, 2, 3]),
|
155
155
|
BenchMeta.param.categorical_vars,
|
156
|
-
|
156
|
+
bch.p("sample_with_repeats", [1, 2]),
|
157
157
|
# BenchMeta.param.sample_over_time,
|
158
158
|
],
|
159
159
|
const_vars=[
|
@@ -10,8 +10,8 @@ def example_meta_cat(
|
|
10
10
|
bench.plot_sweep(
|
11
11
|
title="Sweeping Categorical Variables",
|
12
12
|
input_vars=[
|
13
|
-
|
14
|
-
|
13
|
+
bch.p("categorical_vars", [1, 2, 3]),
|
14
|
+
bch.p("sample_with_repeats", [1, 2]),
|
15
15
|
],
|
16
16
|
const_vars=[
|
17
17
|
BenchMeta.param.float_vars.with_const(0),
|
@@ -9,7 +9,7 @@ def example_meta_float(
|
|
9
9
|
|
10
10
|
bench.plot_sweep(
|
11
11
|
title="Sweeping Floating Point Variables",
|
12
|
-
input_vars=[
|
12
|
+
input_vars=[bch.p("float_vars", [1, 2, 3])],
|
13
13
|
const_vars=[
|
14
14
|
BenchMeta.param.categorical_vars.with_const(0),
|
15
15
|
BenchMeta.param.level.with_const(3),
|