holobench 1.3.5__py3-none-any.whl → 1.23.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 (77) hide show
  1. bencher/__init__.py +12 -0
  2. bencher/bench_cfg.py +29 -33
  3. bencher/bench_plot_server.py +5 -1
  4. bencher/bench_report.py +14 -14
  5. bencher/bench_runner.py +3 -2
  6. bencher/bencher.py +80 -53
  7. bencher/class_enum.py +52 -0
  8. bencher/job.py +6 -4
  9. bencher/optuna_conversions.py +4 -3
  10. bencher/utils.py +55 -4
  11. bencher/video_writer.py +48 -11
  12. holobench-1.23.0.data/data/share/bencher/package.xml +33 -0
  13. holobench-1.23.0.dist-info/LICENSE +21 -0
  14. {holobench-1.3.5.dist-info → holobench-1.23.0.dist-info}/METADATA +41 -31
  15. holobench-1.23.0.dist-info/RECORD +20 -0
  16. {holobench-1.3.5.dist-info → holobench-1.23.0.dist-info}/WHEEL +2 -1
  17. holobench-1.23.0.dist-info/top_level.txt +1 -0
  18. bencher/example/benchmark_data.py +0 -200
  19. bencher/example/example_all.py +0 -45
  20. bencher/example/example_categorical.py +0 -99
  21. bencher/example/example_custom_sweep.py +0 -59
  22. bencher/example/example_docs.py +0 -34
  23. bencher/example/example_float3D.py +0 -101
  24. bencher/example/example_float_cat.py +0 -98
  25. bencher/example/example_floats.py +0 -89
  26. bencher/example/example_floats2D.py +0 -93
  27. bencher/example/example_holosweep.py +0 -104
  28. bencher/example/example_holosweep_objects.py +0 -111
  29. bencher/example/example_holosweep_tap.py +0 -144
  30. bencher/example/example_image.py +0 -82
  31. bencher/example/example_levels.py +0 -181
  32. bencher/example/example_pareto.py +0 -53
  33. bencher/example/example_sample_cache.py +0 -85
  34. bencher/example/example_sample_cache_context.py +0 -116
  35. bencher/example/example_simple.py +0 -134
  36. bencher/example/example_simple_bool.py +0 -34
  37. bencher/example/example_simple_cat.py +0 -47
  38. bencher/example/example_simple_float.py +0 -38
  39. bencher/example/example_strings.py +0 -46
  40. bencher/example/example_time_event.py +0 -62
  41. bencher/example/example_video.py +0 -124
  42. bencher/example/example_workflow.py +0 -189
  43. bencher/example/experimental/example_bokeh_plotly.py +0 -38
  44. bencher/example/experimental/example_hover_ex.py +0 -45
  45. bencher/example/experimental/example_hvplot_explorer.py +0 -39
  46. bencher/example/experimental/example_interactive.py +0 -75
  47. bencher/example/experimental/example_streamnd.py +0 -49
  48. bencher/example/experimental/example_streams.py +0 -36
  49. bencher/example/experimental/example_template.py +0 -40
  50. bencher/example/experimental/example_updates.py +0 -84
  51. bencher/example/experimental/example_vector.py +0 -84
  52. bencher/example/meta/example_meta.py +0 -171
  53. bencher/example/meta/example_meta_cat.py +0 -25
  54. bencher/example/meta/example_meta_float.py +0 -23
  55. bencher/example/meta/example_meta_levels.py +0 -26
  56. bencher/example/optuna/example_optuna.py +0 -78
  57. bencher/example/shelved/example_float2D_scatter.py +0 -109
  58. bencher/example/shelved/example_float3D_cone.py +0 -96
  59. bencher/example/shelved/example_kwargs.py +0 -63
  60. bencher/plotting/__init__.py +0 -0
  61. bencher/plotting/plot_filter.py +0 -110
  62. bencher/plotting/plt_cnt_cfg.py +0 -74
  63. bencher/results/__init__.py +0 -0
  64. bencher/results/bench_result.py +0 -80
  65. bencher/results/bench_result_base.py +0 -405
  66. bencher/results/float_formatter.py +0 -44
  67. bencher/results/holoview_result.py +0 -592
  68. bencher/results/optuna_result.py +0 -354
  69. bencher/results/panel_result.py +0 -113
  70. bencher/results/plotly_result.py +0 -65
  71. bencher/variables/inputs.py +0 -193
  72. bencher/variables/parametrised_sweep.py +0 -206
  73. bencher/variables/results.py +0 -176
  74. bencher/variables/sweep_base.py +0 -167
  75. bencher/variables/time.py +0 -74
  76. holobench-1.3.5.dist-info/RECORD +0 -74
  77. /bencher/example/__init__.py → /holobench-1.23.0.data/data/share/ament_index/resource_index/packages/bencher +0 -0
