class_docstr: Lineages of trials for workers in PBT
  
  This class regroup all lineages of trials generated by PBT for a given experiment.
  
  Each lineage is a path from a leaf trial (highest fidelity level) up to the root
  (lowest fidelity level). Multiple lineages can fork from the same root, forming a tree.
  A Lineages object may reference multiple trees of lineages. Iterating a Lineages object will
  iterate on the roots of these trees.
docstr: Get best trials of each lineage
  
  Each lineage is a path from a leaf to the root. When there is a forking,
  the path followed is not from child (new trial) to parent (forked trial), but
  rather to base trial (trial dropped). This is to represent the path taken
  by the sequence of trial execution within a worker. This also avoids having
  duplicate elite trials on different lineages.
  
  Best trials may be looked for up to a ``max_depth``.
  
  Parameters
  ----------
  max_depth: int or ``orion.core.worker.trial.Trial``, optional
      The maximum depth to look for best trials. It can be an int to represent the depth
      directly, or a trial, from which the depth will be inferred. If a trial, this trial
      should be in the Lineages. Default: None, that is, no max depth.
docstr_tok: ["Get","best","trials","of","each","lineage","Each","lineage","is","a","path","from","a","leaf","to","the","root",".","When","there","is","a","forking",",","the","path","followed","is","not","from","child","(","new","trial",")","to","parent","(","forked","trial",")",",","but","rather","to","base","trial","(","trial","dropped",")",".","This","is","to","represent","the","path","taken","by","the","sequence","of","trial","execution","within","a","worker",".","This","also","avoids","having","duplicate","elite","trials","on","different","lineages",".","Best","trials","may","be","looked","for","up","to","a","``","max_depth","``",".","Parameters","--","--","--","--","--","max_depth",":","int","or","``","orion.core.worker.trial.Trial","``",",","optional","The","maximum","depth","to","look","for","best","trials",".","It","can","be","an","int","to","represent","the","depth","directly",",","or","a","trial",",","from","which","the","depth","will","be","inferred",".","If","a","trial",",","this","trial","should","be","in","the","Lineages",".","Default",":","None",",","that","is",",","no","max","depth","."]
code: def get_elites(self, max_depth: int | None = None) -> list[Trial]:
      """Get best trials of each lineage
  
      Each lineage is a path from a leaf to the root. When there is a forking,
      the path followed is not from child (new trial) to parent (forked trial), but
      rather to base trial (trial dropped). This is to represent the path taken
      by the sequence of trial execution within a worker. This also avoids having
      duplicate elite trials on different lineages.
  
      Best trials may be looked for up to a ``max_depth``.
  
      Parameters
      ----------
      max_depth: int or ``orion.core.worker.trial.Trial``, optional
          The maximum depth to look for best trials. It can be an int to represent the depth
          directly, or a trial, from which the depth will be inferred. If a trial, this trial
          should be in the Lineages. Default: None, that is, no max depth.
      """
      if max_depth and not isinstance(max_depth, int):
          max_depth = self.get_lineage(max_depth).node_depth
  
      def get_parent_at_depth(node, depth):
          while node.node_depth > depth:
              node = node.parent
  
          return node
  
      trials: list[Trial] = []
      for lineage in self._lineage_roots:
          nodes = lineage.leafs
  
          if max_depth is not None:
              trimmed_nodes = set()
              for node in nodes:
                  node = get_parent_at_depth(node, max_depth)
                  trimmed_nodes.add(node)
              nodes = list(trimmed_nodes)
  
          for node in nodes:
              if node.jumps and (
                  (max_depth is None) or (node.node_depth < max_depth)
              ):
                  continue
  
              best_trial = node.get_best_trial()
              if best_trial is not None:
                  trials.append(best_trial)
  
      return trials
  
imports: from __future__ import annotations
  import copy
  import logging
  import time
  from typing import Any, ClassVar, Iterable, Sequence
  import numpy
  from orion.algo.base import BaseAlgorithm
  from orion.algo.pbt.exploit import exploit_factory
  from orion.algo.pbt.explore import explore_factory
  from orion.algo.random import Random
  from orion.algo.space import Fidelity, Space
  from orion.core.utils.flatten import flatten
  from orion.core.utils.tree import TreeNode
  from orion.core.worker.transformer import TransformedDimension
  from orion.core.worker.trial import Trial
label_desc: Use image node_id 9 for calling the Lineages obj's underlying member method code with example usage: obj.get_elites(max_depth) and returns: trials, node