bencher.sweep_executor

Sweep execution for benchmarking.

This module provides the SweepExecutor class for managing parameter sweep execution, job creation, and cache management in benchmark runs.

Attributes

_META_KEYS

logger

Classes

SweepExecutor

Manages parameter sweep execution, job creation, and caching.

Functions

_resolve_param(→ param.Parameter)

Look up a param.Parameter by name on worker, raising a helpful KeyError if missing.

worker_kwargs_wrapper(→ dict)

Prepare keyword arguments and pass them to a worker function.

Module Contents

bencher.sweep_executor._resolve_param(name: str, worker: bencher.variables.parametrised_sweep.ParametrizedSweep, var_type: str) param.Parameter

Look up a param.Parameter by name on worker, raising a helpful KeyError if missing.

bencher.sweep_executor._META_KEYS
bencher.sweep_executor.logger
bencher.sweep_executor.worker_kwargs_wrapper(worker: Callable, bench_cfg: bencher.bench_cfg.BenchCfg, **kwargs) dict

Prepare keyword arguments and pass them to a worker function.

This wrapper filters out metadata parameters that should not be passed to the worker function (like ‘repeat’, ‘over_time’, and ‘time_event’), then deep-copies the filtered dict for mutation safety before calling the worker.

Parameters:
  • worker (Callable) – The worker function to call

  • bench_cfg (BenchCfg) – Benchmark configuration with parameters like pass_repeat

  • **kwargs – The keyword arguments to filter and pass to the worker

Returns:

The result from the worker function

Return type:

dict

class bencher.sweep_executor.SweepExecutor(cache_size: int = DEFAULT_CACHE_SIZE_BYTES)

Manages parameter sweep execution, job creation, and caching.

This class handles the conversion of variables to parameters, initialization of sample caches, and management of cache entries.

cache_size

Maximum size of the cache in bytes

Type:

int

sample_cache

Cache for storing sample results

Type:

FutureCache

cache_size = 0
sample_cache: bencher.job.FutureCache | None = None
convert_vars_to_params(variable: param.Parameter | str | dict | tuple, var_type: str, run_cfg: bencher.bench_cfg.BenchRunCfg | None, worker_class_instance: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None, worker_input_cfg: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None) param.Parameter

Convert various input formats to param.Parameter objects.

This method handles different ways of specifying variables in benchmark sweeps, including direct param.Parameter objects, string names of parameters, or dictionaries with parameter configuration details. It ensures all inputs are properly converted to param.Parameter objects with the correct configuration.

Parameters:
  • variable (param.Parameter | str | dict | tuple) – The variable to convert, can be: - param.Parameter: Already a parameter object - str: Name of a parameter in the worker_class_instance - dict: Configuration with ‘name’ and optional ‘values’, ‘samples’, ‘max_subsampling_divisions’ - tuple: Tuple that can be converted to a parameter

  • var_type (str) – Type of variable (‘input’, ‘result’, or ‘const’) for error messages

  • run_cfg (BenchRunCfg | None) – Run configuration for level settings

  • worker_class_instance (ParametrizedSweep | None) – The worker class instance for looking up parameters by name

  • worker_input_cfg (ParametrizedSweep | None) – The worker input configuration class

Returns:

The converted parameter object

Return type:

param.Parameter

Raises:

TypeError – If the variable cannot be converted to a param.Parameter

define_const_inputs(const_vars: list[tuple[param.Parameter, Any]]) dict | None

Convert constant variable tuples into a dictionary of name-value pairs.

Parameters:

const_vars (list[tuple[param.Parameter, Any]]) – List of (parameter, value) tuples representing constant parameters and their values

Returns:

Dictionary mapping parameter names to their constant values,

or None if const_vars is None

Return type:

dict | None

init_sample_cache(run_cfg: bencher.bench_cfg.BenchRunCfg) bencher.job.FutureCache

Initialize the sample cache for storing benchmark function results.

This method creates a FutureCache for storing and retrieving benchmark results based on the run configuration settings.

Parameters:

run_cfg (BenchRunCfg) – Configuration with cache settings such as overwrite policy, executor type, and whether to cache results

Returns:

A configured cache for storing benchmark results

Return type:

FutureCache

clear_tag_from_sample_cache(tag: str, run_cfg: bencher.bench_cfg.BenchRunCfg) None

Clear all samples from the cache that match a specific tag.

This method is useful when you want to rerun a benchmark with the same tag but want fresh results instead of using cached data.

Parameters:
  • tag (str) – The tag identifying samples to clear from the cache

  • run_cfg (BenchRunCfg) – Run configuration used to initialize the sample cache if needed

clear_call_counts() None

Clear the worker and cache call counts.

This helps debug and assert caching is happening properly.

close_cache() None

Close the sample cache if it exists.

get_cache_stats() str

Get statistics about cache usage.

Returns:

A string with cache statistics

Return type:

str