holobench 1.15.0__tar.gz → 1.16.0__tar.gz

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 (81) hide show
  1. {holobench-1.15.0 → holobench-1.16.0}/PKG-INFO +1 -1
  2. {holobench-1.15.0 → holobench-1.16.0}/bencher/bench_cfg.py +7 -3
  3. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_image.py +27 -2
  4. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_video.py +19 -2
  5. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/bench_result_base.py +2 -2
  6. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/holoview_result.py +191 -42
  7. {holobench-1.15.0 → holobench-1.16.0}/bencher/utils.py +3 -0
  8. {holobench-1.15.0 → holobench-1.16.0}/pyproject.toml +1 -1
  9. {holobench-1.15.0 → holobench-1.16.0}/README.md +0 -0
  10. {holobench-1.15.0 → holobench-1.16.0}/bencher/__init__.py +0 -0
  11. {holobench-1.15.0 → holobench-1.16.0}/bencher/bench_plot_server.py +0 -0
  12. {holobench-1.15.0 → holobench-1.16.0}/bencher/bench_report.py +0 -0
  13. {holobench-1.15.0 → holobench-1.16.0}/bencher/bench_runner.py +0 -0
  14. {holobench-1.15.0 → holobench-1.16.0}/bencher/bencher.py +0 -0
  15. {holobench-1.15.0 → holobench-1.16.0}/bencher/caching.py +0 -0
  16. {holobench-1.15.0 → holobench-1.16.0}/bencher/class_enum.py +0 -0
  17. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/__init__.py +0 -0
  18. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/benchmark_data.py +0 -0
  19. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_all.py +0 -0
  20. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_categorical.py +0 -0
  21. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_custom_sweep.py +0 -0
  22. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_docs.py +0 -0
  23. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_float3D.py +0 -0
  24. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_float_cat.py +0 -0
  25. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_floats.py +0 -0
  26. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_floats2D.py +0 -0
  27. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_holosweep.py +0 -0
  28. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_holosweep_objects.py +0 -0
  29. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_holosweep_tap.py +0 -0
  30. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_levels.py +0 -0
  31. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_pareto.py +0 -0
  32. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_sample_cache.py +0 -0
  33. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_sample_cache_context.py +0 -0
  34. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_simple.py +0 -0
  35. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_simple_bool.py +0 -0
  36. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_simple_cat.py +0 -0
  37. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_simple_float.py +0 -0
  38. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_strings.py +0 -0
  39. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_time_event.py +0 -0
  40. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/example_workflow.py +0 -0
  41. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_bokeh_plotly.py +0 -0
  42. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_hover_ex.py +0 -0
  43. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_hvplot_explorer.py +0 -0
  44. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_interactive.py +0 -0
  45. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_streamnd.py +0 -0
  46. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_streams.py +0 -0
  47. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_template.py +0 -0
  48. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_updates.py +0 -0
  49. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/experimental/example_vector.py +0 -0
  50. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/meta/example_meta.py +0 -0
  51. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/meta/example_meta_cat.py +0 -0
  52. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/meta/example_meta_float.py +0 -0
  53. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/meta/example_meta_levels.py +0 -0
  54. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/optuna/example_optuna.py +0 -0
  55. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/shelved/example_float2D_scatter.py +0 -0
  56. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/shelved/example_float3D_cone.py +0 -0
  57. {holobench-1.15.0 → holobench-1.16.0}/bencher/example/shelved/example_kwargs.py +0 -0
  58. {holobench-1.15.0 → holobench-1.16.0}/bencher/job.py +0 -0
  59. {holobench-1.15.0 → holobench-1.16.0}/bencher/optuna_conversions.py +0 -0
  60. {holobench-1.15.0 → holobench-1.16.0}/bencher/plotting/__init__.py +0 -0
  61. {holobench-1.15.0 → holobench-1.16.0}/bencher/plotting/plot_filter.py +0 -0
  62. {holobench-1.15.0 → holobench-1.16.0}/bencher/plotting/plt_cnt_cfg.py +0 -0
  63. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/__init__.py +0 -0
  64. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/bench_result.py +0 -0
  65. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/composable_container/__init__.py +0 -0
  66. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/composable_container/composable_container_base.py +0 -0
  67. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/composable_container/composable_container_panel.py +0 -0
  68. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/composable_container/composable_container_video.py +0 -0
  69. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/float_formatter.py +0 -0
  70. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/optuna_result.py +0 -0
  71. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/panel_result.py +0 -0
  72. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/plotly_result.py +0 -0
  73. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/video_result.py +0 -0
  74. {holobench-1.15.0 → holobench-1.16.0}/bencher/results/video_summary.py +0 -0
  75. {holobench-1.15.0 → holobench-1.16.0}/bencher/variables/inputs.py +0 -0
  76. {holobench-1.15.0 → holobench-1.16.0}/bencher/variables/parametrised_sweep.py +0 -0
  77. {holobench-1.15.0 → holobench-1.16.0}/bencher/variables/results.py +0 -0
  78. {holobench-1.15.0 → holobench-1.16.0}/bencher/variables/sweep_base.py +0 -0
  79. {holobench-1.15.0 → holobench-1.16.0}/bencher/variables/time.py +0 -0
  80. {holobench-1.15.0 → holobench-1.16.0}/bencher/video_writer.py +0 -0
  81. {holobench-1.15.0 → holobench-1.16.0}/bencher/worker_job.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: holobench
