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.
- bencher/bench_report.py +6 -109
- bencher/example/__init__.py +0 -0
- 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.27.0.data/data/share/ament_index/resource_index/packages/bencher +0 -0
- holobench-1.27.0.data/data/share/bencher/package.xml +33 -0
- {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/METADATA +5 -5
- holobench-1.27.0.dist-info/RECORD +93 -0
- holobench-1.25.2.dist-info/RECORD +0 -18
- {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/LICENSE +0 -0
- {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/WHEEL +0 -0
- {holobench-1.25.2.dist-info → holobench-1.27.0.dist-info}/top_level.txt +0 -0
@@ -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()
|
@@ -0,0 +1,84 @@
|
|
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()
|
@@ -0,0 +1,84 @@
|
|
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()
|
@@ -0,0 +1,171 @@
|
|
1
|
+
from typing import Any
|
2
|
+
import bencher as bch
|
3
|
+
import numpy as np
|
4
|
+
|
5
|
+
from enum import auto
|
6
|
+
from strenum import StrEnum
|
7
|
+
import random
|
8
|
+
import holoviews as hv
|
9
|
+
import math
|
10
|
+
|
11
|
+
|
12
|
+
class NoiseDistribution(StrEnum):
|
13
|
+
"""A categorical variable describing the types of random noise"""
|
14
|
+
|
15
|
+
uniform = auto() # uniform random noiase
|
16
|
+
gaussian = auto() # gaussian noise
|
17
|
+
|
18
|
+
@staticmethod
|
19
|
+
def calculate_noise(noisy, noise_distribution, sigma) -> float:
|
20
|
+
if noisy:
|
21
|
+
match noise_distribution:
|
22
|
+
case NoiseDistribution.uniform:
|
23
|
+
return random.uniform(0, sigma)
|
24
|
+
case NoiseDistribution.gaussian:
|
25
|
+
return random.gauss(0, sigma)
|
26
|
+
return 0.0
|
27
|
+
|
28
|
+
|
29
|
+
class BenchableObject(bch.ParametrizedSweep):
|
30
|
+
"""A class to represent a 3D point in space."""
|
31
|
+
|
32
|
+
# floating point variables
|
33
|
+
float1 = bch.FloatSweep(default=0, bounds=[0, 1.0], doc="x coordinate of the sample volume")
|
34
|
+
float2 = bch.FloatSweep(default=0, bounds=[0, 1.0], doc="y coordinate of the sample volume")
|
35
|
+
float3 = bch.FloatSweep(default=0, bounds=[0, 1.0], doc="z coordinate of the sample volume")
|
36
|
+
|
37
|
+
sigma = bch.FloatSweep(default=1, bounds=[1, 10], doc="standard deviation of the added noise")
|
38
|
+
|
39
|
+
# categorial variables
|
40
|
+
noisy = bch.BoolSweep(
|
41
|
+
default=False, doc="Optionally add random noise to the output of the function"
|
42
|
+
)
|
43
|
+
noise_distribution = bch.EnumSweep(NoiseDistribution, doc=NoiseDistribution.__doc__)
|
44
|
+
|
45
|
+
negate_output = bch.StringSweep(["positive", "negative"])
|
46
|
+
|
47
|
+
distance = bch.ResultVar("m", doc="The distance from the sample point to the origin")
|
48
|
+
sample_noise = bch.ResultVar("m", doc="The amount of noise added to the distance sample")
|
49
|
+
|
50
|
+
result_hmap = bch.ResultHmap()
|
51
|
+
# result_im
|
52
|
+
##todo all var types
|
53
|
+
|
54
|
+
def __call__(self, **kwargs):
|
55
|
+
self.update_params_from_kwargs(**kwargs)
|
56
|
+
|
57
|
+
# distance to origin
|
58
|
+
self.distance = math.pow(
|
59
|
+
np.linalg.norm(np.array([self.float1, self.float2, self.float3])), 2
|
60
|
+
)
|
61
|
+
self.sample_noise = NoiseDistribution.calculate_noise(
|
62
|
+
self.noisy, self.noise_distribution, self.sigma
|
63
|
+
)
|
64
|
+
|
65
|
+
self.distance += self.sample_noise
|
66
|
+
|
67
|
+
if self.negate_output == "negative":
|
68
|
+
self.distance *= -1
|
69
|
+
|
70
|
+
self.result_hmap = hv.Text(
|
71
|
+
x=0, y=0, text=f"distance:{self.distance}\nnoise:{self.sample_noise}"
|
72
|
+
)
|
73
|
+
|
74
|
+
return super().__call__()
|
75
|
+
|
76
|
+
|
77
|
+
class BenchMeta(bch.ParametrizedSweep):
|
78
|
+
"""This class uses bencher to display the multidimensional types bencher can represent"""
|
79
|
+
|
80
|
+
float_vars = bch.IntSweep(
|
81
|
+
default=1, bounds=(0, 4), doc="The number of floating point variables that are swept"
|
82
|
+
)
|
83
|
+
categorical_vars = bch.IntSweep(
|
84
|
+
default=1, bounds=(0, 3), doc="The number of categorical variables that are swept"
|
85
|
+
)
|
86
|
+
sample_with_repeats = bch.IntSweep(default=1, bounds=(1, 10))
|
87
|
+
|
88
|
+
sample_over_time = bch.BoolSweep(default=False)
|
89
|
+
|
90
|
+
level = bch.IntSweep(default=2, units="level", bounds=(2, 5))
|
91
|
+
|
92
|
+
# plots = bch.ResultHmap()
|
93
|
+
# plots = bch.ResultContainer()
|
94
|
+
plots = bch.ResultReference(units="int")
|
95
|
+
|
96
|
+
def __call__(self, **kwargs: Any) -> Any:
|
97
|
+
self.update_params_from_kwargs(**kwargs)
|
98
|
+
|
99
|
+
run_cfg = bch.BenchRunCfg()
|
100
|
+
run_cfg.level = self.level
|
101
|
+
run_cfg.repeats = self.sample_with_repeats
|
102
|
+
run_cfg.over_time = self.sample_over_time
|
103
|
+
run_cfg.plot_size = 500
|
104
|
+
|
105
|
+
bench = bch.Bench("benchable", BenchableObject(), run_cfg=run_cfg)
|
106
|
+
|
107
|
+
inputs_vars_float = [
|
108
|
+
"float1",
|
109
|
+
"float2",
|
110
|
+
"float3",
|
111
|
+
"sigma",
|
112
|
+
]
|
113
|
+
|
114
|
+
inputs_vars_cat = [
|
115
|
+
"noisy",
|
116
|
+
"noise_distribution",
|
117
|
+
"negate_output",
|
118
|
+
]
|
119
|
+
|
120
|
+
input_vars = (
|
121
|
+
inputs_vars_float[0 : self.float_vars] + inputs_vars_cat[0 : self.categorical_vars]
|
122
|
+
)
|
123
|
+
|
124
|
+
res = bench.plot_sweep(
|
125
|
+
"test",
|
126
|
+
input_vars=input_vars,
|
127
|
+
result_vars=[BenchableObject.param.distance],
|
128
|
+
# result_vars=[BenchableObject.param.distance, BenchableObject.param.sample_noise],
|
129
|
+
# result_vars=[ BenchableObject.param.sample_noise],
|
130
|
+
# result_vars=[BenchableObject.param.result_hmap],
|
131
|
+
plot_callbacks=False,
|
132
|
+
)
|
133
|
+
|
134
|
+
self.plots = bch.ResultReference()
|
135
|
+
self.plots.obj = res.to_auto()
|
136
|
+
|
137
|
+
# self.plots.obj = res.to_heatmap_multi()
|
138
|
+
|
139
|
+
# self.plots.obj = res.to_line_multi(width=500, height=300)
|
140
|
+
|
141
|
+
return super().__call__()
|
142
|
+
|
143
|
+
|
144
|
+
def example_meta(
|
145
|
+
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
146
|
+
) -> bch.Bench:
|
147
|
+
bench = BenchMeta().to_bench(run_cfg, report)
|
148
|
+
|
149
|
+
bench.plot_sweep(
|
150
|
+
title="Meta Bench",
|
151
|
+
description="""## All Combinations of Variable Sweeps and Resulting Plots
|
152
|
+
This uses bencher to display all the combinatios of plots bencher is able to produce""",
|
153
|
+
input_vars=[
|
154
|
+
bch.p("float_vars", [0, 1, 2, 3]),
|
155
|
+
BenchMeta.param.categorical_vars,
|
156
|
+
bch.p("sample_with_repeats", [1, 2]),
|
157
|
+
# BenchMeta.param.sample_over_time,
|
158
|
+
],
|
159
|
+
const_vars=[
|
160
|
+
# BenchMeta.param.float_vars.with_const(1),
|
161
|
+
# BenchMeta.param.sample_with_repeats.with_const(2),
|
162
|
+
# BenchMeta.param.categorical_vars.with_const(2),
|
163
|
+
# BenchMeta.param.sample_over_time.with_const(True),
|
164
|
+
],
|
165
|
+
)
|
166
|
+
|
167
|
+
return bench
|
168
|
+
|
169
|
+
|
170
|
+
if __name__ == "__main__":
|
171
|
+
example_meta().report.show()
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
from bencher.example.meta.example_meta import BenchMeta
|
3
|
+
|
4
|
+
|
5
|
+
def example_meta_cat(
|
6
|
+
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
7
|
+
) -> bch.Bench:
|
8
|
+
bench = BenchMeta().to_bench(run_cfg, report)
|
9
|
+
|
10
|
+
bench.plot_sweep(
|
11
|
+
title="Sweeping Categorical Variables",
|
12
|
+
input_vars=[
|
13
|
+
bch.p("categorical_vars", [1, 2, 3]),
|
14
|
+
bch.p("sample_with_repeats", [1, 2]),
|
15
|
+
],
|
16
|
+
const_vars=[
|
17
|
+
BenchMeta.param.float_vars.with_const(0),
|
18
|
+
],
|
19
|
+
)
|
20
|
+
|
21
|
+
return bench
|
22
|
+
|
23
|
+
|
24
|
+
if __name__ == "__main__":
|
25
|
+
example_meta_cat().report.show()
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
from bencher.example.meta.example_meta import BenchMeta
|
3
|
+
|
4
|
+
|
5
|
+
def example_meta_float(
|
6
|
+
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
7
|
+
) -> bch.Bench:
|
8
|
+
bench = BenchMeta().to_bench(run_cfg, report)
|
9
|
+
|
10
|
+
bench.plot_sweep(
|
11
|
+
title="Sweeping Floating Point Variables",
|
12
|
+
input_vars=[bch.p("float_vars", [1, 2, 3])],
|
13
|
+
const_vars=[
|
14
|
+
BenchMeta.param.categorical_vars.with_const(0),
|
15
|
+
BenchMeta.param.level.with_const(3),
|
16
|
+
],
|
17
|
+
)
|
18
|
+
|
19
|
+
return bench
|
20
|
+
|
21
|
+
|
22
|
+
if __name__ == "__main__":
|
23
|
+
example_meta_float().report.show()
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import bencher as bch
|
2
|
+
from bencher.example.meta.example_meta import BenchMeta
|
3
|
+
|
4
|
+
|
5
|
+
def example_meta_levels(
|
6
|
+
run_cfg: bch.BenchRunCfg = bch.BenchRunCfg(), report: bch.BenchReport = bch.BenchReport()
|
7
|
+
) -> bch.Bench:
|
8
|
+
bench = BenchMeta().to_bench(run_cfg, report)
|
9
|
+
|
10
|
+
bench.plot_sweep(
|
11
|
+
title="Using Levels to define sample density",
|
12
|
+
description="Sample levels let you perform parameter sweeps without having to decide how many samples to take when defining the class. If you perform a sweep at level 2, then all the points are reused when sampling at level 3. The higher levels reuse the points from lower levels to avoid having to recompute potentially expensive samples. The other advantage is that it enables a workflow where you can quickly see the results of the sweep at a low resolution to sense check the code, and then run it at a high level to get the fidelity you want. When calling a sweep at a high level, you can publish the intermediate lower level results as the computiation continues so that you can track the progress of the computation and end the sweep early when you have sufficient resolution",
|
13
|
+
input_vars=[
|
14
|
+
bch.p("float_vars", [1, 2]),
|
15
|
+
bch.p("level", [2, 3, 4]),
|
16
|
+
],
|
17
|
+
const_vars=[
|
18
|
+
BenchMeta.param.categorical_vars.with_const(0),
|
19
|
+
],
|
20
|
+
)
|
21
|
+
|
22
|
+
return bench
|
23
|
+
|
24
|
+
|
25
|
+
if __name__ == "__main__":
|
26
|
+
example_meta_levels().report.show()
|