class_docstr: A sampler that uses BoTorch, a Bayesian optimization library built on top of PyTorch.
  
  This sampler allows using BoTorch's optimization algorithms from Optuna to suggest parameter
  configurations. Parameters are transformed to continuous space and passed to BoTorch, and then
  transformed back to Optuna's representations. Categorical parameters are one-hot encoded.
  
  .. seealso::
      See an `example <https://github.com/optuna/optuna-examples/blob/main/multi_objective/
      botorch_simple.py>`_ how to use the sampler.
  
  .. seealso::
      See the `BoTorch <https://botorch.org/>`_ homepage for details and for how to implement
      your own ``candidates_func``.
  
  .. note::
      An instance of this sampler *should not be used with different studies* when used with
      constraints. Instead, a new instance should be created for each new study. The reason for
      this is that the sampler is stateful keeping all the computed constraints.
  
  Args:
      candidates_func:
          An optional function that suggests the next candidates. It must take the training
          data, the objectives, the constraints, the search space bounds and return the next
          candidates. The arguments are of type ``torch.Tensor``. The return value must be a
          ``torch.Tensor``. However, if ``constraints_func`` is omitted, constraints will be
          :obj:`None`. For any constraints that failed to compute, the tensor will contain
          NaN.
  
          If omitted, it is determined automatically based on the number of objectives and
          whether a constraint is specified. If the
          number of objectives is one and no constraint is specified, log-Expected Improvement
          is used. If constraints are specified, quasi MC-based batch Expected Improvement
          (qEI) is used.
          If the number of objectives is either two or three, Quasi MC-based
          batch Expected Hypervolume Improvement (qEHVI) is used. Otherwise, for a larger number
          of objectives, analytic Expected Hypervolume Improvement is used if no constraints
          are specified, or the faster Quasi MC-based extended ParEGO (qParEGO) is used if
          constraints are present.
  
          The function should assume *maximization* of the objective.
  
          .. seealso::
              See :func:`optuna.integration.botorch.qei_candidates_func` for an example.
      constraints_func:
          An optional function that computes the objective constraints. It must take a
          :class:`~optuna.trial.FrozenTrial` and return the constraints. The return value must
          be a sequence of :obj:`float` s. A value strictly larger than 0 means that a
          constraint is violated. A value equal to or smaller than 0 is considered feasible.
  
          If omitted, no constraints will be passed to ``candidates_func`` nor taken into
          account during suggestion.
      n_startup_trials:
          Number of initial trials, that is the number of trials to resort to independent
          sampling.
      consider_running_trials:
          If True, the acquisition function takes into consideration the running parameters
          whose evaluation has not completed. Enabling this option is considered to improve the
          performance of parallel optimization.
  
          .. note::
              Added in v3.2.0 as an experimental argument.
      independent_sampler:
          An independent sampler to use for the initial trials and for parameters that are
          conditional.
      seed:
          Seed for random number generator.
      device:
          A ``torch.device`` to store input and output data of BoTorch. Please set a CUDA device
          if you fasten sampling.