@@ -1,189 +0,0 @@
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()
@@ -1,38 +0,0 @@
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()
@@ -1,45 +0,0 @@
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()
@@ -1,39 +0,0 @@
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()
@@ -1,75 +0,0 @@
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()
@@ -1,49 +0,0 @@
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()
@@ -1,36 +0,0 @@
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()
@@ -1,40 +0,0 @@
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()
@@ -1,84 +0,0 @@
1
- # pylint: skip-file #this is experimental still
2
-
3
-
4
- import numpy as np
5
- import pandas as pd
6
- import holoviews as hv
7
- import panel as pn
8
-
9
- # import streamz
10
- # import streamz.dataframe
11
-
12
- from holoviews import opts
13
- from holoviews.streams import Buffer
14
-
15
- from tornado.ioloop import PeriodicCallback
16
- from tornado import gen
17
-
18
-
19
- hv.extension("bokeh")
20
-
21
-
22
- count = 0
23
- buffer = Buffer(np.zeros((0, 2)), length=50)
24
-
25
- dataType = pd.DataFrame()
26
-
27
-
28
- @gen.coroutine
29
- def f():
30
- global count
31
- count += 1
32
- buffer.send(np.array([[count, np.random.rand()]]))
33
-
34
-
35
- def plot(**kwargs):
36
- # print(dat)
37
- return hv.Curve(**kwargs)
38
-
39
-
40
- cb = PeriodicCallback(f, 1)
41
- cb.start()
42
-
43
- # dmap = hv.DynamicMap(hv.Curve, streams=[buffer]).opts(padding=0.1, width=600)
44
- dmap = hv.DynamicMap(plot, streams=[buffer]).opts(padding=0.1, width=600)
45
-
46
- pn.Row(dmap).show()
47
-
48
-
49
- example = pd.DataFrame({"x": [], "y": [], "count": []}, columns=["x", "y", "count"])
50
- dfstream = Buffer(example, length=100, index=False)
51
-
52
-
53
- def plot():
54
- curve_dmap = hv.DynamicMap(hv.Curve, streams=[dfstream])
55
- point_dmap = hv.DynamicMap(hv.Points, streams=[dfstream])
56
- (curve_dmap * point_dmap).opts(
57
- opts.Points(color="count", line_color="black", size=5, padding=0.1, xaxis=None, yaxis=None),
58
- opts.Curve(line_width=1, color="black"),
59
- )
60
-
61
-
62
- def gen_brownian():
63
- x, y, count = 0, 0, 0
64
- while True:
65
- x += np.random.randn()
66
- y += np.random.randn()
67
- count += 1
68
- yield pd.DataFrame([(x, y, count)], columns=["x", "y", "count"])
69
-
70
-
71
- @gen.coroutine
72
- def update_callback():
73
- brownian = gen_brownian()
74
- for i in range(2):
75
- dfstream.send(next(brownian))
76
-
77
-
78
- cb = PeriodicCallback(update_callback, 1)
79
- cb.start()
80
-
81
- # update_button = pn.widgets.Button(name="Update Grid", button_type="primary")
82
- # update_button.on_click(update_callback)
83
-
84
- pn.Row(plot()).show()
@@ -1,84 +0,0 @@
1
- # """Example on how to sweep over function with vector outputs"""
2
-
3
- # from math import cos, sin
4
-
5
- # import numpy as np
6
-
7
- # import bencher as bch
8
-
9
-
10
- # class OffsetCfg(bch.ParametrizedSweep):
11
- # """A class for describing which parameters to sweep"""
12
-
13
- # dc_offset = bch.FloatSweep(
14
- # default=0,
15
- # bounds=[0.0, 2.0],
16
- # samples=4,
17
- # units="v",
18
- # doc="DC offset to add to the result of the signal",
19
- # )
20
- # phase_offset = bch.FloatSweep(
21
- # default=0,
22
- # bounds=[0.0, 3.14],
23
- # samples=4,
24
- # units="rad",
25
- # doc="phase offset that is added to the input before passing to the trig function",
26
- # )
27
-
28
-
29
- # class SweepResult(bch.ParametrizedSweep):
30
- # """A class to describe the vector outputs of the benchmark function"""
31
-
32
- # sin_sweep = bch.ResultList(
33
- # index_name="time", index_units="s", units="v", doc="A list of values from a sin function"
34
- # )
35
- # cos_sweep = bch.ResultList(
36
- # index_name="time", index_units="s", units="v", doc="A list of values from a cos function"
37
- # )
38
-
39
-
40
- # def sin_sweep(cfg: OffsetCfg) -> SweepResult:
41
- # """A function that returns vector outputs of the sin and cos functions
42
-
43
- # Args:
44
- # cfg (OffsetCfg): Options for phase and dc offset
45
-
46
- # Returns:
47
- # SweepResult: vectors with sin and cos results
48
- # """
49
- # res = SweepResult()
50
- # print(type(res.sin_sweep))
51
- # for i in np.arange(0, 6.28, 0.02):
52
- # res.sin_sweep.append(sin(i + cfg.phase_offset) + cfg.dc_offset, i)
53
- # # res.sin_sweep.indices.append(i)
54
- # for i in np.arange(0, 3.28, 0.02):
55
- # res.cos_sweep.append(cos(i + cfg.phase_offset) + cfg.dc_offset, i)
56
- # # res.cos_sweep.indices.append(i)
57
- # return res
58
-
59
-
60
- # def example_vector() -> bch.Bench:
61
- # """Example on how to sweep over function with vector outputs"""
62
- # bencher = bch.Bench("vector output example", sin_sweep, OffsetCfg)
63
-
64
- # bencher.plot_sweep(
65
- # title="Sweep DC offset",
66
- # input_vars=[OffsetCfg.param.dc_offset],
67
- # result_vars=[SweepResult.param.sin_sweep, SweepResult.param.cos_sweep],
68
- # description="""This is an example of how to sample function that return a vector of unknown or varying size. In this example it returns the output of the sin and cos function for varying angles and a range of dc offsets""",
69
- # post_description="""The output shows stack of sin and cos functions as the dc offset increases""",
70
- # )
71
-
72
- # bencher.plot_sweep(
73
- # title="Sweep phase offset",
74
- # input_vars=[OffsetCfg.param.phase_offset],
75
- # result_vars=[SweepResult.param.sin_sweep, SweepResult.param.cos_sweep],
76
- # description="""This is an example of how to sample function that return a vector of unknown or varying size. In this example it returns the output of the sin and cos function for varying angles and a range of phase offsets""",
77
- # post_description="""The output shows different phases of the sin and cos functions""",
78
- # )
79
-
80
- # return bencher
81
-
82
-
83
- # if __name__ == "__main__":
84
- # example_vector().plot()