bencher.worker_manager

Worker management for benchmarking.

This module provides the WorkerManager class for handling worker function configuration and validation in benchmark runs.

Attributes

logger

Classes

WorkerManager

Manages worker function configuration and validation for benchmarks.

Functions

kwargs_to_input_cfg(...)

Create a configured instance of a ParametrizedSweep with the provided keyword arguments.

worker_cfg_wrapper(→ dict)

Wrap a worker function to accept keyword arguments instead of a config object.

Module Contents

bencher.worker_manager.logger
bencher.worker_manager.kwargs_to_input_cfg(worker_input_cfg: bencher.variables.parametrised_sweep.ParametrizedSweep, **kwargs) bencher.variables.parametrised_sweep.ParametrizedSweep

Create a configured instance of a ParametrizedSweep with the provided keyword arguments.

Parameters:
  • worker_input_cfg (ParametrizedSweep) – The ParametrizedSweep class to instantiate

  • **kwargs – Keyword arguments to update the configuration with

Returns:

A configured instance of the worker_input_cfg class

Return type:

ParametrizedSweep

bencher.worker_manager.worker_cfg_wrapper(worker: Callable, worker_input_cfg: bencher.variables.parametrised_sweep.ParametrizedSweep, **kwargs) dict

Wrap a worker function to accept keyword arguments instead of a config object.

This wrapper creates an instance of the worker_input_cfg class, updates it with the provided keyword arguments, and passes it to the worker function.

Parameters:
  • worker (Callable) – The worker function that expects a config object

  • worker_input_cfg (ParametrizedSweep) – The class defining the configuration

  • **kwargs – Keyword arguments to update the configuration with

Returns:

The result of calling the worker function with the configured input

Return type:

dict

class bencher.worker_manager.WorkerManager

Manages worker function configuration and validation for benchmarks.

This class handles the setup and management of worker functions used in benchmarking, including support for both callable functions and ParametrizedSweep instances.

worker

The configured worker function

Type:

Callable

worker_class_instance

The worker class instance if provided

Type:

ParametrizedSweep

worker_input_cfg

The input configuration class

Type:

ParametrizedSweep

worker: Callable | None = None
worker_class_instance: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None
worker_input_cfg: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None
set_worker(worker: Callable | bencher.variables.parametrised_sweep.ParametrizedSweep, worker_input_cfg: bencher.variables.parametrised_sweep.ParametrizedSweep | None = None) None

Set the benchmark worker function and its input configuration.

This method sets up the worker function to be benchmarked. The worker can be either a callable function that takes a ParametrizedSweep instance or a ParametrizedSweep instance with a __call__ method. In the latter case, worker_input_cfg is not needed.

Parameters:
  • worker (Callable | ParametrizedSweep) – Either a function that will be benchmarked or a ParametrizedSweep instance with a __call__ method. When a ParametrizedSweep is provided, its __call__ method becomes the worker function.

  • worker_input_cfg (ParametrizedSweep, optional) – The class defining the input parameters for the worker function. Only needed if worker is a function rather than a ParametrizedSweep instance. Defaults to None.

Raises:

RuntimeError – If worker is a class type instead of an instance.

get_result_vars(as_str: bool = True) list[str | bencher.variables.parametrised_sweep.ParametrizedSweep]

Retrieve the result variables from the worker class instance.

Parameters:

as_str (bool) – If True, the result variables are returned as strings. If False, they are returned in their original form. Default is True.

Returns:

A list of result variables, either as strings

or in their original form.

Return type:

list[str | ParametrizedSweep]

Raises:

RuntimeError – If the worker class instance is not set.

get_inputs_only() list[bencher.variables.parametrised_sweep.ParametrizedSweep]

Retrieve the input variables from the worker class instance.

Returns:

A list of input variables.

Return type:

list[ParametrizedSweep]

Raises:

RuntimeError – If the worker class instance is not set.

get_input_defaults() list

Retrieve the default input values from the worker class instance.

Returns:

A list of default input values as (parameter, value) tuples.

Return type:

list

Raises:

RuntimeError – If the worker class instance is not set.