holobench 1.25.2__py3-none-any.whl → 1.27.0__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 (82) hide show
  1. bencher/bench_report.py +6 -109
  2. bencher/example/__init__.py +0 -0
  3. bencher/example/benchmark_data.py +196 -0
  4. bencher/example/example_all.py +45 -0
  5. bencher/example/example_categorical.py +99 -0
  6. bencher/example/example_composable_container.py +106 -0
  7. bencher/example/example_composable_container2.py +160 -0
  8. bencher/example/example_consts.py +39 -0
  9. bencher/example/example_custom_sweep.py +59 -0
  10. bencher/example/example_custom_sweep2.py +42 -0
  11. bencher/example/example_docs.py +34 -0
  12. bencher/example/example_filepath.py +27 -0
  13. bencher/example/example_float3D.py +101 -0
  14. bencher/example/example_float_cat.py +99 -0
  15. bencher/example/example_floats.py +89 -0
  16. bencher/example/example_floats2D.py +93 -0
  17. bencher/example/example_holosweep.py +98 -0
  18. bencher/example/example_holosweep_objects.py +111 -0
  19. bencher/example/example_holosweep_tap.py +144 -0
  20. bencher/example/example_image.py +155 -0
  21. bencher/example/example_levels.py +181 -0
  22. bencher/example/example_levels2.py +37 -0
  23. bencher/example/example_pareto.py +53 -0
  24. bencher/example/example_sample_cache.py +85 -0
  25. bencher/example/example_sample_cache_context.py +116 -0
  26. bencher/example/example_simple.py +134 -0
  27. bencher/example/example_simple_bool.py +35 -0
  28. bencher/example/example_simple_cat.py +48 -0
  29. bencher/example/example_simple_float.py +28 -0
  30. bencher/example/example_simple_float2d.py +29 -0
  31. bencher/example/example_strings.py +47 -0
  32. bencher/example/example_time_event.py +63 -0
  33. bencher/example/example_video.py +118 -0
  34. bencher/example/example_workflow.py +189 -0
  35. bencher/example/experimental/example_bokeh_plotly.py +38 -0
  36. bencher/example/experimental/example_hover_ex.py +45 -0
  37. bencher/example/experimental/example_hvplot_explorer.py +39 -0
  38. bencher/example/experimental/example_interactive.py +75 -0
  39. bencher/example/experimental/example_streamnd.py +49 -0
  40. bencher/example/experimental/example_streams.py +36 -0
  41. bencher/example/experimental/example_template.py +40 -0
  42. bencher/example/experimental/example_updates.py +84 -0
  43. bencher/example/experimental/example_vector.py +84 -0
  44. bencher/example/meta/example_meta.py +171 -0
  45. bencher/example/meta/example_meta_cat.py +25 -0
  46. bencher/example/meta/example_meta_float.py +23 -0
  47. bencher/example/meta/example_meta_levels.py +26 -0
  48. bencher/example/optuna/example_optuna.py +78 -0
  49. bencher/example/shelved/example_float2D_scatter.py +109 -0
  50. bencher/example/shelved/example_float3D_cone.py +96 -0
  51. bencher/example/shelved/example_kwargs.py +63 -0
  52. bencher/plotting/__init__.py +0 -0
  53. bencher/plotting/plot_filter.py +110 -0
  54. bencher/plotting/plt_cnt_cfg.py +75 -0
  55. bencher/results/__init__.py +0 -0
  56. bencher/results/bench_result.py +94 -0
  57. bencher/results/bench_result_base.py +476 -0
  58. bencher/results/composable_container/__init__.py +0 -0
  59. bencher/results/composable_container/composable_container_base.py +73 -0
  60. bencher/results/composable_container/composable_container_panel.py +39 -0
  61. bencher/results/composable_container/composable_container_video.py +184 -0
  62. bencher/results/float_formatter.py +44 -0
  63. bencher/results/holoview_result.py +753 -0
  64. bencher/results/optuna_result.py +354 -0
  65. bencher/results/panel_result.py +41 -0
  66. bencher/results/plotly_result.py +65 -0
  67. bencher/results/video_result.py +38 -0
  68. bencher/results/video_summary.py +222 -0
  69. bencher/variables/__init__.py +0 -0
  70. bencher/variables/inputs.py +202 -0
  71. bencher/variables/parametrised_sweep.py +208 -0
  72. bencher/variables/results.py +214 -0
  73. bencher/variables/sweep_base.py +162 -0
  74. bencher/variables/time.py +92 -0
  75. holobench-1.27.0.data/data/share/ament_index/resource_index/packages/bencher +0 -0
  76. holobench-1.27.0.data/data/share/bencher/package.xml +33 -0
  77. {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/METADATA +5 -5
  78. holobench-1.27.0.dist-info/RECORD +93 -0
  79. holobench-1.25.2.dist-info/RECORD +0 -18
  80. {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/LICENSE +0 -0
  81. {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/WHEEL +0 -0
  82. {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,48 @@
1
+ """This file has some examples for how to perform basic benchmarking parameter sweeps"""
2
+
3
+ # pylint: disable=duplicate-code
4
+
5
+ import bencher as bch
6
+
7
+ # All the examples will be using the data structures and benchmark function defined in this file
8
+ from bencher.example.benchmark_data import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
9
+
10
+
11
+ def example_1D_cat(
12
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
13
+ ) -> bch.Bench:
14
+ """This example shows how to sample a 1 dimensional categorical variable and plot the result of passing that parameter sweep to the benchmarking function
15
+
16
+ Args:
17
+ run_cfg (BenchRunCfg): configuration of how to perform the param sweep
18
+
19
+ Returns:
20
+ Bench: results of the parameter sweep
21
+ """
22
+
23
+ explorer = ExampleBenchCfgIn()
24
+ bench = bch.Bench(
25
+ "benchmarking_example_categorical1D",
26
+ bench_function,
27
+ ExampleBenchCfgIn,
28
+ run_cfg=run_cfg,
29
+ report=report,
30
+ )
31
+
32
+ # here we sample the input variable theta and plot the value of output1. The (noisy) function is sampled 20 times so you can see the distribution
33
+ bench.plot_sweep(
34
+ title="Example 1D Categorical",
35
+ description="""This example shows how to sample a 1 dimensional categorical variable and plot the result of passing that parameter sweep to the benchmarking function""",
36
+ input_vars=[ExampleBenchCfgIn.param.postprocess_fn],
37
+ result_vars=[ExampleBenchCfgOut.param.out_cos, ExampleBenchCfgOut.param.out_sin],
38
+ const_vars=explorer.get_input_defaults(),
39
+ )
40
+
41
+ return bench
42
+
43
+
44
+ if __name__ == "__main__":
45
+ ex_run_cfg = bch.BenchRunCfg()
46
+ ex_run_cfg.repeats = 10
47
+
48
+ srv1 = example_1D_cat(ex_run_cfg).report.show()
@@ -0,0 +1,28 @@
1
+ """This file has some examples for how to perform basic benchmarking parameter sweeps"""
2
+
3
+ import math
4
+ import bencher as bch
5
+
6
+
7
+ class SimpleFloat(bch.ParametrizedSweep):
8
+ theta = bch.FloatSweep(
9
+ default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30
10
+ )
11
+ out_sin = bch.ResultVar(units="v", doc="sin of theta")
12
+
13
+ def __call__(self, **kwargs):
14
+ self.update_params_from_kwargs(**kwargs)
15
+ self.out_sin = math.sin(self.theta)
16
+ return super().__call__(**kwargs)
17
+
18
+
19
+ def example_1D_float(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
20
+ """This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
21
+
22
+ bench = SimpleFloat().to_bench(run_cfg, report)
23
+ bench.plot_sweep()
24
+ return bench
25
+
26
+
27
+ if __name__ == "__main__":
28
+ example_1D_float().report.show()
@@ -0,0 +1,29 @@
1
+ """This file contains examples for how to perform basic 2D benchmarking parameter sweeps"""
2
+
3
+ import math
4
+ import bencher as bch
5
+
6
+
7
+ class SimpleFloat(bch.ParametrizedSweep):
8
+ theta = bch.FloatSweep(
9
+ default=0, bounds=[0, math.pi], doc="Input angle", units="rad", samples=30
10
+ )
11
+ offset = bch.FloatSweep(default=0, bounds=[0, 1], doc="Input angle", units="rad")
12
+ out_sin = bch.ResultVar(units="v", doc="sin of theta")
13
+
14
+ def __call__(self, **kwargs):
15
+ self.update_params_from_kwargs(**kwargs)
16
+ self.out_sin = math.sin(self.theta) + self.offset
17
+ return super().__call__(**kwargs)
18
+
19
+
20
+ def example_2D_float(run_cfg: bch.BenchRunCfg = None, report: bch.BenchReport = None) -> bch.Bench:
21
+ """This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
22
+
23
+ bench = SimpleFloat().to_bench(run_cfg, report)
24
+ bench.plot_sweep()
25
+ return bench
26
+
27
+
28
+ if __name__ == "__main__":
29
+ example_2D_float().report.show()
@@ -0,0 +1,47 @@
1
+ import bencher as bch
2
+
3
+
4
+ class TestPrinting(bch.ParametrizedSweep):
5
+ # INPUTS
6
+ a = bch.StringSweep(default=None, string_list=["a1", "a2"], allow_None=True)
7
+ b = bch.StringSweep(default=None, string_list=["b1", "b2"], allow_None=True)
8
+ c = bch.StringSweep(default=None, string_list=["c1", "c2"], allow_None=True)
9
+ d = bch.StringSweep(default=None, string_list=["d1", "d2"], allow_None=True)
10
+
11
+ # RESULTS
12
+ result = bch.ResultString()
13
+
14
+ def __call__(self, **kwargs):
15
+ self.update_params_from_kwargs(**kwargs)
16
+
17
+ self.result = self.a
18
+ if self.b is not None:
19
+ self.result += f",{self.b}"
20
+ if self.c is not None:
21
+ self.result += f",{self.c}"
22
+ if self.d is not None:
23
+ self.result += f",{self.d}"
24
+ self.result += "\n\ttab\n\t\ttab2"
25
+
26
+ self.result = bch.tabs_in_markdown(self.result)
27
+ return super().__call__()
28
+
29
+
30
+ def example_strings(
31
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
32
+ ) -> bch.Bench:
33
+ bench = bch.Bench("strings", TestPrinting(), run_cfg=run_cfg, report=report)
34
+
35
+ for s in [
36
+ [TestPrinting.param.a],
37
+ [TestPrinting.param.a, TestPrinting.param.b],
38
+ [TestPrinting.param.a, TestPrinting.param.b, TestPrinting.param.c],
39
+ [TestPrinting.param.a, TestPrinting.param.b, TestPrinting.param.c, TestPrinting.param.d],
40
+ ]:
41
+ bench.plot_sweep(f"String Panes {[v.name for v in s]}", input_vars=s)
42
+
43
+ return bench
44
+
45
+
46
+ if __name__ == "__main__":
47
+ example_strings().report.show()
@@ -0,0 +1,63 @@
1
+ """This file has some examples for how to perform basic benchmarking parameter sweeps"""
2
+
3
+ # pylint: disable=duplicate-code
4
+
5
+ import bencher as bch
6
+
7
+ # All the examples will be using the data structures and benchmark function defined in this file
8
+ from bencher.example.benchmark_data import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
9
+
10
+
11
+ def example_time_event(
12
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
13
+ ) -> bch.Bench:
14
+ """This example shows how to manually set time events as a string so that progress can be monitored over time"""
15
+
16
+ bencher = bch.Bench(
17
+ "benchmarking_example_categorical1D",
18
+ bench_function,
19
+ ExampleBenchCfgIn,
20
+ run_cfg=run_cfg,
21
+ report=report,
22
+ )
23
+
24
+ ExampleBenchCfgIn.param.offset.bounds = [0, 100]
25
+
26
+ # manually override the default value based on the time event string so that the graphs are not all just straight lines
27
+ ExampleBenchCfgIn.param.offset.default = int(str(hash(run_cfg.time_event))[-1])
28
+
29
+ # here we sample the input variable theta and plot the value of output1. The (noisy) function is sampled 20 times so you can see the distribution
30
+ bencher.plot_sweep(
31
+ title="Example 1D Categorical",
32
+ input_vars=[ExampleBenchCfgIn.param.postprocess_fn],
33
+ result_vars=[ExampleBenchCfgOut.param.out_cos],
34
+ description=example_time_event.__doc__,
35
+ run_cfg=run_cfg,
36
+ )
37
+ return bencher
38
+
39
+
40
+ def run_example_time_event(ex_run_cfg):
41
+ ex_run_cfg.repeats = 1
42
+ ex_run_cfg.print_pandas = True
43
+ ex_run_cfg.over_time = True
44
+
45
+ ex_run_cfg.clear_cache = True
46
+ ex_run_cfg.clear_history = True
47
+
48
+ ex_run_cfg.time_event = "-first_event"
49
+ example_time_event(ex_run_cfg)
50
+
51
+ ex_run_cfg.clear_cache = False
52
+ ex_run_cfg.clear_history = False
53
+ ex_run_cfg.time_event = "_second_event"
54
+ example_time_event(ex_run_cfg)
55
+
56
+ ex_run_cfg.time_event = (
57
+ "*third_event has a very very long label to demonstrate automatic text wrapping"
58
+ )
59
+ return example_time_event(ex_run_cfg)
60
+
61
+
62
+ if __name__ == "__main__":
63
+ run_example_time_event(bch.BenchRunCfg()).report.show()
@@ -0,0 +1,118 @@
1
+ import bencher as bch
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+
6
+ # code from https://ipython-books.github.io/124-simulating-a-partial-differential-equation-reaction-diffusion-systems-and-turing-patterns/
7
+ class TuringPattern(bch.ParametrizedSweep):
8
+ alpha = bch.FloatSweep(default=2.8e-4, bounds=(2e-4, 5e-3))
9
+ beta = bch.FloatSweep(default=5e-3, bounds=(1e-3, 9e-3))
10
+ tau = bch.FloatSweep(default=0.1, bounds=(0.01, 0.5))
11
+ k = bch.FloatSweep(default=-0.005, bounds=(-0.01, 0.01))
12
+
13
+ size = bch.IntSweep(default=30, bounds=(30, 200), doc="size of the 2D grid")
14
+ time = bch.FloatSweep(default=20.0, bounds=(1, 100), doc="total time of simulation")
15
+ dt = bch.FloatSweep(default=0.001, doc="simulation time step")
16
+
17
+ video = bch.ResultVideo()
18
+ score = bch.ResultVar()
19
+ img = bch.ResultImage()
20
+
21
+ def laplacian(self, Z, dx):
22
+ Ztop = Z[0:-2, 1:-1]
23
+ Zleft = Z[1:-1, 0:-2]
24
+ Zbottom = Z[2:, 1:-1]
25
+ Zright = Z[1:-1, 2:]
26
+ Zcenter = Z[1:-1, 1:-1]
27
+ return (Ztop + Zleft + Zbottom + Zright - 4 * Zcenter) / dx**2
28
+
29
+ def update(self, U, V, dx):
30
+ # We compute the Laplacian of u and v.
31
+ deltaU = self.laplacian(U, dx)
32
+ deltaV = self.laplacian(V, dx)
33
+ # We take the values of u and v inside the grid.
34
+ Uc = U[1:-1, 1:-1]
35
+ Vc = V[1:-1, 1:-1]
36
+ # We update the variables.
37
+ U[1:-1, 1:-1], V[1:-1, 1:-1] = (
38
+ Uc + self.dt * (self.alpha * deltaU + Uc - Uc**3 - Vc + self.k),
39
+ Vc + self.dt * (self.beta * deltaV + Uc - Vc) / self.tau,
40
+ )
41
+ # Neumann conditions: derivatives at the edges
42
+ # are null.
43
+ for Z in (U, V):
44
+ Z[0, :] = Z[1, :]
45
+ Z[-1, :] = Z[-2, :]
46
+ Z[:, 0] = Z[:, 1]
47
+ Z[:, -1] = Z[:, -2]
48
+
49
+ def __call__(self, **kwargs):
50
+ self.update_params_from_kwargs(**kwargs)
51
+
52
+ n = int(self.time / self.dt) # number of iterations
53
+ dx = 2.0 / self.size # space step
54
+
55
+ U = np.random.rand(self.size, self.size)
56
+ V = np.random.rand(self.size, self.size)
57
+
58
+ fig, ax = plt.subplots(frameon=False, figsize=(2, 2))
59
+ fig.set_tight_layout(True)
60
+ ax.set_axis_off()
61
+ vid_writer = bch.VideoWriter()
62
+ for i in range(n):
63
+ self.update(U, V, dx)
64
+ if i % 500 == 0:
65
+ ax.imshow(U)
66
+ fig.canvas.draw()
67
+ rgb = np.array(fig.canvas.renderer.buffer_rgba())
68
+ vid_writer.append(rgb)
69
+
70
+ self.img = bch.add_image(rgb)
71
+
72
+ self.video = vid_writer.write()
73
+
74
+ self.score = self.alpha + self.beta
75
+ return super().__call__()
76
+
77
+
78
+ def example_video(
79
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
80
+ ) -> bch.Bench:
81
+ # run_cfg.auto_plot = False
82
+ # run_cfg.use_sample_cache = True
83
+ bench = bch.Bench("example_video", TuringPattern(), run_cfg=run_cfg, report=report)
84
+
85
+ bench.plot_sweep(
86
+ "Turing patterns with different parameters",
87
+ input_vars=[TuringPattern.param.alpha, TuringPattern.param.beta],
88
+ # input_vars=[TuringPattern.param.alpha],
89
+ result_vars=[TuringPattern.param.video],
90
+ )
91
+
92
+ return bench
93
+
94
+
95
+ def example_video_tap(
96
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
97
+ ) -> bch.Bench: # pragma: no cover
98
+ bench = TuringPattern().to_bench(run_cfg=run_cfg, report=report)
99
+ res = bench.plot_sweep(
100
+ input_vars=["alpha", "beta"],
101
+ # result_vars=["video","score"],
102
+ # result_vars=["score"],
103
+ run_cfg=run_cfg,
104
+ )
105
+
106
+ bench.report.append(res.to_video_grid())
107
+
108
+ return bench
109
+
110
+
111
+ if __name__ == "__main__":
112
+ run_cfg_ex = bch.BenchRunCfg()
113
+ run_cfg_ex.level = 2
114
+ run_cfg_ex.use_sample_cache = True
115
+ run_cfg_ex.only_hash_tag = True
116
+
117
+ # example_video(run_cfg_ex).report.show()
118
+ example_video_tap(run_cfg_ex).report.show()
@@ -0,0 +1,189 @@
1
+ # pylint: disable=duplicate-code
2
+
3
+
4
+ import numpy as np
5
+
6
+ import bencher as bch
7
+
8
+
9
+ class VolumeSample(bch.ParametrizedSweep):
10
+ """A class to represent a 3D point in space."""
11
+
12
+ x = bch.FloatSweep(
13
+ default=0, bounds=[-1.0, 1.0], doc="x coordinate of the sample volume", samples=9
14
+ )
15
+ y = bch.FloatSweep(
16
+ default=0, bounds=[-2.0, 2.0], doc="y coordinate of the sample volume", samples=10
17
+ )
18
+ z = bch.FloatSweep(
19
+ default=0, bounds=[-1.0, 1.0], doc="z coordinate of the sample volume", samples=11
20
+ )
21
+
22
+ surf_x = bch.FloatSweep(
23
+ default=0, bounds=[-1.0, 1.0], doc="z coordinate of the sample volume", samples=9
24
+ )
25
+
26
+ surf_y = bch.FloatSweep(
27
+ default=0, bounds=[-1.0, 1.0], doc="z coordinate of the sample volume", samples=11
28
+ )
29
+
30
+
31
+ class VolumeResult(bch.ParametrizedSweep):
32
+ """A class to represent the properties of a volume sample."""
33
+
34
+ # value = bch.ResultVar("ul", doc="The scalar value of the 3D volume field")
35
+ p1_dis = bch.ResultVar("m", direction=bch.OptDir.minimize, doc="The distance to p1")
36
+ p2_dis = bch.ResultVar("m", direction=bch.OptDir.minimize, doc="The distance to p2")
37
+ total_dis = bch.ResultVar(
38
+ "m", direction=bch.OptDir.minimize, doc="The total distance to all points"
39
+ )
40
+ surf_value = bch.ResultVar(
41
+ "ul", direction=bch.OptDir.maximize, doc="The scalar value of the 3D volume field"
42
+ )
43
+ # occupancy = bch.ResultVar("occupied", doc="If the value is > 0.5 this point is considered occupied")
44
+
45
+
46
+ p1 = np.array([0.4, 0.6, 0.0])
47
+ p2 = np.array([-0.8, -0.2, 0.0])
48
+ surf_x_max = 0.5
49
+ surf_y_max = -0.2
50
+
51
+
52
+ def bench_fn(point: VolumeSample) -> VolumeResult:
53
+ """This function takes a 3D point as input and returns distance of that point to the origin.
54
+
55
+ Args:
56
+ point (VolumeSample): Sample point
57
+
58
+ Returns:
59
+ VolumeResult: Value at that point
60
+ """
61
+
62
+ cur_point = np.array([point.x, point.y, point.z])
63
+
64
+ output = VolumeResult()
65
+ output.p1_dis = np.linalg.norm(p1 - cur_point)
66
+ output.p2_dis = np.linalg.norm(p2 - cur_point)
67
+ output.total_dis = output.p1_dis + output.p2_dis
68
+
69
+ output.surf_value = output.total_dis + np.linalg.norm(
70
+ np.array(
71
+ [np.cos(point.surf_x - surf_x_max), 2 * np.cos(point.surf_y - surf_y_max), point.z]
72
+ )
73
+ )
74
+
75
+ return output
76
+
77
+
78
+ def example_floats2D_workflow(run_cfg: bch.BenchRunCfg, bench: bch.Bench = None) -> bch.Bench:
79
+ """Example of how to perform a 3D floating point parameter sweep
80
+
81
+ Args:
82
+ run_cfg (BenchRunCfg): configuration of how to perform the param sweep
83
+
84
+ Returns:
85
+ Bench: results of the parameter sweep
86
+ """
87
+ if bench is None:
88
+ bench = bch.Bench("Bencher_Example_Floats", bench_fn, VolumeSample)
89
+
90
+ # run_cfg.debug = False
91
+
92
+ res = bench.plot_sweep(
93
+ input_vars=[VolumeSample.param.x, VolumeSample.param.y],
94
+ result_vars=[
95
+ VolumeResult.param.total_dis,
96
+ VolumeResult.param.p1_dis,
97
+ VolumeResult.param.p2_dis,
98
+ ],
99
+ const_vars=[VolumeSample.param.z.with_const(0)],
100
+ title="Float 2D Example",
101
+ run_cfg=run_cfg,
102
+ )
103
+ recovered_p1 = res.get_optimal_vec(VolumeResult.param.p1_dis, res.bench_cfg.input_vars)
104
+ print(f"recovered p1: {recovered_p1}, distance: {np.linalg.norm(recovered_p1 - p1[:2])}")
105
+ # within tolerance of sampling
106
+ # assert np.linalg.norm(recovered_p1 - p1[:2]) < 0.15
107
+
108
+ recovered_p2 = res.get_optimal_vec(VolumeResult.param.p2_dis, res.bench_cfg.input_vars)
109
+ print(f"recovered p2: {recovered_p2} distance: {np.linalg.norm(recovered_p2 - p2[:2])}")
110
+ # within tolerance of sampling
111
+ # assert np.linalg.norm(recovered_p2 - p2[:2]) < 0.15
112
+
113
+ run_cfg.use_optuna = True
114
+ for rv in res.bench_cfg.result_vars:
115
+ bench.plot_sweep(
116
+ input_vars=[VolumeSample.param.surf_x, VolumeSample.param.surf_y],
117
+ result_vars=[
118
+ VolumeResult.param.surf_value,
119
+ ],
120
+ const_vars=res.get_optimal_inputs(rv, True),
121
+ title=f"Slice of 5D space for {rv.name}",
122
+ description="""This example shows how to sample 3 floating point variables and plot a 3D vector field of the results.""",
123
+ run_cfg=run_cfg,
124
+ )
125
+
126
+ return bench
127
+
128
+
129
+ def example_floats3D_workflow(run_cfg: bch.BenchRunCfg, bench: bch.Bench = None) -> bch.Bench:
130
+ """Example of how to perform a 3D floating point parameter sweep
131
+
132
+ Args:
133
+ run_cfg (BenchRunCfg): configuration of how to perform the param sweep
134
+
135
+ Returns:
136
+ Bench: results of the parameter sweep
137
+ """
138
+ if bench is None:
139
+ bench = bch.Bench("Bencher_Example_Floats", bench_fn, VolumeSample)
140
+
141
+ # run_cfg.debug = False
142
+
143
+ res = bench.plot_sweep(
144
+ input_vars=[VolumeSample.param.x, VolumeSample.param.y, VolumeSample.param.z],
145
+ result_vars=[
146
+ VolumeResult.param.total_dis,
147
+ VolumeResult.param.p1_dis,
148
+ VolumeResult.param.p2_dis,
149
+ # get_optimal_inputsm.occupancy,
150
+ ],
151
+ title="Float 3D Example",
152
+ description="""This example shows how to sample 3 floating point variables and plot a volumetric representation of the results. The benchmark function returns the distance to the origin""",
153
+ post_description="Here you can see concentric shells as the value of the function increases with distance from the origin. The occupancy graph should show a sphere with radius=0.5",
154
+ run_cfg=run_cfg,
155
+ )
156
+
157
+ recovered_p1 = res.get_optimal_vec(VolumeResult.param.p1_dis, res.bench_cfg.input_vars)
158
+ print(f"recovered p1: {recovered_p1}, distance: {np.linalg.norm(recovered_p1 - p1)}")
159
+ # within tolerance of sampling
160
+ # assert np.linalg.norm(recovered_p1 - p1) < 0.15
161
+
162
+ recovered_p2 = res.get_optimal_vec(VolumeResult.param.p2_dis, res.bench_cfg.input_vars)
163
+ print(f"recovered p2: {recovered_p2} distance: {np.linalg.norm(recovered_p2 - p2)}")
164
+ # within tolerance of sampling
165
+ # assert np.linalg.norm(recovered_p2 - p2) < 0.15
166
+
167
+ run_cfg.use_optuna = True
168
+ for rv in res.bench_cfg.result_vars:
169
+ bench.plot_sweep(
170
+ input_vars=[VolumeSample.param.surf_x, VolumeSample.param.surf_y],
171
+ result_vars=[
172
+ VolumeResult.param.surf_value,
173
+ ],
174
+ const_vars=res.get_optimal_inputs(rv, True),
175
+ title=f"Slice of 5D space for {rv.name}",
176
+ description="""This example shows how to sample 3 floating point variables and plot a 3D vector field of the results.""",
177
+ run_cfg=run_cfg,
178
+ )
179
+
180
+ return bench
181
+
182
+
183
+ if __name__ == "__main__":
184
+ ex_run_cfg = bch.BenchRunCfg()
185
+
186
+ bench_ex = example_floats2D_workflow(ex_run_cfg)
187
+ example_floats3D_workflow(ex_run_cfg, bench_ex)
188
+
189
+ bench_ex.report.show()
@@ -0,0 +1,38 @@
1
+ import holoviews as hv
2
+ import numpy as np
3
+ import panel as pn
4
+
5
+ # hv.extension("bokeh", "plotly")
6
+ backend1 = "plotly"
7
+ # backend1 = "matplotlib"
8
+ backend2 = "bokeh"
9
+
10
+ # matplotlib.use("agg")
11
+
12
+ # hv.extension(backend1, backend2)
13
+ hv.extension(backend2, backend1)
14
+
15
+ # hv.extension(backend1)
16
+
17
+ # opts.defaults(opts.Surface(backend=backend1), opts.HeatMap(backend=backend2))
18
+
19
+ # hv.output(opts.Surface(backend=backend1), opts.HeatMap(backend=backend2))
20
+ # hv.output(surface.opts(fig_size=200, backend='matplotlib'), backend='matplotlib')
21
+
22
+ main = pn.Row()
23
+
24
+ # hv.output(backend="plotly")
25
+
26
+ dat = np.ones([10, 10])
27
+ # main.append(hv.Surface(dat))
28
+
29
+ surf = hv.Surface(dat)
30
+ main.append(hv.render(surf, backend=backend1))
31
+
32
+
33
+ # hv.output(backend="bokeh")
34
+ heat = hv.HeatMap(dat)
35
+ heat *= hv.Text(0, 0, "I only work with bokeh and matplotlib")
36
+ main.append(heat)
37
+
38
+ main.show()
@@ -0,0 +1,45 @@
1
+ # pylint: skip-file #this is experimental still
2
+
3
+
4
+ from bokeh.models import HoverTool
5
+ import pandas as pd
6
+ from hvplot import pandas # noqa
7
+ import holoviews as hv
8
+ import panel as pn
9
+
10
+ datadict = dict(
11
+ x=[1, 5],
12
+ y=[4, 10],
13
+ img=[
14
+ "https://raw.githubusercontent.com/holoviz/panel/master/doc/_static/logo_horizontal.png",
15
+ "https://raw.githubusercontent.com/holoviz/panel/master/doc/_static/logo_stacked.png",
16
+ ],
17
+ )
18
+
19
+
20
+ hover = HoverTool(
21
+ tooltips="""
22
+ <div>
23
+ <div>
24
+ <img src="@img" width=100 style="float: left; margin: 0px 15px 15px 0px; border="2"></img>
25
+ <div>
26
+ <span style="font-size: 15px;">Location</span>
27
+ <span style="font-size: 10px; color: #696;">(@x, @y)</span>
28
+ </div>
29
+ </div>
30
+
31
+ """
32
+ )
33
+
34
+ df_test = pd.DataFrame.from_dict(datadict)
35
+
36
+
37
+ hvds = hv.Dataset(df_test)
38
+
39
+ pt = hv.Scatter(hvds, kdims=["x"], vdims=["y"], hover_cols=["img"], tools=[hover])
40
+
41
+ pn.Row(pt).show()
42
+
43
+ # pt =df_test.hvplot.scatter(x="x", y="y", hover_cols=["img"], tools=[hover])
44
+
45
+ # pt.show()
@@ -0,0 +1,39 @@
1
+ # THIS IS NOT A WORKING EXAMPLE YET
2
+ # pylint: disable=duplicate-code
3
+ import hvplot
4
+ import bencher as bch
5
+ from bencher import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
6
+
7
+ bench = bch.Bench("Bencher_Example_Simple", bench_function, ExampleBenchCfgIn)
8
+
9
+
10
+ if __name__ == "__main__":
11
+ bench_out = bench.plot_sweep(
12
+ input_vars=[ExampleBenchCfgIn.param.theta, ExampleBenchCfgIn.param.offset],
13
+ result_vars=[ExampleBenchCfgOut.param.out_sin],
14
+ title="Float 1D Example",
15
+ description="""Bencher is a tool to make it easy to explore how input parameter affect a range of output metrics. In these examples we are going to benchmark an example function which has been selected to show the features of bencher.
16
+ The example function takes an input theta and returns the absolute value of sin(theta) and cos(theta) +- various types of noise.
17
+
18
+ def bench_function(cfg: ExampleBenchCfgIn) -> ExampleBenchCfgOut:
19
+ "Takes an ExampleBenchCfgIn and returns a ExampleBenchCfgOut output"
20
+ out = ExampleBenchCfgOut()
21
+ noise = calculate_noise(cfg)
22
+ offset = 0.0
23
+
24
+ postprocess_fn = abs if cfg.postprocess_fn == PostprocessFn.absolute else negate_fn
25
+
26
+ out.out_sin = postprocess_fn(offset + math.sin(cfg.theta) + noise)
27
+ out.out_cos = postprocess_fn(offset + math.cos(cfg.theta) + noise)
28
+ return out
29
+ """,
30
+ post_description="Here you can see the output plot of sin theta between 0 and pi. In the tabs at the top you can also view 3 tabular representations of the data",
31
+ run_cfg=bch.BenchRunCfg(
32
+ auto_plot=True,
33
+ use_cache=False,
34
+ repeats=2,
35
+ ),
36
+ )
37
+
38
+ hvexplorer = hvplot.explorer(bench_out.get_dataframe())
39
+ hvexplorer.show()