holobench 1.3.4__py3-none-any.whl → 1.22.2__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 +4 -1
  2. bencher/bench_cfg.py +37 -34
  3. bencher/bench_plot_server.py +5 -1
  4. bencher/bench_report.py +14 -14
  5. bencher/bench_runner.py +2 -1
  6. bencher/bencher.py +87 -50
  7. bencher/class_enum.py +52 -0
  8. bencher/job.py +6 -4
  9. bencher/optuna_conversions.py +1 -1
  10. bencher/utils.py +58 -3
  11. bencher/video_writer.py +110 -6
  12. holobench-1.22.2.data/data/share/bencher/package.xml +33 -0
  13. holobench-1.22.2.dist-info/LICENSE +21 -0
  14. {holobench-1.3.4.dist-info → holobench-1.22.2.dist-info}/METADATA +39 -32
  15. holobench-1.22.2.dist-info/RECORD +20 -0
  16. {holobench-1.3.4.dist-info → holobench-1.22.2.dist-info}/WHEEL +2 -1
  17. holobench-1.22.2.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 -98
  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 -83
  65. bencher/results/bench_result_base.py +0 -401
  66. bencher/results/float_formatter.py +0 -44
  67. bencher/results/holoview_result.py +0 -535
  68. bencher/results/optuna_result.py +0 -332
  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.4.dist-info/RECORD +0 -74
  77. /bencher/example/__init__.py → /holobench-1.22.2.data/data/share/ament_index/resource_index/packages/bencher +0 -0
