parameters: (spec, base_path, cache_dir, seq_name_mapping=None, extra_filter_regex=None, other_specs=[])
return_statement: return exp
docstring: Load a single experiment from logs or cache
          
          The cache key is determined by the 'pattern', 'filter_regex' and 'extend' keys
          in the spec. That means changing the name or display name for example doesn't
          invalidate the cache. If the experiment is not found in cache, it is loaded from 
          the run directories and then saved in cache.
          
          :param spec: experiment spec from the config file 
          :param base_path: base folder to search for run dirs in
          :param cache_dir: cache directory
          :param seq_name_mapping: optional sequence name mapping
          :param extra_filter_regex: additional filter to limit the loaded sequences on top of what is defined in the spec; if set, caching is disabled
          :param other_specs: other experiment specs in case our spec has the 'extend' option defined
          :return: loaded Experiment object
docstring_summary: Load a single experiment from logs or cache
          
          The cache key is determined by the 'pattern', 'filter_regex' and 'extend' keys
          in the spec. That means changing the name or display name for example doesn't
          invalidate the cache. If the experiment is not found in cache, it is loaded from 
          the run directories and then saved in cache.
          
          :param spec: experiment spec from the config file 
          :param base_path: base folder to search for run dirs in
          :param cache_dir: cache directory
          :param seq_name_mapping: optional sequence name mapping
          :param extra_filter_regex: additional filter to limit the loaded sequences on top of what is defined in the spec; if set, caching is disabled
          :param other_specs: other experiment specs in case our spec has the 'extend' option defined
          :return: loaded Experiment object
docstring_tokens: Load a single experiment from logs or cache The cache key is determined by the pattern filter_regex and extend keys in the spec . That means changing the name or display name for example doesn t invalidate the cache . If the experiment is not found in cache it is loaded from the run directories and then saved in cache . : param spec : experiment spec from the config file : param base_path : base folder to search for run dirs in : param cache_dir : cache directory : param seq_name_mapping : optional sequence name mapping : param extra_filter_regex : additional filter to limit the loaded sequences on top of what is defined in the spec ; if set caching is disabled : param other_specs : other experiment specs in case our spec has the extend option defined : return : loaded Experiment object
function: def load_spec(spec, base_path, cache_dir, seq_name_mapping=None, extra_filter_regex=None, other_specs=[]):
          """Load a single experiment from logs or cache
          
          The cache key is determined by the 'pattern', 'filter_regex' and 'extend' keys
          in the spec. That means changing the name or display name for example doesn't
          invalidate the cache. If the experiment is not found in cache, it is loaded from 
          the run directories and then saved in cache.
          
          :param spec: experiment spec from the config file 
          :param base_path: base folder to search for run dirs in
          :param cache_dir: cache directory
          :param seq_name_mapping: optional sequence name mapping
          :param extra_filter_regex: additional filter to limit the loaded sequences on top of what is defined in the spec; if set, caching is disabled
          :param other_specs: other experiment specs in case our spec has the 'extend' option defined
          :return: loaded Experiment object
          """
  
          # disable cache if extra filtering
          if extra_filter_regex is not None:
              cache_dir = None
  
          # extending some other experiment:
          extend = None
          if "extend" in spec:
              other_spec = next((s for s in other_specs if s.name == spec.extend), None)
              if other_spec is None:
                  raise RuntimeError("Experiment {} extends unknown experiment {}.".format(spec.name, spec.extend))
              extend = Experiment.load_spec(other_spec,
                                            base_path,
                                            cache_dir,
                                            seq_name_mapping=seq_name_mapping,
                                            extra_filter_regex=extra_filter_regex,
                                            other_specs=other_specs)
  
          caching_hash = None
          if cache_dir:
              caching_spec = copy_subdict(spec, ["pattern", "filter_regex"])
              if extend is not None:
                  caching_spec["extend"] = extend.caching_hash
              caching_hash = compute_caching_hash(caching_spec)
  
              cache_filename = "experiment-cache-{}.pickle".format(caching_hash)
              cache_path = os.path.join(cache_dir, cache_filename)
  
              if os.path.isfile(cache_path):
                  if not spec.overwrite_cache:
                      with open(cache_path, 'rb') as f:
                          cache = pickle.load(f)
                      if cache.version != _CURRENT_CACHE_VERSION:
                          print("> experiment: {} (cache {} has version {}; expected {})".format(
                              spec.name, cache_path, cache.version, _CURRENT_CACHE_VERSION))
                      else:
                          print("> experiment: {} (from cache: {})".format(spec.name, cache_path))
                          exp = cache.experiment
                          # overwrite names according to config
                          exp.name = spec.name
                          exp.display_name = spec.display_name
                          exp.description = spec.description
                          return exp
                  else:
                      print("> experiment: {} (overwrite cache: {})".format(spec.name, cache_path))
              else:
                  print("> experiment: {} (cache doesn't exist: {})".format(spec.name, cache_path))
          else:
              print("> experiment: {}".format(spec.name))
  
          log_dirs = Experiment.get_log_dirs(base_path, spec, filter_regex=extra_filter_regex)
  
          kwargs = copy_subdict(spec, ["name", "display_name", "description", "extend_override"])
          exp = Experiment(log_dirs,
                           caching_hash=caching_hash,
                           seq_name_mapping=seq_name_mapping,
                           extend=extend,
                           spec=deepcopy(spec),
                           **kwargs)
  
          if cache_dir:
              cache = Munch(version=_CURRENT_CACHE_VERSION, experiment=exp, spec=caching_spec)
              os.makedirs(cache_dir, exist_ok=True)
              with open(cache_path, 'wb') as f:
                  pickle.dump(cache, f)
              print("experiment {} -> saved cache {}".format(spec.name, cache_path))
  
          return exp