class_docstr_tok: ["A","sampler","that","uses","BoTorch",",","a","Bayesian","optimization","library","built","on","top","of","PyTorch",".","This","sampler","allows","using","BoTorch","'s","optimization","algorithms","from","Optuna","to","suggest","parameter","configurations",".","Parameters","are","transformed","to","continuous","space","and","passed","to","BoTorch",",","and","then","transformed","back","to","Optuna","'s","representations",".","Categorical","parameters","are","one-hot","encoded",".","..","seealso",":",":","See","an","`","example","<","https",":","\/\/github.com\/optuna\/optuna-examples\/blob\/main\/multi_objective\/","botorch_simple.py",">","`","_","how","to","use","the","sampler",".","..","seealso",":",":","See","the","`","BoTorch","<","https",":","\/\/botorch.org\/",">","`","_","homepage","for","details","and","for","how","to","implement","your","own","``","candidates_func","``",".","..","note",":",":","An","instance","of","this","sampler","*","should","not","be","used","with","different","studies","*","when","used","with","constraints",".","Instead",",","a","new","instance","should","be","created","for","each","new","study",".","The","reason","for","this","is","that","the","sampler","is","stateful","keeping","all","the","computed","constraints",".","Args",":","candidates_func",":","An","optional","function","that","suggests","the","next","candidates",".","It","must","take","the","training","data",",","the","objectives",",","the","constraints",",","the","search","space","bounds","and","return","the","next","candidates",".","The","arguments","are","of","type","``","torch.Tensor","``",".","The","return","value","must","be","a","``","torch.Tensor","``",".","However",",","if","``","constraints_func","``","is","omitted",",","constraints","will","be",":","obj",":","`","None","`",".","For","any","constraints","that","failed","to","compute",",","the","tensor","will","contain","NaN",".","If","omitted",",","it","is","determined","automatically","based","on","the","number","of","objectives","and","whether","a","constraint","is","specified",".","If","the","number","of","objectives","is","one","and","no","constraint","is","specified",",","log-Expected","Improvement","is","used",".","If","constraints","are","specified",",","quasi","MC-based","batch","Expected","Improvement","(","qEI",")","is","used",".","If","the","number","of","objectives","is","either","two","or","three",",","Quasi","MC-based","batch","Expected","Hypervolume","Improvement","(","qEHVI",")","is","used",".","Otherwise",",","for","a","larger","number","of","objectives",",","analytic","Expected","Hypervolume","Improvement","is","used","if","no","constraints","are","specified",",","or","the","faster","Quasi","MC-based","extended","ParEGO","(","qParEGO",")","is","used","if","constraints","are","present",".","The","function","should","assume","*","maximization","*","of","the","objective",".","..","seealso",":",":","See",":","func",":","`","optuna.integration.botorch.qei_candidates_func","`","for","an","example",".","constraints_func",":","An","optional","function","that","computes","the","objective","constraints",".","It","must","take","a",":","class",":","`","~optuna.trial.FrozenTrial","`","and","return","the","constraints",".","The","return","value","must","be","a","sequence","of",":","obj",":","`","float","`","s.","A","value","strictly","larger","than","0","means","that","a","constraint","is","violated",".","A","value","equal","to","or","smaller","than","0","is","considered","feasible",".","If","omitted",",","no","constraints","will","be","passed","to","``","candidates_func","``","nor","taken","into","account","during","suggestion",".","n_startup_trials",":","Number","of","initial","trials",",","that","is","the","number","of","trials","to","resort","to","independent","sampling",".","consider_running_trials",":","If","True",",","the","acquisition","function","takes","into","consideration","the","running","parameters","whose","evaluation","has","not","completed",".","Enabling","this","option","is","considered","to","improve","the","performance","of","parallel","optimization",".","..","note",":",":","Added","in","v3.2.0","as","an","experimental","argument",".","independent_sampler",":","An","independent","sampler","to","use","for","the","initial","trials","and","for","parameters","that","are","conditional",".","seed",":","Seed","for","random","number","generator",".","device",":","A","``","torch.device","``","to","store","input","and","output","data","of","BoTorch",".","Please","set","a","CUDA","device","if","you","fasten","sampling","."]
code: def infer_relative_search_space(
      self,
      study: Study,
      trial: FrozenTrial,
  ) -> Dict[str, BaseDistribution]:
      if self._study_id is None:
          self._study_id = study._study_id
      if self._study_id != study._study_id:
          # Note that the check below is meaningless when `InMemoryStorage` is used
          # because `InMemoryStorage.create_new_study` always returns the same study ID.
          raise RuntimeError(
              "BoTorchSampler cannot handle multiple studies."
          )
  
      search_space: Dict[str, BaseDistribution] = {}
      for name, distribution in self._search_space.calculate(
          study
      ).items():
          if distribution.single():
              # built-in `candidates_func` cannot handle distributions that contain just a
              # single value, so we skip them. Note that the parameter values for such
              # distributions are sampled in `Trial`.
              continue
          search_space[name] = distribution
  
      return search_space
  
imports: from typing import Any
  from typing import Callable
  from typing import Dict
  from typing import Optional
  from typing import Sequence
  from typing import Union
  import warnings
  import numpy
  from packaging import version
  from optuna import logging
  from optuna._experimental import experimental_class
  from optuna._experimental import experimental_func
  from optuna._imports import try_import
  from optuna._transform import _SearchSpaceTransform
  from optuna.distributions import BaseDistribution
  from optuna.samplers import BaseSampler
  from optuna.samplers import RandomSampler
  from optuna.samplers._base import _CONSTRAINTS_KEY
  from optuna.samplers._base import _process_constraints_after_trial
  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 2 for calling the BoTorchSampler obj's underlying member method code with example usage: obj.infer_relative_search_space(study, trial) and returns: search_space