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.
- bencher/__init__.py +12 -0
- bencher/bench_cfg.py +29 -33
- bencher/bench_plot_server.py +5 -1
- bencher/bench_report.py +14 -14
- bencher/bench_runner.py +3 -2
- bencher/bencher.py +80 -53
- bencher/class_enum.py +52 -0
- bencher/job.py +6 -4
- bencher/optuna_conversions.py +4 -3
- bencher/utils.py +55 -4
- bencher/video_writer.py +48 -11
- holobench-1.23.0.data/data/share/bencher/package.xml +33 -0
- holobench-1.23.0.dist-info/LICENSE +21 -0
- {holobench-1.3.5.dist-info → holobench-1.23.0.dist-info}/METADATA +41 -31
- holobench-1.23.0.dist-info/RECORD +20 -0
- {holobench-1.3.5.dist-info → holobench-1.23.0.dist-info}/WHEEL +2 -1
- holobench-1.23.0.dist-info/top_level.txt +1 -0
- bencher/example/benchmark_data.py +0 -200
- bencher/example/example_all.py +0 -45
- bencher/example/example_categorical.py +0 -99
- bencher/example/example_custom_sweep.py +0 -59
- bencher/example/example_docs.py +0 -34
- bencher/example/example_float3D.py +0 -101
- bencher/example/example_float_cat.py +0 -98
- bencher/example/example_floats.py +0 -89
- bencher/example/example_floats2D.py +0 -93
- bencher/example/example_holosweep.py +0 -104
- bencher/example/example_holosweep_objects.py +0 -111
- bencher/example/example_holosweep_tap.py +0 -144
- bencher/example/example_image.py +0 -82
- bencher/example/example_levels.py +0 -181
- bencher/example/example_pareto.py +0 -53
- bencher/example/example_sample_cache.py +0 -85
- bencher/example/example_sample_cache_context.py +0 -116
- bencher/example/example_simple.py +0 -134
- bencher/example/example_simple_bool.py +0 -34
- bencher/example/example_simple_cat.py +0 -47
- bencher/example/example_simple_float.py +0 -38
- bencher/example/example_strings.py +0 -46
- bencher/example/example_time_event.py +0 -62
- bencher/example/example_video.py +0 -124
- bencher/example/example_workflow.py +0 -189
- bencher/example/experimental/example_bokeh_plotly.py +0 -38
- bencher/example/experimental/example_hover_ex.py +0 -45
- bencher/example/experimental/example_hvplot_explorer.py +0 -39
- bencher/example/experimental/example_interactive.py +0 -75
- bencher/example/experimental/example_streamnd.py +0 -49
- bencher/example/experimental/example_streams.py +0 -36
- bencher/example/experimental/example_template.py +0 -40
- bencher/example/experimental/example_updates.py +0 -84
- bencher/example/experimental/example_vector.py +0 -84
- bencher/example/meta/example_meta.py +0 -171
- bencher/example/meta/example_meta_cat.py +0 -25
- bencher/example/meta/example_meta_float.py +0 -23
- bencher/example/meta/example_meta_levels.py +0 -26
- bencher/example/optuna/example_optuna.py +0 -78
- bencher/example/shelved/example_float2D_scatter.py +0 -109
- bencher/example/shelved/example_float3D_cone.py +0 -96
- bencher/example/shelved/example_kwargs.py +0 -63
- bencher/plotting/__init__.py +0 -0
- bencher/plotting/plot_filter.py +0 -110
- bencher/plotting/plt_cnt_cfg.py +0 -74
- bencher/results/__init__.py +0 -0
- bencher/results/bench_result.py +0 -80
- bencher/results/bench_result_base.py +0 -405
- bencher/results/float_formatter.py +0 -44
- bencher/results/holoview_result.py +0 -592
- bencher/results/optuna_result.py +0 -354
- bencher/results/panel_result.py +0 -113
- bencher/results/plotly_result.py +0 -65
- bencher/variables/inputs.py +0 -193
- bencher/variables/parametrised_sweep.py +0 -206
- bencher/variables/results.py +0 -176
- bencher/variables/sweep_base.py +0 -167
- bencher/variables/time.py +0 -74
- holobench-1.3.5.dist-info/RECORD +0 -74
- /bencher/example/__init__.py → /holobench-1.23.0.data/data/share/ament_index/resource_index/packages/bencher +0 -0
bencher/variables/inputs.py
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
from enum import Enum
|
2
|
-
from typing import List, Any
|
3
|
-
|
4
|
-
import numpy as np
|
5
|
-
from param import Integer, Number, Selector
|
6
|
-
from bencher.variables.sweep_base import SweepBase, shared_slots
|
7
|
-
|
8
|
-
|
9
|
-
class SweepSelector(Selector, SweepBase):
|
10
|
-
"""A class to reprsent a parameter sweep of bools"""
|
11
|
-
|
12
|
-
__slots__ = shared_slots
|
13
|
-
|
14
|
-
def __init__(self, units: str = "ul", samples: int = None, samples_debug: int = 2, **params):
|
15
|
-
SweepBase.__init__(self)
|
16
|
-
Selector.__init__(self, **params)
|
17
|
-
|
18
|
-
self.units = units
|
19
|
-
if samples is None:
|
20
|
-
self.samples = len(self.objects)
|
21
|
-
else:
|
22
|
-
self.samples = samples
|
23
|
-
self.samples_debug = min(self.samples, samples_debug)
|
24
|
-
|
25
|
-
def values(self, debug=False) -> List[Any]:
|
26
|
-
"""return all the values for a parameter sweep. If debug is true return a reduced list"""
|
27
|
-
return self.indices_to_samples(self.samples_debug if debug else self.samples, self.objects)
|
28
|
-
|
29
|
-
|
30
|
-
class BoolSweep(SweepSelector):
|
31
|
-
"""A class to reprsent a parameter sweep of bools"""
|
32
|
-
|
33
|
-
def __init__(
|
34
|
-
self, units: str = "ul", samples: int = None, samples_debug: int = 2, default=True, **params
|
35
|
-
):
|
36
|
-
SweepSelector.__init__(
|
37
|
-
self,
|
38
|
-
units=units,
|
39
|
-
samples=samples,
|
40
|
-
samples_debug=samples_debug,
|
41
|
-
default=default,
|
42
|
-
objects=[True, False] if default else [False, True],
|
43
|
-
**params,
|
44
|
-
)
|
45
|
-
|
46
|
-
|
47
|
-
class StringSweep(SweepSelector):
|
48
|
-
"""A class to reprsent a parameter sweep of strings"""
|
49
|
-
|
50
|
-
def __init__(
|
51
|
-
self,
|
52
|
-
string_list: List[str],
|
53
|
-
units: str = "",
|
54
|
-
samples: int = None,
|
55
|
-
samples_debug: int = 2,
|
56
|
-
**params,
|
57
|
-
):
|
58
|
-
SweepSelector.__init__(
|
59
|
-
self,
|
60
|
-
objects=string_list,
|
61
|
-
instantiate=True,
|
62
|
-
units=units,
|
63
|
-
samples=samples,
|
64
|
-
samples_debug=samples_debug,
|
65
|
-
**params,
|
66
|
-
)
|
67
|
-
|
68
|
-
|
69
|
-
class EnumSweep(SweepSelector):
|
70
|
-
"""A class to reprsent a parameter sweep of enums"""
|
71
|
-
|
72
|
-
__slots__ = shared_slots
|
73
|
-
|
74
|
-
def __init__(
|
75
|
-
self, enum_type: Enum | List[Enum], units=" ", samples=None, samples_debug=2, **params
|
76
|
-
):
|
77
|
-
# The enum can either be an Enum type or a list of enums
|
78
|
-
list_of_enums = isinstance(enum_type, list)
|
79
|
-
selector_list = enum_type if list_of_enums else list(enum_type)
|
80
|
-
SweepSelector.__init__(
|
81
|
-
self,
|
82
|
-
objects=selector_list,
|
83
|
-
instantiate=True,
|
84
|
-
units=units,
|
85
|
-
samples=samples,
|
86
|
-
samples_debug=samples_debug,
|
87
|
-
**params,
|
88
|
-
)
|
89
|
-
if not list_of_enums: # Grab the docs from the enum type def
|
90
|
-
self.doc = enum_type.__doc__
|
91
|
-
|
92
|
-
|
93
|
-
class IntSweep(Integer, SweepBase):
|
94
|
-
"""A class to reprsent a parameter sweep of ints"""
|
95
|
-
|
96
|
-
__slots__ = shared_slots + ["sample_values"]
|
97
|
-
|
98
|
-
def __init__(self, units="ul", samples=None, samples_debug=2, sample_values=None, **params):
|
99
|
-
SweepBase.__init__(self)
|
100
|
-
Integer.__init__(self, **params)
|
101
|
-
|
102
|
-
self.units = units
|
103
|
-
self.samples_debug = samples_debug
|
104
|
-
|
105
|
-
if sample_values is None:
|
106
|
-
if samples is None:
|
107
|
-
if self.bounds is None:
|
108
|
-
raise RuntimeError("You must define bounds for integer types")
|
109
|
-
self.samples = 1 + self.bounds[1] - self.bounds[0]
|
110
|
-
else:
|
111
|
-
self.samples = samples
|
112
|
-
self.sample_values = None
|
113
|
-
else:
|
114
|
-
self.sample_values = sample_values
|
115
|
-
self.samples = len(self.sample_values)
|
116
|
-
if "default" not in params:
|
117
|
-
self.default = sample_values[0]
|
118
|
-
|
119
|
-
def values(self, debug=False) -> List[int]:
|
120
|
-
"""return all the values for a parameter sweep. If debug is true return the list"""
|
121
|
-
sample_values = (
|
122
|
-
self.sample_values
|
123
|
-
if self.sample_values is not None
|
124
|
-
else list(range(int(self.bounds[0]), int(self.bounds[1] + 1)))
|
125
|
-
)
|
126
|
-
|
127
|
-
return self.indices_to_samples(self.samples_debug if debug else self.samples, sample_values)
|
128
|
-
|
129
|
-
###THESE ARE COPIES OF INTEGER VALIDATION BUT ALSO ALLOW NUMPY INT TYPES
|
130
|
-
def _validate_value(self, val, allow_None):
|
131
|
-
if callable(val):
|
132
|
-
return
|
133
|
-
|
134
|
-
if allow_None and val is None:
|
135
|
-
return
|
136
|
-
|
137
|
-
if not isinstance(val, (int, np.integer)):
|
138
|
-
raise ValueError(
|
139
|
-
"Integer parameter %r must be an integer, " "not type %r." % (self.name, type(val))
|
140
|
-
)
|
141
|
-
|
142
|
-
###THESE ARE COPIES OF INTEGER VALIDATION BUT ALSO ALLOW NUMPY INT TYPES
|
143
|
-
def _validate_step(self, val, step):
|
144
|
-
if step is not None and not isinstance(step, (int, np.integer)):
|
145
|
-
raise ValueError(
|
146
|
-
"Step can only be None or an " "integer value, not type %r" % type(step)
|
147
|
-
)
|
148
|
-
|
149
|
-
|
150
|
-
class FloatSweep(Number, SweepBase):
|
151
|
-
"""A class to represent a parameter sweep of floats"""
|
152
|
-
|
153
|
-
__slots__ = shared_slots + ["sample_values"]
|
154
|
-
|
155
|
-
def __init__(
|
156
|
-
self, units="ul", samples=10, samples_debug=2, sample_values=None, step=None, **params
|
157
|
-
):
|
158
|
-
SweepBase.__init__(self)
|
159
|
-
Number.__init__(self, step=step, **params)
|
160
|
-
|
161
|
-
self.units = units
|
162
|
-
self.samples_debug = samples_debug
|
163
|
-
|
164
|
-
self.sample_values = sample_values
|
165
|
-
|
166
|
-
if sample_values is None:
|
167
|
-
self.samples = samples
|
168
|
-
else:
|
169
|
-
self.samples = len(self.sample_values)
|
170
|
-
if "default" not in params:
|
171
|
-
self.default = sample_values[0]
|
172
|
-
|
173
|
-
def values(self, debug=False) -> List[float]:
|
174
|
-
"""return all the values for a parameter sweep. If debug is true return a reduced list"""
|
175
|
-
samps = self.samples_debug if debug else self.samples
|
176
|
-
if self.sample_values is None:
|
177
|
-
if self.step is None:
|
178
|
-
return np.linspace(self.bounds[0], self.bounds[1], samps)
|
179
|
-
|
180
|
-
return np.arange(self.bounds[0], self.bounds[1], self.step)
|
181
|
-
if debug:
|
182
|
-
indices = [
|
183
|
-
int(i)
|
184
|
-
for i in np.linspace(0, len(self.sample_values) - 1, self.samples_debug, dtype=int)
|
185
|
-
]
|
186
|
-
return [self.sample_values[i] for i in indices]
|
187
|
-
return self.sample_values
|
188
|
-
|
189
|
-
|
190
|
-
def box(name, center, width):
|
191
|
-
var = FloatSweep(default=center, bounds=(center - width, center + width))
|
192
|
-
var.name = name
|
193
|
-
return var
|
@@ -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)
|
bencher/variables/results.py
DELETED
@@ -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)
|