bencher.sweep_executor ====================== .. py:module:: bencher.sweep_executor .. autoapi-nested-parse:: Sweep execution for benchmarking. This module provides the SweepExecutor class for managing parameter sweep execution, job creation, and cache management in benchmark runs. Attributes ---------- .. autoapisummary:: bencher.sweep_executor._META_KEYS bencher.sweep_executor.logger Classes ------- .. autoapisummary:: bencher.sweep_executor.SweepExecutor Functions --------- .. autoapisummary:: bencher.sweep_executor._resolve_param bencher.sweep_executor.worker_kwargs_wrapper Module Contents --------------- .. py:function:: _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. .. py:data:: _META_KEYS .. py:data:: logger .. py:function:: 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. :param worker: The worker function to call :type worker: Callable :param bench_cfg: Benchmark configuration with parameters like pass_repeat :type bench_cfg: BenchCfg :param \*\*kwargs: The keyword arguments to filter and pass to the worker :returns: The result from the worker function :rtype: dict .. py:class:: 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. .. attribute:: cache_size Maximum size of the cache in bytes :type: int .. attribute:: sample_cache Cache for storing sample results :type: FutureCache .. py:attribute:: cache_size :value: 0 .. py:attribute:: sample_cache :type: bencher.job.FutureCache | None :value: None .. py:method:: 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. :param variable: 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 :type variable: param.Parameter | str | dict | tuple :param var_type: Type of variable ('input', 'result', or 'const') for error messages :type var_type: str :param run_cfg: Run configuration for level settings :type run_cfg: BenchRunCfg | None :param worker_class_instance: The worker class instance for looking up parameters by name :type worker_class_instance: ParametrizedSweep | None :param worker_input_cfg: The worker input configuration class :type worker_input_cfg: ParametrizedSweep | None :returns: The converted parameter object :rtype: param.Parameter :raises TypeError: If the variable cannot be converted to a param.Parameter .. py:method:: define_const_inputs(const_vars: list[tuple[param.Parameter, Any]]) -> dict | None Convert constant variable tuples into a dictionary of name-value pairs. :param const_vars: List of (parameter, value) tuples representing constant parameters and their values :type const_vars: list[tuple[param.Parameter, Any]] :returns: Dictionary mapping parameter names to their constant values, or None if const_vars is None :rtype: dict | None .. py:method:: 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. :param run_cfg: Configuration with cache settings such as overwrite policy, executor type, and whether to cache results :type run_cfg: BenchRunCfg :returns: A configured cache for storing benchmark results :rtype: FutureCache .. py:method:: 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. :param tag: The tag identifying samples to clear from the cache :type tag: str :param run_cfg: Run configuration used to initialize the sample cache if needed :type run_cfg: BenchRunCfg .. py:method:: clear_call_counts() -> None Clear the worker and cache call counts. This helps debug and assert caching is happening properly. .. py:method:: close_cache() -> None Close the sample cache if it exists. .. py:method:: get_cache_stats() -> str Get statistics about cache usage. :returns: A string with cache statistics :rtype: str