class_docstr: A Sampler using cma library as the backend.
  
  Example:
  
      Optimize a simple quadratic function by using :class:`~optuna.integration.PyCmaSampler`.
  
      .. testcode::
  
          import optuna
  
  
          def objective(trial):
              x = trial.suggest_float("x", -1, 1)
              y = trial.suggest_int("y", -1, 1)
              return x**2 + y
  
  
          sampler = optuna.integration.PyCmaSampler()
          study = optuna.create_study(sampler=sampler)
          study.optimize(objective, n_trials=20)
  
  Note that parallel execution of trials may affect the optimization performance of CMA-ES,
  especially if the number of trials running in parallel exceeds the population size.
  
  .. note::
      :class:`~optuna.integration.CmaEsSampler` is deprecated and renamed to
      :class:`~optuna.integration.PyCmaSampler` in v2.0.0. Please use
      :class:`~optuna.integration.PyCmaSampler` instead of
      :class:`~optuna.integration.CmaEsSampler`.
  
  Args:
  
      x0:
          A dictionary of an initial parameter values for CMA-ES. By default, the mean of ``low``
          and ``high`` for each distribution is used.
          Please refer to cma.CMAEvolutionStrategy_ for further details of ``x0``.
  
      sigma0:
          Initial standard deviation of CMA-ES. By default, ``sigma0`` is set to
          ``min_range / 6``, where ``min_range`` denotes the minimum range of the distributions
          in the search space. If distribution is categorical, ``min_range`` is
          ``len(choices) - 1``.
          Please refer to cma.CMAEvolutionStrategy_ for further details of ``sigma0``.
  
      cma_stds:
          A dictionary of multipliers of sigma0 for each parameters. The default value is 1.0.
          Please refer to cma.CMAEvolutionStrategy_ for further details of ``cma_stds``.
  
      seed:
          A random seed for CMA-ES.
  
      cma_opts:
          Options passed to the constructor of cma.CMAEvolutionStrategy_ class.
  
          Note that default option is cma_default_options_,
          but ``BoundaryHandler``, ``bounds``, ``CMA_stds`` and ``seed`` arguments in
          ``cma_opts`` will be ignored because it is added by
          :class:`~optuna.integration.PyCmaSampler` automatically.
  
      n_startup_trials:
          The independent sampling is used instead of the CMA-ES algorithm until the given number
          of trials finish in the same study.
  
      independent_sampler:
          A :class:`~optuna.samplers.BaseSampler` instance that is used for independent
          sampling. The parameters not contained in the relative search space are sampled
          by this sampler.
          The search space for :class:`~optuna.integration.PyCmaSampler` is determined by
          :func:`~optuna.search_space.intersection_search_space()`.
  
          If :obj:`None` is specified, :class:`~optuna.samplers.RandomSampler` is used
          as the default.
  
          .. seealso::
              :class:`optuna.samplers` module provides built-in independent samplers
              such as :class:`~optuna.samplers.RandomSampler` and
              :class:`~optuna.samplers.TPESampler`.
  
      warn_independent_sampling:
          If this is :obj:`True`, a warning message is emitted when
          the value of a parameter is sampled by using an independent sampler.
  
          Note that the parameters of the first trial in a study are always sampled
          via an independent sampler, so no warning messages are emitted in this case.
  
  .. _cma.CMAEvolutionStrategy: https://cma-es.github.io/apidocs-pycma/    cma.evolution_strategy.CMAEvolutionStrategy.html
  .. _cma_default_options: https://cma-es.github.io/apidocs-pycma/    cma.evolution_strategy.html#cma_default_options_
