def test_get_wrapper(env_wrapper): env = gym.make("HalfCheetahBulletEnv-v0") hyperparams = {"env_wrapper": env_wrapper} wrapper_class = get_wrapper_class(hyperparams) if env_wrapper is not None: env = wrapper_class(env) check_env(env)
def _preprocess_hyperparams( self, hyperparams: Dict[str, Any] ) -> Tuple[Dict[str, Any], Optional[Callable], List[BaseCallback]]: self.n_envs = 4 if self.verbose > 0: print(f"Using {self.n_envs} environments") # Convert schedule strings to objects hyperparams = self._preprocess_schedules(hyperparams) # Pre-process train_freq if "train_freq" in hyperparams and isinstance( hyperparams["train_freq"], list): hyperparams["train_freq"] = tuple(hyperparams["train_freq"]) # Should we overwrite the number of timesteps? if self.n_timesteps > 0: if self.verbose: print(f"Overwriting n_timesteps with n={self.n_timesteps}") else: self.n_timesteps = int(hyperparams["n_timesteps"]) # Pre-process normalize config hyperparams = self._preprocess_normalization(hyperparams) # Pre-process policy/buffer keyword arguments # Convert to python object if needed for kwargs_key in { "policy_kwargs", "replay_buffer_class", "replay_buffer_kwargs", }: if kwargs_key in hyperparams.keys() and isinstance( hyperparams[kwargs_key], str): hyperparams[kwargs_key] = eval(hyperparams[kwargs_key]) # Delete keys so the dict can be pass to the model constructor if "n_envs" in hyperparams.keys(): del hyperparams["n_envs"] del hyperparams["n_timesteps"] if "frame_stack" in hyperparams.keys(): self.frame_stack = hyperparams["frame_stack"] del hyperparams["frame_stack"] # obtain a class object from a wrapper name string in hyperparams # and delete the entry env_wrapper = get_wrapper_class(hyperparams) if "env_wrapper" in hyperparams.keys(): del hyperparams["env_wrapper"] callbacks = get_callback_list(hyperparams) if "callback" in hyperparams.keys(): del hyperparams["callback"] return hyperparams, env_wrapper, callbacks
def _preprocess_hyperparams( self, hyperparams: Dict[str, Any] ) -> Tuple[Dict[str, Any], Optional[Callable], List[BaseCallback]]: self.n_envs = hyperparams.get("n_envs", 1) if self.verbose > 0: print(f"Using {self.n_envs} environments") # Convert model class string to an object if needed (when using HER) hyperparams = self._preprocess_her_model_class(hyperparams) hyperparams = self._preprocess_schedules(hyperparams) # Should we overwrite the number of timesteps? if self.n_timesteps > 0: if self.verbose: print(f"Overwriting n_timesteps with n={self.n_timesteps}") else: self.n_timesteps = int(hyperparams["n_timesteps"]) # Pre-process normalize config hyperparams = self._preprocess_normalization(hyperparams) # Pre-process policy keyword arguments if "policy_kwargs" in hyperparams.keys(): # Convert to python object if needed if isinstance(hyperparams["policy_kwargs"], str): hyperparams["policy_kwargs"] = eval( hyperparams["policy_kwargs"]) # Delete keys so the dict can be pass to the model constructor if "n_envs" in hyperparams.keys(): del hyperparams["n_envs"] del hyperparams["n_timesteps"] if "frame_stack" in hyperparams.keys(): self.frame_stack = hyperparams["frame_stack"] del hyperparams["frame_stack"] # obtain a class object from a wrapper name string in hyperparams # and delete the entry env_wrapper = get_wrapper_class(hyperparams) if "env_wrapper" in hyperparams.keys(): del hyperparams["env_wrapper"] callbacks = get_callback_list(hyperparams) if "callback" in hyperparams.keys(): del hyperparams["callback"] return hyperparams, env_wrapper, callbacks