"""The configuration module for the ``cambrian`` module."""frompathlibimportPathfromtypingimportAny,List,Optionalfromhydra_configimportHydraContainerConfig,config_wrapper,register_new_resolverfromomegaconfimportDictConfig,OmegaConffromcambrian.envs.envimportMjCambrianEnvConfigfromcambrian.ml.evoimportMjCambrianEvoConfigfromcambrian.ml.trainerimportMjCambrianTrainerConfigfromcambrian.utilsimportis_integer# =============================================================================@config_wrapper
[docs]classMjCambrianConfig(HydraContainerConfig):"""The base config for the mujoco cambrian environment. Used for type hinting. Attributes: logdir (Path): The primary directory which simulation data is stored in. This is the highest level directory used for the experiment. `expdir` is the subdirectory used for a specific experiment. expdir (Path): The directory used for a specific experiment. This is the directory where the experiment's data is stored. Should evaluate to `logdir / `expsubdir` expsubdir (Path): The subdirectory relative to logdir where the experiment's data is stored. This is the directory where the experiment's data is stored. expname (str): The name of the experiment. Used to name the logging subdirectory. seed (int): The base seed used when initializing the default thread/process. Launched processes should use this seed value to calculate their own seed values. This is used to ensure that each process has a unique seed. training (MjCambrianTrainingConfig): The config for the training process. env (MjCambrianEnvConfig): The config for the environment. eval_env (MjCambrianEnvConfig): The config for the evaluation environment. """logdir:Pathexpdir:Pathexpsubdir:Pathexpname:Anyseed:inttrainer:MjCambrianTrainerConfigevo:Optional[MjCambrianEvoConfig]=Noneenv:MjCambrianEnvConfigeval_env:MjCambrianEnvConfig|Any
[docs]defpackage_resolver(package:str="cambrian")->Path:"""Get the path to installed package directory."""importimportlib.utilpackage_path=importlib.util.find_spec(package).submodule_search_locations[0]returnPath(package_path)
@register_new_resolver("clean_overrides")defclean_overrides_resolver(overrides:List[str],ignore_after_override:Optional[str]="",use_seed_as_subfolder:bool=True,)->str:cleaned_overrides:List[str]=[]seed:Optional[Any]=Noneforoverrideinoverrides:if"="notinoverrideoroverride.count("=")>1:continueifignore_after_overrideandoverride==ignore_after_override:breakkey,value=override.split("=",1)ifkey=="exp":continueifkey=="seed"anduse_seed_as_subfolder:seed=valuecontinue# Special key cases that we want the second key rather than the firstif(key.startswith("env.reward_fn")orkey.startswith("env.truncation_fn")orkey.startswith("env.termination_fn")orkey.startswith("env.step_fn")oris_integer(key.split(".")[-1])):key="_".join(key.split(".")[-2:])else:key=key.split("/")[-1].split(".")[-1]# Clean the key and valuekey=(key.replace("+","").replace("[","").replace("]","").replace(",","_").replace(" ",""))value=(value.replace(".","p").replace("-","n").replace("[","").replace("]","").replace(",","_").replace(" ",""))cleaned_overrides.append(f"{key}_{value}")return"_".join(cleaned_overrides)+(f"/seed_{seed}"ifseedisnotNoneelse"")@register_new_resolver("num_cpus")defnum_cpus_resolver()->int:importmultiprocessingreturnmultiprocessing.cpu_count()@register_new_resolver("unresolved")defunresolved_resolver(path:str,*,_parent_:DictConfig)->str:returnOmegaConf.to_container(OmegaConf.select(_parent_,path))