@@ -1,206 +0,0 @@
1
- from functools import partial
2
- from typing import List, Tuple, Any
3
- from param import Parameter, Parameterized
4
- import holoviews as hv
5
- import panel as pn
6
-
7
-
8
- from bencher.utils import make_namedtuple, hash_sha1
9
- from bencher.variables.results import (
10
- ResultVar,
11
- ResultVec,
12
- ResultHmap,
13
- ResultVideo,
14
- ResultImage,
15
- ResultString,
16
- ResultContainer,
17
- ResultReference,
18
- )
19
-
20
-
21
- class ParametrizedSweep(Parameterized):
22
- """Parent class for all Sweep types that need a custom hash"""
23
-
24
- @staticmethod
25
- def param_hash(param_type: Parameterized, hash_value: bool = True) -> int:
26
- """A custom hash function for parametrised types with options for hashing the value of the type and hashing metadata
27
-
28
- Args:
29
- param_type (Parameterized): A parameter
30
- hash_value (bool, optional): use the value as part of the hash. Defaults to True.
31
- # hash_meta (bool, optional): use metadata as part of the hash. Defaults to False.
32
-
33
- Returns:
34
- int: a hash
35
- """
36
-
37
- curhash = 0
38
- if hash_value:
39
- for k, v in param_type.param.values().items():
40
- if k != "name":
41
- curhash = hash_sha1((curhash, hash_sha1(v)))
42
-
43
- # if hash_meta:
44
- # for k, v in param_type.param.objects().items():
45
- # if k != "name":
46
- # print(f"key:{k}, hash:{hash_sha1(k)}")
47
- # print(f"value:{v}, hash:{hash_sha1(v)}")
48
- # curhash = hash_sha1((curhash, hash_sha1(k), hash_sha1(v)))
49
- return curhash
50
-
51
- def hash_persistent(self) -> str:
52
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
53
- return ParametrizedSweep.param_hash(self, True)
54
-
55
- def update_params_from_kwargs(self, **kwargs) -> None:
56
- """Given a dictionary of kwargs, set the parameters of the passed class 'self' to the values in the dictionary."""
57
- used_params = {}
58
- for key in self.param.objects().keys():
59
- if key in kwargs:
60
- if key != "name":
61
- used_params[key] = kwargs[key]
62
-
63
- self.param.update(**used_params)
64
-
65
- @classmethod
66
- def get_input_and_results(cls, include_name: bool = False) -> Tuple[dict, dict]:
67
- """Get dictionaries of input parameters and result parameters
68
-
69
- Args:
70
- cls: A parametrised class
71
- include_name (bool): Include the name parameter that all parametrised classes have. Default False
72
-
73
- Returns:
74
- Tuple[dict, dict]: a tuple containing the inputs and result parameters as dictionaries
75
- """
76
- inputs = {}
77
- results = {}
78
- for k, v in cls.param.objects().items():
79
- if isinstance(
80
- v,
81
- (
82
- ResultVar,
83
- ResultVec,
84
- ResultHmap,
85
- ResultVideo,
86
- ResultImage,
87
- ResultString,
88
- ResultContainer,
89
- ResultReference,
90
- ),
91
- ):
92
- results[k] = v
93
- else:
94
- inputs[k] = v
95
-
96
- if not include_name:
97
- inputs.pop("name")
98
- return make_namedtuple("inputresult", inputs=inputs, results=results)
99
-
100
- def get_inputs_as_dict(self) -> dict:
101
- """Get the key:value pairs for all the input variables"""
102
- inp = self.get_input_and_results().inputs
103
- vals = self.param.values()
104
- return {i: vals[i] for i, v in inp.items()}
105
-
106
- def get_results_values_as_dict(self, holomap=None) -> dict:
107
- """Get a dictionary of result variables with the name and the current value"""
108
- values = self.param.values()
109
- output = {key: values[key] for key in self.get_input_and_results().results}
110
- if holomap is not None:
111
- output |= {"hmap": holomap}
112
- return output
113
-
114
- @classmethod
115
- def get_inputs_only(cls) -> List[Parameter]:
116
- """Return a list of input parameters
117
-
118
- Returns:
119
- List[param.Parameter]: A list of input parameters
120
- """
121
- return list(cls.get_input_and_results().inputs.values())
122
-
123
- @staticmethod
124
- def filter_fn(item, p_name):
125
- return item.name != p_name
126
-
127
- @classmethod
128
- def get_input_defaults(cls, override_defaults=None) -> List[Tuple[Parameter, Any]]:
129
- inp = cls.get_inputs_only()
130
- if override_defaults is None:
131
- override_defaults = []
132
- assert isinstance(override_defaults, list)
133
- for p in override_defaults:
134
- inp = filter(partial(ParametrizedSweep.filter_fn, p_name=p[0].name), inp)
135
- return override_defaults + [[i, i.default] for i in inp]
136
-
137
- @classmethod
138
- def get_results_only(cls) -> List[Parameter]:
139
- """Return a list of input parameters
140
-
141
- Returns:
142
- List[param.Parameter]: A list of result parameters
143
- """
144
- return list(cls.get_input_and_results().results.values())
145
-
146
- @classmethod
147
- def get_inputs_as_dims(
148
- self, compute_values=False, remove_dims: str | List[str] = None
149
- ) -> List[hv.Dimension]:
150
- inputs = self.get_inputs_only()
151
-
152
- if remove_dims is not None:
153
- if isinstance(remove_dims, str):
154
- remove_dims = [remove_dims]
155
- filtered_inputs = [i for i in inputs if i.name not in remove_dims]
156
- inputs = filtered_inputs
157
-
158
- return [iv.as_dim(compute_values) for iv in inputs]
159
-
160
- def to_dynamic_map(
161
- self,
162
- callback=None,
163
- name=None,
164
- remove_dims: str | List[str] = None,
165
- ) -> hv.DynamicMap:
166
- if callback is None:
167
- callback = self.__call__
168
-
169
- def callback_wrapper(**kwargs):
170
- return callback(**kwargs)["hmap"]
171
-
172
- return hv.DynamicMap(
173
- callback=callback_wrapper,
174
- kdims=self.get_inputs_as_dims(compute_values=False, remove_dims=remove_dims),
175
- name=name,
176
- ).opts(shared_axes=False, framewise=True, width=1000, height=1000)
177
-
178
- def to_gui(self): # pragma: no cover
179
- main = pn.Row(
180
- self.to_dynamic_map(),
181
- )
182
- main.show()
183
-
184
- def to_holomap(self, callback, remove_dims: str | List[str] = None) -> hv.DynamicMap:
185
- return hv.HoloMap(
186
- hv.DynamicMap(
187
- callback=callback,
188
- kdims=self.get_inputs_as_dims(compute_values=True, remove_dims=remove_dims),
189
- )
190
- )
191
-
192
- def __call__(self):
193
- return self.get_results_values_as_dict()
194
-
195
- def plot_hmap(self, **kwargs):
196
- return self.__call__(**kwargs)["hmap"]
197
-
198
- def to_bench(self, run_cfg=None, report=None, name: str = None):
199
- from bencher import Bench
200
-
201
- assert isinstance(self, ParametrizedSweep)
202
-
203
- if name is None:
204
- name = self.name[:-5] # param adds 5 digit number to the end, so remove it
205
-
206
- return Bench(name, self, run_cfg=run_cfg, report=report)
@@ -1,176 +0,0 @@
1
- from enum import auto
2
- from typing import List, Callable, Any
3
-
4
- import panel as pn
5
- import param
6
- from param import Number
7
- from strenum import StrEnum
8
- import holoviews as hv
9
- from bencher.utils import hash_sha1
10
-
11
- # from bencher.variables.parametrised_sweep import ParametrizedSweep
12
-
13
-
14
- class OptDir(StrEnum):
15
- minimize = auto()
16
- maximize = auto()
17
- none = auto() # If none this var will not appear in pareto plots
18
-
19
-
20
- class ResultVar(Number):
21
- """A class to represent result variables and the desired optimisation direction"""
22
-
23
- __slots__ = ["units", "direction"]
24
-
25
- def __init__(self, units="ul", direction: OptDir = OptDir.minimize, **params):
26
- Number.__init__(self, **params)
27
- assert isinstance(units, str)
28
- self.units = units
29
- self.default = 0 # json is terrible and does not support nan values
30
- self.direction = direction
31
-
32
- def as_dim(self) -> hv.Dimension:
33
- return hv.Dimension((self.name, self.name), unit=self.units)
34
-
35
- def hash_persistent(self) -> str:
36
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
37
- return hash_sha1((self.units, self.direction))
38
-
39
-
40
- class ResultVec(param.List):
41
- """A class to represent fixed size vector result variable"""
42
-
43
- __slots__ = ["units", "direction", "size"]
44
-
45
- def __init__(self, size, units="ul", direction: OptDir = OptDir.minimize, **params):
46
- param.List.__init__(self, **params)
47
- self.units = units
48
- self.default = 0 # json is terrible and does not support nan values
49
- self.direction = direction
50
- self.size = size
51
-
52
- def hash_persistent(self) -> str:
53
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
54
- return hash_sha1((self.units, self.direction))
55
-
56
- def index_name(self, idx: int) -> str:
57
- """given the index of the vector, return the column name that
58
-
59
- Args:
60
- idx (int): index of the result vector
61
-
62
- Returns:
63
- str: column name of the vector for the xarray dataset
64
- """
65
-
66
- mapping = ["x", "y", "z"]
67
- if idx < 3:
68
- index = mapping[idx]
69
- else:
70
- index = idx
71
- return f"{self.name}_{index}"
72
-
73
- def index_names(self) -> List[str]:
74
- """Returns a list of all the xarray column names for the result vector
75
-
76
- Returns:
77
- list[str]: column names
78
- """
79
- return [self.index_name(i) for i in range(self.size)]
80
-
81
-
82
- class ResultHmap(param.Parameter):
83
- """A class to represent a holomap return type"""
84
-
85
- def hash_persistent(self) -> str:
86
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
87
- return hash_sha1(self)
88
-
89
-
90
- def curve(x_vals: List[float], y_vals: List[float], x_name: str, y_name: str, **kwargs) -> hv.Curve:
91
- return hv.Curve(zip(x_vals, y_vals), kdims=[x_name], vdims=[y_name], label=y_name, **kwargs)
92
-
93
-
94
- class PathResult(param.Filename):
95
- __slots__ = ["units"]
96
-
97
- def __init__(self, default=None, units="path", **params):
98
- super().__init__(default=default, check_exists=False, **params)
99
- self.units = units
100
-
101
- def hash_persistent(self) -> str:
102
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
103
- return hash_sha1(self)
104
-
105
-
106
- class ResultVideo(PathResult):
107
- def __init__(self, default=None, units="video", **params):
108
- super().__init__(default=default, units=units, **params)
109
-
110
-
111
- class ResultImage(PathResult):
112
- def __init__(self, default=None, units="image", **params):
113
- super().__init__(default=default, units=units, **params)
114
-
115
-
116
- class ResultString(param.String):
117
- __slots__ = ["units"]
118
-
119
- def __init__(self, default=None, units="str", **params):
120
- super().__init__(default=default, **params)
121
- self.units = units
122
-
123
- def hash_persistent(self) -> str:
124
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
125
- return hash_sha1(self)
126
-
127
-
128
- class ResultContainer(param.Parameter):
129
- __slots__ = ["units"]
130
-
131
- def __init__(self, default=None, units="container", **params):
132
- super().__init__(default=default, **params)
133
- self.units = units
134
-
135
- def hash_persistent(self) -> str:
136
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
137
- return hash_sha1(self)
138
-
139
-
140
- class ResultReference(param.Parameter):
141
- """Use this class to save arbitrary objects that are not picklable or native to panel. You can pass a container callback that takes the object and returns a panel pane to be displayed"""
142
-
143
- __slots__ = ["units", "obj", "container"]
144
-
145
- def __init__(
146
- self,
147
- obj: Any = None,
148
- container: Callable[Any, pn.pane.panel] = None,
149
- default: Any = None,
150
- units: str = "container",
151
- **params,
152
- ):
153
- super().__init__(default=default, **params)
154
- self.units = units
155
- self.obj = obj
156
- self.container = container
157
-
158
- def hash_persistent(self) -> str:
159
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
160
- return hash_sha1(self)
161
-
162
-
163
- class ResultVolume(param.Parameter):
164
- __slots__ = ["units", "obj"]
165
-
166
- def __init__(self, obj=None, default=None, units="container", **params):
167
- super().__init__(default=default, **params)
168
- self.units = units
169
- self.obj = obj
170
-
171
- def hash_persistent(self) -> str:
172
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
173
- return hash_sha1(self)
174
-
175
-
176
- PANEL_TYPES = (ResultImage, ResultContainer, ResultString, ResultReference)
@@ -1,167 +0,0 @@
1
- from __future__ import annotations
2
- from typing import List, Any, Tuple
3
- from copy import deepcopy
4
-
5
- import numpy as np
6
- import param
7
- from param import Parameterized
8
- import holoviews as hv
9
- import panel as pn
10
- from bencher.utils import hash_sha1
11
-
12
- # slots that are shared across all Sweep classes
13
- # param and slots don't work easily with multiple inheritance so define here
14
- shared_slots = ["units", "samples", "samples_debug"]
15
-
16
-
17
- def describe_variable(
18
- v: Parameterized, debug: bool, include_samples: bool, value=None
19
- ) -> List[str]:
20
- """Generate a string description of a variable
21
-
22
- Args:
23
- v (param.Parameterized): parameter to describe
24
- debug (bool): Generate a reduced number of samples from the variable
25
- include_samples (bool): Include a description of the samples
26
-
27
- Returns:
28
- str: String description of the variable
29
- """
30
- indent = " "
31
- sampling_str = []
32
- sampling_str.append(f"{v.name}:")
33
- if include_samples:
34
- # sampling_str.append(f"{indent}{v.sampling_str(debug)}")
35
- sampling_str.append(f"{indent}number of samples: {len(v.values(debug))}")
36
- sampling_str.append(f"{indent}sample values: {[str(v) for v in v.values(debug)]}")
37
-
38
- if value is not None:
39
- sampling_str.append(f"{indent}value: {value}")
40
- if hasattr(v, "units"):
41
- if v.units != "ul" and len(v.units) > 0:
42
- sampling_str.append(f"{indent}units: [{v.units}]")
43
- if v.doc is not None:
44
- sampling_str.append(f"{indent}docs: {v.doc}")
45
- for i in range(len(sampling_str)):
46
- sampling_str[i] = f"{indent}{sampling_str[i]}"
47
- return sampling_str
48
-
49
-
50
- class SweepBase(param.Parameter):
51
- # def __init__(self, **params):
52
- # super().__init__(**params)
53
- # self.units = ""
54
- # slots = ["units", "samples", "samples_debug"]
55
- # __slots__ = shared_slots
56
-
57
- def values(self, debug: bool) -> List[Any]:
58
- """All sweep classes must implement this method. This generates sample values from based on the parameters bounds and sample number.
59
-
60
- Args:
61
- debug (bool): Return a reduced set of samples to enable fast debugging of a data generation and plotting pipeline. Ideally when debug is true, 2 samples will be returned
62
-
63
- Returns:
64
- List[Any]: A list of samples from the variable
65
- """
66
- raise NotImplementedError
67
-
68
- def hash_persistent(self) -> str:
69
- """A hash function that avoids the PYTHONHASHSEED 'feature' which returns a different hash value each time the program is run"""
70
- return hash_sha1(
71
- (self.units, self.samples, self.samples_debug) # pylint: disable=no-member
72
- )
73
-
74
- def sampling_str(self, debug=False) -> str:
75
- """Generate a string representation of the of the sampling procedure
76
-
77
- Args:
78
- debug (bool): If true then self.samples_debug is used
79
- """
80
-
81
- samples = self.values(debug)
82
- object_str = ",".join([str(i) for i in samples])
83
- return f"Taking {len(samples)} samples from {self.name} with values: [{object_str}]"
84
-
85
- def as_slider(self, debug=False) -> pn.widgets.slider.DiscreteSlider:
86
- """given a sweep variable (self), return the range of values as a panel slider
87
-
88
- Args:
89
- debug (bool, optional): pass to the sweepvar to produce a full set of varaibles, or when debug=True, a reduces number of sweep vars. Defaults to False.
90
-
91
- Returns:
92
- pn.widgets.slider.DiscreteSlider: A panel slider with the values() of the sweep variable
93
- """
94
- return pn.widgets.slider.DiscreteSlider(name=self.name, options=list(self.values(debug)))
95
-
96
- def as_dim(self, compute_values=False, debug=False) -> hv.Dimension:
97
- """Takes a sweep variable and turns it into a holoview dimension
98
-
99
- Returns:
100
- hv.Dimension:
101
- """
102
- name_tuple = (self.name, self.name)
103
-
104
- params = {}
105
- if hasattr(self, "bounds"):
106
- if compute_values:
107
- params["values"] = self.values(debug)
108
- # params["range"] = tuple(self.bounds)
109
- else:
110
- params["range"] = tuple(self.bounds)
111
- params["default"] = self.default
112
-
113
- else:
114
- params["values"] = self.values(debug)
115
- params["default"] = self.default
116
-
117
- if hasattr(self, "step"):
118
- params["step"] = getattr(self, "step")
119
-
120
- return hv.Dimension(name_tuple, unit=self.units, **params) # pylint: disable=no-member
121
-
122
- def indices_to_samples(self, desires_num_samples, sample_values):
123
- indices = [
124
- int(i) for i in np.linspace(0, len(sample_values) - 1, desires_num_samples, dtype=int)
125
- ]
126
-
127
- if len(indices) > len(sample_values):
128
- return sample_values
129
-
130
- return [sample_values[i] for i in indices]
131
-
132
- def with_samples(self, samples: int) -> SweepBase:
133
- output = deepcopy(self)
134
- # TODO set up class properly. Slightly complicated due to slots
135
- output.samples = samples # pylint: disable = attribute-defined-outside-init
136
- if hasattr(output, "step"):
137
- # hack TODO fix this
138
- output.step = None # pylint: disable = attribute-defined-outside-init
139
- return output
140
-
141
- def with_sample_values(self, sample_values: int) -> SweepBase:
142
- output = deepcopy(self)
143
- # TODO set up class properly. Slightly complicated due to slots
144
- try:
145
- output.sample_values = sample_values # pylint: disable = attribute-defined-outside-init
146
- except AttributeError:
147
- output.objects = sample_values # pylint: disable = attribute-defined-outside-init
148
- output.samples = len(sample_values) # pylint: disable = attribute-defined-outside-init
149
- return output
150
-
151
- def with_const(self, const_value: Any) -> Tuple[SweepBase, Any]:
152
- """Create a new instance of SweepBase with a constant value.
153
-
154
- Args:
155
- const_value (Any): The constant value to be associated with the new instance.
156
-
157
- Returns:
158
- Tuple[SweepBase, Any]: A tuple containing the new instance of SweepBase and the constant value.
159
- """
160
- return (deepcopy(self), const_value)
161
-
162
- def with_level(self, level: int = 1, max_level: int = 12) -> SweepBase:
163
- assert level >= 1
164
- # TODO work out if the order can be returned in level order always
165
- samples = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049]
166
- out = self.with_sample_values(self.with_samples(samples[min(max_level, level)]).values())
167
- return out
bencher/variables/time.py DELETED
@@ -1,74 +0,0 @@
1
- from datetime import datetime
2
- from typing import List
3
-
4
- from pandas import Timestamp
5
- from param import Selector
6
- from bencher.variables.sweep_base import SweepBase, shared_slots
7
-
8
-
9
- class TimeBase(SweepBase, Selector):
10
- """A class to capture a time snapshot of benchmark values. Time is reprented as a continous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables"""
11
-
12
- __slots__ = shared_slots
13
-
14
- def values(self, debug=False) -> List[str]:
15
- """return all the values for a parameter sweep. If debug is true return a reduced list"""
16
- # print(self.sampling_str(debug))
17
- return self.objects
18
-
19
-
20
- class TimeSnapshot(TimeBase):
21
- """A class to capture a time snapshot of benchmark values. Time is reprented as a continous value i.e a datetime which is converted into a np.datetime64. To represent time as a discrete value use the TimeEvent class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables"""
22
-
23
- __slots__ = shared_slots
24
-
25
- def __init__(
26
- self,
27
- datetime_src: datetime | str,
28
- units: str = "time",
29
- samples: int = None,
30
- samples_debug: int = 2,
31
- **params,
32
- ):
33
- if isinstance(datetime_src, str):
34
- TimeBase.__init__(self, [datetime_src], instantiate=True, **params)
35
- else:
36
- TimeBase.__init__(
37
- self,
38
- objects=[Timestamp(datetime_src)],
39
- instantiate=True,
40
- **params,
41
- )
42
- self.units = units
43
- if samples is None:
44
- self.samples = len(self.objects)
45
- else:
46
- self.samples = samples
47
- self.samples_debug = min(self.samples, samples_debug)
48
-
49
-
50
- class TimeEvent(TimeBase):
51
- """A class to represent a discrete event in time where the data was captured i.e a series of pull requests. Here time is discrete and can't be interpolated, to represent time as a continous value use the TimeSnapshot class. The distinction is because holoview and plotly code makes different assumptions about discrete vs continous variables"""
52
-
53
- __slots__ = shared_slots
54
-
55
- def __init__(
56
- self,
57
- time_event: str,
58
- units: str = "event",
59
- samples: int = None,
60
- samples_debug: int = 2,
61
- **params,
62
- ):
63
- TimeBase.__init__(
64
- self,
65
- objects=[time_event],
66
- instantiate=True,
67
- **params,
68
- )
69
- self.units = units
70
- if samples is None:
71
- self.samples = len(self.objects)
72
- else:
73
- self.samples = samples
74
- self.samples_debug = min(self.samples, samples_debug)