Files
Gymnasium/gym/error.py

227 lines
4.5 KiB
Python
Raw Normal View History

2016-04-27 08:00:58 -07:00
import sys
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class Error(Exception):
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
# Local errors
2021-07-29 02:26:34 +02:00
class Unregistered(Error):
"""Raised when the user requests an item from the registry that does
not actually exist.
"""
2021-07-29 02:26:34 +02:00
pass
2021-07-29 02:26:34 +02:00
class UnregisteredEnv(Unregistered):
"""Raised when the user requests an env from the registry that does
not actually exist.
"""
2021-07-29 02:26:34 +02:00
pass
2021-07-29 02:26:34 +02:00
class UnregisteredBenchmark(Unregistered):
2016-04-27 08:00:58 -07:00
"""Raised when the user requests an env from the registry that does
not actually exist.
"""
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
pass
2021-07-29 02:26:34 +02:00
class DeprecatedEnv(Error):
[WIP] add support for seeding environments (#135) * Make environments seedable * Fix monitor bugs - Set monitor_id before setting the infix. This was a bug that would yield incorrect results with multiple monitors. - Remove extra pid from stats recorder filename. This should be purely cosmetic. * Start uploading seeds in episode_batch * Fix _bigint_from_bytes for python3 * Set seed explicitly in random_agent * Pass through seed argument * Also pass through random state to spaces * Pass random state into the observation/action spaces * Make all _seed methods return the list of used seeds * Switch over to np.random where possible * Start hashing seeds, and also seed doom engine * Fixup seeding determinism in many cases * Seed before loading the ROM * Make seeding more Python3 friendly * Make the MuJoCo skipping a bit more forgiving * Remove debugging PDB calls * Make setInt argument into raw bytes * Validate and upload seeds * Skip box2d * Make seeds smaller, and change representation of seeds in upload * Handle long seeds * Fix RandomAgent example to be deterministic * Handle integer types correctly in Python2 and Python3 * Try caching pip * Try adding swap * Add df and free calls * Bump swap * Bump swap size * Try setting overcommit * Try other sysctls * Try fixing overcommit * Try just setting overcommit_memory=1 * Add explanatory comment * Add what's new section to readme * BUG: Mark ElevatorAction-ram-v0 as non-deterministic for now * Document seed * Move nondetermistic check into spec
2016-05-29 09:07:09 -07:00
"""Raised when the user requests an env from the registry with an
older version number than the latest env with the same name.
"""
2021-07-29 02:26:34 +02:00
[WIP] add support for seeding environments (#135) * Make environments seedable * Fix monitor bugs - Set monitor_id before setting the infix. This was a bug that would yield incorrect results with multiple monitors. - Remove extra pid from stats recorder filename. This should be purely cosmetic. * Start uploading seeds in episode_batch * Fix _bigint_from_bytes for python3 * Set seed explicitly in random_agent * Pass through seed argument * Also pass through random state to spaces * Pass random state into the observation/action spaces * Make all _seed methods return the list of used seeds * Switch over to np.random where possible * Start hashing seeds, and also seed doom engine * Fixup seeding determinism in many cases * Seed before loading the ROM * Make seeding more Python3 friendly * Make the MuJoCo skipping a bit more forgiving * Remove debugging PDB calls * Make setInt argument into raw bytes * Validate and upload seeds * Skip box2d * Make seeds smaller, and change representation of seeds in upload * Handle long seeds * Fix RandomAgent example to be deterministic * Handle integer types correctly in Python2 and Python3 * Try caching pip * Try adding swap * Add df and free calls * Bump swap * Bump swap size * Try setting overcommit * Try other sysctls * Try fixing overcommit * Try just setting overcommit_memory=1 * Add explanatory comment * Add what's new section to readme * BUG: Mark ElevatorAction-ram-v0 as non-deterministic for now * Document seed * Move nondetermistic check into spec
2016-05-29 09:07:09 -07:00
pass
2021-07-29 02:26:34 +02:00
[WIP] add support for seeding environments (#135) * Make environments seedable * Fix monitor bugs - Set monitor_id before setting the infix. This was a bug that would yield incorrect results with multiple monitors. - Remove extra pid from stats recorder filename. This should be purely cosmetic. * Start uploading seeds in episode_batch * Fix _bigint_from_bytes for python3 * Set seed explicitly in random_agent * Pass through seed argument * Also pass through random state to spaces * Pass random state into the observation/action spaces * Make all _seed methods return the list of used seeds * Switch over to np.random where possible * Start hashing seeds, and also seed doom engine * Fixup seeding determinism in many cases * Seed before loading the ROM * Make seeding more Python3 friendly * Make the MuJoCo skipping a bit more forgiving * Remove debugging PDB calls * Make setInt argument into raw bytes * Validate and upload seeds * Skip box2d * Make seeds smaller, and change representation of seeds in upload * Handle long seeds * Fix RandomAgent example to be deterministic * Handle integer types correctly in Python2 and Python3 * Try caching pip * Try adding swap * Add df and free calls * Bump swap * Bump swap size * Try setting overcommit * Try other sysctls * Try fixing overcommit * Try just setting overcommit_memory=1 * Add explanatory comment * Add what's new section to readme * BUG: Mark ElevatorAction-ram-v0 as non-deterministic for now * Document seed * Move nondetermistic check into spec
2016-05-29 09:07:09 -07:00
class UnseedableEnv(Error):
"""Raised when the user tries to seed an env that does not support
seeding.
"""
2021-07-29 02:26:34 +02:00
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class DependencyNotInstalled(Error):
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class UnsupportedMode(Exception):
"""Raised when the user requests a rendering mode not supported by the
environment.
"""
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class ResetNeeded(Exception):
"""When the monitor is active, raised when the user tries to step an
environment that's already done.
"""
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class ResetNotAllowed(Exception):
"""When the monitor is active, raised when the user tries to step an
environment that's not yet done.
"""
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
pass
2021-07-29 02:26:34 +02:00
class InvalidAction(Exception):
"""Raised when the user performs an action not contained within the
action space
"""
2021-07-29 02:26:34 +02:00
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
# API errors
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class APIError(Error):
2021-07-29 02:26:34 +02:00
def __init__(
self,
message=None,
http_body=None,
http_status=None,
json_body=None,
headers=None,
):
2016-04-27 08:00:58 -07:00
super(APIError, self).__init__(message)
2021-07-29 02:26:34 +02:00
if http_body and hasattr(http_body, "decode"):
2016-04-27 08:00:58 -07:00
try:
2021-07-29 02:26:34 +02:00
http_body = http_body.decode("utf-8")
2016-04-27 08:00:58 -07:00
except:
2021-07-29 15:39:42 -04:00
http_body = (
"<Could not decode body as utf-8. "
"Please report to gym@openai.com>"
)
2016-04-27 08:00:58 -07:00
self._message = message
self.http_body = http_body
self.http_status = http_status
self.json_body = json_body
self.headers = headers or {}
2021-07-29 02:26:34 +02:00
self.request_id = self.headers.get("request-id", None)
2016-04-27 08:00:58 -07:00
def __unicode__(self):
if self.request_id is not None:
msg = self._message or "<empty message>"
return u"Request {0}: {1}".format(self.request_id, msg)
else:
return self._message
def __str__(self):
2021-07-29 02:26:34 +02:00
try: # Python 2
return unicode(self).encode("utf-8")
except NameError: # Python 3
return self.__unicode__()
2016-04-27 08:00:58 -07:00
class APIConnectionError(APIError):
pass
class InvalidRequestError(APIError):
2021-07-29 02:26:34 +02:00
def __init__(
self,
message,
param,
http_body=None,
http_status=None,
json_body=None,
headers=None,
):
2021-07-29 15:39:42 -04:00
super(InvalidRequestError, self).__init__(
message, http_body, http_status, json_body, headers
)
2016-04-27 08:00:58 -07:00
self.param = param
class AuthenticationError(APIError):
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class RateLimitError(APIError):
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
# Video errors
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class VideoRecorderError(Error):
pass
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
class InvalidFrame(Error):
pass
2021-07-29 02:26:34 +02:00
# Wrapper errors
2021-07-29 02:26:34 +02:00
class DoubleWrapperError(Error):
pass
class WrapAfterConfigureError(Error):
pass
2017-03-05 19:54:09 -08:00
class RetriesExceededError(Error):
pass
2021-07-29 02:26:34 +02:00
# Vectorized environments errors
2021-07-29 02:26:34 +02:00
class AlreadyPendingCallError(Exception):
"""
Raised when `reset`, or `step` is called asynchronously (e.g. with
`reset_async`, or `step_async` respectively), and `reset_async`, or
`step_async` (respectively) is called again (without a complete call to
`reset_wait`, or `step_wait` respectively).
"""
2021-07-29 02:26:34 +02:00
def __init__(self, message, name):
super(AlreadyPendingCallError, self).__init__(message)
self.name = name
2021-07-29 02:26:34 +02:00
class NoAsyncCallError(Exception):
"""
Raised when an asynchronous `reset`, or `step` is not running, but
`reset_wait`, or `step_wait` (respectively) is called.
"""
2021-07-29 02:26:34 +02:00
def __init__(self, message, name):
super(NoAsyncCallError, self).__init__(message)
self.name = name
2021-07-29 02:26:34 +02:00
class ClosedEnvironmentError(Exception):
"""
Trying to call `reset`, or `step`, while the environment is closed.
"""
2021-07-29 02:26:34 +02:00
pass
2021-07-29 02:26:34 +02:00
class CustomSpaceError(Exception):
"""
The space is a custom gym.Space instance, and is not supported by
`AsyncVectorEnv` with `shared_memory=True`.
"""
2021-07-29 02:26:34 +02:00
pass