holobench 1.3.5__py3-none-any.whl → 1.22.2__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.
Files changed (77) hide show
  1. bencher/__init__.py +3 -0
  2. bencher/bench_cfg.py +29 -33
  3. bencher/bench_plot_server.py +5 -1
  4. bencher/bench_report.py +14 -14
  5. bencher/bench_runner.py +2 -1
  6. bencher/bencher.py +77 -52
  7. bencher/class_enum.py +52 -0
  8. bencher/job.py +6 -4
  9. bencher/optuna_conversions.py +1 -1
  10. bencher/utils.py +42 -4
  11. bencher/video_writer.py +101 -10
  12. holobench-1.22.2.data/data/share/bencher/package.xml +33 -0
  13. holobench-1.22.2.dist-info/LICENSE +21 -0
  14. {holobench-1.3.5.dist-info → holobench-1.22.2.dist-info}/METADATA +39 -31
  15. holobench-1.22.2.dist-info/RECORD +20 -0
  16. {holobench-1.3.5.dist-info → holobench-1.22.2.dist-info}/WHEEL +2 -1
  17. holobench-1.22.2.dist-info/top_level.txt +1 -0
  18. bencher/example/benchmark_data.py +0 -200
  19. bencher/example/example_all.py +0 -45
  20. bencher/example/example_categorical.py +0 -99
  21. bencher/example/example_custom_sweep.py +0 -59
  22. bencher/example/example_docs.py +0 -34
  23. bencher/example/example_float3D.py +0 -101
  24. bencher/example/example_float_cat.py +0 -98
  25. bencher/example/example_floats.py +0 -89
  26. bencher/example/example_floats2D.py +0 -93
  27. bencher/example/example_holosweep.py +0 -104
  28. bencher/example/example_holosweep_objects.py +0 -111
  29. bencher/example/example_holosweep_tap.py +0 -144
  30. bencher/example/example_image.py +0 -82
  31. bencher/example/example_levels.py +0 -181
  32. bencher/example/example_pareto.py +0 -53
  33. bencher/example/example_sample_cache.py +0 -85
  34. bencher/example/example_sample_cache_context.py +0 -116
  35. bencher/example/example_simple.py +0 -134
  36. bencher/example/example_simple_bool.py +0 -34
  37. bencher/example/example_simple_cat.py +0 -47
  38. bencher/example/example_simple_float.py +0 -38
  39. bencher/example/example_strings.py +0 -46
  40. bencher/example/example_time_event.py +0 -62
  41. bencher/example/example_video.py +0 -124
  42. bencher/example/example_workflow.py +0 -189
  43. bencher/example/experimental/example_bokeh_plotly.py +0 -38
  44. bencher/example/experimental/example_hover_ex.py +0 -45
  45. bencher/example/experimental/example_hvplot_explorer.py +0 -39
  46. bencher/example/experimental/example_interactive.py +0 -75
  47. bencher/example/experimental/example_streamnd.py +0 -49
  48. bencher/example/experimental/example_streams.py +0 -36
  49. bencher/example/experimental/example_template.py +0 -40
  50. bencher/example/experimental/example_updates.py +0 -84
  51. bencher/example/experimental/example_vector.py +0 -84
  52. bencher/example/meta/example_meta.py +0 -171
  53. bencher/example/meta/example_meta_cat.py +0 -25
  54. bencher/example/meta/example_meta_float.py +0 -23
  55. bencher/example/meta/example_meta_levels.py +0 -26
  56. bencher/example/optuna/example_optuna.py +0 -78
  57. bencher/example/shelved/example_float2D_scatter.py +0 -109
  58. bencher/example/shelved/example_float3D_cone.py +0 -96
  59. bencher/example/shelved/example_kwargs.py +0 -63
  60. bencher/plotting/__init__.py +0 -0
  61. bencher/plotting/plot_filter.py +0 -110
  62. bencher/plotting/plt_cnt_cfg.py +0 -74
  63. bencher/results/__init__.py +0 -0
  64. bencher/results/bench_result.py +0 -80
  65. bencher/results/bench_result_base.py +0 -405
  66. bencher/results/float_formatter.py +0 -44
  67. bencher/results/holoview_result.py +0 -592
  68. bencher/results/optuna_result.py +0 -354
  69. bencher/results/panel_result.py +0 -113
  70. bencher/results/plotly_result.py +0 -65
  71. bencher/variables/inputs.py +0 -193
  72. bencher/variables/parametrised_sweep.py +0 -206
  73. bencher/variables/results.py +0 -176
  74. bencher/variables/sweep_base.py +0 -167
  75. bencher/variables/time.py +0 -74
  76. holobench-1.3.5.dist-info/RECORD +0 -74
  77. /bencher/example/__init__.py → /holobench-1.22.2.data/data/share/ament_index/resource_index/packages/bencher +0 -0
