class_docstr: Population Based Bandits
  
  Warning: PB2 is broken in current version v0.2.4. We are working on a fix to be released in
  v0.2.5, ETA July 2022.
  
  Population Based Bandits is a variant of Population Based Training using probabilistic model
  to guide the search instead of relying on purely random perturbations.
  PB2 implementation uses a time-varying Gaussian process to model the optimization curves
  during training. This implementation is based on ray-tune implementation. Oríon's version
  supports discrete and categorical dimensions, and offers better resiliency to broken
  trials by using back-tracking.
  
  See PBT documentation for more information on how to use PBT algorithms.
  
  For more information on the algorithm,
  see original paper at https://arxiv.org/abs/2002.02518.
  
  Parker-Holder, Jack, Vu Nguyen, and Stephen J. Roberts.
  "Provably efficient online hyperparameter optimization with population-based bandits."
  Advances in Neural Information Processing Systems 33 (2020): 17200-17211.
  
  Parameters
  ----------
  space: `orion.algo.space.Space`
      Optimisation space with priors for each dimension.
  seed: None, int or sequence of int
      Seed for the random number generator used to sample new trials.
      Default: ``None``
  population_size: int, optional
      Size of the population. No trial will be continued until there are `population_size`
      trials executed until lowest fidelity. If a trial is broken during execution at lowest
      fidelity, the algorithm will sample a new trial, keeping the population of *non-broken*
      trials at `population_size`.  For efficiency it is better to have less workers running than
      population_size. Default: 50.
  generations: int, optional
      Number of generations, from lowest fidelity to highest one. This will determine how
      many branchings occur during the execution of PBT. Default: 10
  exploit: dict or None, optional
      Configuration for a ``pbt.exploit.BaseExploit`` object that determines
      when if a trial should be exploited or not. If None, default configuration
      is a ``PipelineExploit`` with ``BacktrackExploit`` and ``TruncateExploit``.
  fork_timeout: int, optional
      Maximum amount of time in seconds that an attempt to mutate a trial should take, otherwise
      algorithm.suggest() will raise ``SuggestionTimeout``. Default: 60
