code: def use_named_args(dimensions):
      """
      Wrapper / decorator for an objective function that uses named arguments
      to make it compatible with optimizers that use a single list of parameters.
  
      Your objective function can be defined as being callable using named
      arguments: `func(foo=123, bar=3.0, baz='hello')` for a search-space
      with dimensions named `['foo', 'bar', 'baz']`. But the optimizer
      will only pass a single list `x` of unnamed arguments when calling
      the objective function: `func(x=[123, 3.0, 'hello'])`. This wrapper
      converts your objective function with named arguments into one that
      accepts a list as argument, while doing the conversion automatically.
  
      The advantage of this is that you don't have to unpack the list of
      arguments `x` yourself, which makes the code easier to read and
      also reduces the risk of bugs if you change the number of dimensions
      or their order in the search-space.
  
      Examples
      --------
      >>> # Define the search-space dimensions. They must all have names!
      >>> from guild._skopt.space import Real
      >>> from guild._skopt import forest_minimize
      >>> from guild._skopt.utils import use_named_args
      >>> dim1 = Real(name='foo', low=0.0, high=1.0)
      >>> dim2 = Real(name='bar', low=0.0, high=1.0)
      >>> dim3 = Real(name='baz', low=0.0, high=1.0)
      >>>
      >>> # Gather the search-space dimensions in a list.
      >>> dimensions = [dim1, dim2, dim3]
      >>>
      >>> # Define the objective function with named arguments
      >>> # and use this function-decorator to specify the
      >>> # search-space dimensions.
      >>> @use_named_args(dimensions=dimensions)
      ... def my_objective_function(foo, bar, baz):
      ...     return foo ** 2 + bar ** 4 + baz ** 8
      >>>
      >>> # Not the function is callable from the outside as
      >>> # `my_objective_function(x)` where `x` is a list of unnamed arguments,
      >>> # which then wraps your objective function that is callable as
      >>> # `my_objective_function(foo, bar, baz)`.
      >>> # The conversion from a list `x` to named parameters `foo`,
      >>> # `bar`, `baz`
      >>> # is done automatically.
      >>>
      >>> # Run the optimizer on the wrapped objective function which is called
      >>> # as `my_objective_function(x)` as expected by `forest_minimize()`.
      >>> result = forest_minimize(func=my_objective_function,
      ...                          dimensions=dimensions,
      ...                          n_calls=20, base_estimator="ET",
      ...                          random_state=4)
      >>>
      >>> # Print the best-found results in same format as the expected result.
      >>> print("Best fitness: " + str(result.fun))
      Best fitness: 0.1948080835239698
      >>> print("Best parameters: {}".format(result.x))
      Best parameters: [0.44134853091052617, 0.06570954323368307, 0.17586123323419825]
  
      Parameters
      ----------
      dimensions : list(Dimension)
          List of `Dimension`-objects for the search-space dimensions.
  
      Returns
      -------
      wrapped_func : callable
          Wrapped objective function.
      """
  
      def decorator(func):
          """
          This uses more advanced Python features to wrap `func` using a
          function-decorator, which are not explained so well in the
          official Python documentation.
  
          A good video tutorial explaining how this works is found here:
          https://www.youtube.com/watch?v=KlBPCzcQNU8
  
          Parameters
          ----------
          func : callable
              Function to minimize. Should take *named arguments*
              and return the objective value.
          """
  
          # Ensure all dimensions are correctly typed.
          check_list_types(dimensions, Dimension)
  
          # Ensure all dimensions have names.
          check_dimension_names(dimensions)
  
          @wraps(func)
          def wrapper(x):
              """
              This is the code that will be executed every time the
              wrapped / decorated `func` is being called.
              It takes `x` as a single list of parameters and
              converts them to named arguments and calls `func` with them.
  
              Parameters
              ----------
              x : list
                  A single list of parameters e.g. `[123, 3.0, 'linear']`
                  which will be converted to named arguments and passed
                  to `func`.
  
              Returns
              -------
              objective_value
                  The objective value returned by `func`.
              """
  
              # Ensure the number of dimensions match
              # the number of parameters in the list x.
              if len(x) != len(dimensions):
                  msg = (
                      "Mismatch in number of search-space dimensions. "
                      "len(dimensions)=={} and len(x)=={}"
                  )
                  msg = msg.format(len(dimensions), len(x))
                  raise ValueError(msg)
  
              # Create a dict where the keys are the names of the dimensions
              # and the values are taken from the list of parameters x.
              arg_dict = {
                  dim.name: value for dim, value in zip(dimensions, x)
              }
  
              # Call the wrapped objective function with the named arguments.
              objective_value = func(**arg_dict)
  
              return objective_value
  
          return wrapper
  
      return decorator
  
imports: from copy import deepcopy
  from functools import wraps
  from sklearn.utils import check_random_state
  import numpy
  from scipy.optimize import OptimizeResult
  from scipy.optimize import minimize
  from sklearn.base import is_regressor
  from sklearn.ensemble import GradientBoostingRegressor
  from joblib import dump
  from joblib import load
  from collections import OrderedDict
  from .learning import ExtraTreesRegressor
  from .learning import GaussianProcessRegressor
  from .learning import GradientBoostingQuantileRegressor
  from .learning import RandomForestRegressor
  from .learning.gaussian_process.kernels import ConstantKernel
  from .learning.gaussian_process.kernels import HammingKernel
  from .learning.gaussian_process.kernels import Matern
  from .sampler import Sobol, Lhs, Hammersly, Halton, Grid
  from .sampler import InitialPointGenerator
  from .space import Space, Categorical, Integer, Real, Dimension
label_desc: Use image node_id 19 for calling a global function with example usage: use_named_args(dimensions) and returns: decorator, wrapper, objective_value