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
bencher/__init__.py
CHANGED
@@ -6,7 +6,7 @@ from .variables.sweep_base import hash_sha1
|
|
6
6
|
from .variables.inputs import IntSweep, FloatSweep, StringSweep, EnumSweep, BoolSweep, SweepBase
|
7
7
|
from .variables.time import TimeSnapshot
|
8
8
|
|
9
|
-
from .variables.inputs import box
|
9
|
+
from .variables.inputs import box, p
|
10
10
|
from .variables.results import (
|
11
11
|
ResultVar,
|
12
12
|
ResultVec,
|
@@ -19,9 +19,19 @@ from .variables.results import (
|
|
19
19
|
ResultReference,
|
20
20
|
ResultVolume,
|
21
21
|
OptDir,
|
22
|
+
ResultDataSet,
|
22
23
|
curve,
|
23
24
|
)
|
24
25
|
|
26
|
+
from .results.composable_container.composable_container_base import (
|
27
|
+
ComposeType,
|
28
|
+
ComposableContainerBase,
|
29
|
+
)
|
30
|
+
from .results.composable_container.composable_container_video import (
|
31
|
+
ComposableContainerVideo,
|
32
|
+
RenderCfg,
|
33
|
+
)
|
34
|
+
|
25
35
|
from .plotting.plot_filter import VarRange, PlotFilter
|
26
36
|
from .utils import (
|
27
37
|
hmap_canonical_input,
|
@@ -31,6 +41,7 @@ from .utils import (
|
|
31
41
|
gen_image_path,
|
32
42
|
gen_video_path,
|
33
43
|
lerp,
|
44
|
+
tabs_in_markdown,
|
34
45
|
)
|
35
46
|
from .variables.parametrised_sweep import ParametrizedSweep
|
36
47
|
from .caching import CachedParams
|
bencher/bench_report.py
CHANGED
@@ -157,112 +157,9 @@ class BenchReport(BenchPlotServer):
|
|
157
157
|
|
158
158
|
return publish_url
|
159
159
|
|
160
|
-
|
161
|
-
# def
|
162
|
-
#
|
163
|
-
|
164
|
-
#
|
165
|
-
#
|
166
|
-
# # Don't pickle baz
|
167
|
-
# del state["pane"]
|
168
|
-
# return state
|
169
|
-
|
170
|
-
# def __setstate__(self, state):
|
171
|
-
# self.__dict__.update(state)
|
172
|
-
# # Add baz back since it doesn't exist in the pickle
|
173
|
-
# self.report = []
|
174
|
-
|
175
|
-
# def publish_old(
|
176
|
-
# self,
|
177
|
-
# directory: str = "bench_results",
|
178
|
-
# branch_name: str = "bench_results",
|
179
|
-
# url_postprocess: Callable = None,
|
180
|
-
# **kwargs,
|
181
|
-
# ) -> str:
|
182
|
-
# """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.
|
183
|
-
|
184
|
-
# Args:
|
185
|
-
# directory (str, optional): Directory to save the results. Defaults to "bench_results".
|
186
|
-
# branch_name (str, optional): Branch to publish on. Defaults to "bench_results".
|
187
|
-
# url_postprocess (Callable, optional): A function that maps the origin url to a github pages url. Pass your own function if you are using another git providers. Defaults to None.
|
188
|
-
|
189
|
-
# Returns:
|
190
|
-
# str: _description_
|
191
|
-
# """
|
192
|
-
|
193
|
-
# def get_output(cmd: str) -> str:
|
194
|
-
# return (
|
195
|
-
# subprocess.run(cmd.split(" "), stdout=subprocess.PIPE, check=False)
|
196
|
-
# .stdout.decode("utf=8")
|
197
|
-
# .strip()
|
198
|
-
# )
|
199
|
-
|
200
|
-
# def postprocess_url(publish_url: str, branch_name: str, report_path: str, **kwargs) -> str:
|
201
|
-
# # import re
|
202
|
-
|
203
|
-
# # return re.sub(
|
204
|
-
# # """((git|ssh|http(s)?)|(git@[\w\.-]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?""",
|
205
|
-
# # """https://$7/""",
|
206
|
-
# # publish_url,
|
207
|
-
# # )
|
208
|
-
# # git@github.com:user/project.git
|
209
|
-
# # https://github.com/user/project.git
|
210
|
-
# # http://github.com/user/project.git
|
211
|
-
# # git@192.168.101.127:user/project.git
|
212
|
-
# # https://192.168.101.127/user/project.git
|
213
|
-
# # http://192.168.101.127/user/project.git
|
214
|
-
# # ssh://user@host.xz:port/path/to/repo.git/
|
215
|
-
# # ssh://user@host.xz/path/to/repo.git/
|
216
|
-
# # ssh://host.xz:port/path/to/repo.git/
|
217
|
-
# # ssh://host.xz/path/to/repo.git/
|
218
|
-
# # ssh://user@host.xz/path/to/repo.git/
|
219
|
-
# # ssh://host.xz/path/to/repo.git/
|
220
|
-
# # ssh://user@host.xz/~user/path/to/repo.git/
|
221
|
-
# # ssh://host.xz/~user/path/to/repo.git/
|
222
|
-
# # ssh://user@host.xz/~/path/to/repo.git
|
223
|
-
# # ssh://host.xz/~/path/to/repo.git
|
224
|
-
# # git://host.xz/path/to/repo.git/
|
225
|
-
# # git://host.xz/~user/path/to/repo.git/
|
226
|
-
# # http://host.xz/path/to/repo.git/
|
227
|
-
# # https://host.xz/path/to/repo.git/
|
228
|
-
# # https://regex101.com/r/qT7NP0/3
|
229
|
-
|
230
|
-
# return publish_url.replace(".git", f"/blob/{directory}/{report_path}")
|
231
|
-
|
232
|
-
# if url_postprocess is None:
|
233
|
-
# url_postprocess = postprocess_url
|
234
|
-
# current_branch = get_output("git symbolic-ref --short HEAD")
|
235
|
-
# logging.info(f"on branch: {current_branch}")
|
236
|
-
# stash_msg = get_output("git stash")
|
237
|
-
# logging.info(f"stashing current work :{stash_msg}")
|
238
|
-
# checkout_msg = get_output(f"git checkout -b {branch_name}")
|
239
|
-
# checkout_msg = get_output(f"git checkout {branch_name}")
|
240
|
-
# get_output("git pull")
|
241
|
-
|
242
|
-
# logging.info(f"checking out branch: {checkout_msg}")
|
243
|
-
# report_path = self.save(directory, in_html_folder=False)
|
244
|
-
# logging.info(f"created report at: {report_path.absolute()}")
|
245
|
-
# # commit_msg = f""
|
246
|
-
# logging.info("adding report to git")
|
247
|
-
# get_output(f"git add {report_path.absolute()}")
|
248
|
-
# get_output("git status")
|
249
|
-
# logging.info("committing report")
|
250
|
-
# cmd = f'git commit -m "generate_report:{self.bench_name}"'
|
251
|
-
# logging.info(cmd)
|
252
|
-
# get_output(cmd)
|
253
|
-
# logging.info("pushing report to origin")
|
254
|
-
# get_output(f"git push --set-upstream origin {branch_name}")
|
255
|
-
# logging.info("checking out original branch")
|
256
|
-
# get_output(f"git checkout {current_branch}")
|
257
|
-
# if "No local changes" not in stash_msg:
|
258
|
-
# logging.info("restoring work with git stash pop")
|
259
|
-
# get_output("git stash pop")
|
260
|
-
|
261
|
-
# publish_url = get_output("git remote get-url --push origin")
|
262
|
-
# logging.info(f"raw url:{publish_url}")
|
263
|
-
# publish_url = url_postprocess(
|
264
|
-
# publish_url, branch_name=branch_name, report_path=report_path, **kwargs
|
265
|
-
# )
|
266
|
-
# logging.info("Published report @")
|
267
|
-
# logging.info(publish_url)
|
268
|
-
# return publish_url
|
160
|
+
# @staticmethod
|
161
|
+
# def publish_github(github_user: str, repo_name: str, branch_name: str) -> Tuple[str, str]:
|
162
|
+
# return (
|
163
|
+
# f"https://github.com/{github_user}/{repo_name}.git",
|
164
|
+
# f"https://github.com/{github_user}/{repo_name}/blob/{branch_name}",
|
165
|
+
# )
|
bencher/bench_runner.py
CHANGED
@@ -121,7 +121,7 @@ class BenchRunner:
|
|
121
121
|
self.show_publish(report_level, show, publish, save, debug)
|
122
122
|
return self.results
|
123
123
|
|
124
|
-
def show_publish(self, report, show, publish, save, debug):
|
124
|
+
def show_publish(self, report: BenchReport, show: bool, publish: bool, save: bool, debug: bool):
|
125
125
|
if save:
|
126
126
|
report.save_index()
|
127
127
|
if publish and self.publisher is not None:
|
bencher/bencher.py
CHANGED
@@ -2,7 +2,7 @@ import logging
|
|
2
2
|
from datetime import datetime
|
3
3
|
from itertools import product, combinations
|
4
4
|
|
5
|
-
from typing import Callable, List
|
5
|
+
from typing import Callable, List, Optional
|
6
6
|
from copy import deepcopy
|
7
7
|
import numpy as np
|
8
8
|
import param
|
@@ -30,6 +30,7 @@ from bencher.variables.results import (
|
|
30
30
|
ResultString,
|
31
31
|
ResultContainer,
|
32
32
|
ResultReference,
|
33
|
+
ResultDataSet,
|
33
34
|
)
|
34
35
|
from bencher.results.bench_result import BenchResult
|
35
36
|
from bencher.variables.parametrised_sweep import ParametrizedSweep
|
@@ -220,9 +221,11 @@ class Bench(BenchPlotServer):
|
|
220
221
|
relationship_cb=None,
|
221
222
|
plot_callbacks: List | bool = None,
|
222
223
|
) -> List[BenchResult]:
|
223
|
-
results = []
|
224
224
|
if relationship_cb is None:
|
225
225
|
relationship_cb = combinations
|
226
|
+
if input_vars is None:
|
227
|
+
input_vars = self.worker_class_instance.get_inputs_only()
|
228
|
+
results = []
|
226
229
|
for it in range(iterations):
|
227
230
|
for input_group in relationship_cb(input_vars, group_size):
|
228
231
|
title_gen = title + "Sweeping " + " vs ".join(params_to_str(input_group))
|
@@ -278,57 +281,42 @@ class Bench(BenchPlotServer):
|
|
278
281
|
BenchResult: A class with all the data used to generate the results and the results
|
279
282
|
"""
|
280
283
|
|
284
|
+
input_vars_in = deepcopy(input_vars)
|
285
|
+
result_vars_in = deepcopy(result_vars)
|
286
|
+
const_vars_in = deepcopy(const_vars)
|
287
|
+
|
281
288
|
if self.worker_class_instance is not None:
|
282
|
-
if
|
289
|
+
if input_vars_in is None:
|
283
290
|
logging.info(
|
284
291
|
"No input variables passed, using all param variables in bench class as inputs"
|
285
292
|
)
|
286
293
|
if self.input_vars is None:
|
287
|
-
|
294
|
+
input_vars_in = self.worker_class_instance.get_inputs_only()
|
288
295
|
else:
|
289
|
-
|
290
|
-
for i in
|
296
|
+
input_vars_in = deepcopy(self.input_vars)
|
297
|
+
for i in input_vars_in:
|
291
298
|
logging.info(f"input var: {i.name}")
|
292
|
-
if
|
299
|
+
if result_vars_in is None:
|
293
300
|
logging.info(
|
294
301
|
"No results variables passed, using all result variables in bench class:"
|
295
302
|
)
|
296
303
|
if self.result_vars is None:
|
297
|
-
|
304
|
+
result_vars_in = self.worker_class_instance.get_results_only()
|
298
305
|
else:
|
299
|
-
|
306
|
+
result_vars_in = deepcopy(self.result_vars)
|
300
307
|
|
301
|
-
if
|
308
|
+
if const_vars_in is None:
|
302
309
|
if self.const_vars is None:
|
303
|
-
|
310
|
+
const_vars_in = self.worker_class_instance.get_input_defaults()
|
304
311
|
else:
|
305
|
-
|
312
|
+
const_vars_in = deepcopy(self.const_vars)
|
306
313
|
else:
|
307
|
-
if
|
308
|
-
|
309
|
-
if
|
310
|
-
|
311
|
-
if
|
312
|
-
|
313
|
-
else:
|
314
|
-
const_vars = deepcopy(const_vars)
|
315
|
-
|
316
|
-
for i in range(len(input_vars)):
|
317
|
-
input_vars[i] = self.convert_vars_to_params(input_vars[i], "input")
|
318
|
-
for i in range(len(result_vars)):
|
319
|
-
result_vars[i] = self.convert_vars_to_params(result_vars[i], "result")
|
320
|
-
|
321
|
-
for r in result_vars:
|
322
|
-
logging.info(f"result var: {r.name}")
|
323
|
-
|
324
|
-
if isinstance(const_vars, dict):
|
325
|
-
const_vars = list(const_vars.items())
|
326
|
-
|
327
|
-
for i in range(len(const_vars)):
|
328
|
-
# consts come as tuple pairs
|
329
|
-
cv_list = list(const_vars[i])
|
330
|
-
cv_list[0] = self.convert_vars_to_params(cv_list[0], "const")
|
331
|
-
const_vars[i] = cv_list
|
314
|
+
if input_vars_in is None:
|
315
|
+
input_vars_in = []
|
316
|
+
if result_vars_in is None:
|
317
|
+
result_vars_in = []
|
318
|
+
if const_vars_in is None:
|
319
|
+
const_vars_in = []
|
332
320
|
|
333
321
|
if run_cfg is None:
|
334
322
|
if self.run_cfg is None:
|
@@ -343,37 +331,68 @@ class Bench(BenchPlotServer):
|
|
343
331
|
|
344
332
|
self.last_run_cfg = run_cfg
|
345
333
|
|
334
|
+
if isinstance(input_vars_in, dict):
|
335
|
+
input_lists = []
|
336
|
+
for k, v in input_vars_in.items():
|
337
|
+
param_var = self.convert_vars_to_params(k, "input", run_cfg)
|
338
|
+
if isinstance(v, list):
|
339
|
+
assert len(v) > 0
|
340
|
+
param_var = param_var.with_sample_values(v)
|
341
|
+
|
342
|
+
else:
|
343
|
+
raise RuntimeError("Unsupported type")
|
344
|
+
input_lists.append(param_var)
|
345
|
+
|
346
|
+
input_vars_in = input_lists
|
347
|
+
else:
|
348
|
+
for i in range(len(input_vars_in)):
|
349
|
+
input_vars_in[i] = self.convert_vars_to_params(input_vars_in[i], "input", run_cfg)
|
350
|
+
for i in range(len(result_vars_in)):
|
351
|
+
result_vars_in[i] = self.convert_vars_to_params(result_vars_in[i], "result", run_cfg)
|
352
|
+
|
353
|
+
for r in result_vars_in:
|
354
|
+
logging.info(f"result var: {r.name}")
|
355
|
+
|
356
|
+
if isinstance(const_vars_in, dict):
|
357
|
+
const_vars_in = list(const_vars_in.items())
|
358
|
+
|
359
|
+
for i in range(len(const_vars_in)):
|
360
|
+
# consts come as tuple pairs
|
361
|
+
cv_list = list(const_vars_in[i])
|
362
|
+
cv_list[0] = self.convert_vars_to_params(cv_list[0], "const", run_cfg)
|
363
|
+
const_vars_in[i] = cv_list
|
364
|
+
|
346
365
|
if title is None:
|
347
|
-
if len(
|
348
|
-
title = "Sweeping " + " vs ".join([i.name for i in
|
349
|
-
elif len(
|
366
|
+
if len(input_vars_in) > 0:
|
367
|
+
title = "Sweeping " + " vs ".join([i.name for i in input_vars_in])
|
368
|
+
elif len(const_vars_in) > 0:
|
350
369
|
title = "Constant Value"
|
351
|
-
if len(
|
370
|
+
if len(const_vars_in) > 1:
|
352
371
|
title += "s"
|
353
|
-
title += ": " + ", ".join([f"{c[0].name}={c[1]}" for c in
|
372
|
+
title += ": " + ", ".join([f"{c[0].name}={c[1]}" for c in const_vars_in])
|
354
373
|
else:
|
355
374
|
raise RuntimeError("you must pass a title, or define inputs or consts")
|
356
375
|
|
357
376
|
if run_cfg.level > 0:
|
358
377
|
inputs = []
|
359
|
-
print(
|
360
|
-
if len(
|
361
|
-
for i in
|
378
|
+
print(input_vars_in)
|
379
|
+
if len(input_vars_in) > 0:
|
380
|
+
for i in input_vars_in:
|
362
381
|
inputs.append(i.with_level(run_cfg.level))
|
363
|
-
|
382
|
+
input_vars_in = inputs
|
364
383
|
|
365
384
|
# if any of the inputs have been include as constants, remove those variables from the list of constants
|
366
385
|
with suppress(ValueError, AttributeError):
|
367
|
-
for i in
|
368
|
-
for c in
|
386
|
+
for i in input_vars_in:
|
387
|
+
for c in const_vars_in:
|
369
388
|
# print(i.hash_persistent())
|
370
389
|
if i.name == c[0].name:
|
371
|
-
|
390
|
+
const_vars_in.remove(c)
|
372
391
|
logging.info(f"removing {i.name} from constants")
|
373
392
|
|
374
393
|
result_hmaps = []
|
375
394
|
result_vars_only = []
|
376
|
-
for i in
|
395
|
+
for i in result_vars_in:
|
377
396
|
if isinstance(i, ResultHmap):
|
378
397
|
result_hmaps.append(i)
|
379
398
|
else:
|
@@ -393,10 +412,10 @@ class Bench(BenchPlotServer):
|
|
393
412
|
plot_callbacks = [BenchResult.to_auto_plots] if plot_callbacks else []
|
394
413
|
|
395
414
|
bench_cfg = BenchCfg(
|
396
|
-
input_vars=
|
415
|
+
input_vars=input_vars_in,
|
397
416
|
result_vars=result_vars_only,
|
398
417
|
result_hmaps=result_hmaps,
|
399
|
-
const_vars=
|
418
|
+
const_vars=const_vars_in,
|
400
419
|
bench_name=self.bench_name,
|
401
420
|
description=description,
|
402
421
|
post_description=post_description,
|
@@ -470,7 +489,12 @@ class Bench(BenchPlotServer):
|
|
470
489
|
self.results.append(bench_res)
|
471
490
|
return bench_res
|
472
491
|
|
473
|
-
def convert_vars_to_params(
|
492
|
+
def convert_vars_to_params(
|
493
|
+
self,
|
494
|
+
variable: param.Parameter | str | dict | tuple,
|
495
|
+
var_type: str,
|
496
|
+
run_cfg: Optional[BenchRunCfg],
|
497
|
+
) -> param.Parameter:
|
474
498
|
"""check that a variable is a subclass of param
|
475
499
|
|
476
500
|
Args:
|
@@ -482,6 +506,17 @@ class Bench(BenchPlotServer):
|
|
482
506
|
"""
|
483
507
|
if isinstance(variable, str):
|
484
508
|
variable = self.worker_class_instance.param.objects(instance=False)[variable]
|
509
|
+
if isinstance(variable, dict):
|
510
|
+
param_var = self.worker_class_instance.param.objects(instance=False)[variable["name"]]
|
511
|
+
if variable.get("values"):
|
512
|
+
param_var = param_var.with_sample_values(variable["values"])
|
513
|
+
|
514
|
+
if variable.get("samples"):
|
515
|
+
param_var = param_var.with_samples(variable["samples"])
|
516
|
+
if variable.get("max_level"):
|
517
|
+
if run_cfg is not None:
|
518
|
+
param_var = param_var.with_level(run_cfg.level, variable["max_level"])
|
519
|
+
variable = param_var
|
485
520
|
if not isinstance(variable, param.Parameter):
|
486
521
|
raise TypeError(
|
487
522
|
f"You need to use {var_type}_vars =[{self.worker_input_cfg}.param.your_variable], instead of {var_type}_vars =[{self.worker_input_cfg}.your_variable]"
|
@@ -578,12 +613,13 @@ class Bench(BenchPlotServer):
|
|
578
613
|
)
|
579
614
|
# xarray stores K N-dimensional arrays of data. Each array is named and in this case we have a nd array for each result variable
|
580
615
|
data_vars = {}
|
616
|
+
dataset_list = []
|
581
617
|
|
582
618
|
for rv in bench_cfg.result_vars:
|
583
619
|
if isinstance(rv, ResultVar):
|
584
620
|
result_data = np.full(dims_cfg.dims_size, np.nan, dtype=float)
|
585
621
|
data_vars[rv.name] = (dims_cfg.dims_name, result_data)
|
586
|
-
if isinstance(rv, ResultReference):
|
622
|
+
if isinstance(rv, (ResultReference, ResultDataSet)):
|
587
623
|
result_data = np.full(dims_cfg.dims_size, -1, dtype=int)
|
588
624
|
data_vars[rv.name] = (dims_cfg.dims_name, result_data)
|
589
625
|
if isinstance(
|
@@ -591,7 +627,8 @@ class Bench(BenchPlotServer):
|
|
591
627
|
):
|
592
628
|
result_data = np.full(dims_cfg.dims_size, "NAN", dtype=object)
|
593
629
|
data_vars[rv.name] = (dims_cfg.dims_name, result_data)
|
594
|
-
|
630
|
+
|
631
|
+
elif type(rv) is ResultVec:
|
595
632
|
for i in range(rv.size):
|
596
633
|
result_data = np.full(dims_cfg.dims_size, np.nan)
|
597
634
|
data_vars[rv.index_name(i)] = (dims_cfg.dims_name, result_data)
|
@@ -599,6 +636,7 @@ class Bench(BenchPlotServer):
|
|
599
636
|
bench_res = BenchResult(bench_cfg)
|
600
637
|
bench_res.ds = xr.Dataset(data_vars=data_vars, coords=dims_cfg.coords)
|
601
638
|
bench_res.ds_dynamic = self.ds_dynamic
|
639
|
+
bench_res.dataset_list = dataset_list
|
602
640
|
bench_res.setup_object_index()
|
603
641
|
|
604
642
|
return bench_res, function_inputs, dims_cfg.dims_name
|
@@ -736,6 +774,13 @@ class Bench(BenchPlotServer):
|
|
736
774
|
),
|
737
775
|
):
|
738
776
|
set_xarray_multidim(bench_res.ds[rv.name], worker_job.index_tuple, result_value)
|
777
|
+
elif isinstance(rv, ResultDataSet):
|
778
|
+
bench_res.dataset_list.append(result_value)
|
779
|
+
set_xarray_multidim(
|
780
|
+
bench_res.ds[rv.name],
|
781
|
+
worker_job.index_tuple,
|
782
|
+
len(bench_res.dataset_list) - 1,
|
783
|
+
)
|
739
784
|
elif isinstance(rv, ResultReference):
|
740
785
|
bench_res.object_index.append(result_value)
|
741
786
|
set_xarray_multidim(
|
@@ -743,6 +788,7 @@ class Bench(BenchPlotServer):
|
|
743
788
|
worker_job.index_tuple,
|
744
789
|
len(bench_res.object_index) - 1,
|
745
790
|
)
|
791
|
+
|
746
792
|
elif isinstance(rv, ResultVec):
|
747
793
|
if isinstance(result_value, (list, np.ndarray)):
|
748
794
|
if len(result_value) == rv.size:
|
@@ -788,10 +834,10 @@ class Bench(BenchPlotServer):
|
|
788
834
|
"""
|
789
835
|
|
790
836
|
for rv in bench_res.bench_cfg.result_vars:
|
791
|
-
if type(rv)
|
837
|
+
if type(rv) is ResultVar:
|
792
838
|
bench_res.ds[rv.name].attrs["units"] = rv.units
|
793
839
|
bench_res.ds[rv.name].attrs["long_name"] = rv.name
|
794
|
-
elif type(rv)
|
840
|
+
elif type(rv) is ResultVec:
|
795
841
|
for i in range(rv.size):
|
796
842
|
bench_res.ds[rv.index_name(i)].attrs["units"] = rv.units
|
797
843
|
bench_res.ds[rv.index_name(i)].attrs["long_name"] = rv.name
|
@@ -6,13 +6,9 @@ You can define a subclass which contains an input configuration which can be pas
|
|
6
6
|
import math
|
7
7
|
import random
|
8
8
|
from enum import auto
|
9
|
-
|
10
9
|
from strenum import StrEnum
|
11
|
-
|
12
|
-
|
13
10
|
from bencher.variables.inputs import IntSweep, FloatSweep, StringSweep, EnumSweep, BoolSweep
|
14
11
|
from bencher.variables.results import ResultVar, OptDir
|
15
|
-
|
16
12
|
from bencher.variables.parametrised_sweep import ParametrizedSweep
|
17
13
|
|
18
14
|
|
@@ -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()
|