mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-11-18 09:54:10 +00:00
Fix exception cause in base_class.py (#940)
This commit is contained in:
parent
7ce7b6a8c2
commit
d64bcb401a
8 changed files with 20 additions and 17 deletions
|
|
@ -32,6 +32,7 @@ Bug Fixes:
|
||||||
- Fixed a bug where ``EvalCallback`` would crash when trying to synchronize ``VecNormalize`` stats when observation normalization was disabled
|
- Fixed a bug where ``EvalCallback`` would crash when trying to synchronize ``VecNormalize`` stats when observation normalization was disabled
|
||||||
- Added a check for unbounded actions
|
- Added a check for unbounded actions
|
||||||
- Fixed issues due to newer version of protobuf (tensorboard) and sphinx
|
- Fixed issues due to newer version of protobuf (tensorboard) and sphinx
|
||||||
|
- Fix exception causes all over the codebase (@cool-RR)
|
||||||
|
|
||||||
Deprecations:
|
Deprecations:
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
@ -978,4 +979,4 @@ And all the contributors:
|
||||||
@wkirgsn @AechPro @CUN-bjy @batu @IljaAvadiev @timokau @kachayev @cleversonahum
|
@wkirgsn @AechPro @CUN-bjy @batu @IljaAvadiev @timokau @kachayev @cleversonahum
|
||||||
@eleurent @ac-93 @cove9988 @theDebugger811 @hsuehch @Demetrio92 @thomasgubler @IperGiove @ScheiklP
|
@eleurent @ac-93 @cove9988 @theDebugger811 @hsuehch @Demetrio92 @thomasgubler @IperGiove @ScheiklP
|
||||||
@simoninithomas @armandpl @manuel-delverme @Gautam-J @gianlucadecola @buoyancy99 @caburu @xy9485
|
@simoninithomas @armandpl @manuel-delverme @Gautam-J @gianlucadecola @buoyancy99 @caburu @xy9485
|
||||||
@Gregwar @ycheng517 @quantitative-technologies @bcollazo @git-thor @TibiGG
|
@Gregwar @ycheng517 @quantitative-technologies @bcollazo @git-thor @TibiGG @cool-RR
|
||||||
|
|
|
||||||
|
|
@ -628,11 +628,11 @@ class BaseAlgorithm(ABC):
|
||||||
attr = None
|
attr = None
|
||||||
try:
|
try:
|
||||||
attr = recursive_getattr(self, name)
|
attr = recursive_getattr(self, name)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
# What errors recursive_getattr could throw? KeyError, but
|
# What errors recursive_getattr could throw? KeyError, but
|
||||||
# possible something else too (e.g. if key is an int?).
|
# possible something else too (e.g. if key is an int?).
|
||||||
# Catch anything for now.
|
# Catch anything for now.
|
||||||
raise ValueError(f"Key {name} is an invalid object name.")
|
raise ValueError(f"Key {name} is an invalid object name.") from e
|
||||||
|
|
||||||
if isinstance(attr, th.optim.Optimizer):
|
if isinstance(attr, th.optim.Optimizer):
|
||||||
# Optimizers do not support "strict" keyword...
|
# Optimizers do not support "strict" keyword...
|
||||||
|
|
|
||||||
|
|
@ -380,12 +380,12 @@ class EvalCallback(EventCallback):
|
||||||
if self.model.get_vec_normalize_env() is not None:
|
if self.model.get_vec_normalize_env() is not None:
|
||||||
try:
|
try:
|
||||||
sync_envs_normalization(self.training_env, self.eval_env)
|
sync_envs_normalization(self.training_env, self.eval_env)
|
||||||
except AttributeError:
|
except AttributeError as e:
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Training and eval env are not wrapped the same way, "
|
"Training and eval env are not wrapped the same way, "
|
||||||
"see https://stable-baselines3.readthedocs.io/en/master/guide/callbacks.html#evalcallback "
|
"see https://stable-baselines3.readthedocs.io/en/master/guide/callbacks.html#evalcallback "
|
||||||
"and warning above."
|
"and warning above."
|
||||||
)
|
) from e
|
||||||
|
|
||||||
# Reset success rate buffer
|
# Reset success rate buffer
|
||||||
self._is_success_buffer = []
|
self._is_success_buffer = []
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ def _check_returned_values(env: gym.Env, observation_space: spaces.Space, action
|
||||||
try:
|
try:
|
||||||
_check_obs(obs[key], observation_space.spaces[key], "reset")
|
_check_obs(obs[key], observation_space.spaces[key], "reset")
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
raise AssertionError(f"Error while checking key={key}: " + str(e))
|
raise AssertionError(f"Error while checking key={key}: " + str(e)) from e
|
||||||
else:
|
else:
|
||||||
_check_obs(obs, observation_space, "reset")
|
_check_obs(obs, observation_space, "reset")
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ def _check_returned_values(env: gym.Env, observation_space: spaces.Space, action
|
||||||
try:
|
try:
|
||||||
_check_obs(obs[key], observation_space.spaces[key], "step")
|
_check_obs(obs[key], observation_space.spaces[key], "step")
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
raise AssertionError(f"Error while checking key={key}: " + str(e))
|
raise AssertionError(f"Error while checking key={key}: " + str(e)) from e
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_check_obs(obs, observation_space, "step")
|
_check_obs(obs, observation_space, "step")
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,8 @@ class VectorizedActionNoise(ActionNoise):
|
||||||
try:
|
try:
|
||||||
self.n_envs = int(n_envs)
|
self.n_envs = int(n_envs)
|
||||||
assert self.n_envs > 0
|
assert self.n_envs > 0
|
||||||
except (TypeError, AssertionError):
|
except (TypeError, AssertionError) as e:
|
||||||
raise ValueError(f"Expected n_envs={n_envs} to be positive integer greater than 0")
|
raise ValueError(f"Expected n_envs={n_envs} to be positive integer greater than 0") from e
|
||||||
|
|
||||||
self.base_noise = base_noise
|
self.base_noise = base_noise
|
||||||
self.noises = [copy.deepcopy(self.base_noise) for _ in range(n_envs)]
|
self.noises = [copy.deepcopy(self.base_noise) for _ in range(n_envs)]
|
||||||
|
|
|
||||||
|
|
@ -157,8 +157,10 @@ class OffPolicyAlgorithm(BaseAlgorithm):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
train_freq = (train_freq[0], TrainFrequencyUnit(train_freq[1]))
|
train_freq = (train_freq[0], TrainFrequencyUnit(train_freq[1]))
|
||||||
except ValueError:
|
except ValueError as e:
|
||||||
raise ValueError(f"The unit of the `train_freq` must be either 'step' or 'episode' not '{train_freq[1]}'!")
|
raise ValueError(
|
||||||
|
f"The unit of the `train_freq` must be either 'step' or 'episode' not '{train_freq[1]}'!"
|
||||||
|
) from e
|
||||||
|
|
||||||
if not isinstance(train_freq[0], int):
|
if not isinstance(train_freq[0], int):
|
||||||
raise ValueError(f"The frequency of `train_freq` must be an integer and not {train_freq[0]}")
|
raise ValueError(f"The frequency of `train_freq` must be an integer and not {train_freq[0]}")
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,8 @@ def open_path(path: Union[str, pathlib.Path, io.BufferedIOBase], mode: str, verb
|
||||||
mode = mode.lower()
|
mode = mode.lower()
|
||||||
try:
|
try:
|
||||||
mode = {"write": "w", "read": "r", "w": "w", "r": "r"}[mode]
|
mode = {"write": "w", "read": "r", "w": "w", "r": "r"}[mode]
|
||||||
except KeyError:
|
except KeyError as e:
|
||||||
raise ValueError("Expected mode to be either 'w' or 'r'.")
|
raise ValueError("Expected mode to be either 'w' or 'r'.") from e
|
||||||
if ("w" == mode) and not path.writable() or ("r" == mode) and not path.readable():
|
if ("w" == mode) and not path.writable() or ("r" == mode) and not path.readable():
|
||||||
e1 = "writable" if "w" == mode else "readable"
|
e1 = "writable" if "w" == mode else "readable"
|
||||||
raise ValueError(f"Expected a {e1} file.")
|
raise ValueError(f"Expected a {e1} file.")
|
||||||
|
|
@ -441,7 +441,7 @@ def load_from_zip_file(
|
||||||
# State dicts. Store into params dictionary
|
# State dicts. Store into params dictionary
|
||||||
# with same name as in .zip file (without .pth)
|
# with same name as in .zip file (without .pth)
|
||||||
params[os.path.splitext(file_path)[0]] = th_object
|
params[os.path.splitext(file_path)[0]] = th_object
|
||||||
except zipfile.BadZipFile:
|
except zipfile.BadZipFile as e:
|
||||||
# load_path wasn't a zip file
|
# load_path wasn't a zip file
|
||||||
raise ValueError(f"Error: the file {load_path} wasn't a zip-file")
|
raise ValueError(f"Error: the file {load_path} wasn't a zip-file") from e
|
||||||
return data, params, pytorch_variables
|
return data, params, pytorch_variables
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,13 @@ def get_time_limit(env: VecEnv, current_max_episode_length: Optional[int]) -> in
|
||||||
if current_max_episode_length is None:
|
if current_max_episode_length is None:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
# if not available check if a valid value was passed as an argument
|
# if not available check if a valid value was passed as an argument
|
||||||
except AttributeError:
|
except AttributeError as e:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"The max episode length could not be inferred.\n"
|
"The max episode length could not be inferred.\n"
|
||||||
"You must specify a `max_episode_steps` when registering the environment,\n"
|
"You must specify a `max_episode_steps` when registering the environment,\n"
|
||||||
"use a `gym.wrappers.TimeLimit` wrapper "
|
"use a `gym.wrappers.TimeLimit` wrapper "
|
||||||
"or pass `max_episode_length` to the model constructor"
|
"or pass `max_episode_length` to the model constructor"
|
||||||
)
|
) from e
|
||||||
return current_max_episode_length
|
return current_max_episode_length
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue