class_docstr: Combination of a Storage containing previous experiments and an optional similarity metric.
  
  The Knowledge base is used to fetch previous experiments and their trials, which are then used
  to initialize (a.k.a. "warm-start" the hyper-parameter optimization algorithm.
  
  By default, the HPO algorithms of Orion are unable to reuse trials if they are not compatible
  with the space of the current (a.k.a. "target") experiment. Therefore, when warm-starting, a
  `MultiTaskWrapper` is added, which enables a limited form of warm-starting for all algorithms,
  by only considering the trials which are compatible with the target experiment, and training
  the algorithm in a multi-task fashion.
  
  When passed, the similarity function will be used to order the experiments such that the most
  related experiments are given first.
class_docstr_tok: ["Combination","of","a","Storage","containing","previous","experiments","and","an","optional","similarity","metric",".","The","Knowledge","base","is","used","to","fetch","previous","experiments","and","their","trials",",","which","are","then","used","to","initialize","(","a.k.a",".","``","warm-start","''","the","hyper-parameter","optimization","algorithm",".","By","default",",","the","HPO","algorithms","of","Orion","are","unable","to","reuse","trials","if","they","are","not","compatible","with","the","space","of","the","current","(","a.k.a",".","``","target","''",")","experiment",".","Therefore",",","when","warm-starting",",","a","`","MultiTaskWrapper","`","is","added",",","which","enables","a","limited","form","of","warm-starting","for","all","algorithms",",","by","only","considering","the","trials","which","are","compatible","with","the","target","experiment",",","and","training","the","algorithm","in","a","multi-task","fashion",".","When","passed",",","the","similarity","function","will","be","used","to","order","the","experiments","such","that","the","most","related","experiments","are","given","first","."]
docstr: Retrieve the trials from experiments 'similar' to `target_experiment`.
  
  When `max_trials` is given, only up to `max_trials` are returned in total.
  
  Parameters
  ----------
  target_experiment : Union[Experiment, ExperimentClient, ExperimentConfig]
      The target experiment, or experiment client, or experiment configuration.
  max_trials : int, optional
      Maximum total number of trials to fetch. By default `None`, in which case
      all trials are returned.
  
  Returns
  -------
  list[tuple[ExperimentConfig, list[Trial]]]
      A list of tuples of experiments and the similar trials from that experiment.
docstr_tok: ["Retrieve","the","trials","from","experiments","'similar","'","to","`","target_experiment","`",".","When","`","max_trials","`","is","given",",","only","up","to","`","max_trials","`","are","returned","in","total",".","Parameters","--","--","--","--","--","target_experiment",":","Union","[","Experiment",",","ExperimentClient",",","ExperimentConfig","]","The","target","experiment",",","or","experiment","client",",","or","experiment","configuration",".","max_trials",":","int",",","optional","Maximum","total","number","of","trials","to","fetch",".","By","default","`","None","`",",","in","which","case","all","trials","are","returned",".","Returns","--","--","--","-","list","[","tuple","[","ExperimentConfig",",","list","[","Trial","]","]","]","A","list","of","tuples","of","experiments","and","the","similar","trials","from","that","experiment","."]
code: def get_related_trials(
      self,
      target_experiment: Experiment
      | ExperimentClient
      | ExperimentConfig,
      max_trials: int | None = None,
  ) -> list[tuple[ExperimentConfig, list[Trial]]]:
      """Retrieve the trials from experiments 'similar' to `target_experiment`.
  
      When `max_trials` is given, only up to `max_trials` are returned in total.
  
      Parameters
      ----------
      target_experiment : Union[Experiment, ExperimentClient, ExperimentConfig]
          The target experiment, or experiment client, or experiment configuration.
      max_trials : int, optional
          Maximum total number of trials to fetch. By default `None`, in which case
          all trials are returned.
  
      Returns
      -------
      list[tuple[ExperimentConfig, list[Trial]]]
          A list of tuples of experiments and the similar trials from that experiment.
      """
      target_config: ExperimentConfig
      if isinstance(target_experiment, dict):
          target_config = target_experiment
      else:
          target_config = target_experiment.configuration
  
      experiment_configs = self.storage.fetch_experiments({})
      # NOTE: Here we remove the target experiment from the list of experiments.
      # This occurs because we use a singleton for the storage, so creating the target experiment
      # implicitly adds it to the storage (and to the knowledge base).
      experiment_configs = _remove_target_config(
          target_config, experiment_configs
      )
  
      if self.similarity_metric:
          # Order the experiments with decreasing similarity w.r.t the target experiment.
          sort_fn = partial(self.similarity_metric, target_config)
          experiment_configs = sorted(
              experiment_configs, key=sort_fn, reverse=True
          )
  
      return self._get_trials(experiment_configs, max_trials=max_trials)
  
file_path: orion/src/orion/core/worker/warm_start/knowledge_base.py
imports: from __future__ import annotations
  import inspect
  import typing
  from functools import partial
  from logging import getLogger
  from typing import Any, Callable, Iterable
label_desc: Use image node_id 2 for calling the KnowledgeBase obj's underlying member method code with example usage: obj.get_related_trials(target_experiment, max_trials) and returns: self