3
- Version: 1.15.0
3
+ Version: 1.16.0
4
4
  Summary: A package for benchmarking the performance of arbitrary functions
5
5
  Author-email: Austin Gregg-Smith <blooop@gmail.com>
6
6
  Description-Content-Type: text/markdown
@@ -344,9 +344,13 @@ class BenchCfg(BenchRunCfg):
344
344
  def inputs_as_str(self) -> List[str]:
345
345
  return [i.name for i in self.input_vars]
346
346
 
347
- def describe_sweep(self, width: int = 800) -> pn.pane.Markdown:
347
+ def describe_sweep(self, width: int = 800, accordion=True) -> pn.pane.Markdown:
348
348
  """Produce a markdown summary of the sweep settings"""
349
- return pn.pane.Markdown(self.describe_benchmark(), width=width)
349
+
350
+ desc = pn.pane.Markdown(self.describe_benchmark(), width=width)
351
+ if accordion:
352
+ return pn.Accordion(("Data Collection Parameters", desc))
353
+ return desc
350
354
 
351
355
  def describe_benchmark(self) -> str:
352
356
  """Generate a string summary of the inputs and results from a BenchCfg
@@ -427,7 +431,7 @@ class BenchCfg(BenchRunCfg):
427
431
  if self.description is not None and description:
428
432
  col.append(self.to_description())
429
433
  if describe_sweep:
430
- col.append(pn.Accordion(("Data Collection Parameters", self.describe_sweep())))
434
+ col.append(self.describe_sweep())
431
435
  if results_suffix:
432
436
  col.append(pn.pane.Markdown("## Results:"))
433
437
  return col
@@ -19,7 +19,7 @@ class BenchPolygons(bch.ParametrizedSweep):
19
19
  color = bch.StringSweep(["red", "green", "blue"])
20
20
  polygon = bch.ResultImage()
21
21
  area = bch.ResultVar()
22
- # hmap = bch.ResultHmap()
22
+ side_length = bch.ResultVar()
23
23
 
24
24
  def __call__(self, **kwargs):
25
25
  self.update_params_from_kwargs(**kwargs)
@@ -27,6 +27,9 @@ class BenchPolygons(bch.ParametrizedSweep):
27
27
  # self.hmap = hv.Curve(points)
28
28
  self.polygon = self.points_to_polygon_png(points, bch.gen_image_path("polygon"))
29
29
  self.area = self.radius * self.sides
30
+
31
+ self.side_length = 2 * self.radius * math.sin(math.pi / self.sides)
32
+ self.area = (self.sides * self.side_length**2) / (4 * math.tan(math.pi / self.sides))
30
33
  return super().__call__()
31
34
 
32
35
  def points_to_polygon_png(self, points: list[float], filename: str):
@@ -74,6 +77,8 @@ def example_image(
74
77
  f"Polygons Sweeping {len(s)} Parameters",
75
78
  input_vars=s,
76
79
  )
80
+ bench.report.append(bench.get_result().to_panes())
81
+
77
82
  return bench
78
83
 
79
84
 
@@ -92,6 +97,24 @@ def example_image_vid(
92
97
 
93
98
  if __name__ == "__main__":
94
99
 
100
+ def simple():
101
+ bench = BenchPolygons().to_bench(bch.BenchRunCfg(level=4))
102
+
103
+ # bench.plot_sweep(input_vars=["sides","color","radius"])
104
+
105
+ # res = bench.sweep(input_vars=["sides", "radius"])
106
+
107
+ # bench.report.append(res.to_heatmap(target_dimension=3))
108
+
109
+ bench.plot_sweep(input_vars=["sides"])
110
+ bench.plot_sweep(input_vars=["sides", "color"])
111
+
112
+ bench.plot_sweep(input_vars=["sides", "radius"])
113
+
114
+ # bench.report.append(res.to_line(target_dimension=1))
115
+
116
+ return bench
117
+
95
118
  def example_image_vid_sequential(
96
119
  run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
97
120
  ) -> bch.Bench:
@@ -108,6 +131,8 @@ if __name__ == "__main__":
108
131
  # ex_run_cfg.debug = True
109
132
  # ex_run_cfg.repeats = 2
110
133
  ex_run_cfg.level = 4
111
- example_image_vid(ex_run_cfg).report.show()
134
+ # example_image_vid(ex_run_cfg).report.show()
135
+ simple().report.show()
136
+
112
137
  # example_image_vid_sequential(ex_run_cfg).report.show()
113
138
  # example_image(ex_run_cfg).report.show()
@@ -16,6 +16,7 @@ class TuringPattern(bch.ParametrizedSweep):
16
16
 
17
17
  video = bch.ResultVideo()
18
18
  score = bch.ResultVar()
19
+ img = bch.ResultImage()
19
20
 
20
21
  def laplacian(self, Z, dx):
21
22
  Ztop = Z[0:-2, 1:-1]
@@ -66,6 +67,8 @@ class TuringPattern(bch.ParametrizedSweep):
66
67
  rgb = np.array(fig.canvas.renderer.buffer_rgba())
67
68
  vid_writer.append(rgb)
68
69
 
70
+ self.img = bch.add_image(rgb)
71
+
69
72
  self.video = vid_writer.write()
70
73
 
71
74
  self.score = self.alpha + self.beta
@@ -92,12 +95,25 @@ def example_video(
92
95
  def example_video_tap(
93
96
  run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
94
97
  ) -> bch.Bench: # pragma: no cover
95
- bench = TuringPattern().to_bench(run_cfg=run_cfg, report=report)
96
- bench.plot_sweep(
98
+ tp = TuringPattern()
99
+
100
+ # run_cfg.use_sample_cache = False
101
+ # run_cfg.use_optuna = True
102
+ run_cfg.auto_plot = False
103
+ run_cfg.run_tag = "3"
104
+ bench = tp.to_bench(run_cfg=run_cfg, report=report)
105
+
106
+ res = bench.plot_sweep(
107
+ "phase",
97
108
  input_vars=["alpha", "beta"],
98
109
  # result_vars=["video","score"],
110
+ # result_vars=["score"],
111
+ run_cfg=run_cfg,
99
112
  )
100
113
 
114
+ bench.report.append(res.describe_sweep())
115
+ bench.report.append(res.to_heatmap())
116
+
101
117
  return bench
102
118
 
103
119
 
@@ -105,6 +121,7 @@ if __name__ == "__main__":
105
121
  run_cfg_ex = bch.BenchRunCfg()
106
122
  run_cfg_ex.level = 2
107
123
  run_cfg_ex.use_sample_cache = True
124
+ run_cfg_ex.only_hash_tag = True
108
125
 
109
126
  # example_video(run_cfg_ex).report.show()
110
127
  example_video_tap(run_cfg_ex).report.show()
@@ -17,13 +17,13 @@ from copy import deepcopy
17
17
  from bencher.results.optuna_result import OptunaResult
18
18
  from bencher.variables.results import ResultVar
19
19
  from bencher.plotting.plot_filter import VarRange, PlotFilter
20
+ from bencher.utils import listify
20
21
 
21
22
  from bencher.variables.results import (
22
23
  ResultReference,
23
24
  )
24
25
 
25
26
  from bencher.results.composable_container.composable_container_panel import ComposableContainerPanel
26
- from bencher.utils import listify
27
27
 
28
28
  # todo add plugins
29
29
  # https://gist.github.com/dorneanu/cce1cd6711969d581873a88e0257e312
@@ -228,7 +228,7 @@ class BenchResultBase(OptunaResult):
228
228
  return " vs ".join(tit)
229
229
 
230
230
  def get_results_var_list(self, result_var: ParametrizedSweep = None) -> List[ResultVar]:
231
- return self.bench_cfg.result_vars if result_var is None else [result_var]
231
+ return self.bench_cfg.result_vars if result_var is None else listify(result_var)
232
232
 
233
233
  def map_plots(
234
234
  self,
@@ -8,12 +8,12 @@ from functools import partial
8
8
  import hvplot.xarray # noqa pylint: disable=duplicate-code,unused-import
9
9
  import xarray as xr
10
10
 
11
- from bencher.utils import hmap_canonical_input, get_nearest_coords, get_nearest_coords1D
11
+ from bencher.utils import hmap_canonical_input, get_nearest_coords, get_nearest_coords1D, listify
12
12
  from bencher.results.panel_result import PanelResult
13
13
  from bencher.results.bench_result_base import ReduceType
14
14
 
15
15
  from bencher.plotting.plot_filter import PlotFilter, VarRange
16
- from bencher.variables.results import ResultVar
16
+ from bencher.variables.results import ResultVar, ResultImage, ResultVideo
17
17
 
18
18
 
19
19
  hv.extension("bokeh", "plotly")
@@ -85,6 +85,7 @@ class HoloviewResult(PanelResult):
85
85
  float_range=VarRange(0, 0),
86
86
  cat_range=VarRange(0, None),
87
87
  repeats_range=VarRange(1, 1),
88
+ panel_range=VarRange(0, None),
88
89
  reduce=ReduceType.SQUEEZE,
89
90
  target_dimension=2,
90
91
  result_var=result_var,
@@ -124,15 +125,34 @@ class HoloviewResult(PanelResult):
124
125
  **kwargs,
125
126
  )
126
127
 
127
- def to_line(self, result_var: Parameter = None, **kwargs) -> Optional[pn.panel]:
128
+ def to_line(
129
+ self,
130
+ result_var: Parameter = None,
131
+ tap_var=None,
132
+ tap_container: pn.pane.panel = None,
133
+ target_dimension=2,
134
+ **kwargs,
135
+ ) -> Optional[pn.panel]:
136
+ if tap_var is None:
137
+ tap_var = self.plt_cnt_cfg.panel_vars
138
+ elif not isinstance(tap_var, list):
139
+ tap_var = [tap_var]
140
+
141
+ if len(tap_var) == 0 or self.plt_cnt_cfg.inputs_cnt > 1:
142
+ heatmap_cb = self.to_line_ds
143
+ else:
144
+ heatmap_cb = partial(
145
+ self.to_line_tap_ds, result_var_plots=tap_var, container=tap_container
146
+ )
147
+
128
148
  return self.filter(
129
- self.to_line_ds,
149
+ heatmap_cb,
130
150
  float_range=VarRange(1, 1),
131
151
  cat_range=VarRange(0, None),
132
152
  repeats_range=VarRange(1, 1),
133
153
  panel_range=VarRange(0, None),
134
154
  reduce=ReduceType.SQUEEZE,
135
- target_dimension=2,
155
+ target_dimension=target_dimension,
136
156
  result_var=result_var,
137
157
  result_types=(ResultVar),
138
158
  **kwargs,
@@ -140,7 +160,6 @@ class HoloviewResult(PanelResult):
140
160
 
141
161
  def to_line_ds(self, dataset: xr.Dataset, result_var: Parameter, **kwargs):
142
162
  x = self.plt_cnt_cfg.float_vars[0].name
143
- # y = self.plt_cnt_cfg.result_vars[0].name
144
163
  by = None
145
164
  if self.plt_cnt_cfg.cat_cnt >= 1:
146
165
  by = self.plt_cnt_cfg.cat_vars[0].name
@@ -178,22 +197,28 @@ class HoloviewResult(PanelResult):
178
197
  self,
179
198
  result_var: Parameter = None,
180
199
  tap_var=None,
181
- tap_container=None,
200
+ tap_container: pn.pane.panel = None,
182
201
  target_dimension=2,
183
202
  **kwargs,
184
203
  ) -> Optional[pn.panel]:
185
204
  if tap_var is None:
205
+ tap_var = self.plt_cnt_cfg.panel_vars
206
+ elif not isinstance(tap_var, list):
207
+ tap_var = [tap_var]
208
+
209
+ if len(tap_var) == 0:
186
210
  heatmap_cb = self.to_heatmap_ds
187
211
  else:
188
212
  heatmap_cb = partial(
189
- self.to_heatmap_container_tap_ds, result_var_plot=tap_var, container=tap_container
213
+ self.to_heatmap_container_tap_ds, result_var_plots=tap_var, container=tap_container
190
214
  )
191
215
 
192
216
  return self.filter(
193
217
  heatmap_cb,
194
- float_range=VarRange(2, None),
218
+ float_range=VarRange(0, None),
195
219
  cat_range=VarRange(0, None),
196
- input_range=VarRange(1, None),
220
+ input_range=VarRange(2, None),
221
+ panel_range=VarRange(0, None),
197
222
  target_dimension=target_dimension,
198
223
  result_var=result_var,
199
224
  result_types=(ResultVar),
@@ -204,56 +229,180 @@ class HoloviewResult(PanelResult):
204
229
  self, dataset: xr.Dataset, result_var: Parameter, **kwargs
205
230
  ) -> Optional[hv.HeatMap]:
206
231
  if len(dataset.dims) >= 2:
207
- x = self.plt_cnt_cfg.float_vars[0].name
208
- y = self.plt_cnt_cfg.float_vars[1].name
232
+ x = self.bench_cfg.input_vars[0].name
233
+ y = self.bench_cfg.input_vars[1].name
209
234
  C = result_var.name
210
235
  title = f"Heatmap of {result_var.name}"
211
236
  time_args = self.time_widget(title)
212
237
  return dataset.hvplot.heatmap(x=x, y=y, C=C, cmap="plasma", **time_args, **kwargs)
213
238
  return None
214
239
 
240
+ def result_var_to_container(self, result_var):
241
+ if isinstance(result_var, ResultImage):
242
+ return pn.pane.PNG
243
+ return pn.pane.Video if isinstance(result_var, ResultVideo) else pn.pane.panel
244
+
245
+ def setup_results_and_containers(self, result_var_plots, container, **kwargs):
246
+ result_var_plots = listify(result_var_plots)
247
+ if container is None:
248
+ containers = [self.result_var_to_container(rv) for rv in result_var_plots]
249
+ else:
250
+ containers = listify(container)
251
+
252
+ cont_instances = [c(**kwargs) for c in containers]
253
+ return result_var_plots, cont_instances
254
+
215
255
  def to_heatmap_container_tap_ds(
216
256
  self,
217
257
  dataset: xr.Dataset,
218
258
  result_var: Parameter,
219
- result_var_plot: Parameter,
220
- container: pn.pane.panel = pn.pane.panel,
259
+ result_var_plots: List[Parameter] = None,
260
+ container: pn.pane.panel = None,
221
261
  **kwargs,
222
262
  ) -> pn.Row:
223
- htmap = self.to_heatmap_ds(dataset, result_var).opts(tools=["hover", "tap"], **kwargs)
224
- htmap_posxy = hv.streams.Tap(source=htmap, x=0, y=0)
225
-
226
- container_instance = container(**kwargs)
263
+ htmap = self.to_heatmap_ds(dataset, result_var).opts(tools=["hover"], **kwargs)
264
+ result_var_plots, cont_instances = self.setup_results_and_containers(
265
+ result_var_plots, container
266
+ )
227
267
  title = pn.pane.Markdown("Selected: None")
228
268
 
229
- def tap_plot(x, y): # pragma: no cover
230
- x_nearest = get_nearest_coords1D(
269
+ state = dict(x=None, y=None, update=False)
270
+
271
+ def tap_plot_heatmap(x, y): # pragma: no cover
272
+ # print(f"moved {x}{y}")
273
+ x_nearest_new = get_nearest_coords1D(
231
274
  x, dataset.coords[self.bench_cfg.input_vars[0].name].data
232
275
  )
233
- y_nearest = get_nearest_coords1D(
276
+ y_nearest_new = get_nearest_coords1D(
234
277
  y, dataset.coords[self.bench_cfg.input_vars[1].name].data
235
278
  )
236
- kdims = {}
237
- kdims[self.bench_cfg.input_vars[0].name] = x_nearest
238
- kdims[self.bench_cfg.input_vars[1].name] = y_nearest
239
-
240
- if hasattr(htmap, "current_key"):
241
- for d, k in zip(htmap.kdims, htmap.current_key):
242
- kdims[d.name] = k
243
-
244
- ds = dataset[result_var_plot.name]
245
- val = ds.sel(**kdims)
246
- item = self.zero_dim_da_to_val(val)
247
- title.object = "Selected: " + ", ".join([f"{k}:{v}" for k, v in kdims.items()])
248
- container_instance.object = item
249
- if hasattr(container, "autoplay"): # container is a video, set to autoplay
250
- container_instance.paused = False
251
- container_instance.time = 0
252
- container_instance.loop = True
253
- container_instance.autoplay = True
254
-
255
- htmap_posxy.add_subscriber(tap_plot)
256
- bound_plot = pn.Column(title, container_instance)
279
+
280
+ # xv = self.bench_cfg.input_vars[0].name
281
+ # yv = self.bench_cfg.input_vars[1].name
282
+ # nearest = get_nearest_coords(dataset, **{xv: x, yv: y})
283
+ # print(nearest)
284
+ # print(x_nearest_new,y_nearest_new)
285
+
286
+ if x_nearest_new != state["x"]:
287
+ state["x"] = x_nearest_new
288
+ state["update"] = True
289
+ if y_nearest_new != state["y"]:
290
+ state["y"] = y_nearest_new
291
+ state["update"] = True
292
+
293
+ if state["update"]:
294
+ kdims = {}
295
+ kdims[self.bench_cfg.input_vars[0].name] = state["x"]
296
+ kdims[self.bench_cfg.input_vars[1].name] = state["y"]
297
+
298
+ if hasattr(htmap, "current_key"):
299
+ for d, k in zip(htmap.kdims, htmap.current_key):
300
+ kdims[d.name] = k
301
+ for rv, cont in zip(result_var_plots, cont_instances):
302
+ ds = dataset[rv.name]
303
+ val = ds.sel(**kdims)
304
+ item = self.zero_dim_da_to_val(val)
305
+ title.object = "Selected: " + ", ".join([f"{k}:{v}" for k, v in kdims.items()])
306
+ cont.object = item
307
+ if hasattr(cont, "autoplay"): # container is a video, set to autoplay
308
+ cont.paused = False
309
+ cont.time = 0
310
+ cont.loop = True
311
+ cont.autoplay = True
312
+ state["update"] = False
313
+
314
+ def on_exit(x, y): # pragma: no cover # pylint: disable=unused-argument
315
+ state["update"] = True
316
+
317
+ htmap_posxy = hv.streams.PointerXY(source=htmap)
318
+ htmap_posxy.add_subscriber(tap_plot_heatmap)
319
+ ls = hv.streams.MouseLeave(source=htmap)
320
+ ls.add_subscriber(on_exit)
321
+
322
+ bound_plot = pn.Column(title, *cont_instances)
323
+ return pn.Row(htmap, bound_plot)
324
+
325
+ def to_line_tap_ds(
326
+ self,
327
+ dataset: xr.Dataset,
328
+ result_var: Parameter,
329
+ result_var_plots: List[Parameter] = None,
330
+ container: pn.pane.panel = pn.pane.panel,
331
+ **kwargs,
332
+ ) -> pn.Row:
333
+ htmap = self.to_line_ds(dataset, result_var).opts(tools=["hover"], **kwargs)
334
+ result_var_plots, cont_instances = self.setup_results_and_containers(
335
+ result_var_plots, container
336
+ )
337
+ title = pn.pane.Markdown("Selected: None")
338
+
339
+ state = dict(x=None, y=None, update=False)
340
+
341
+ def tap_plot_line(x, y): # pragma: no cover
342
+ # print(f"{x},{y}")
343
+ # print(dataset)
344
+
345
+ # xv = self.bench_cfg.input_vars[0].name
346
+ # yv = self.bench_cfg.input_vars[1].name
347
+
348
+ # x_nearest_new = get_nearest_coords1D(
349
+ # x, dataset.coords[self.bench_cfg.input_vars[0].name].data
350
+ # )
351
+ # y_nearest_new = get_nearest_coords1D(
352
+ # y, dataset.coords[self.bench_cfg.input_vars[1].name].data
353
+ # )
354
+
355
+ # kwargs = {xv: x, yv: y}
356
+
357
+ # nearest = get_nearest_coords(dataset, **kwargs)
358
+ # print(nearest)
359
+
360
+ x_nearest_new = get_nearest_coords1D(
361
+ x, dataset.coords[self.bench_cfg.input_vars[0].name].data
362
+ )
363
+
364
+ if x_nearest_new != state["x"]:
365
+ state["x"] = x_nearest_new
366
+ state["update"] = True
367
+
368
+ if self.plt_cnt_cfg.inputs_cnt > 1:
369
+ y_nearest_new = get_nearest_coords1D(
370
+ y, dataset.coords[self.bench_cfg.input_vars[1].name].data
371
+ )
372
+ if y_nearest_new != state["y"]:
373
+ state["y"] = y_nearest_new
374
+ state["update"] = True
375
+
376
+ if state["update"]:
377
+ kdims = {}
378
+ kdims[self.bench_cfg.input_vars[0].name] = state["x"]
379
+ if self.plt_cnt_cfg.inputs_cnt > 1:
380
+ kdims[self.bench_cfg.input_vars[1].name] = state["y"]
381
+
382
+ if hasattr(htmap, "current_key"):
383
+ for d, k in zip(htmap.kdims, htmap.current_key):
384
+ kdims[d.name] = k
385
+ for rv, cont in zip(result_var_plots, cont_instances):
386
+ ds = dataset[rv.name]
387
+ val = ds.sel(**kdims)
388
+ item = self.zero_dim_da_to_val(val)
389
+ title.object = "Selected: " + ", ".join([f"{k}:{v}" for k, v in kdims.items()])
390
+ cont.object = item
391
+ if hasattr(cont, "autoplay"): # container is a video, set to autoplay
392
+ cont.paused = False
393
+ cont.time = 0
394
+ cont.loop = True
395
+ cont.autoplay = True
396
+ state["update"] = False
397
+
398
+ def on_exit(x, y): # pragma: no cover # pylint: disable=unused-argument
399
+ state["update"] = True
400
+
401
+ htmap_posxy = hv.streams.PointerXY(source=htmap)
402
+ htmap_posxy.add_subscriber(tap_plot_line)
403
+ ls = hv.streams.MouseLeave(source=htmap)
404
+ ls.add_subscriber(on_exit)
405
+ bound_plot = pn.Column(title, *cont_instances)
257
406
  return pn.Row(htmap, bound_plot)
258
407
 
259
408
  def to_error_bar(self) -> hv.Bars:
@@ -61,6 +61,9 @@ def get_nearest_coords(dataset: xr.Dataset, collapse_list=False, **kwargs) -> di
61
61
  def get_nearest_coords1D(val: Any, coords) -> Any:
62
62
  if isinstance(val, (int, float)):
63
63
  return min(coords, key=lambda x_: abs(x_ - val))
64
+ for i in coords:
65
+ if val == i:
66
+ return i
64
67
  return val
65
68
 
66
69
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "holobench"
3
- version = "1.15.0"
3
+ version = "1.16.0"
4
4
 
5
5
  authors = [{ name = "Austin Gregg-Smith", email = "blooop@gmail.com" }]
6
6
  description = "A package for benchmarking the performance of arbitrary functions"
File without changes
File without changes