holobench 1.25.1__py3-none-any.whl → 1.26.3__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.
- bencher/example/benchmark_data.py +196 -0
- bencher/example/example_all.py +45 -0
- bencher/example/example_categorical.py +99 -0
- bencher/example/example_composable_container.py +106 -0
- bencher/example/example_composable_container2.py +160 -0
- bencher/example/example_consts.py +39 -0
- bencher/example/example_custom_sweep.py +59 -0
- bencher/example/example_custom_sweep2.py +42 -0
- bencher/example/example_docs.py +34 -0
- bencher/example/example_filepath.py +27 -0
- bencher/example/example_float3D.py +101 -0
- bencher/example/example_float_cat.py +99 -0
- bencher/example/example_floats.py +89 -0
- bencher/example/example_floats2D.py +93 -0
- bencher/example/example_holosweep.py +98 -0
- bencher/example/example_holosweep_objects.py +111 -0
- bencher/example/example_holosweep_tap.py +144 -0
- bencher/example/example_image.py +155 -0
- bencher/example/example_levels.py +181 -0
- bencher/example/example_levels2.py +37 -0
- bencher/example/example_pareto.py +53 -0
- bencher/example/example_sample_cache.py +85 -0
- bencher/example/example_sample_cache_context.py +116 -0
- bencher/example/example_simple.py +134 -0
- bencher/example/example_simple_bool.py +35 -0
- bencher/example/example_simple_cat.py +48 -0
- bencher/example/example_simple_float.py +28 -0
- bencher/example/example_simple_float2d.py +29 -0
- bencher/example/example_strings.py +47 -0
- bencher/example/example_time_event.py +63 -0
- bencher/example/example_video.py +118 -0
- bencher/example/example_workflow.py +189 -0
- bencher/example/experimental/example_bokeh_plotly.py +38 -0
- bencher/example/experimental/example_hover_ex.py +45 -0
- bencher/example/experimental/example_hvplot_explorer.py +39 -0
- bencher/example/experimental/example_interactive.py +75 -0
- bencher/example/experimental/example_streamnd.py +49 -0
- bencher/example/experimental/example_streams.py +36 -0
- bencher/example/experimental/example_template.py +40 -0
- bencher/example/experimental/example_updates.py +84 -0
- bencher/example/experimental/example_vector.py +84 -0
- bencher/example/meta/example_meta.py +171 -0
- bencher/example/meta/example_meta_cat.py +25 -0
- bencher/example/meta/example_meta_float.py +23 -0
- bencher/example/meta/example_meta_levels.py +26 -0
- bencher/example/optuna/example_optuna.py +78 -0
- bencher/example/shelved/example_float2D_scatter.py +109 -0
- bencher/example/shelved/example_float3D_cone.py +96 -0
- bencher/example/shelved/example_kwargs.py +63 -0
- bencher/plotting/__init__.py +0 -0
- bencher/plotting/plot_filter.py +110 -0
- bencher/plotting/plt_cnt_cfg.py +75 -0
- bencher/results/__init__.py +0 -0
- bencher/results/bench_result.py +94 -0
- bencher/results/bench_result_base.py +476 -0
- bencher/results/composable_container/__init__.py +0 -0
- bencher/results/composable_container/composable_container_base.py +73 -0
- bencher/results/composable_container/composable_container_panel.py +39 -0
- bencher/results/composable_container/composable_container_video.py +184 -0
- bencher/results/float_formatter.py +44 -0
- bencher/results/holoview_result.py +753 -0
- bencher/results/optuna_result.py +354 -0
- bencher/results/panel_result.py +41 -0
- bencher/results/plotly_result.py +65 -0
- bencher/results/video_result.py +38 -0
- bencher/results/video_summary.py +222 -0
- bencher/variables/__init__.py +0 -0
- bencher/variables/inputs.py +202 -0
- bencher/variables/parametrised_sweep.py +208 -0
- bencher/variables/results.py +214 -0
- bencher/variables/sweep_base.py +162 -0
- bencher/variables/time.py +92 -0
- holobench-1.26.3.data/data/share/ament_index/resource_index/packages/bencher +0 -0
- {holobench-1.25.1.dist-info → holobench-1.26.3.dist-info}/METADATA +5 -7
- holobench-1.26.3.dist-info/RECORD +93 -0
- holobench-1.25.1.dist-info/RECORD +0 -20
- /holobench-1.25.1.data/data/share/ament_index/resource_index/packages/bencher → /bencher/example/__init__.py +0 -0
- {holobench-1.25.1.data → holobench-1.26.3.data}/data/share/bencher/package.xml +0 -0
- {holobench-1.25.1.dist-info → holobench-1.26.3.dist-info}/LICENSE +0 -0
- {holobench-1.25.1.dist-info → holobench-1.26.3.dist-info}/WHEEL +0 -0
- {holobench-1.25.1.dist-info → holobench-1.26.3.dist-info}/top_level.txt +0 -0
@@ -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()
|
@@ -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()
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# pylint: skip-file #this is experimental still
|
2
|
+
|
3
|
+
|
4
|
+
import time
|
5
|
+
import numpy as np
|
6
|
+
import holoviews as hv
|
7
|
+
from holoviews import streams
|
8
|
+
import panel as pn
|
9
|
+
|
10
|
+
hv.extension("bokeh")
|
11
|
+
|
12
|
+
# Step 1: Set up your initial data
|
13
|
+
# For demonstration purposes, let's create a simple initial Image plot.
|
14
|
+
|
15
|
+
# Initial data (replace this with your actual data source)
|
16
|
+
initial_data = np.random.rand(10, 10)
|
17
|
+
|
18
|
+
# Create an Image plot from the initial data
|
19
|
+
initial_plot = hv.Image(initial_data)
|
20
|
+
|
21
|
+
|
22
|
+
# Step 2: Create a callback function to update the plot with new data
|
23
|
+
def update_plot(new_data):
|
24
|
+
# Update the Image plot with the new data
|
25
|
+
new_plot = hv.Image(new_data)
|
26
|
+
return new_plot
|
27
|
+
|
28
|
+
|
29
|
+
# Step 3: Create a DynamicMap that triggers the update_plot callback
|
30
|
+
# The DynamicMap will automatically update the plot when new_data changes.
|
31
|
+
dmap = hv.DynamicMap(
|
32
|
+
update_plot, streams=[streams.Stream.define("NewData", new_data=initial_data)()]
|
33
|
+
)
|
34
|
+
|
35
|
+
# Display the initial plot and start streaming updates
|
36
|
+
layout = initial_plot + dmap
|
37
|
+
layout = layout.cols(1)
|
38
|
+
|
39
|
+
# Simulate streaming updates by continuously updating the new_data stream
|
40
|
+
for i in range(10):
|
41
|
+
# Replace this line with your actual data source/streaming mechanism
|
42
|
+
new_data = np.random.rand(10, 10)
|
43
|
+
# Update the new_data stream to trigger the DynamicMap callback
|
44
|
+
dmap.event(NewData=new_data)
|
45
|
+
# Sleep for a specified interval
|
46
|
+
time.sleep(1)
|
47
|
+
|
48
|
+
|
49
|
+
pn.Row(dmap).show()
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# pylint: skip-file #this is experimental still
|
2
|
+
|
3
|
+
import numpy as np
|
4
|
+
import holoviews as hv
|
5
|
+
from holoviews import opts
|
6
|
+
from holoviews import streams
|
7
|
+
import panel as pn
|
8
|
+
|
9
|
+
xs = np.linspace(-3, 3, 400)
|
10
|
+
|
11
|
+
hv.extension("bokeh")
|
12
|
+
|
13
|
+
|
14
|
+
def function(xs, time):
|
15
|
+
"Some time varying function"
|
16
|
+
return np.exp(np.sin(xs + np.pi / time))
|
17
|
+
|
18
|
+
|
19
|
+
def integral(limit, time):
|
20
|
+
print(limit, time)
|
21
|
+
limit = -3 if limit is None else np.clip(limit, -3, 3)
|
22
|
+
curve = hv.Curve((xs, function(xs, time)))[limit:]
|
23
|
+
area = hv.Area((xs, function(xs, time)))[:limit]
|
24
|
+
summed = area.dimension_values("y").sum() * 0.015 # Numeric approximation
|
25
|
+
return area * curve * hv.VLine(limit) * hv.Text(limit + 0.8, 2.0, "%.2f" % summed)
|
26
|
+
|
27
|
+
|
28
|
+
integral_streams = [streams.Stream.define("Time", time=1.0)(), streams.PointerX().rename(x="limit")]
|
29
|
+
|
30
|
+
integral_dmap = hv.DynamicMap(integral, streams=integral_streams)
|
31
|
+
|
32
|
+
integral_dmap.opts(
|
33
|
+
opts.Area(color="#fff8dc", line_width=2), opts.Curve(color="black"), opts.VLine(color="red")
|
34
|
+
)
|
35
|
+
|
36
|
+
pn.Row(integral_dmap).show()
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import holoviews as hv
|
2
|
+
import numpy as np
|
3
|
+
import panel as pn
|
4
|
+
|
5
|
+
pn.extension(sizing_mode="stretch_width")
|
6
|
+
|
7
|
+
ACCENT_COLOR = pn.template.FastListTemplate.accent_base_color
|
8
|
+
XS = np.linspace(0, np.pi)
|
9
|
+
|
10
|
+
|
11
|
+
def sine(freq, phase):
|
12
|
+
return (
|
13
|
+
hv.Curve((XS, np.sin(XS * freq + phase)))
|
14
|
+
.opts(responsive=True, min_height=400, title="Sine", color=ACCENT_COLOR)
|
15
|
+
.opts(line_width=6)
|
16
|
+
)
|
17
|
+
|
18
|
+
|
19
|
+
def cosine(freq, phase):
|
20
|
+
return (
|
21
|
+
hv.Curve((XS, np.cos(XS * freq + phase)))
|
22
|
+
.opts(responsive=True, min_height=400, title="Cosine", color=ACCENT_COLOR)
|
23
|
+
.opts(line_width=6)
|
24
|
+
)
|
25
|
+
|
26
|
+
|
27
|
+
freq_widget = pn.widgets.FloatSlider(name="Frequency", start=0, end=10, value=2)
|
28
|
+
phase_widget = pn.widgets.FloatSlider(name="Phase", start=0, end=np.pi)
|
29
|
+
|
30
|
+
sine = pn.bind(sine, freq=freq_widget, phase=phase_widget)
|
31
|
+
cosine = pn.bind(cosine, freq=freq_widget, phase=phase_widget)
|
32
|
+
|
33
|
+
template = pn.template.FastListTemplate(
|
34
|
+
site="Panel",
|
35
|
+
title="FastListTemplate",
|
36
|
+
sidebar=[pn.pane.Markdown("## Settings"), freq_widget, phase_widget],
|
37
|
+
main=[
|
38
|
+
pn.pane.HoloViews(hv.DynamicMap(sine) + hv.DynamicMap(cosine), sizing_mode="stretch_both")
|
39
|
+
],
|
40
|
+
).show()
|