holobench 1.25.2__py3-none-any.whl → 1.26.3__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/example/__init__.py +0 -0
- bencher/example/benchmark_data.py +196 -0
- bencher/example/example_all.py +45 -0
- bencher/example/example_categorical.py +99 -0
- 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_sweep.py +59 -0
- bencher/example/example_custom_sweep2.py +42 -0
- bencher/example/example_docs.py +34 -0
- bencher/example/example_filepath.py +27 -0
- bencher/example/example_float3D.py +101 -0
- bencher/example/example_float_cat.py +99 -0
- bencher/example/example_floats.py +89 -0
- bencher/example/example_floats2D.py +93 -0
- bencher/example/example_holosweep.py +98 -0
- bencher/example/example_holosweep_objects.py +111 -0
- bencher/example/example_holosweep_tap.py +144 -0
- bencher/example/example_image.py +155 -0
- bencher/example/example_levels.py +181 -0
- bencher/example/example_levels2.py +37 -0
- bencher/example/example_pareto.py +53 -0
- bencher/example/example_sample_cache.py +85 -0
- bencher/example/example_sample_cache_context.py +116 -0
- bencher/example/example_simple.py +134 -0
- bencher/example/example_simple_bool.py +35 -0
- bencher/example/example_simple_cat.py +48 -0
- bencher/example/example_simple_float.py +28 -0
- bencher/example/example_simple_float2d.py +29 -0
- bencher/example/example_strings.py +47 -0
- bencher/example/example_time_event.py +63 -0
- bencher/example/example_video.py +118 -0
- bencher/example/example_workflow.py +189 -0
- bencher/example/experimental/example_bokeh_plotly.py +38 -0
- bencher/example/experimental/example_hover_ex.py +45 -0
- bencher/example/experimental/example_hvplot_explorer.py +39 -0
- bencher/example/experimental/example_interactive.py +75 -0
- bencher/example/experimental/example_streamnd.py +49 -0
- bencher/example/experimental/example_streams.py +36 -0
- bencher/example/experimental/example_template.py +40 -0
- bencher/example/experimental/example_updates.py +84 -0
- bencher/example/experimental/example_vector.py +84 -0
- bencher/example/meta/example_meta.py +171 -0
- bencher/example/meta/example_meta_cat.py +25 -0
- bencher/example/meta/example_meta_float.py +23 -0
- bencher/example/meta/example_meta_levels.py +26 -0
- bencher/example/optuna/example_optuna.py +78 -0
- bencher/example/shelved/example_float2D_scatter.py +109 -0
- bencher/example/shelved/example_float3D_cone.py +96 -0
- bencher/example/shelved/example_kwargs.py +63 -0
- bencher/plotting/__init__.py +0 -0
- bencher/plotting/plot_filter.py +110 -0
- bencher/plotting/plt_cnt_cfg.py +75 -0
- bencher/results/__init__.py +0 -0
- bencher/results/bench_result.py +94 -0
- bencher/results/bench_result_base.py +476 -0
- bencher/results/composable_container/__init__.py +0 -0
- bencher/results/composable_container/composable_container_base.py +73 -0
- bencher/results/composable_container/composable_container_panel.py +39 -0
- bencher/results/composable_container/composable_container_video.py +184 -0
- bencher/results/float_formatter.py +44 -0
- bencher/results/holoview_result.py +753 -0
- bencher/results/optuna_result.py +354 -0
- bencher/results/panel_result.py +41 -0
- bencher/results/plotly_result.py +65 -0
- bencher/results/video_result.py +38 -0
- bencher/results/video_summary.py +222 -0
- bencher/variables/__init__.py +0 -0
- bencher/variables/inputs.py +202 -0
- bencher/variables/parametrised_sweep.py +208 -0
- bencher/variables/results.py +214 -0
- bencher/variables/sweep_base.py +162 -0
- bencher/variables/time.py +92 -0
- holobench-1.26.3.data/data/share/ament_index/resource_index/packages/bencher +0 -0
- holobench-1.26.3.data/data/share/bencher/package.xml +33 -0
- {holobench-1.25.2.dist-info → holobench-1.26.3.dist-info}/METADATA +5 -5
- holobench-1.26.3.dist-info/RECORD +93 -0
- holobench-1.25.2.dist-info/RECORD +0 -18
- {holobench-1.25.2.dist-info → holobench-1.26.3.dist-info}/LICENSE +0 -0
- {holobench-1.25.2.dist-info → holobench-1.26.3.dist-info}/WHEEL +0 -0
- {holobench-1.25.2.dist-info → holobench-1.26.3.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,196 @@
|
|
1
|
+
"""This file contains an example of how to define benchmarking parameters sweeps. Categorical values are defined as enums and passed to EnumSweep classes, other types of sweeps are defined by their respective classes.
|
2
|
+
|
3
|
+
You can define a subclass which contains an input configuration which can be passed to a function in a type safe way. You can combine the subclass with a higher level class which contains more configuation parameters. This is to help manage the complexity of large configuration/parameter spaces.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import math
|
7
|
+
import random
|
8
|
+
from enum import auto
|
9
|
+
from strenum import StrEnum
|
10
|
+
from bencher.variables.inputs import IntSweep, FloatSweep, StringSweep, EnumSweep, BoolSweep
|
11
|
+
from bencher.variables.results import ResultVar, OptDir
|
12
|
+
from bencher.variables.parametrised_sweep import ParametrizedSweep
|
13
|
+
|
14
|
+
|
15
|
+
class PostprocessFn(StrEnum):
|
16
|
+
"""Apply a postprocessing step to the data"""
|
17
|
+
|
18
|
+
absolute = auto() # return the abs of the output data
|
19
|
+
negate = auto() # return the negative of the output data
|
20
|
+
|
21
|
+
|
22
|
+
class NoiseDistribution(StrEnum):
|
23
|
+
"""A categorical variable describing the types of random noise"""
|
24
|
+
|
25
|
+
uniform = auto() # uniform random noiase
|
26
|
+
gaussian = auto() # gaussian noise
|
27
|
+
lognorm = auto() # lognorm noise
|
28
|
+
|
29
|
+
|
30
|
+
class NoiseCfg(ParametrizedSweep):
|
31
|
+
"""A class for storing the parameters for generating various types of noise"""
|
32
|
+
|
33
|
+
noisy = BoolSweep(
|
34
|
+
default=False, doc="Optionally add random noise to the output of the function"
|
35
|
+
)
|
36
|
+
|
37
|
+
noise_distribution = EnumSweep(NoiseDistribution, doc=NoiseDistribution.__doc__)
|
38
|
+
|
39
|
+
sigma = FloatSweep(
|
40
|
+
default=1,
|
41
|
+
bounds=[0, 10],
|
42
|
+
doc="The standard deviation of the noise",
|
43
|
+
units="v",
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
def calculate_noise(config: NoiseCfg) -> float:
|
48
|
+
"""Generate a float value based on a noise distribution and scale
|
49
|
+
|
50
|
+
Args:
|
51
|
+
config (NoiseCfg): see NoiseCfg type
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
float: a noisy float value
|
55
|
+
"""
|
56
|
+
|
57
|
+
noise = 0.0
|
58
|
+
if config.noisy:
|
59
|
+
match config.noise_distribution:
|
60
|
+
case NoiseDistribution.uniform:
|
61
|
+
noise = random.uniform(0, config.sigma)
|
62
|
+
case NoiseDistribution.gaussian:
|
63
|
+
noise = random.gauss(0, config.sigma)
|
64
|
+
case NoiseDistribution.lognorm:
|
65
|
+
noise = random.lognormvariate(0, config.sigma)
|
66
|
+
|
67
|
+
return noise
|
68
|
+
|
69
|
+
|
70
|
+
class ExampleBenchCfgIn(NoiseCfg):
|
71
|
+
"""A class for representing a set of configuration options for the example worker. This class inherits from NoiseCfg so it also stores all its values as well."""
|
72
|
+
|
73
|
+
theta = FloatSweep(default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30)
|
74
|
+
offset = FloatSweep(default=0, bounds=[0, 0.3], doc="dc offset", units="v", samples=30)
|
75
|
+
postprocess_fn = EnumSweep(PostprocessFn)
|
76
|
+
|
77
|
+
|
78
|
+
class ExampleBenchCfgOut(ParametrizedSweep):
|
79
|
+
out_sin = ResultVar(units="v", direction=OptDir.minimize, doc="sin of theta with some noise")
|
80
|
+
out_cos = ResultVar(units="v", direction=OptDir.minimize, doc="cos of theta with some noise")
|
81
|
+
out_bool = ResultVar(units="%", doc="sin > 0.5")
|
82
|
+
|
83
|
+
|
84
|
+
def negate_fn(fn_input: float):
|
85
|
+
"""returns the negative of the input
|
86
|
+
|
87
|
+
Args:
|
88
|
+
fn_input (float): any float value
|
89
|
+
|
90
|
+
Returns:
|
91
|
+
float: negative of the input
|
92
|
+
"""
|
93
|
+
return -fn_input
|
94
|
+
|
95
|
+
|
96
|
+
def bench_function(cfg: ExampleBenchCfgIn) -> ExampleBenchCfgOut:
|
97
|
+
"""Takes an ExampleBenchCfgIn and returns a ExampleBenchCfgOut output"""
|
98
|
+
out = ExampleBenchCfgOut()
|
99
|
+
noise = calculate_noise(cfg)
|
100
|
+
|
101
|
+
postprocess_fn = abs if cfg.postprocess_fn == PostprocessFn.absolute else negate_fn
|
102
|
+
|
103
|
+
out.out_sin = postprocess_fn(cfg.offset + math.sin(cfg.theta) + noise)
|
104
|
+
out.out_cos = postprocess_fn(cfg.offset + math.cos(cfg.theta) + noise)
|
105
|
+
|
106
|
+
out.out_bool = out.out_sin > 0.5
|
107
|
+
return out
|
108
|
+
|
109
|
+
|
110
|
+
class ExampleBenchCfg(ParametrizedSweep):
|
111
|
+
theta = FloatSweep(default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30)
|
112
|
+
offset = FloatSweep(default=0, bounds=[0, 0.3], doc="dc offset", units="v", samples=30)
|
113
|
+
postprocess_fn = EnumSweep(PostprocessFn)
|
114
|
+
|
115
|
+
noisy = BoolSweep(
|
116
|
+
default=False, doc="Optionally add random noise to the output of the function"
|
117
|
+
)
|
118
|
+
noise_distribution = EnumSweep(NoiseDistribution, doc=NoiseDistribution.__doc__)
|
119
|
+
sigma = FloatSweep(
|
120
|
+
default=1,
|
121
|
+
bounds=[0, 10],
|
122
|
+
doc="The standard deviation of the noise",
|
123
|
+
units="v",
|
124
|
+
)
|
125
|
+
|
126
|
+
out_sin = ResultVar(units="v", direction=OptDir.minimize, doc="sin of theta with some noise")
|
127
|
+
out_cos = ResultVar(units="v", direction=OptDir.minimize, doc="cos of theta with some noise")
|
128
|
+
out_bool = ResultVar(units="%", doc="sin > 0.5")
|
129
|
+
|
130
|
+
def __call__(self, **kwwargs) -> dict:
|
131
|
+
self.update_params_from_kwargs(**kwwargs)
|
132
|
+
|
133
|
+
noise = self.calculate_noise()
|
134
|
+
postprocess_fn = abs if self.postprocess_fn == PostprocessFn.absolute else negate_fn
|
135
|
+
|
136
|
+
self.out_sin = postprocess_fn(self.offset + math.sin(self.theta) + noise)
|
137
|
+
self.out_cos = postprocess_fn(self.offset + math.cos(self.theta) + noise)
|
138
|
+
self.out_bool = self.out_sin > 0.5
|
139
|
+
return self.get_results_values_as_dict()
|
140
|
+
|
141
|
+
def calculate_noise(self):
|
142
|
+
noise = 0.0
|
143
|
+
if self.noisy:
|
144
|
+
match self.noise_distribution:
|
145
|
+
case NoiseDistribution.uniform:
|
146
|
+
noise = random.uniform(0, self.sigma)
|
147
|
+
case NoiseDistribution.gaussian:
|
148
|
+
noise = random.gauss(0, self.sigma)
|
149
|
+
case NoiseDistribution.lognorm:
|
150
|
+
noise = random.lognormvariate(0, self.sigma)
|
151
|
+
|
152
|
+
return noise
|
153
|
+
|
154
|
+
|
155
|
+
def call(**kwargs) -> dict:
|
156
|
+
return ExampleBenchCfg().__call__(**kwargs)
|
157
|
+
|
158
|
+
|
159
|
+
class AllSweepVars(ParametrizedSweep):
|
160
|
+
"""A class containing all the sweep types, This class is used for unit testing how the configuration classes are serialised and hashed"""
|
161
|
+
|
162
|
+
var_float = FloatSweep(default=5, bounds=(0, 10), units="m/s")
|
163
|
+
var_int = IntSweep(default=3, bounds=[0, 4])
|
164
|
+
var_int_big = IntSweep(default=0, bounds=[0, 100], samples=3)
|
165
|
+
var_bool = BoolSweep()
|
166
|
+
var_string = StringSweep(["string1", "string2"])
|
167
|
+
var_enum = EnumSweep(PostprocessFn)
|
168
|
+
|
169
|
+
result = ResultVar()
|
170
|
+
|
171
|
+
def __call__(self, **kwargs) -> dict:
|
172
|
+
self.update_params_from_kwargs(**kwargs)
|
173
|
+
self.result = self.var_float + self.var_int
|
174
|
+
return self.get_results_values_as_dict()
|
175
|
+
|
176
|
+
|
177
|
+
class SimpleBenchClass(ParametrizedSweep):
|
178
|
+
var1 = IntSweep(default=0, bounds=[0, 2])
|
179
|
+
|
180
|
+
result = ResultVar()
|
181
|
+
|
182
|
+
def __call__(self, **kwargs) -> dict:
|
183
|
+
self.update_params_from_kwargs(**kwargs)
|
184
|
+
self.result = self.var1
|
185
|
+
return self.get_results_values_as_dict()
|
186
|
+
|
187
|
+
|
188
|
+
class SimpleBenchClassFloat(ParametrizedSweep):
|
189
|
+
var1 = FloatSweep(bounds=[0, 100])
|
190
|
+
|
191
|
+
result = ResultVar()
|
192
|
+
|
193
|
+
def __call__(self, **kwargs) -> dict:
|
194
|
+
self.update_params_from_kwargs(**kwargs)
|
195
|
+
self.result = self.var1
|
196
|
+
return self.get_results_values_as_dict()
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
|
3
|
+
from bencher.example.example_categorical import example_categorical
|
4
|
+
from bencher.example.example_floats import example_floats
|
5
|
+
from bencher.example.example_floats2D import example_floats2D
|
6
|
+
from bencher.example.example_pareto import example_pareto
|
7
|
+
from bencher.example.example_simple_cat import example_1D_cat
|
8
|
+
from bencher.example.example_simple_float import example_1D_float
|
9
|
+
from bencher.example.example_float_cat import example_float_cat
|
10
|
+
from bencher.example.example_time_event import example_time_event
|
11
|
+
from bencher.example.example_float3D import example_floats3D
|
12
|
+
|
13
|
+
from bencher.example.example_custom_sweep import example_custom_sweep
|
14
|
+
from bencher.example.example_holosweep import example_holosweep
|
15
|
+
from bencher.example.example_holosweep_tap import example_holosweep_tap
|
16
|
+
|
17
|
+
from bencher.example.optuna.example_optuna import optuna_rastrigin
|
18
|
+
from bencher.example.example_sample_cache import example_sample_cache
|
19
|
+
|
20
|
+
# from bencher.example.example_workflow import example_floats2D_workflow, example_floats3D_workflow
|
21
|
+
|
22
|
+
|
23
|
+
if __name__ == "__main__":
|
24
|
+
run_cfg = bch.BenchRunCfg()
|
25
|
+
run_cfg.overwrite_sample_cache = True
|
26
|
+
bench_runner = bch.BenchRunner("bencher_examples", run_cfg=run_cfg)
|
27
|
+
|
28
|
+
bench_runner.add_run(example_categorical)
|
29
|
+
bench_runner.add_run(example_floats)
|
30
|
+
bench_runner.add_run(example_floats2D)
|
31
|
+
bench_runner.add_run(example_floats3D)
|
32
|
+
bench_runner.add_run(example_1D_cat)
|
33
|
+
bench_runner.add_run(example_1D_float)
|
34
|
+
bench_runner.add_run(example_pareto)
|
35
|
+
bench_runner.add_run(example_float_cat)
|
36
|
+
bench_runner.add_run(example_time_event)
|
37
|
+
bench_runner.add_run(example_custom_sweep)
|
38
|
+
bench_runner.add_run(example_holosweep)
|
39
|
+
bench_runner.add_run(example_holosweep_tap)
|
40
|
+
bench_runner.add_run(optuna_rastrigin)
|
41
|
+
bench_runner.add_run(example_sample_cache)
|
42
|
+
|
43
|
+
# bench_runner.run(level=2, show=True, grouped=True)
|
44
|
+
|
45
|
+
bench_runner.run(level=4, show=True, grouped=True, save=False)
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# pylint: disable=duplicate-code
|
2
|
+
|
3
|
+
import bencher as bch
|
4
|
+
|
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
|
+
|
8
|
+
|
9
|
+
def example_categorical(
|
10
|
+
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
11
|
+
) -> bch.Bench:
|
12
|
+
"""Example of how to perform a categorical parameter sweep
|
13
|
+
|
14
|
+
Args:
|
15
|
+
run_cfg (BenchRunCfg): configuration of how to perform the param sweep
|
16
|
+
|
17
|
+
Returns:
|
18
|
+
Bench: results of the parameter sweep
|
19
|
+
"""
|
20
|
+
|
21
|
+
with open("README.md", "r", encoding="utf-8") as file:
|
22
|
+
readme = file.read()
|
23
|
+
|
24
|
+
# run_cfg.over_time = True
|
25
|
+
|
26
|
+
bench = bch.Bench(
|
27
|
+
"Bencher_Example_Categorical",
|
28
|
+
bench_function,
|
29
|
+
ExampleBenchCfgIn,
|
30
|
+
run_cfg=run_cfg,
|
31
|
+
report=report,
|
32
|
+
)
|
33
|
+
|
34
|
+
bench.report.append(readme, "Intro")
|
35
|
+
|
36
|
+
bench.plot_sweep(
|
37
|
+
input_vars=[ExampleBenchCfgIn.param.noisy],
|
38
|
+
result_vars=[ExampleBenchCfgOut.param.out_sin],
|
39
|
+
title="Categorical 1D Example",
|
40
|
+
description="""This example shows how to sample categorical values. The same objective from the float examples is used but theta is kept constant with a value of 0 (as described in the ExampleBenchCfgIn class definition).
|
41
|
+
|
42
|
+
|
43
|
+
```
|
44
|
+
def bench_function(cfg: ExampleBenchCfgIn) -> ExampleBenchCfgOut:
|
45
|
+
"Takes an ExampleBenchCfgIn and returns a ExampleBenchCfgOut output"
|
46
|
+
out = ExampleBenchCfgOut()
|
47
|
+
noise = calculate_noise(cfg)
|
48
|
+
offset = 0.0
|
49
|
+
|
50
|
+
postprocess_fn = abs if cfg.postprocess_fn == PostprocessFn.absolute else negate_fn
|
51
|
+
|
52
|
+
out.out_sin = postprocess_fn(offset + math.sin(cfg.theta) + noise)
|
53
|
+
return out
|
54
|
+
```
|
55
|
+
|
56
|
+
""",
|
57
|
+
post_description="The plot shows when noise=True the output has uniform random noise.",
|
58
|
+
)
|
59
|
+
|
60
|
+
bench.plot_sweep(
|
61
|
+
input_vars=[ExampleBenchCfgIn.param.noisy, ExampleBenchCfgIn.param.noise_distribution],
|
62
|
+
result_vars=[ExampleBenchCfgOut.param.out_sin],
|
63
|
+
title="Categorical 2D Example",
|
64
|
+
description="""Adding another categorical value creates a facet plot over that dimension""",
|
65
|
+
post_description="The output shows swarm plots of different noise distributions",
|
66
|
+
)
|
67
|
+
|
68
|
+
bench.plot_sweep(
|
69
|
+
input_vars=[
|
70
|
+
ExampleBenchCfgIn.param.noisy,
|
71
|
+
ExampleBenchCfgIn.param.noise_distribution,
|
72
|
+
ExampleBenchCfgIn.param.postprocess_fn,
|
73
|
+
],
|
74
|
+
result_vars=[ExampleBenchCfgOut.param.out_sin],
|
75
|
+
title="Categorical 3D Example",
|
76
|
+
description="""Adding another categorical value extends the facets to the right""",
|
77
|
+
post_description="The output shows swarm plots of different noise distributions",
|
78
|
+
)
|
79
|
+
|
80
|
+
run_cfg.over_time = True
|
81
|
+
bench.plot_sweep(
|
82
|
+
input_vars=[
|
83
|
+
ExampleBenchCfgIn.param.noisy,
|
84
|
+
ExampleBenchCfgIn.param.noise_distribution,
|
85
|
+
ExampleBenchCfgIn.param.postprocess_fn,
|
86
|
+
],
|
87
|
+
title="Categorical 3D Example Over Time",
|
88
|
+
result_vars=[ExampleBenchCfgOut.param.out_sin],
|
89
|
+
description="""Lastly, what if you want to track these distributions over time? Set over_time=True and bencher will cache and display historical resuts alongside the latest result. Use clear_history=True to clear that cache.""",
|
90
|
+
post_description="The output shows faceted line plot with confidence intervals for the mean value over time.",
|
91
|
+
run_cfg=run_cfg,
|
92
|
+
)
|
93
|
+
|
94
|
+
return bench
|
95
|
+
|
96
|
+
|
97
|
+
if __name__ == "__main__":
|
98
|
+
ex_run_cfg = bch.BenchRunCfg()
|
99
|
+
example_categorical(ex_run_cfg).report.show()
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
|
3
|
+
from bencher.example.example_image import BenchPolygons
|
4
|
+
|
5
|
+
|
6
|
+
class BenchComposableContainerImage(BenchPolygons):
|
7
|
+
compose_method = bch.EnumSweep(bch.ComposeType)
|
8
|
+
labels = bch.BoolSweep()
|
9
|
+
num_frames = bch.IntSweep(default=5, bounds=[1, 100])
|
10
|
+
polygon_vid = bch.ResultVideo()
|
11
|
+
|
12
|
+
def __call__(self, **kwargs):
|
13
|
+
self.update_params_from_kwargs(**kwargs)
|
14
|
+
var_name = None
|
15
|
+
var_value = None
|
16
|
+
|
17
|
+
if self.labels:
|
18
|
+
var_name = "sides"
|
19
|
+
var_value = self.sides
|
20
|
+
vr = bch.ComposableContainerVideo()
|
21
|
+
for i in range(self.num_frames):
|
22
|
+
res = super().__call__(start_angle=i)
|
23
|
+
print(res)
|
24
|
+
vr.append(res["polygon"])
|
25
|
+
self.polygon_vid = vr.to_video(
|
26
|
+
bch.RenderCfg(
|
27
|
+
compose_method=self.compose_method,
|
28
|
+
var_name=var_name,
|
29
|
+
var_value=var_value,
|
30
|
+
max_frame_duration=1.0 / 20.0,
|
31
|
+
)
|
32
|
+
)
|
33
|
+
return self.get_results_values_as_dict()
|
34
|
+
|
35
|
+
|
36
|
+
class BenchComposableContainerVideo(bch.ParametrizedSweep):
|
37
|
+
unequal_length = bch.BoolSweep()
|
38
|
+
compose_method = bch.EnumSweep(bch.ComposeType)
|
39
|
+
labels = bch.BoolSweep()
|
40
|
+
polygon_vid = bch.ResultVideo()
|
41
|
+
|
42
|
+
def __call__(self, **kwargs):
|
43
|
+
self.update_params_from_kwargs(**kwargs)
|
44
|
+
vr = bch.ComposableContainerVideo()
|
45
|
+
for i in range(3, 5):
|
46
|
+
num_frames = i * 10 if self.unequal_length else 5
|
47
|
+
res = BenchComposableContainerImage().__call__(
|
48
|
+
compose_method=bch.ComposeType.sequence, sides=i, num_frames=num_frames
|
49
|
+
)
|
50
|
+
vr.append(res["polygon_vid"])
|
51
|
+
|
52
|
+
self.polygon_vid = vr.to_video(bch.RenderCfg(compose_method=kwargs.get("compose_method")))
|
53
|
+
return self.get_results_values_as_dict()
|
54
|
+
|
55
|
+
|
56
|
+
def example_composable_container_image(
|
57
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
58
|
+
) -> bch.Bench:
|
59
|
+
bench = BenchComposableContainerImage().to_bench(run_cfg, report)
|
60
|
+
bench.result_vars = ["polygon_vid"]
|
61
|
+
# bench.add_plot_callback(bch.BenchResult.to_panes)
|
62
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_grid, result_types=(bch.ResultVideo))
|
63
|
+
# bench.add_plot_callback(bch.BenchResult.to_video_summary, result_types=(bch.ResultVideo))
|
64
|
+
# bench.plot_sweep(input_vars=["compose_method", "labels"])
|
65
|
+
|
66
|
+
bench.plot_sweep(input_vars=["compose_method"])
|
67
|
+
|
68
|
+
# bench.compose_
|
69
|
+
# bench.plot_sweep(
|
70
|
+
# input_vars=[bch.p("num_frames", [2, 8, 20])],
|
71
|
+
# const_vars=dict(compose_method=bch.ComposeType.sequence),
|
72
|
+
# )
|
73
|
+
|
74
|
+
return bench
|
75
|
+
|
76
|
+
|
77
|
+
def example_composable_container_video(
|
78
|
+
run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None
|
79
|
+
) -> bch.Bench:
|
80
|
+
bench = BenchComposableContainerVideo().to_bench(run_cfg, report)
|
81
|
+
|
82
|
+
bench.result_vars = ["polygon_vid"]
|
83
|
+
bench.add_plot_callback(bch.BenchResult.to_panes)
|
84
|
+
bench.add_plot_callback(bch.BenchResult.to_video_grid, result_types=(bch.ResultVideo))
|
85
|
+
bench.add_plot_callback(bch.BenchResult.to_video_summary, result_types=(bch.ResultVideo))
|
86
|
+
bench.plot_sweep(input_vars=["compose_method", "labels"], const_vars=dict(unequal_length=True))
|
87
|
+
|
88
|
+
res = bench.plot_sweep(
|
89
|
+
input_vars=[],
|
90
|
+
const_vars=dict(unequal_length=False, compose_method=bch.ComposeType.sequence),
|
91
|
+
plot_callbacks=False,
|
92
|
+
)
|
93
|
+
|
94
|
+
bench.report.append(res.to_video_grid())
|
95
|
+
|
96
|
+
return bench
|
97
|
+
|
98
|
+
|
99
|
+
if __name__ == "__main__":
|
100
|
+
ex_run_cfg = bch.BenchRunCfg()
|
101
|
+
ex_run_cfg.use_sample_cache = False
|
102
|
+
# ex_run_cfg.level = 2
|
103
|
+
ex_report = bch.BenchReport()
|
104
|
+
example_composable_container_image(ex_run_cfg, report=ex_report)
|
105
|
+
# example_composable_container_video(ex_run_cfg, report=ex_report)
|
106
|
+
ex_report.show()
|
@@ -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()
|