holobench 1.3.4__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 +4 -1
  2. bencher/bench_cfg.py +37 -34
  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 +87 -50
  7. bencher/class_enum.py +52 -0
  8. bencher/job.py +6 -4
  9. bencher/optuna_conversions.py +1 -1
  10. bencher/utils.py +58 -3
  11. bencher/video_writer.py +110 -6
  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.4.dist-info → holobench-1.22.2.dist-info}/METADATA +39 -32
  15. holobench-1.22.2.dist-info/RECORD +20 -0
  16. {holobench-1.3.4.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 -98
  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 -83
  65. bencher/results/bench_result_base.py +0 -401
  66. bencher/results/float_formatter.py +0 -44
  67. bencher/results/holoview_result.py +0 -535
  68. bencher/results/optuna_result.py +0 -332
  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.4.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,535 +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
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(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
177
- return self.filter(
178
- self.to_heatmap_ds,
179
- float_range=VarRange(2, None),
180
- cat_range=VarRange(0, None),
181
- input_range=VarRange(1, None),
182
- target_dimension=2,
183
- result_var=result_var,
184
- result_types=(ResultVar),
185
- **kwargs,
186
- )
187
-
188
- def to_heatmap_ds(
189
- self, dataset: xr.Dataset, result_var: Parameter, **kwargs
190
- ) -> Optional[hv.HeatMap]:
191
- if len(dataset.dims) >= 2:
192
- # dims = [d for d in da.sizes]
193
- # x = dims[0]
194
- # y = dims[1]
195
- x = self.plt_cnt_cfg.float_vars[0].name
196
- y = self.plt_cnt_cfg.float_vars[1].name
197
- C = result_var.name
198
- title = f"Heatmap of {result_var.name}"
199
- time_args = self.time_widget(title)
200
- return dataset.hvplot.heatmap(x=x, y=y, C=C, cmap="plasma", **time_args, **kwargs)
201
- return None
202
-
203
- def to_error_bar(self) -> hv.Bars:
204
- return self.to_hv_dataset(ReduceType.REDUCE).to(hv.ErrorBars)
205
-
206
- def to_points(self, reduce: ReduceType = ReduceType.AUTO) -> hv.Points:
207
- ds = self.to_hv_dataset(reduce)
208
- pt = ds.to(hv.Points)
209
- if reduce:
210
- pt *= ds.to(hv.ErrorBars)
211
- return pt
212
-
213
- def to_scatter(self, **kwargs) -> Optional[pn.panel]:
214
- match_res = PlotFilter(
215
- float_range=VarRange(0, 0), cat_range=VarRange(0, None), repeats_range=VarRange(1, 1)
216
- ).matches_result(self.plt_cnt_cfg, "to_hvplot_scatter")
217
- if match_res.overall:
218
- hv_ds = self.to_hv_dataset(ReduceType.SQUEEZE)
219
- by = None
220
- subplots = False
221
- if self.plt_cnt_cfg.cat_cnt > 1:
222
- by = [v.name for v in self.bench_cfg.input_vars[1:]]
223
- subplots = False
224
- return hv_ds.data.hvplot.scatter(by=by, subplots=subplots, **kwargs).opts(
225
- title=self.to_plot_title()
226
- )
227
- return match_res.to_panel(**kwargs)
228
-
229
- # def to_scatter_jitter(self, **kwargs) -> Optional[hv.Scatter]:
230
- # matches = PlotFilter(
231
- # float_range=VarRange(0, 0),
232
- # cat_range=VarRange(0, None),
233
- # repeats_range=VarRange(2, None),
234
- # input_range=VarRange(1, None),
235
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
236
- # if matches.overall:
237
- # hv_ds = self.to_hv_dataset(ReduceType.NONE)
238
-
239
- # by = None
240
- # groupby = None
241
- # subplots=False
242
- # if self.plt_cnt_cfg.cat_cnt > 1:
243
- # by = [v.name for v in self.bench_cfg.all_vars[1:]]
244
- # subplots=False
245
- # return hv_ds.data.hvplot.scatter(by=by,subplots=subplots, **kwargs).opts(title=self.to_plot_title())
246
-
247
- # # pt = (
248
- # # hv_ds.to(hv.Scatter)
249
- # # .opts(jitter=0.1)
250
- # # .overlay("repeat")
251
- # # .opts(show_legend=False, title=self.to_plot_title(), **kwargs)
252
- # # )
253
- # # return pt
254
- # return matches.to_panel()
255
-
256
- # def to_scatter_jitter_multi(self, **kwargs) -> Optional[hv.Scatter]:
257
- # matches = PlotFilter(
258
- # float_range=VarRange(0, 0),
259
- # cat_range=VarRange(0, None),
260
- # repeats_range=VarRange(2, None),
261
- # input_range=VarRange(1, None),
262
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
263
- # if matches.overall:
264
- # hv_dataset = self.to_hv_dataset(ReduceType.NONE)
265
-
266
- # print("KDIMS",hv_dataset.kdims)
267
- # # hv_dataset.kdims =[hv_dataset.kdims[2],hv_dataset.kdims[1],hv_dataset.kdims[0]]
268
- # # print("KDIMS",hv_dataset.kdims)
269
-
270
- # # exit()
271
- # cb = partial(self.to_scatter_jitter_da, **kwargs)
272
- # return self.to_panes_multi_panel(hv_dataset, None, plot_callback=cb, target_dimension=3)
273
- # return matches.to_panel()
274
-
275
- # def to_scatter_jitter_da(self, ds: xr.Dataset, **kwargs) -> Optional[hv.Scatter]:
276
- # matches = PlotFilter(
277
- # float_range=VarRange(0, 0),
278
- # cat_range=VarRange(0, None),
279
- # repeats_range=VarRange(2, None),
280
- # input_range=VarRange(1, None),
281
- # ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
282
- # if matches.overall:
283
-
284
- # print("DA IN",da)
285
- # da = self.to_hv_dataset(ReduceType.NONE)
286
- # hvds = hv.Dataset(da)
287
- # # return None
288
-
289
- # # print("DA FRESH",da)
290
- # result_var = self.bench_cfg.result_vars[0]
291
-
292
- # print(hvds.data.sizes)
293
- # print("repeat" in hvds.data.sizes)
294
- # # if "repeat" in hvds.data.sizes:
295
- # # try:
296
- # # pt = (
297
- # # hvds.to(hv.Scatter)
298
- # # .opts(jitter=0.1)
299
- # # # .overlay()
300
- # # .overlay("repeat")
301
- # # .opts(show_legend=False, title=self.to_plot_title(), clabel=result_var.name, **kwargs)
302
- # # )
303
- # # except:
304
- # pt = (
305
- # hvds.to(hv.Scatter)
306
- # .opts(jitter=0.1)
307
- # # .overlay()
308
- # # .overlay("repeat")
309
- # .opts(show_legend=False, title=self.to_plot_title(), clabel=result_var.name, **kwargs)
310
- # )
311
- # return pt
312
- # return matches.to_panel()
313
-
314
- def to_scatter_jitter(
315
- self, result_var: Parameter = None, **kwargs # pylint: disable=unused-argument
316
- ) -> List[hv.Scatter]:
317
- return self.overlay_plots(partial(self.to_scatter_jitter_single, **kwargs))
318
-
319
- def to_scatter_jitter_single(self, result_var: Parameter, **kwargs) -> Optional[hv.Scatter]:
320
- matches = PlotFilter(
321
- float_range=VarRange(0, 0),
322
- cat_range=VarRange(0, None),
323
- repeats_range=VarRange(2, None),
324
- input_range=VarRange(1, None),
325
- ).matches_result(self.plt_cnt_cfg, "to_scatter_jitter")
326
- if matches.overall:
327
- ds = self.to_hv_dataset(ReduceType.NONE)
328
- pt = (
329
- ds.to(hv.Scatter, vdims=[result_var.name], label=result_var.name)
330
- .opts(jitter=0.1, show_legend=False, title=self.to_plot_title(), **kwargs)
331
- .overlay("repeat")
332
- )
333
- return pt
334
- return matches.to_panel()
335
-
336
- def to_heatmap_single(
337
- self, result_var: Parameter, reduce: ReduceType = ReduceType.AUTO, **kwargs
338
- ) -> hv.HeatMap:
339
- matches_res = PlotFilter(
340
- float_range=VarRange(2, None),
341
- cat_range=VarRange(0, None),
342
- input_range=VarRange(1, None),
343
- ).matches_result(self.plt_cnt_cfg, "to_heatmap")
344
- if matches_res.overall:
345
- z = result_var
346
- title = f"{z.name} vs ("
347
-
348
- for iv in self.bench_cfg.input_vars:
349
- title += f" vs {iv.name}"
350
- title += ")"
351
-
352
- color_label = f"{z.name} [{z.units}]"
353
-
354
- return self.to(hv.HeatMap, reduce).opts(clabel=color_label, **kwargs)
355
- return matches_res.to_panel()
356
-
357
- def to_heatmap_tap(
358
- self,
359
- result_var: Parameter,
360
- reduce: ReduceType = ReduceType.AUTO,
361
- width=800,
362
- height=800,
363
- **kwargs,
364
- ):
365
- htmap = self.to_heatmap_single(result_var, reduce).opts(
366
- tools=["hover", "tap"], width=width, height=height
367
- )
368
- htmap_posxy = hv.streams.Tap(source=htmap, x=0, y=0)
369
-
370
- def tap_plot(x, y):
371
- kwargs[self.bench_cfg.input_vars[0].name] = x
372
- kwargs[self.bench_cfg.input_vars[1].name] = y
373
- return self.get_nearest_holomap(**kwargs).opts(width=width, height=height)
374
-
375
- tap_htmap = hv.DynamicMap(tap_plot, streams=[htmap_posxy])
376
- return htmap + tap_htmap
377
-
378
- def to_nd_layout(self, hmap_name: str) -> hv.NdLayout:
379
- return hv.NdLayout(self.get_hmap(hmap_name), kdims=self.bench_cfg.hmap_kdims).opts(
380
- shared_axes=False, shared_datasource=False
381
- )
382
-
383
- def to_holomap(self, name: str = None) -> hv.HoloMap:
384
- return hv.HoloMap(self.to_nd_layout(name)).opts(shared_axes=False)
385
-
386
- def to_holomap_list(self, hmap_names: List[str] = None) -> hv.HoloMap:
387
- if hmap_names is None:
388
- hmap_names = [i.name for i in self.result_hmaps]
389
- col = pn.Column()
390
- for name in hmap_names:
391
- self.to_holomap(name)
392
- return col
393
-
394
- def get_nearest_holomap(self, name: str = None, **kwargs):
395
- canonical_inp = hmap_canonical_input(
396
- get_nearest_coords(self.ds, collapse_list=True, **kwargs)
397
- )
398
- return self.get_hmap(name)[canonical_inp].opts(framewise=True)
399
-
400
- def to_dynamic_map(self, name: str = None) -> hv.DynamicMap:
401
- """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"""
402
-
403
- def cb(**kwargs):
404
- return self.get_hmap(name)[hmap_canonical_input(kwargs)].opts(
405
- framewise=True, shared_axes=False
406
- )
407
-
408
- kdims = []
409
- for i in self.bench_cfg.input_vars + [self.bench_cfg.iv_repeat]:
410
- kdims.append(i.as_dim(compute_values=True, debug=self.bench_cfg.debug))
411
-
412
- return hv.DynamicMap(cb, kdims=kdims)
413
-
414
- def to_grid(self, inputs=None):
415
- if inputs is None:
416
- inputs = self.bench_cfg.inputs_as_str()
417
- if len(inputs) > 2:
418
- inputs = inputs[:2]
419
- return self.to_holomap().grid(inputs)
420
-
421
- def to_table(self):
422
- return self.to(hv.Table, ReduceType.SQUEEZE)
423
-
424
- def to_surface(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
425
- return self.filter(
426
- self.to_surface_ds,
427
- float_range=VarRange(2, None),
428
- cat_range=VarRange(0, None),
429
- input_range=VarRange(1, None),
430
- reduce=ReduceType.REDUCE,
431
- target_dimension=2,
432
- result_var=result_var,
433
- result_types=(ResultVar),
434
- **kwargs,
435
- )
436
-
437
- def to_surface_ds(
438
- self, dataset: xr.Dataset, result_var: Parameter, alpha: float = 0.3, **kwargs
439
- ) -> Optional[pn.panel]:
440
- """Given a benchCfg generate a 2D surface plot
441
-
442
- Args:
443
- result_var (Parameter): result variable to plot
444
-
445
- Returns:
446
- pn.pane.holoview: A 2d surface plot as a holoview in a pane
447
- """
448
- matches_res = PlotFilter(
449
- float_range=VarRange(2, 2),
450
- cat_range=VarRange(0, None),
451
- vector_len=VarRange(1, 1),
452
- result_vars=VarRange(1, 1),
453
- ).matches_result(self.plt_cnt_cfg, "to_surface_hv")
454
- if matches_res.overall:
455
- # xr_cfg = plot_float_cnt_2(self.plt_cnt_cfg, result_var, self.bench_cfg.debug)
456
-
457
- # TODO a warning suggests setting this parameter, but it does not seem to help as expected, leaving here to fix in the future
458
- # hv.config.image_rtol = 1.0
459
-
460
- mean = dataset[result_var.name]
461
-
462
- hvds = hv.Dataset(dataset[result_var.name])
463
-
464
- x = self.plt_cnt_cfg.float_vars[0]
465
- y = self.plt_cnt_cfg.float_vars[1]
466
-
467
- try:
468
- surface = hvds.to(hv.Surface, vdims=[result_var.name])
469
- surface = surface.opts(colorbar=True)
470
- except Exception as e:
471
- logging.warning(e)
472
-
473
- if self.bench_cfg.repeats > 1:
474
- std_dev = dataset[f"{result_var.name}_std"]
475
-
476
- upper = mean + std_dev
477
- upper.name = result_var.name
478
-
479
- lower = mean - std_dev
480
- lower.name = result_var.name
481
-
482
- surface *= (
483
- hv.Dataset(upper)
484
- .to(hv.Surface)
485
- .opts(alpha=alpha, colorbar=False, backend="plotly")
486
- )
487
- surface *= (
488
- hv.Dataset(lower)
489
- .to(hv.Surface)
490
- .opts(alpha=alpha, colorbar=False, backend="plotly")
491
- )
492
-
493
- surface = surface.opts(
494
- zlabel=f"{result_var.name} [{result_var.units}]",
495
- title=f"{result_var.name} vs ({x.name} and {y.name})",
496
- backend="plotly",
497
- **kwargs,
498
- )
499
-
500
- if self.bench_cfg.render_plotly:
501
- hv.extension("plotly")
502
- out = surface
503
- else:
504
- # using render disabled the holoviews sliders :(
505
- out = hv.render(surface, backend="plotly")
506
- return pn.Column(out, name="surface_hv")
507
-
508
- return matches_res.to_panel()
509
-
510
- # def plot_scatter2D_hv(self, rv: ParametrizedSweep) -> pn.pane.Plotly:
511
- # import plotly.express as px
512
-
513
- # """Given a benchCfg generate a 2D scatter plot
514
-
515
- # Args:
516
- # bench_cfg (BenchCfg): description of benchmark
517
- # rv (ParametrizedSweep): result variable to plot
518
-
519
- # Returns:
520
- # pn.pane.Plotly: A 3d volume plot as a holoview in a pane
521
- # """
522
-
523
- # # bench_cfg = wrap_long_time_labels(bench_cfg)
524
- # self.ds.drop_vars("repeat")
525
-
526
- # df = self.to_pandas()
527
-
528
- # names = rv.index_names()
529
-
530
- # return px.scatter(
531
- # df, x=names[0], y=names[1], marginal_x="histogram", marginal_y="histogram"
532
- # )
533
-
534
-
535
- HoloviewResult.set_default_opts()