function_tokens: def load_spec ( spec , base_path , cache_dir , seq_name_mapping = None , extra_filter_regex = None , other_specs = [ ] ) : # disable cache if extra filtering if extra_filter_regex is not None : cache_dir = None # extending some other experiment: extend = None if "extend" in spec : other_spec = next ( ( s for s in other_specs if s . name == spec . extend ) , None ) if other_spec is None : raise RuntimeError ( "Experiment {} extends unknown experiment {}." . format ( spec . name , spec . extend ) ) extend = Experiment . load_spec ( other_spec , base_path , cache_dir , seq_name_mapping = seq_name_mapping , extra_filter_regex = extra_filter_regex , other_specs = other_specs ) caching_hash = None if cache_dir : caching_spec = copy_subdict ( spec , [ "pattern" , "filter_regex" ] ) if extend is not None : caching_spec [ "extend" ] = extend . caching_hash caching_hash = compute_caching_hash ( caching_spec ) cache_filename = "experiment-cache-{}.pickle" . format ( caching_hash ) cache_path = os . path . join ( cache_dir , cache_filename ) if os . path . isfile ( cache_path ) : if not spec . overwrite_cache : with open ( cache_path , 'rb' ) as f : cache = pickle . load ( f ) if cache . version != _CURRENT_CACHE_VERSION : print ( "> experiment: {} (cache {} has version {}; expected {})" . format ( spec . name , cache_path , cache . version , _CURRENT_CACHE_VERSION ) ) else : print ( "> experiment: {} (from cache: {})" . format ( spec . name , cache_path ) ) exp = cache . experiment # overwrite names according to config exp . name = spec . name exp . display_name = spec . display_name exp . description = spec . description return exp else : print ( "> experiment: {} (overwrite cache: {})" . format ( spec . name , cache_path ) ) else : print ( "> experiment: {} (cache doesn't exist: {})" . format ( spec . name , cache_path ) ) else : print ( "> experiment: {}" . format ( spec . name ) ) log_dirs = Experiment . get_log_dirs ( base_path , spec , filter_regex = extra_filter_regex ) kwargs = copy_subdict ( spec , [ "name" , "display_name" , "description" , "extend_override" ] ) exp = Experiment ( log_dirs , caching_hash = caching_hash , seq_name_mapping = seq_name_mapping , extend = extend , spec = deepcopy ( spec ) , * * kwargs ) if cache_dir : cache = Munch ( version = _CURRENT_CACHE_VERSION , experiment = exp , spec = caching_spec ) os . makedirs ( cache_dir , exist_ok = True ) with open ( cache_path , 'wb' ) as f : pickle . dump ( cache , f ) print ( "experiment {} -> saved cache {}" . format ( spec . name , cache_path ) ) return exp