bencher.results.bench_result_base

Classes

ReduceType

Generic enumeration.

EmptyContainer

A wrapper for list like containers that only appends if the item is not None

BenchResultBase

Functions

convert_dataset_bool_dims_to_str(→ xarray.Dataset)

Given a dataarray that contains boolean coordinates, convert them to strings so that holoviews loads the data properly

Module Contents

class bencher.results.bench_result_base.ReduceType

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

AUTO
SQUEEZE
REDUCE
MINMAX
NONE
class bencher.results.bench_result_base.EmptyContainer(pane)

A wrapper for list like containers that only appends if the item is not None

pane
append(child)
get()
bencher.results.bench_result_base.convert_dataset_bool_dims_to_str(dataset: xarray.Dataset) xarray.Dataset

Given a dataarray that contains boolean coordinates, convert them to strings so that holoviews loads the data properly

Parameters:

dataarray (xr.DataArray) – dataarray with boolean coordinates

Returns:

dataarray with boolean coordinates converted to strings

Return type:

xr.DataArray

class bencher.results.bench_result_base.BenchResultBase(bench_cfg: bencher.bench_cfg.BenchCfg)
bench_cfg
ds
object_index = []
hmaps
result_hmaps
studies = []
plt_cnt_cfg
plot_inputs = []
dataset_list = []
regression_report = None
perf_report = None
_to_dataset_cache: dict
to_xarray() xarray.Dataset
setup_object_index()
to_pandas(reset_index=True) pandas.DataFrame

Get the xarray results as a pandas dataframe

Returns:

The xarray results array as a pandas dataframe

Return type:

pd.DataFrame

wrap_long_time_labels(bench_cfg)

Takes a benchCfg and formats over_time coordinate labels for display.

For discrete TimeEvent labels, wraps long strings for readability. For datetime TimeSnapshot labels, replaces with integer indices so that Panel renders a slider widget. Without this, Panel’s DiscreteSlider truncates np.datetime64 values to second precision, which causes sub-second timestamps to collide into fewer slider positions.

Parameters:

bench_cfg (BenchCfg)

Returns:

updated config with wrapped labels

Return type:

BenchCfg

post_setup()
result_samples() int

The number of samples in the results dataframe

to_hv_dataset(reduce: ReduceType = ReduceType.AUTO, result_var: bencher.variables.results.ResultFloat | None = None, subsampling_divisions: int | None = None, agg_over_dims: list[str] | None = None, agg_fn: Literal['mean', 'sum', 'max', 'min', 'median'] | None = None) holoviews.Dataset

Generate a holoviews dataset from the xarray dataset.

Parameters:

reduce (ReduceType, optional) – Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard deviation over the “repeat” dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the “reduce” variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO.

Returns:

results in the form of a holoviews dataset

Return type:

hv.Dataset

_resolve_auto(reduce: ReduceType) ReduceType

Resolve AUTO to a concrete ReduceType based on repeat count.

_to_dataset_cache_key(reduce: ReduceType, result_var: bencher.variables.results.ResultFloat | str | None, subsampling_divisions: int | None, agg_over_dims: list[str] | None, agg_fn: str | None) tuple

Build a hashable cache key from normalized to_dataset() arguments.

to_dataset(reduce: ReduceType = ReduceType.AUTO, result_var: bencher.variables.results.ResultFloat | str | None = None, subsampling_divisions: int | None = None, agg_over_dims: list[str] | None = None, agg_fn: Literal['mean', 'sum', 'max', 'min', 'median'] | None = None, deep: bool = True) xarray.Dataset

Generate a summarised xarray dataset.

Parameters:
  • reduce (ReduceType, optional) – Optionally perform reduce options on the dataset. By default the returned dataset will calculate the mean and standard deviation over the “repeat” dimension so that the dataset plays nicely with most of the holoviews plot types. Reduce.Sqeeze is used if there is only 1 repeat and you want the “reduce” variable removed from the dataset. ReduceType.None returns an unaltered dataset. Defaults to ReduceType.AUTO.

  • deep (bool, optional) – If True (default), return a deep copy that is safe to mutate. Pass False to get the cached object directly for read-only use (avoids the copy cost).

Returns:

results in the form of an xarray dataset

Return type:

xr.Dataset

Note

Results are computed once and cached per instance. By default (deep=True) a deep copy is returned so callers can safely mutate the result. Internal hot paths pass deep=False to reuse the cached object directly.

get_optimal_vec(result_var: bencher.variables.parametrised_sweep.ParametrizedSweep, input_vars: list[bencher.variables.parametrised_sweep.ParametrizedSweep]) list[Any]

Get the optimal values from the sweep as a vector.

Parameters:
  • result_var (bn.ParametrizedSweep) – Optimal values of this result variable

  • input_vars (list[bn.ParametrizedSweep]) – Define which input vars values are returned in the vector

Returns:

A vector of optimal values for the desired input vector

Return type:

list[Any]

get_optimal_value_indices(result_var: bencher.variables.parametrised_sweep.ParametrizedSweep) xarray.DataArray

Get an xarray mask of the values with the best values found during a parameter sweep

Parameters:

result_var (bn.ParametrizedSweep) – Optimal value of this result variable

Returns:

xarray mask of optimal values

Return type:

xr.DataArray

get_optimal_inputs(result_var: bencher.variables.parametrised_sweep.ParametrizedSweep, keep_existing_consts: bool = True, as_dict: bool = False) tuple[bencher.variables.parametrised_sweep.ParametrizedSweep, Any] | dict[bencher.variables.parametrised_sweep.ParametrizedSweep, Any]

Get a list of tuples of optimal variable names and value pairs, that can be fed in as constant values to subsequent parameter sweeps

Parameters:
  • result_var (bn.ParametrizedSweep) – Optimal values of this result variable

  • keep_existing_consts (bool) – Include any const values that were defined as part of the parameter sweep

  • as_dict (bool) – return value as a dictionary

Returns:

Tuples of variable name and optimal values

Return type:

tuple[bn.ParametrizedSweep, Any]|[ParametrizedSweep, Any]

describe_sweep()
get_hmap(name: str | None = None)
to_plot_title() str
title_from_ds(dataset: xarray.Dataset, result_var: param.Parameter, **kwargs)
get_results_var_list(result_var: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None) list[param.Parameter]
map_plots(plot_callback: Callable, result_var: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None, row: EmptyContainer | None = None) panel.Row | None
static zip_results1D(args)
static zip_results1D1(panel_list)
static zip_results1D2(panel_list)
map_plot_panes(plot_callback: Callable, hv_dataset: holoviews.Dataset = None, target_dimension: int = 2, result_var: bencher.variables.results.ResultFloat | None = None, result_types=None, pane_collection: panel.pane = None, zip_results=False, reduce: ReduceType | None = None, pane_layout: bencher.results.composable_container.composable_container_base.PaneLayout = PaneLayout.grid, **kwargs) panel.Row | None
filter(plot_callback: Callable, plot_filter=None, float_range: bencher.plotting.plot_filter.VarRange | None = None, cat_range: bencher.plotting.plot_filter.VarRange | None = None, vector_len: bencher.plotting.plot_filter.VarRange | None = None, result_vars: bencher.plotting.plot_filter.VarRange | None = None, panel_range: bencher.plotting.plot_filter.VarRange | None = None, repeats_range: bencher.plotting.plot_filter.VarRange | None = None, input_range: bencher.plotting.plot_filter.VarRange | None = None, reduce: ReduceType = ReduceType.AUTO, target_dimension: int = 2, result_var: bencher.variables.results.ResultFloat | None = None, result_types=None, pane_collection: panel.pane = None, override=False, hv_dataset: holoviews.Dataset | None = None, agg_over_dims: list[str] | None = None, agg_fn: Literal['mean', 'sum', 'max', 'min', 'median'] = 'mean', pane_layout: bencher.results.composable_container.composable_container_base.PaneLayout = PaneLayout.grid, **kwargs) panel.panel | None
to_panes_multi_panel(hv_dataset: holoviews.Dataset, result_var: bencher.variables.results.ResultFloat, plot_callback: Callable | None = None, target_dimension: int = 1, pane_layout: bencher.results.composable_container.composable_container_base.PaneLayout = PaneLayout.grid, **kwargs)
static _child_pane_layout(pane_layout: bencher.results.composable_container.composable_container_base.PaneLayout) bencher.results.composable_container.composable_container_base.PaneLayout

Return the layout to use for child dimensions during recursion.

_iter_pane_slices(dataset, selected_dim, plot_callback, target_dimension, result_var, child_layout)

Yield (label_val, panes) for each slice along selected_dim.

_to_panes_da(dataset: xarray.Dataset, plot_callback: Callable | None = None, target_dimension=1, horizontal=False, result_var=None, pane_layout: bencher.results.composable_container.composable_container_base.PaneLayout = PaneLayout.grid, **kwargs) panel.panel
_pane_over_time_slider(dataset: xarray.Dataset, result_var) panel.Column

Create a Panel slider widget for over_time with pane-type results.

Numeric plot callbacks (line, heatmap) handle over_time internally via hv.HoloMap. Pane-type callbacks (images, videos, rerun) cannot use HoloMap because they produce Panel objects, not HoloViews elements. This method builds per-time-point content and swaps it via a Bokeh JS callback to avoid Panel’s ImportedStyleSheet document-ownership errors.

_pane_over_time_grid(dataset: xarray.Dataset, result_var) panel.Row | panel.pane.Markdown

Render over_time pane results as a grid of labelled panels.

Used for ResultRerun because rerun iframes do not work inside a Bokeh JS slider swap (the viewer fails to re-initialise).

zero_dim_da_to_val(da_ds: xarray.DataArray | xarray.Dataset) Any
ds_to_container(dataset: xarray.Dataset, result_var: param.Parameter, container, **kwargs) Any
static select_subsampling_divisions(dataset: xarray.Dataset, subsampling_divisions: int, include_types: list[type] | None = None, exclude_names: list[str] | None = None) xarray.Dataset

Given a dataset, return a reduced dataset that only contains data from a specified subsampling_divisions. By default all types of variables are filtered at the specified subsampling_divisions. If you only want to get a reduced subsampling_divisions for some types of data you can pass in a list of types to get filtered, You can also pass a list of variables names to exclude from getting filtered :param dataset: dataset to filter :type dataset: xr.Dataset :param subsampling_divisions: desired data resolution subsampling_divisions :type subsampling_divisions: int :param include_types: Only filter data of these types. Defaults to None. :type include_types: list[type], optional :param exclude_names: Only filter data with these variable names. Defaults to None. :type exclude_names: list[str], optional

Returns:

A reduced dataset at the specified subsampling_divisions

Return type:

xr.Dataset

Example: a dataset with float_var: [1,2,3,4,5] cat_var: [a,b,c,d,e]

select_subsampling_divisions(ds,2) -> [1,5] [a,e] select_subsampling_divisions(ds,2,(float)) -> [1,5] [a,b,c,d,e] select_subsampling_divisions(ds,2,exclude_names=[“cat_var]) -> [1,5] [a,b,c,d,e]

see test_bench_result_base.py -> test_select_subsampling_divisions()

static select_level(dataset: xarray.Dataset, level: int, include_types: list[type] | None = None, exclude_names: list[str] | None = None) xarray.Dataset

Deprecated: use select_subsampling_divisions() instead.

to_sweep_summary(**kwargs)
to_title(panel_name: str | None = None) panel.pane.Markdown
to_description(width: int = 800) panel.pane.Markdown
set_plot_size(**kwargs) dict