holobench 1.3.6__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. bencher/__init__.py +41 -0
  2. bencher/bench_cfg.py +462 -0
  3. bencher/bench_plot_server.py +100 -0
  4. bencher/bench_report.py +268 -0
  5. bencher/bench_runner.py +136 -0
  6. bencher/bencher.py +805 -0
  7. bencher/caching.py +51 -0
  8. bencher/example/__init__.py +0 -0
  9. bencher/example/benchmark_data.py +200 -0
  10. bencher/example/example_all.py +45 -0
  11. bencher/example/example_categorical.py +99 -0
  12. bencher/example/example_custom_sweep.py +59 -0
  13. bencher/example/example_docs.py +34 -0
  14. bencher/example/example_float3D.py +101 -0
  15. bencher/example/example_float_cat.py +98 -0
  16. bencher/example/example_floats.py +89 -0
  17. bencher/example/example_floats2D.py +93 -0
  18. bencher/example/example_holosweep.py +104 -0
  19. bencher/example/example_holosweep_objects.py +111 -0
  20. bencher/example/example_holosweep_tap.py +144 -0
  21. bencher/example/example_image.py +82 -0
  22. bencher/example/example_levels.py +181 -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 +34 -0
  28. bencher/example/example_simple_cat.py +47 -0
  29. bencher/example/example_simple_float.py +38 -0
  30. bencher/example/example_strings.py +46 -0
  31. bencher/example/example_time_event.py +62 -0
  32. bencher/example/example_video.py +124 -0
  33. bencher/example/example_workflow.py +189 -0
  34. bencher/example/experimental/example_bokeh_plotly.py +38 -0
  35. bencher/example/experimental/example_hover_ex.py +45 -0
  36. bencher/example/experimental/example_hvplot_explorer.py +39 -0
  37. bencher/example/experimental/example_interactive.py +75 -0
  38. bencher/example/experimental/example_streamnd.py +49 -0
  39. bencher/example/experimental/example_streams.py +36 -0
  40. bencher/example/experimental/example_template.py +40 -0
  41. bencher/example/experimental/example_updates.py +84 -0
  42. bencher/example/experimental/example_vector.py +84 -0
  43. bencher/example/meta/example_meta.py +171 -0
  44. bencher/example/meta/example_meta_cat.py +25 -0
  45. bencher/example/meta/example_meta_float.py +23 -0
  46. bencher/example/meta/example_meta_levels.py +26 -0
  47. bencher/example/optuna/example_optuna.py +78 -0
  48. bencher/example/shelved/example_float2D_scatter.py +109 -0
  49. bencher/example/shelved/example_float3D_cone.py +96 -0
  50. bencher/example/shelved/example_kwargs.py +63 -0
  51. bencher/job.py +184 -0
  52. bencher/optuna_conversions.py +168 -0
  53. bencher/plotting/__init__.py +0 -0
  54. bencher/plotting/plot_filter.py +110 -0
  55. bencher/plotting/plt_cnt_cfg.py +74 -0
  56. bencher/results/__init__.py +0 -0
  57. bencher/results/bench_result.py +80 -0
  58. bencher/results/bench_result_base.py +405 -0
  59. bencher/results/float_formatter.py +44 -0
  60. bencher/results/holoview_result.py +592 -0
  61. bencher/results/optuna_result.py +354 -0
  62. bencher/results/panel_result.py +113 -0
  63. bencher/results/plotly_result.py +65 -0
  64. bencher/utils.py +148 -0
  65. bencher/variables/inputs.py +193 -0
  66. bencher/variables/parametrised_sweep.py +206 -0
  67. bencher/variables/results.py +176 -0
  68. bencher/variables/sweep_base.py +167 -0
  69. bencher/variables/time.py +74 -0
  70. bencher/video_writer.py +30 -0
  71. bencher/worker_job.py +40 -0
  72. holobench-1.3.6.dist-info/METADATA +85 -0
  73. holobench-1.3.6.dist-info/RECORD +74 -0
  74. holobench-1.3.6.dist-info/WHEEL +5 -0