class_docstr_tok: ["Population","Based","Bandits","Warning",":","PB2","is","broken","in","current","version","v0.2.4",".","We","are","working","on","a","fix","to","be","released","in","v0.2.5",",","ETA","July","2022",".","Population","Based","Bandits","is","a","variant","of","Population","Based","Training","using","probabilistic","model","to","guide","the","search","instead","of","relying","on","purely","random","perturbations",".","PB2","implementation","uses","a","time-varying","Gaussian","process","to","model","the","optimization","curves","during","training",".","This","implementation","is","based","on","ray-tune","implementation",".","Or\u00edon","'s","version","supports","discrete","and","categorical","dimensions",",","and","offers","better","resiliency","to","broken","trials","by","using","back-tracking",".","See","PBT","documentation","for","more","information","on","how","to","use","PBT","algorithms",".","For","more","information","on","the","algorithm",",","see","original","paper","at","https",":","\/\/arxiv.org\/abs\/2002.02518",".","Parker-Holder",",","Jack",",","Vu","Nguyen",",","and","Stephen","J.","Roberts",".","``","Provably","efficient","online","hyperparameter","optimization","with","population-based","bandits",".","''","Advances","in","Neural","Information","Processing","Systems","33","(","2020",")",":","17200-17211",".","Parameters","--","--","--","--","--","space",":","`","orion.algo.space.Space","`","Optimisation","space","with","priors","for","each","dimension",".","seed",":","None",",","int","or","sequence","of","int","Seed","for","the","random","number","generator","used","to","sample","new","trials",".","Default",":","``","None","``","population_size",":","int",",","optional","Size","of","the","population",".","No","trial","will","be","continued","until","there","are","`","population_size","`","trials","executed","until","lowest","fidelity",".","If","a","trial","is","broken","during","execution","at","lowest","fidelity",",","the","algorithm","will","sample","a","new","trial",",","keeping","the","population","of","*","non-broken","*","trials","at","`","population_size","`",".","For","efficiency","it","is","better","to","have","less","workers","running","than","population_size",".","Default",":","50.","generations",":","int",",","optional","Number","of","generations",",","from","lowest","fidelity","to","highest","one",".","This","will","determine","how","many","branchings","occur","during","the","execution","of","PBT",".","Default",":","10","exploit",":","dict","or","None",",","optional","Configuration","for","a","``","pbt.exploit.BaseExploit","``","object","that","determines","when","if","a","trial","should","be","exploited","or","not",".","If","None",",","default","configuration","is","a","``","PipelineExploit","``","with","``","BacktrackExploit","``","and","``","TruncateExploit","``",".","fork_timeout",":","int",",","optional","Maximum","amount","of","time","in","seconds","that","an","attempt","to","mutate","a","trial","should","take",",","otherwise","algorithm.suggest","(",")","will","raise","``","SuggestionTimeout","``",".","Default",":","60"]
docstr: Try to promote or fork a given trial.
docstr_tok: ["Try","to","promote","or","fork","a","given","trial","."]
code: def _generate_offspring(self, trial):
      """Try to promote or fork a given trial."""
  
      new_trial = trial
  
      if not self.has_suggested(new_trial):
          raise RuntimeError(
              "Trying to fork a trial that was not registered yet. This should never happen"
          )
  
      attempts = 0
      start = time.perf_counter()
      while (
          self.has_suggested(new_trial)
          and time.perf_counter() - start <= self.fork_timeout
      ):
          trial_to_explore = self.exploit_func(
              self.rng,
              trial,
              self.lineages,
          )
  
          if trial_to_explore is None:
              return None, None
          elif trial_to_explore is trial:
              new_params = {}
              trial_to_branch = trial
              logger.debug(
                  "Promoting trial %s, parameters stay the same.", trial
              )
          else:
              new_params = flatten(
                  self._explore(self.space, trial_to_explore)
              )
              trial_to_branch = trial_to_explore
              logger.debug(
                  "Forking trial %s with new parameters %s",
                  trial_to_branch,
                  new_params,
              )
  
          # Set next level of fidelity
          new_params[self.fidelity_index] = self.fidelity_upgrades[
              flatten(trial_to_branch.params)[self.fidelity_index]
          ]
  
          new_trial = trial_to_branch.branch(params=new_params)
          assert isinstance(
              self.space, (TransformedSpace, ReshapedSpace)
          )
          new_trial = self.space.transform(
              self.space.reverse(new_trial)
          )
  
          logger.debug(
              "Attempt %s - Creating new trial %s", attempts, new_trial
          )
  
          attempts += 1
  
      if (
          self.has_suggested(new_trial)
          and time.perf_counter() - start > self.fork_timeout
      ):
          trial_to_branch = None
          new_trial = None
          logger.info(
              f"Could not generate unique new parameters for trial {trial.id} in "
              f"less than {self.fork_timeout} seconds. Attempted {attempts} times."
          )
  
      return trial_to_branch, new_trial
  
imports: from __future__ import annotations
  import copy
  import logging
  import time
  from typing import Any, ClassVar, Sequence
  import numpy
  import pandas
  from orion.algo.pbt.pb2_utils import import_optional, select_config
  from orion.algo.pbt.pbt import PBT
  from orion.core.utils.flatten import flatten
  from orion.core.utils.random_state import RandomState, control_randomness
  from orion.core.worker.transformer import ReshapedSpace, TransformedSpace
  from orion.core.worker.trial import Trial
label_desc: Use image node_id 6 for calling the PB2 obj's underlying member method code with example usage: obj._generate_offspring(trial) and returns: trial_to_branch,  new_trial, None,  None