bencher.worker_manager ====================== .. py:module:: bencher.worker_manager .. autoapi-nested-parse:: Worker management for benchmarking. This module provides the WorkerManager class for handling worker function configuration and validation in benchmark runs. Attributes ---------- .. autoapisummary:: bencher.worker_manager.logger Classes ------- .. autoapisummary:: bencher.worker_manager.WorkerManager Functions --------- .. autoapisummary:: bencher.worker_manager.kwargs_to_input_cfg bencher.worker_manager.worker_cfg_wrapper Module Contents --------------- .. py:data:: logger .. py:function:: 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. :param worker_input_cfg: The ParametrizedSweep class to instantiate :type worker_input_cfg: ParametrizedSweep :param \*\*kwargs: Keyword arguments to update the configuration with :returns: A configured instance of the worker_input_cfg class :rtype: ParametrizedSweep .. py:function:: 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. :param worker: The worker function that expects a config object :type worker: Callable :param worker_input_cfg: The class defining the configuration :type worker_input_cfg: ParametrizedSweep :param \*\*kwargs: Keyword arguments to update the configuration with :returns: The result of calling the worker function with the configured input :rtype: dict .. py:class:: 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. .. attribute:: worker The configured worker function :type: Callable .. attribute:: worker_class_instance The worker class instance if provided :type: ParametrizedSweep .. attribute:: worker_input_cfg The input configuration class :type: ParametrizedSweep .. py:attribute:: worker :type: Callable | None :value: None .. py:attribute:: worker_class_instance :type: bencher.variables.parametrised_sweep.ParametrizedSweep | None :value: None .. py:attribute:: worker_input_cfg :type: bencher.variables.parametrised_sweep.ParametrizedSweep | None :value: None .. py:method:: 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. :param worker: 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. :type worker: Callable | ParametrizedSweep :param worker_input_cfg: 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. :type worker_input_cfg: ParametrizedSweep, optional :raises RuntimeError: If worker is a class type instead of an instance. .. py:method:: get_result_vars(as_str: bool = True) -> list[str | bencher.variables.parametrised_sweep.ParametrizedSweep] Retrieve the result variables from the worker class instance. :param as_str: If True, the result variables are returned as strings. If False, they are returned in their original form. Default is True. :type as_str: bool :returns: A list of result variables, either as strings or in their original form. :rtype: list[str | ParametrizedSweep] :raises RuntimeError: If the worker class instance is not set. .. py:method:: get_inputs_only() -> list[bencher.variables.parametrised_sweep.ParametrizedSweep] Retrieve the input variables from the worker class instance. :returns: A list of input variables. :rtype: list[ParametrizedSweep] :raises RuntimeError: If the worker class instance is not set. .. py:method:: 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. :rtype: list :raises RuntimeError: If the worker class instance is not set.