@@ -1,44 +0,0 @@
1
- # from https://stackoverflow.com/questions/22989372/how-to-format-a-floating-number-to-maximum-fixed-width-in-python
2
-
3
-
4
- class FormatFloat:
5
- def __init__(self, width=8):
6
- self.width = width
7
- self.maxnum = int("9" * (width - 1)) # 9999999
8
- self.minnum = -int("9" * (width - 2)) # -999999
9
-
10
- def __call__(self, x):
11
- # for small numbers
12
- # if -999,999 < given < 9,999,999:
13
- if self.minnum < x < self.maxnum:
14
- # o = f'{x:7}'
15
- o = f"{x:{self.width - 1}}"
16
-
17
- # converting int to float without adding zero
18
- if "." not in o:
19
- o += "."
20
-
21
- # float longer than 8 will need rounding to fit width
22
- elif len(o) > self.width:
23
- # output = str(round(x, 7 - str(x).index(".")))
24
- o = str(round(x, self.width - 1 - str(x).index(".")))
25
- if len(o) < self.width:
26
- o += (self.width - len(o)) * "0"
27
-
28
- else:
29
- # for exponents
30
- # added a loop for super large numbers or negative as "-" is another char
31
- # Added max(max_char, 5) to account for max length of less
32
- # than 5, was having too much fun
33
- # TODO can i come up with a threshold value for these up front,
34
- # so that i dont have to do this calc for every value??
35
- for n in range(max(self.width, 5) - 5, 0, -1):
36
- fill = f".{n}e"
37
- o = f"{x:{fill}}".replace("+0", "+")
38
-
39
- # if all good stop looping
40
- if len(o) == self.width:
41
- break
42
- else:
43
- raise ValueError(f"Number is too large to fit in {self.width} characters", x)
44
- return o
@@ -1,592 +0,0 @@
1
- from __future__ import annotations
2
- import logging
3
- from typing import List, Optional
4
- import panel as pn
5
- import holoviews as hv
6
- from param import Parameter
7
- from functools import partial
8
- import hvplot.xarray # noqa pylint: disable=duplicate-code,unused-import
9
- import xarray as xr
10
-
11
- from bencher.utils import hmap_canonical_input, get_nearest_coords, get_nearest_coords1D
12
- from bencher.results.panel_result import PanelResult
13
- from bencher.results.bench_result_base import ReduceType
14
-
15
- from bencher.plotting.plot_filter import PlotFilter, VarRange
16
- from bencher.variables.results import ResultVar
17
-
18
-
19
- hv.extension("bokeh", "plotly")
20
-
21
-
22
- class HoloviewResult(PanelResult):
23
- @staticmethod
24
- def set_default_opts(width=600, height=600):
25
- width_heigh = {"width": width, "height": height, "tools": ["hover"]}
26
- hv.opts.defaults(
27
- hv.opts.Curve(**width_heigh),
28
- hv.opts.Points(**width_heigh),
29
- hv.opts.Bars(**width_heigh),
30
- hv.opts.Scatter(**width_heigh),
31
- hv.opts.HeatMap(cmap="plasma", **width_heigh, colorbar=True),
32
- # hv.opts.Surface(**width_heigh),
33
- hv.opts.GridSpace(plot_size=400),
34
- )
35
- return width_heigh
36
-
37
- def to(self, hv_type: hv.Chart, reduce: ReduceType = ReduceType.AUTO, **kwargs) -> hv.Chart:
38
- return self.to_hv_dataset(reduce).to(hv_type, **kwargs)
39
-
40
- def overlay_plots(self, plot_callback: callable) -> Optional[hv.Overlay]:
41
- results = []
42
- markdown_results = pn.Row()
43
- for rv in self.bench_cfg.result_vars:
44
- res = plot_callback(rv)
45
- if res is not None:
46
- if isinstance(res, pn.pane.Markdown):
47
- markdown_results.append(res)
48
- else:
49
- results.append(res)
50
- if len(results) > 0:
51
- overlay = hv.Overlay(results).collate()
52
- if len(markdown_results) == 0:
53
- return overlay
54
- return pn.Row(overlay, markdown_results)
55
- if len(markdown_results) > 0:
56
- return markdown_results
57
- return None
58
-
59
- def layout_plots(self, plot_callback: callable):
60
- if len(self.bench_cfg.result_vars) > 0:
61
- pt = hv.Layout()
62
- got_results = False
63
- for rv in self.bench_cfg.result_vars:
64
- res = plot_callback(rv)
65
- if res is not None:
66
- got_results = True
67
- pt += plot_callback(rv)
68
- return pt if got_results else None
69
- return plot_callback(self.bench_cfg.result_vars[0])
70
-
71
- def time_widget(self, title):
72
- return {"title": title}
73
- # if self.bench_cfg.over_time:
74
- # time_widget_args = {"widget_type": "scrubber", "widget_location": "bottom"}
75
- # time_widget_args["title"] = None # use the title generated by the widget instead
76
- # else:
77
- # time_widget_args = {"widget_type": "individual"}
78
- # time_widget_args["title"] = title
79
-
80
- # return time_widget_args
81
-
82
- def to_bar(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
83
- return self.filter(
84
- self.to_bar_ds,
85
- float_range=VarRange(0, 0),
86
- cat_range=VarRange(0, None),
87
- repeats_range=VarRange(1, 1),
88
- reduce=ReduceType.SQUEEZE,
89
- target_dimension=2,
90
- result_var=result_var,
91
- result_types=(ResultVar),
92
- **kwargs,
93
- )
94
-
95
- def to_bar_ds(self, dataset: xr.Dataset, result_var: Parameter = None, **kwargs):
96
- by = None
97
- if self.plt_cnt_cfg.cat_cnt >= 2:
98
- by = self.plt_cnt_cfg.cat_vars[1].name
99
- da_plot = dataset[result_var.name]
100
- title = self.title_from_ds(da_plot, result_var, **kwargs)
101
- time_widget_args = self.time_widget(title)
102
- return da_plot.hvplot.bar(by=by, **time_widget_args, **kwargs)
103
-
104
- def hv_container_ds(
105
- self, dataset: xr.Dataset, result_var: Parameter, container: hv.Chart = None, **kwargs
106
- ):
107
- return hv.Dataset(dataset[result_var.name]).to(container).opts(**kwargs)
108
-
109
- def to_hv_container(
110
- self,
111
- container: pn.pane.panel,
112
- reduce_type=ReduceType.AUTO,
113
- target_dimension: int = 2,
114
- result_var: Parameter = None,
115
- result_types=(ResultVar),
116
- **kwargs,
117
- ) -> Optional[pn.pane.panel]:
118
- return self.map_plot_panes(
119
- partial(self.hv_container_ds, container=container),
120
- hv_dataset=self.to_hv_dataset(reduce_type),
121
- target_dimension=target_dimension,
122
- result_var=result_var,
123
- result_types=result_types,
124
- **kwargs,
125
- )
126
-
127
- def to_line(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
128
- return self.filter(
129
- self.to_line_ds,
130
- float_range=VarRange(1, 1),
131
- cat_range=VarRange(0, None),
132
- repeats_range=VarRange(1, 1),
133
- reduce=ReduceType.SQUEEZE,
134
- target_dimension=2,
135
- result_var=result_var,
136
- result_types=(ResultVar),
137
- **kwargs,
138
- )
139
-
140
- def to_line_ds(self, dataset: xr.Dataset, result_var: Parameter, **kwargs):
141
- x = self.plt_cnt_cfg.float_vars[0].name
142
- # y = self.plt_cnt_cfg.result_vars[0].name
143
- by = None
144
- if self.plt_cnt_cfg.cat_cnt >= 1:
145
- by = self.plt_cnt_cfg.cat_vars[0].name
146
- da_plot = dataset[result_var.name]
147
- title = self.title_from_ds(da_plot, result_var, **kwargs)
148
- time_widget_args = self.time_widget(title)
149
- return da_plot.hvplot.line(x=x, by=by, **time_widget_args, **kwargs)
150
-
151
- def to_curve(self, result_var: Parameter = None, **kwargs):
152
- return self.filter(
153
- self.to_curve_ds,
154
- float_range=VarRange(1, 1),
155
- cat_range=VarRange(0, None),
156
- repeats_range=VarRange(2, None),
157
- reduce=ReduceType.REDUCE,
158
- target_dimension=2,
159
- result_var=result_var,
160
- result_types=(ResultVar),
161
- **kwargs,
162
- )
163
-
164
- def to_curve_ds(
165
- self, dataset: xr.Dataset, result_var: Parameter, **kwargs
166
- ) -> Optional[hv.Curve]:
167
- hvds = hv.Dataset(dataset)
168
- # result_var = self.get_results_var_list(result_var)[0]
169
- title = self.title_from_ds(dataset, result_var, **kwargs)
170
- pt = hvds.to(hv.Curve).opts(title=title, **kwargs)
171
- pt *= hvds.to(hv.Spread).opts(alpha=0.2)
172
- if len(dataset.sizes) > 1:
173
- return pt.opts(legend_position="right").overlay()
174
- return pt.opts(legend_position="right")
175
-
176
- def to_heatmap(
177
- self,
178
- result_var: Parameter = None,
179
- tap_var=None,
180
- tap_container=None,
181
- target_dimension=2,
182
- **kwargs,
183
- ) -> Optional[pn.panel]:
184
- if tap_var is None:
185
- heatmap_cb = self.to_heatmap_ds
186
- else:
187
- heatmap_cb = partial(
188
- self.to_heatmap_container_tap_ds, result_var_plot=tap_var, container=tap_container
189
- )
190
-
191
- return self.filter(
192
- heatmap_cb,
193
- float_range=VarRange(2, None),
194
- cat_range=VarRange(0, None),
195
- input_range=VarRange(1, None),
196
- target_dimension=target_dimension,
197
- result_var=result_var,
198
- result_types=(ResultVar),
199
- **kwargs,
200
- )
201
-
202
- def to_heatmap_ds(
203
- self, dataset: xr.Dataset, result_var: Parameter, **kwargs
204
- ) -> Optional[hv.HeatMap]:
205
- if len(dataset.dims) >= 2:
206
- x = self.plt_cnt_cfg.float_vars[0].name
207
- y = self.plt_cnt_cfg.float_vars[1].name
208
- C = result_var.name
209
- title = f"Heatmap of {result_var.name}"
210
- time_args = self.time_widget(title)
211
- return dataset.hvplot.heatmap(x=x, y=y, C=C, cmap="plasma", **time_args, **kwargs)
212
- return None
213
-
214
- def to_heatmap_container_tap_ds(
215
- self,
216
- dataset: xr.Dataset,
217
- result_var: Parameter,
218
- result_var_plot: Parameter,
219
- container: pn.pane.panel = pn.pane.panel,
220
- **kwargs,
221
- ) -> pn.Row:
222
- htmap = self.to_heatmap_ds(dataset, result_var).opts(tools=["hover", "tap"], **kwargs)
223
- htmap_posxy = hv.streams.Tap(source=htmap, x=0, y=0)
224
-
225
- container_instance = container(**kwargs)
226
- title = pn.pane.Markdown("Selected: None")
227
-
228
- def tap_plot(x, y): # pragma: no cover
229
- x_nearest = get_nearest_coords1D(
230
- x, dataset.coords[self.bench_cfg.input_vars[0].name].data
231
- )
232
- y_nearest = get_nearest_coords1D(
233
- y, dataset.coords[self.bench_cfg.input_vars[1].name].data
234
- )
235
- kdims = {}
236
- kdims[self.bench_cfg.input_vars[0].name] = x_nearest
237
- kdims[self.bench_cfg.input_vars[1].name] = y_nearest
238
-
239
- if hasattr(htmap, "current_key"):
240
- for d, k in zip(htmap.kdims, htmap.current_key):
241
- kdims[d.name] = k
242
-
243
- ds = dataset[result_var_plot.name]
244
- val = ds.sel(**kdims)
245
- item = self.zero_dim_da_to_val(val)
246
- title.object = "Selected: " + ", ".join([f"{k}:{v}" for k, v in kdims.items()])
247
- container_instance.object = item
248
- if hasattr(container, "autoplay"): # container is a video, set to autoplay
249
- container_instance.paused = False
250
- container_instance.time = 0
251
- container_instance.loop = True
252
- container_instance.autoplay = True
253
-
254
- htmap_posxy.add_subscriber(tap_plot)
255
- bound_plot = pn.Column(title, container_instance)
256
- return pn.Row(htmap, bound_plot)
257
-
258
- def to_error_bar(self) -> hv.Bars:
259
- return self.to_hv_dataset(ReduceType.REDUCE).to(hv.ErrorBars)
260
-
261
- def to_points(self, reduce: ReduceType = ReduceType.AUTO) -> hv.Points:
262
- ds = self.to_hv_dataset(reduce)
263
- pt = ds.to(hv.Points)
264
- if reduce:
265
- pt *= ds.to(hv.ErrorBars)
266
- return pt
267
-
268
- def to_scatter(self, **kwargs) -> Optional[pn.panel]:
269
- match_res = PlotFilter(
270
- float_range=VarRange(0, 0), cat_range=VarRange(0, None), repeats_range=VarRange(1, 1)
271
- ).matches_result(self.plt_cnt_cfg, "to_hvplot_scatter")
272
- if match_res.overall:
273
- hv_ds = self.to_hv_dataset(ReduceType.SQUEEZE)
274
- by = None
275
- subplots = False
276
- if self.plt_cnt_cfg.cat_cnt > 1:
277
- by = [v.name for v in self.bench_cfg.input_vars[1:]]
278
- subplots = False
279
- return hv_ds.data.hvplot.scatter(by=by, subplots=subplots, **kwargs).opts(
280
- title=self.to_plot_title()
281
- )
282
- return match_res.to_panel(**kwargs)
283
-
284
- # def to_scatter_jitter(self, **kwargs) -> Optional[hv.Scatter]:
285
- # matches = PlotFilter(
286
- # float_range=VarRange(0, 0),
287
- # cat_range=VarRange(0, None),
288
- # repeats_range=VarRange(2, None),
289
- # input_range=VarRange(1, None),
290
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
291
- # if matches.overall:
292
- # hv_ds = self.to_hv_dataset(ReduceType.NONE)
293
-
294
- # by = None
295
- # groupby = None
296
- # subplots=False
297
- # if self.plt_cnt_cfg.cat_cnt > 1:
298
- # by = [v.name for v in self.bench_cfg.all_vars[1:]]
299
- # subplots=False
300
- # return hv_ds.data.hvplot.scatter(by=by,subplots=subplots, **kwargs).opts(title=self.to_plot_title())
301
-
302
- # # pt = (
303
- # # hv_ds.to(hv.Scatter)
304
- # # .opts(jitter=0.1)
305
- # # .overlay("repeat")
306
- # # .opts(show_legend=False, title=self.to_plot_title(), **kwargs)
307
- # # )
308
- # # return pt
309
- # return matches.to_panel()
310
-
311
- # def to_scatter_jitter_multi(self, **kwargs) -> Optional[hv.Scatter]:
312
- # matches = PlotFilter(
313
- # float_range=VarRange(0, 0),
314
- # cat_range=VarRange(0, None),
315
- # repeats_range=VarRange(2, None),
316
- # input_range=VarRange(1, None),
317
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
318
- # if matches.overall:
319
- # hv_dataset = self.to_hv_dataset(ReduceType.NONE)
320
-
321
- # print("KDIMS",hv_dataset.kdims)
322
- # # hv_dataset.kdims =[hv_dataset.kdims[2],hv_dataset.kdims[1],hv_dataset.kdims[0]]
323
- # # print("KDIMS",hv_dataset.kdims)
324
-
325
- # # exit()
326
- # cb = partial(self.to_scatter_jitter_da, **kwargs)
327
- # return self.to_panes_multi_panel(hv_dataset, None, plot_callback=cb, target_dimension=3)
328
- # return matches.to_panel()
329
-
330
- # def to_scatter_jitter_da(self, ds: xr.Dataset, **kwargs) -> Optional[hv.Scatter]:
331
- # matches = PlotFilter(
332
- # float_range=VarRange(0, 0),
333
- # cat_range=VarRange(0, None),
334
- # repeats_range=VarRange(2, None),
335
- # input_range=VarRange(1, None),
336
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
337
- # if matches.overall:
338
-
339
- # print("DA IN",da)
340
- # da = self.to_hv_dataset(ReduceType.NONE)
341
- # hvds = hv.Dataset(da)
342
- # # return None
343
-
344
- # # print("DA FRESH",da)
345
- # result_var = self.bench_cfg.result_vars[0]
346
-
347
- # print(hvds.data.sizes)
348
- # print("repeat" in hvds.data.sizes)
349
- # # if "repeat" in hvds.data.sizes:
350
- # # try:
351
- # # pt = (
352
- # # hvds.to(hv.Scatter)
353
- # # .opts(jitter=0.1)
354
- # # # .overlay()
355
- # # .overlay("repeat")
356
- # # .opts(show_legend=False, title=self.to_plot_title(), clabel=result_var.name, **kwargs)
357
- # # )
358
- # # except:
359
- # pt = (
360
- # hvds.to(hv.Scatter)
361
- # .opts(jitter=0.1)
362
- # # .overlay()
363
- # # .overlay("repeat")
364
- # .opts(show_legend=False, title=self.to_plot_title(), clabel=result_var.name, **kwargs)
365
- # )
366
- # return pt
367
- # return matches.to_panel()
368
-
369
- def to_scatter_jitter(
370
- self,
371
- result_var: Parameter = None,
372
- **kwargs, # pylint: disable=unused-argument
373
- ) -> List[hv.Scatter]:
374
- return self.overlay_plots(partial(self.to_scatter_jitter_single, **kwargs))
375
-
376
- def to_scatter_jitter_single(self, result_var: Parameter, **kwargs) -> Optional[hv.Scatter]:
377
- matches = PlotFilter(
378
- float_range=VarRange(0, 0),
379
- cat_range=VarRange(0, None),
380
- repeats_range=VarRange(2, None),
381
- input_range=VarRange(1, None),
382
- ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
383
- if matches.overall:
384
- ds = self.to_hv_dataset(ReduceType.NONE)
385
- pt = (
386
- ds.to(hv.Scatter, vdims=[result_var.name], label=result_var.name)
387
- .opts(jitter=0.1, show_legend=False, title=self.to_plot_title(), **kwargs)
388
- .overlay("repeat")
389
- )
390
- return pt
391
- return matches.to_panel()
392
-
393
- def to_heatmap_single(
394
- self, result_var: Parameter, reduce: ReduceType = ReduceType.AUTO, **kwargs
395
- ) -> hv.HeatMap:
396
- matches_res = PlotFilter(
397
- float_range=VarRange(2, None),
398
- cat_range=VarRange(0, None),
399
- input_range=VarRange(1, None),
400
- ).matches_result(self.plt_cnt_cfg, "to_heatmap")
401
- if matches_res.overall:
402
- z = result_var
403
- title = f"{z.name} vs ("
404
-
405
- for iv in self.bench_cfg.input_vars:
406
- title += f" vs {iv.name}"
407
- title += ")"
408
-
409
- color_label = f"{z.name} [{z.units}]"
410
-
411
- return self.to(hv.HeatMap, reduce).opts(clabel=color_label, **kwargs)
412
- return matches_res.to_panel()
413
-
414
- def to_heatmap_tap(
415
- self,
416
- result_var: Parameter,
417
- reduce: ReduceType = ReduceType.AUTO,
418
- width=800,
419
- height=800,
420
- **kwargs,
421
- ):
422
- htmap = self.to_heatmap_single(result_var, reduce).opts(
423
- tools=["hover", "tap"], width=width, height=height
424
- )
425
- htmap_posxy = hv.streams.Tap(source=htmap, x=0, y=0)
426
-
427
- def tap_plot(x, y):
428
- kwargs[self.bench_cfg.input_vars[0].name] = x
429
- kwargs[self.bench_cfg.input_vars[1].name] = y
430
- return self.get_nearest_holomap(**kwargs).opts(width=width, height=height)
431
-
432
- tap_htmap = hv.DynamicMap(tap_plot, streams=[htmap_posxy])
433
- return htmap + tap_htmap
434
-
435
- def to_nd_layout(self, hmap_name: str) -> hv.NdLayout:
436
- return hv.NdLayout(self.get_hmap(hmap_name), kdims=self.bench_cfg.hmap_kdims).opts(
437
- shared_axes=False, shared_datasource=False
438
- )
439
-
440
- def to_holomap(self, name: str = None) -> hv.HoloMap:
441
- return hv.HoloMap(self.to_nd_layout(name)).opts(shared_axes=False)
442
-
443
- def to_holomap_list(self, hmap_names: List[str] = None) -> hv.HoloMap:
444
- if hmap_names is None:
445
- hmap_names = [i.name for i in self.result_hmaps]
446
- col = pn.Column()
447
- for name in hmap_names:
448
- self.to_holomap(name)
449
- return col
450
-
451
- def get_nearest_holomap(self, name: str = None, **kwargs):
452
- canonical_inp = hmap_canonical_input(
453
- get_nearest_coords(self.ds, collapse_list=True, **kwargs)
454
- )
455
- return self.get_hmap(name)[canonical_inp].opts(framewise=True)
456
-
457
- def to_dynamic_map(self, name: str = None) -> hv.DynamicMap:
458
- """use the values stored in the holomap dictionary to populate a dynamic map. Note that this is much faster than passing the holomap to a holomap object as the values are calculated on the fly"""
459
-
460
- def cb(**kwargs):
461
- return self.get_hmap(name)[hmap_canonical_input(kwargs)].opts(
462
- framewise=True, shared_axes=False
463
- )
464
-
465
- kdims = []
466
- for i in self.bench_cfg.input_vars + [self.bench_cfg.iv_repeat]:
467
- kdims.append(i.as_dim(compute_values=True, debug=self.bench_cfg.debug))
468
-
469
- return hv.DynamicMap(cb, kdims=kdims)
470
-
471
- def to_grid(self, inputs=None):
472
- if inputs is None:
473
- inputs = self.bench_cfg.inputs_as_str()
474
- if len(inputs) > 2:
475
- inputs = inputs[:2]
476
- return self.to_holomap().grid(inputs)
477
-
478
- def to_table(self):
479
- return self.to(hv.Table, ReduceType.SQUEEZE)
480
-
481
- def to_surface(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
482
- return self.filter(
483
- self.to_surface_ds,
484
- float_range=VarRange(2, None),
485
- cat_range=VarRange(0, None),
486
- input_range=VarRange(1, None),
487
- reduce=ReduceType.REDUCE,
488
- target_dimension=2,
489
- result_var=result_var,
490
- result_types=(ResultVar),
491
- **kwargs,
492
- )
493
-
494
- def to_surface_ds(
495
- self, dataset: xr.Dataset, result_var: Parameter, alpha: float = 0.3, **kwargs
496
- ) -> Optional[pn.panel]:
497
- """Given a benchCfg generate a 2D surface plot
498
-
499
- Args:
500
- result_var (Parameter): result variable to plot
501
-
502
- Returns:
503
- pn.pane.holoview: A 2d surface plot as a holoview in a pane
504
- """
505
- matches_res = PlotFilter(
506
- float_range=VarRange(2, 2),
507
- cat_range=VarRange(0, None),
508
- vector_len=VarRange(1, 1),
509
- result_vars=VarRange(1, 1),
510
- ).matches_result(self.plt_cnt_cfg, "to_surface_hv")
511
- if matches_res.overall:
512
- # xr_cfg = plot_float_cnt_2(self.plt_cnt_cfg, result_var, self.bench_cfg.debug)
513
-
514
- # TODO a warning suggests setting this parameter, but it does not seem to help as expected, leaving here to fix in the future
515
- # hv.config.image_rtol = 1.0
516
-
517
- mean = dataset[result_var.name]
518
-
519
- hvds = hv.Dataset(dataset[result_var.name])
520
-
521
- x = self.plt_cnt_cfg.float_vars[0]
522
- y = self.plt_cnt_cfg.float_vars[1]
523
-
524
- try:
525
- surface = hvds.to(hv.Surface, vdims=[result_var.name])
526
- surface = surface.opts(colorbar=True)
527
- except Exception as e:
528
- logging.warning(e)
529
-
530
- if self.bench_cfg.repeats > 1:
531
- std_dev = dataset[f"{result_var.name}_std"]
532
-
533
- upper = mean + std_dev
534
- upper.name = result_var.name
535
-
536
- lower = mean - std_dev
537
- lower.name = result_var.name
538
-
539
- surface *= (
540
- hv.Dataset(upper)
541
- .to(hv.Surface)
542
- .opts(alpha=alpha, colorbar=False, backend="plotly")
543
- )
544
- surface *= (
545
- hv.Dataset(lower)
546
- .to(hv.Surface)
547
- .opts(alpha=alpha, colorbar=False, backend="plotly")
548
- )
549
-
550
- surface = surface.opts(
551
- zlabel=f"{result_var.name} [{result_var.units}]",
552
- title=f"{result_var.name} vs ({x.name} and {y.name})",
553
- backend="plotly",
554
- **kwargs,
555
- )
556
-
557
- if self.bench_cfg.render_plotly:
558
- hv.extension("plotly")
559
- out = surface
560
- else:
561
- # using render disabled the holoviews sliders :(
562
- out = hv.render(surface, backend="plotly")
563
- return pn.Column(out, name="surface_hv")
564
-
565
- return matches_res.to_panel()
566
-
567
- # def plot_scatter2D_hv(self, rv: ParametrizedSweep) -> pn.pane.Plotly:
568
- # import plotly.express as px
569
-
570
- # """Given a benchCfg generate a 2D scatter plot
571
-
572
- # Args:
573
- # bench_cfg (BenchCfg): description of benchmark
574
- # rv (ParametrizedSweep): result variable to plot
575
-
576
- # Returns:
577
- # pn.pane.Plotly: A 3d volume plot as a holoview in a pane
578
- # """
579
-
580
- # # bench_cfg = wrap_long_time_labels(bench_cfg)
581
- # self.ds.drop_vars("repeat")
582
-
583
- # df = self.to_pandas()
584
-
585
- # names = rv.index_names()
586
-
587
- # return px.scatter(
588
- # df, x=names[0], y=names[1], marginal_x="histogram", marginal_y="histogram"
589
- # )
590
-
591
-
592
- HoloviewResult.set_default_opts()