class_docstr: Supports the creation of instances from configuration, that can be plugged into the environments
  (like demand generators or reward schemes).
  
  :param base_type: A common interface (parent class) of the registered types (e.g. DemandGenerator)
class_docstr_tok: ["Supports","the","creation","of","instances","from","configuration",",","that","can","be","plugged","into","the","environments","(","like","demand","generators","or","reward","schemes",")",".",":","param","base_type",":","A","common","interface","(","parent","class",")","of","the","registered","types","(","e.g",".","DemandGenerator",")"]
docstr: Instantiate an object from configuration.
  
  This is implemented as a thin layer on top of Hydra's instantiate() function, with the following additions
  
  * Provides type hinting
  * Asserts the returned type matches the `base_type`
  * Throws an error if there the field '_target_' is missing (Hydra's instantiate() returns the config object
    in this case)
  * In case `config` is already an instantiated object, immediately return this existing instance (useful in
    the frequent case of a constructor that accepts either a config object or an already instantiated
    object)
  
  :param config: The configuration as dictionary
  :param kwargs: Additional arguments that are merged with the configuration dictionary (useful to sideload
                 objects that can not conveniently be specified in the config, e.g. a shared RandomState)
  
  :return The instantiated object, of type `base_type`
docstr_tok: ["Instantiate","an","object","from","configuration",".","This","is","implemented","as","a","thin","layer","on","top","of","Hydra","'s","instantiate","(",")","function",",","with","the","following","additions","*","Provides","type","hinting","*","Asserts","the","returned","type","matches","the","`","base_type","`","*","Throws","an","error","if","there","the","field","'_target_","'","is","missing","(","Hydra","'s","instantiate","(",")","returns","the","config","object","in","this","case",")","*","In","case","`","config","`","is","already","an","instantiated","object",",","immediately","return","this","existing","instance","(","useful","in","the","frequent","case","of","a","constructor","that","accepts","either","a","config","object","or","an","already","instantiated","object",")",":","param","config",":","The","configuration","as","dictionary",":","param","kwargs",":","Additional","arguments","that","are","merged","with","the","configuration","dictionary","(","useful","to","sideload","objects","that","can","not","conveniently","be","specified","in","the","config",",","e.g",".","a","shared","RandomState",")",":","return","The","instantiated","object",",","of","type","`","base_type","`"]
code: def instantiate(
      self, config: Union[BaseType, ConfigType], **kwargs: Any
  ) -> BaseType:
      """Instantiate an object from configuration.
  
      This is implemented as a thin layer on top of Hydra's instantiate() function, with the following additions
  
      * Provides type hinting
      * Asserts the returned type matches the `base_type`
      * Throws an error if there the field '_target_' is missing (Hydra's instantiate() returns the config object
        in this case)
      * In case `config` is already an instantiated object, immediately return this existing instance (useful in
        the frequent case of a constructor that accepts either a config object or an already instantiated
        object)
  
      :param config: The configuration as dictionary
      :param kwargs: Additional arguments that are merged with the configuration dictionary (useful to sideload
                     objects that can not conveniently be specified in the config, e.g. a shared RandomState)
  
      :return The instantiated object, of type `base_type`
      """
      if config is None:
          return None
  
      # To ensure full Hydra compatibility: Convert config to OmegaConf, if necessary.
      if isinstance(config, dict):
          config = omegaconf.OmegaConf.create(
              config, flags={"allow_objects": True}
          )
  
      if not isinstance(config, DictConfig) and isinstance(
          config, self.base_type
      ):
          # nothing to do, object is already instantiated
          return config
  
      assert not isinstance(
          config, str
      ), f"instantiation from string not supported, please pass as '_target_' arg"
      assert hasattr(
          config, "__getitem__"
      ), f"unexpected type {type(config)}"
      assert (
          "_target_" in config
      ), f"Can't instantiate, field '_target_' is missing, config={config}"
  
      if "_" in config:
          config = copy.deepcopy(config)
          # removing the reserved name "_" is only possible by accessing internal Hydra structures
          with open_dict(config):
              del config["_"]
  
      o = instantiate(
          config, _recursive_=config.get("_recursive_", False), **kwargs
      )
      assert isinstance(
          o, self.base_type
      ), f"{o} is not of type {self.base_type}"
  
      return o
  
file_path: maze/maze/core/utils/factory.py
imports: import copy
  import importlib
  from typing import TypeVar, Type, Dict, Union, Any, List, Mapping, Generic, Tuple, Sequence, Callable
  import omegaconf
  from hydra.utils import instantiate
  from omegaconf import open_dict, DictConfig
label_desc: Use image node_id 2 for calling the Factory obj's underlying member method code with example usage: obj.instantiate(config) and returns: o, None, config