class_docstr: Wrapper that makes the algo "multi-task" by adding a task id to the inputs.
class_docstr_tok: ["Wrapper","that","makes","the","algo","``","multi-task","''","by","adding","a","task","id","to","the","inputs","."]
docstr: Transform an (outer) space, returning the (inner) space of the wrapped algorithm.
  
  This returns what will become `self.algorithm.space` in an instance of this class.
docstr_tok: ["Transform","an","(","outer",")","space",",","returning","the","(","inner",")","space","of","the","wrapped","algorithm",".","This","returns","what","will","become","`","self.algorithm.space","`","in","an","instance","of","this","class","."]
code: def transform_space(
      cls, space: Space, knowledge_base: KnowledgeBase
  ) -> Space:
      """Transform an (outer) space, returning the (inner) space of the wrapped algorithm.
  
      This returns what will become `self.algorithm.space` in an instance of this class.
      """
      if "task_id" in space:
          raise RuntimeError(
              f"Space already has a task_id dimension: {space}"
          )
      # NOTE: The task dimension here has the size of the total number of experiments in the KB,
      # not the number of compatible experiments.
      # This is because we don't yet know how many of them are directly compatible.
      # Note: The +1 here represents the current experiment.
      max_task_id = 1 + knowledge_base.n_stored_experiments
      # NOTE: We set a non-zero probability only on the task_id==target dimension, since:
      # 1. It also doesn't really make sense for the algo to try to optimize the other tasks, and
      # 2. this makes the algorithm only suggest trials with task_id==target, to reduce the risk
      #    of collisions if it were to suggest the same trials with different task ids.
      task_label_dimension = Categorical(
          "task_id",
          {
              task_id: (1 if task_id == TARGET_TASK_ID else 0)
              for task_id in range(0, max_task_id)
          },
          default_value=TARGET_TASK_ID,
      )
      new_space = copy.deepcopy(space)
      new_space.register(task_label_dimension)
      return new_space
  
imports: from __future__ import annotations
  import copy
  from collections import defaultdict
  from contextlib import contextmanager
  from logging import getLogger
  from orion.algo.space import Categorical, Space
  from orion.core.utils.format_trials import dict_to_trial
  from orion.core.worker.algo_wrappers.algo_wrapper import AlgoT
  from orion.core.worker.algo_wrappers.transform_wrapper import TransformWrapper, _copy_status_and_results
  from orion.core.worker.experiment_config import ExperimentConfig
  from orion.core.worker.trial import Trial
  from orion.core.worker.warm_start.knowledge_base import KnowledgeBase
  from orion.core.worker.warm_start.warm_starteable import WarmStarteable
label_desc: Use image node_id 4 for calling the MultiTaskWrapper obj's underlying member method code with example usage: obj.transform_space(cls, space, knowledge_base) and returns: new_space