class_docstr_tok: ["A","Sampler","using","cma","library","as","the","backend",".","Example",":","Optimize","a","simple","quadratic","function","by","using",":","class",":","`","~optuna.integration.PyCmaSampler","`",".","..","testcode",":",":","import","optuna","def","objective","(","trial",")",":","x","=","trial.suggest_float","(","``","x","''",",","-1",",","1",")","y","=","trial.suggest_int","(","``","y","''",",","-1",",","1",")","return","x","*","*","2","+","y","sampler","=","optuna.integration.PyCmaSampler","(",")","study","=","optuna.create_study","(","sampler=sampler",")","study.optimize","(","objective",",","n_trials=20",")","Note","that","parallel","execution","of","trials","may","affect","the","optimization","performance","of","CMA-ES",",","especially","if","the","number","of","trials","running","in","parallel","exceeds","the","population","size",".","..","note",":",":",":","class",":","`","~optuna.integration.CmaEsSampler","`","is","deprecated","and","renamed","to",":","class",":","`","~optuna.integration.PyCmaSampler","`","in","v2.0.0",".","Please","use",":","class",":","`","~optuna.integration.PyCmaSampler","`","instead","of",":","class",":","`","~optuna.integration.CmaEsSampler","`",".","Args",":","x0",":","A","dictionary","of","an","initial","parameter","values","for","CMA-ES",".","By","default",",","the","mean","of","``","low","``","and","``","high","``","for","each","distribution","is","used",".","Please","refer","to","cma.CMAEvolutionStrategy_","for","further","details","of","``","x0","``",".","sigma0",":","Initial","standard","deviation","of","CMA-ES",".","By","default",",","``","sigma0","``","is","set","to","``","min_range","\/","6","``",",","where","``","min_range","``","denotes","the","minimum","range","of","the","distributions","in","the","search","space",".","If","distribution","is","categorical",",","``","min_range","``","is","``","len","(","choices",")","-","1","``",".","Please","refer","to","cma.CMAEvolutionStrategy_","for","further","details","of","``","sigma0","``",".","cma_stds",":","A","dictionary","of","multipliers","of","sigma0","for","each","parameters",".","The","default","value","is","1.0",".","Please","refer","to","cma.CMAEvolutionStrategy_","for","further","details","of","``","cma_stds","``",".","seed",":","A","random","seed","for","CMA-ES",".","cma_opts",":","Options","passed","to","the","constructor","of","cma.CMAEvolutionStrategy_","class",".","Note","that","default","option","is","cma_default_options_",",","but","``","BoundaryHandler","``",",","``","bounds","``",",","``","CMA_stds","``","and","``","seed","``","arguments","in","``","cma_opts","``","will","be","ignored","because","it","is","added","by",":","class",":","`","~optuna.integration.PyCmaSampler","`","automatically",".","n_startup_trials",":","The","independent","sampling","is","used","instead","of","the","CMA-ES","algorithm","until","the","given","number","of","trials","finish","in","the","same","study",".","independent_sampler",":","A",":","class",":","`","~optuna.samplers.BaseSampler","`","instance","that","is","used","for","independent","sampling",".","The","parameters","not","contained","in","the","relative","search","space","are","sampled","by","this","sampler",".","The","search","space","for",":","class",":","`","~optuna.integration.PyCmaSampler","`","is","determined","by",":","func",":","`","~optuna.search_space.intersection_search_space","(",")","`",".","If",":","obj",":","`","None","`","is","specified",",",":","class",":","`","~optuna.samplers.RandomSampler","`","is","used","as","the","default",".","..","seealso",":",":",":","class",":","`","optuna.samplers","`","module","provides","built-in","independent","samplers","such","as",":","class",":","`","~optuna.samplers.RandomSampler","`","and",":","class",":","`","~optuna.samplers.TPESampler","`",".","warn_independent_sampling",":","If","this","is",":","obj",":","`","True","`",",","a","warning","message","is","emitted","when","the","value","of","a","parameter","is","sampled","by","using","an","independent","sampler",".","Note","that","the","parameters","of","the","first","trial","in","a","study","are","always","sampled","via","an","independent","sampler",",","so","no","warning","messages","are","emitted","in","this","case",".","..","_cma.CMAEvolutionStrategy",":","https",":","\/\/cma-es.github.io\/apidocs-pycma\/","cma.evolution_strategy.CMAEvolutionStrategy.html","..","_cma_default_options",":","https",":","\/\/cma-es.github.io\/apidocs-pycma\/","cma.evolution_strategy.html","#","cma_default_options_"]
code: def sample_relative(
      self,
      study: Study,
      trial: FrozenTrial,
      search_space: Dict[str, BaseDistribution],
  ) -> Dict[str, float]:
      self._raise_error_if_multi_objective(study)
  
      if len(search_space) == 0:
          return {}
  
      if len(search_space) == 1:
          _logger.info(
              "`PyCmaSampler` does not support optimization of 1-D search space. "
              "`{}` is used instead of `PyCmaSampler`.".format(
                  self._independent_sampler.__class__.__name__
              )
          )
          self._warn_independent_sampling = False
          return {}
  
      complete_trials = study._get_trials(
          deepcopy=False, states=(TrialState.COMPLETE,), use_cache=True
      )
      if len(complete_trials) < self._n_startup_trials:
          return {}
  
      if self._x0 is None:
          self._x0 = self._initialize_x0(search_space)
  
      if self._sigma0 is None:
          sigma0 = self._initialize_sigma0(search_space)
      else:
          sigma0 = self._sigma0
      # Avoid ZeroDivisionError in cma.CMAEvolutionStrategy.
      sigma0 = max(sigma0, _EPS)
  
      optimizer = _Optimizer(
          search_space, self._x0, sigma0, self._cma_stds, self._cma_opts
      )
      trials = study.trials
      last_told_trial_number = optimizer.tell(trials, study.direction)
      return optimizer.ask(trials, last_told_trial_number)
  
imports: import math
  import random
  from typing import Any
  from typing import Container
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Sequence
  import numpy
  import optuna
  from optuna import distributions
  from optuna import logging
  from optuna._deprecated import deprecated_class
  from optuna._imports import try_import
  from optuna.distributions import BaseDistribution
  from optuna.distributions import CategoricalDistribution
  from optuna.distributions import FloatDistribution
  from optuna.distributions import IntDistribution
  from optuna.samplers import BaseSampler
  from optuna.search_space import IntersectionSearchSpace
  from optuna.study import Study
  from optuna.study import StudyDirection
  from optuna.trial import FrozenTrial
  from optuna.trial import TrialState
label_desc: Use image node_id 5 for calling the PyCmaSampler obj's underlying member method code with example usage: obj.sample_relative(study, trial, search_space) and returns: optimizer, dict, dict, dict