@@ -0,0 +1,38 @@
1
+ """This file has some examples for how to perform basic benchmarking parameter sweeps"""
2
+
3
+ import bencher as bch
4
+
5
+ # All the examples will be using the data structures and benchmark function defined in this file
6
+ from bencher.example.benchmark_data import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
7
+
8
+
9
+ def example_1D_float(
10
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
11
+ ) -> bch.Bench:
12
+ """This example shows how to sample a 1 dimensional float variable and plot the result of passing that parameter sweep to the benchmarking function"""
13
+
14
+ bench = bch.Bench(
15
+ "benchmarking_example_float1D",
16
+ bench_function,
17
+ ExampleBenchCfgIn,
18
+ run_cfg=run_cfg,
19
+ report=report,
20
+ )
21
+
22
+ # 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
23
+ bench.plot_sweep(
24
+ title="Example 1D Float",
25
+ input_vars=[ExampleBenchCfgIn.param.theta],
26
+ result_vars=[ExampleBenchCfgOut.param.out_sin],
27
+ description=example_1D_float.__doc__,
28
+ )
29
+
30
+ return bench
31
+
32
+
33
+ if __name__ == "__main__":
34
+ ex_run_cfg = bch.BenchRunCfg()
35
+ ex_run_cfg.repeats = 2
36
+ # ex_run_cfg.over_time = True
37
+
38
+ example_1D_float(ex_run_cfg).report.show()
@@ -0,0 +1,46 @@
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
+ return super().__call__()
25
+
26
+
27
+ def example_strings(
28
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
29
+ ) -> bch.Bench:
30
+ bench = bch.Bench("strings", TestPrinting(), run_cfg=run_cfg, report=report)
31
+
32
+ for s in [
33
+ [TestPrinting.param.a],
34
+ [TestPrinting.param.a, TestPrinting.param.b],
35
+ [TestPrinting.param.a, TestPrinting.param.b, TestPrinting.param.c],
36
+ [TestPrinting.param.a, TestPrinting.param.b, TestPrinting.param.c, TestPrinting.param.d],
37
+ ]:
38
+ bench.plot_sweep(f"String Panes {[v.name for v in s]}", input_vars=s)
39
+ # bench.report.append(res.to_sweep_summary())
40
+ # bench.report.append(res.to_panes())
41
+
42
+ return bench
43
+
44
+
45
+ if __name__ == "__main__":
46
+ example_strings().report.show()
@@ -0,0 +1,62 @@
1
+ """This file has some examples for how to perform basic benchmarking parameter sweeps"""
2
+ # pylint: disable=duplicate-code
3
+
4
+ import bencher as bch
5
+
6
+ # All the examples will be using the data structures and benchmark function defined in this file
7
+ from bencher.example.benchmark_data import ExampleBenchCfgIn, ExampleBenchCfgOut, bench_function
8
+
9
+
10
+ def example_time_event(
11
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
12
+ ) -> bch.Bench:
13
+ """This example shows how to manually set time events as a string so that progress can be monitored over time"""
14
+
15
+ bencher = bch.Bench(
16
+ "benchmarking_example_categorical1D",
17
+ bench_function,
18
+ ExampleBenchCfgIn,
19
+ run_cfg=run_cfg,
20
+ report=report,
21
+ )
22
+
23
+ ExampleBenchCfgIn.param.offset.bounds = [0, 100]
24
+
25
+ # manually override the default value based on the time event string so that the graphs are not all just straight lines
26
+ ExampleBenchCfgIn.param.offset.default = int(str(hash(run_cfg.time_event))[-1])
27
+
28
+ # 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
29
+ bencher.plot_sweep(
30
+ title="Example 1D Categorical",
31
+ input_vars=[ExampleBenchCfgIn.param.postprocess_fn],
32
+ result_vars=[ExampleBenchCfgOut.param.out_cos],
33
+ description=example_time_event.__doc__,
34
+ run_cfg=run_cfg,
35
+ )
36
+ return bencher
37
+
38
+
39
+ def run_example_time_event(ex_run_cfg):
40
+ ex_run_cfg.repeats = 1
41
+ ex_run_cfg.print_pandas = True
42
+ ex_run_cfg.over_time = True
43
+
44
+ ex_run_cfg.clear_cache = True
45
+ ex_run_cfg.clear_history = True
46
+
47
+ ex_run_cfg.time_event = "-first_event"
48
+ example_time_event(ex_run_cfg)
49
+
50
+ ex_run_cfg.clear_cache = False
51
+ ex_run_cfg.clear_history = False
52
+ ex_run_cfg.time_event = "_second_event"
53
+ example_time_event(ex_run_cfg)
54
+
55
+ ex_run_cfg.time_event = (
56
+ "*third_event has a very very long label to demonstrate automatic text wrapping"
57
+ )
58
+ return example_time_event(ex_run_cfg)
59
+
60
+
61
+ if __name__ == "__main__":
62
+ run_example_time_event(bch.BenchRunCfg()).report.show()
@@ -0,0 +1,124 @@
1
+ import bencher as bch
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ import panel as pn
5
+
6
+
7
+ # code from https://ipython-books.github.io/124-simulating-a-partial-differential-equation-reaction-diffusion-systems-and-turing-patterns/
8
+ class TuringPattern(bch.ParametrizedSweep):
9
+ alpha = bch.FloatSweep(default=2.8e-4, bounds=(2e-4, 5e-3))
10
+ beta = bch.FloatSweep(default=5e-3, bounds=(1e-3, 9e-3))
11
+ tau = bch.FloatSweep(default=0.1, bounds=(0.01, 0.5))
12
+ k = bch.FloatSweep(default=-0.005, bounds=(-0.01, 0.01))
13
+
14
+ size = bch.IntSweep(default=30, bounds=(30, 200), doc="size of the 2D grid")
15
+ time = bch.FloatSweep(default=20.0, bounds=(1, 100), doc="total time of simulation")
16
+ dt = bch.FloatSweep(default=0.001, doc="simulation time step")
17
+
18
+ video = bch.ResultVideo()
19
+ score = bch.ResultVar()
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.video = vid_writer.write()
71
+
72
+ self.score = self.alpha + self.beta
73
+ return super().__call__()
74
+
75
+
76
+ def example_video(
77
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
78
+ ) -> bch.Bench:
79
+ # run_cfg.auto_plot = False
80
+ # run_cfg.use_sample_cache = True
81
+ bench = bch.Bench("example_video", TuringPattern(), run_cfg=run_cfg, report=report)
82
+
83
+ bench.plot_sweep(
84
+ "Turing patterns with different parameters",
85
+ input_vars=[TuringPattern.param.alpha, TuringPattern.param.beta],
86
+ # input_vars=[TuringPattern.param.alpha],
87
+ result_vars=[TuringPattern.param.video],
88
+ )
89
+
90
+ return bench
91
+
92
+
93
+ def example_video_tap(
94
+ run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
95
+ ) -> bch.Bench: # pragma: no cover
96
+ tp = TuringPattern()
97
+
98
+ run_cfg.use_sample_cache = False
99
+ # run_cfg.use_optuna = True
100
+ run_cfg.auto_plot = False
101
+ run_cfg.run_tag = "3"
102
+ bench = tp.to_bench(run_cfg=run_cfg, report=report)
103
+
104
+ res = bench.plot_sweep(
105
+ "phase",
106
+ input_vars=["alpha", "beta"],
107
+ # result_vars=["video","score"],
108
+ run_cfg=run_cfg,
109
+ )
110
+
111
+ bench.report.append(res.describe_sweep())
112
+ bench.report.append(
113
+ res.to_heatmap(tp.param.score, tap_var=tp.param.video, tap_container=pn.pane.Video)
114
+ )
115
+
116
+ return bench
117
+
118
+
119
+ if __name__ == "__main__":
120
+ run_cfg_ex = bch.BenchRunCfg()
121
+ run_cfg_ex.level = 2
122
+
123
+ # example_video(run_cfg_ex).report.show()
124
+ 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()
@@ -0,0 +1,75 @@
1
+ # import holoviews as hv
2
+ # import numpy as np
3
+ # import param
4
+ # from holoviews import opts, streams
5
+ # from holoviews.plotting.links import DataLink
6
+
7
+ # import panel as pn
8
+
9
+ # hv.extension("bokeh")
10
+
11
+ # datasets = {
12
+ # "data1": np.random.randint(1, 10, size=(4, 2)),
13
+ # "data2": np.random.randint(1, 10, size=(4, 2)),
14
+ # }
15
+
16
+ # other_data = {i: np.random.randint(1, 10, size=(100, 100)) for i in range(4)}
17
+
18
+
19
+ # class Explorer(param.Parameterized):
20
+ # dataset = param.ObjectSelector(default=list(datasets.keys())[0], objects=list(datasets.keys()))
21
+
22
+ # lines = param.Boolean(default=False)
23
+
24
+ # # streams
25
+ # stream = param.ClassSelector(
26
+ # default=streams.PointDraw(drag=False, add=False), class_=(streams.PointDraw), precedence=-1
27
+ # )
28
+
29
+ # selection = param.ClassSelector(
30
+ # default=streams.Selection1D(), class_=(streams.Selection1D), precedence=-1
31
+ # )
32
+
33
+ # @param.depends("dataset")
34
+ # def load_file(self):
35
+ # name = self.dataset
36
+ # datum = datasets[name]
37
+ # scatter = hv.Scatter(datum).opts(size=8)
38
+
39
+ # # update the PointDraw/Selection1D sources/data
40
+ # self.stream.source = scatter
41
+ # self.selection.source = scatter
42
+ # self.stream.update(data=scatter.columns()) # reset PointDraw data
43
+ # self.selection.update(index=[]) # reset selection index
44
+
45
+ # table = hv.Table(scatter).opts(index_position=False, editable=True, selectable=True)
46
+ # DataLink(scatter, table)
47
+
48
+ # return (scatter + table).opts(
49
+ # opts.Scatter(tools=["tap", "hover", "box_select"]), opts.Table(editable=True)
50
+ # )
51
+
52
+ # @param.depends("dataset", "selection.index", "lines")
53
+ # def view(self):
54
+ # """update 3rd plot whenever dataset, selection.index, or lines is changed"""
55
+ # if self.selection.index == []:
56
+ # return None
57
+ # else:
58
+ # # modify with your "other" data
59
+ # if self.lines is True:
60
+ # return hv.Path(other_data[self.selection.index[0]]).opts(shared_axes=False)
61
+
62
+ # return hv.operation.datashader.regrid(
63
+ # hv.Image(other_data[self.selection.index[0]]),
64
+ # upsample=True,
65
+ # interpolation="bilinear",
66
+ # ).opts(shared_axes=False)
67
+
68
+ # @param.depends("stream.data", watch=True)
69
+ # def update_data(self):
70
+ # """update dataset whenever a point is deleted using PointDraw"""
71
+ # datasets[self.dataset] = np.vstack((self.stream.data["x"], self.stream.data["y"])).T
72
+
73
+
74
+ # explorer = Explorer()
75
+ # pn.Row(pn.Column(explorer.param, explorer.view), explorer.load_file).show()