本文整理匯總了Python中gym.error.Error方法的典型用法代碼示例。如果您正苦於以下問題:Python error.Error方法的具體用法?Python error.Error怎麽用?Python error.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gym.error
的用法示例。
在下文中一共展示了error.Error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: spec
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def spec(self, id):
# +-+--+-+-+-+ PATCHING --+-+-+-+-+-+
_self = gym.envs.registry
# +-+--+-+-+-+ /PATCHING --+-+-+-+-+-+
match = env_id_re.search(id)
if not match:
raise error.Error('Attempted to look up malformed environment ID: {}. (Currently all IDs must be of the form {}.)'.format(id.encode('utf-8'), env_id_re.pattern))
try:
return _self.env_specs[id]
except KeyError:
# Parse the env name and check to see if it matches the non-version
# part of a valid env (could also check the exact number here)
env_name = match.group(1)
matching_envs = [valid_env_name for valid_env_name, valid_env_spec in _self.env_specs.items()
if env_name == valid_env_spec._env_name]
if matching_envs:
raise error.DeprecatedEnv('Env {} not found (valid versions include {})'.format(id, matching_envs))
else:
raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
示例2: __init__
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def __init__(self, id, entry_point=None, timestep_limit=1000, trials=100, reward_threshold=None, local_only=False, kwargs=None, nondeterministic=False, wrappers=None):
self.id = id
# Evaluation parameters
self.timestep_limit = timestep_limit
self.trials = trials
self.reward_threshold = reward_threshold
# Environment properties
self.nondeterministic = nondeterministic
# We may make some of these other parameters public if they're
# useful.
match = env_id_re.search(id)
if not match:
raise error.Error('Attempted to register malformed environment ID: {}. (Currently all IDs must be of the form {}.)'.format(id, env_id_re.pattern))
self._env_name = match.group(1)
self._entry_point = entry_point
self._local_only = local_only
self._kwargs = {} if kwargs is None else kwargs
self._wrappers = wrappers
示例3: create_seed
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def create_seed(a=None, max_bytes=8):
"""Create a strong random seed. Otherwise, Python 2 would seed using
the system time, which might be non-robust especially in the
presence of concurrency.
Args:
a (Optional[int, str]): None seeds from an operating system specific randomness source.
max_bytes: Maximum number of bytes to use in the seed.
"""
# Adapted from https://svn.python.org/projects/python/tags/r32/Lib/random.py
if a is None:
a = _bigint_from_bytes(os.urandom(max_bytes))
elif isinstance(a, str):
a = a.encode('utf8')
a += hashlib.sha512(a).digest()
a = _bigint_from_bytes(a[:max_bytes])
elif isinstance(a, integer_types):
a = a % 2**(8 * max_bytes)
else:
raise error.Error('Invalid type for seed: {} ({})'.format(type(a), a))
return a
# TODO: don't hardcode sizeof_int here
示例4: spec
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def spec(self, id):
match = env_id_re.search(id)
if not match:
raise error.Error('Attempted to look up malformed environment ID: {}. (Currently all IDs must be of the form {}.)'.format(id.encode('utf-8'), env_id_re.pattern))
try:
return self.env_specs[id]
except KeyError:
# Parse the env name and check to see if it matches the non-version
# part of a valid env (could also check the exact number here)
env_name = match.group(1)
matching_envs = [valid_env_name for valid_env_name, valid_env_spec in self.env_specs.items()
if env_name == valid_env_spec._env_name]
if matching_envs:
raise error.DeprecatedEnv('Env {} not found (valid versions include {})'.format(id, matching_envs))
else:
raise error.UnregisteredEnv('No registered env with id: {}'.format(id))
示例5: check_five_in_row
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def check_five_in_row(self, board_state):
''' Args: board_state 2D list
Return: exist, color
'''
size = len(board_state)
black_pattern = [self.color_dict[self.BLACK] for _ in range(5)] # [1,1,1,1,1]
white_pattern = [self.color_dict[self.WHITE] for _ in range(5)] # [2,2,2,2,2]
exist_final = False
color_final = "empty"
black_win, _ = self.check_pattern(board_state, black_pattern)
white_win, _ = self.check_pattern(board_state, white_pattern)
if (black_win and white_win):
raise error.Error('Both Black and White has 5-in-row, rules conflicts')
# Check if there is any one party wins
if not (black_win or white_win):
return exist_final, "empty"
else:
exist_final = True
if (black_win):
return exist_final, self.BLACK
if (white_win):
return exist_final, self.WHITE
示例6: play
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def play(self, action, color):
'''
Args: input action, current player color
Return: new copy of board object
'''
b = Board(self.size)
b.copy(self.board_state) # create a board copy of current board_state
b.move = self.move
coord = self.action_to_coord(action)
# check if it's legal move
if (b.board_state[coord[0]][coord[1]] != 0): # the action coordinate is not empty
raise error.Error("Action is illegal, position [%d, %d] on board is not empty" % ((coord[0]+1),(coord[1]+1)))
b.board_state[coord[0]][coord[1]] = gomoku_util.color_dict[color]
b.move += 1 # move counter add 1
b.last_coord = coord # save last coordinate
b.last_action = action
return b
示例7: get_display
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def get_display(spec):
"""Convert a display specification (such as :0) into an actual Display
object.
Pyglet only supports multiple Displays on Linux.
"""
if spec is None:
return None
elif isinstance(spec, six.string_types):
return pyglet.canvas.Display(spec)
else:
raise error.Error(
"Invalid display specification: {}. (Must be a string like :0 or None.)".format(
spec
)
)
示例8: spec
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def spec(self, id):
match = agent_id_re.search(id)
if not match:
raise error.Error('Attempted to look up malformed agent ID: {}. (Currently all IDs must be of the form {}.)'.format(id.encode('utf-8'), agent_id_re.pattern))
try:
return self.agent_specs[id]
except KeyError:
# Parse the agent name and check to see if it matches the non-version
# part of a valid agent (could also check the exact number here)
agent_name = match.group(1)
matching_agents = [valid_agent_name for valid_agent_name, valid_agent_spec in self.agent_specs.items()
if agent_name == valid_agent_spec._agent_name]
if matching_agents:
raise error.DeprecatedEnv('Agent {} not found (valid versions include {})'.format(id, matching_agents))
else:
raise error.UnregisteredEnv('No registered agent with id: {}'.format(id))
示例9: __init__
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def __init__(self, id, entry_point=None, reward_threshold=None, kwargs=None, nondeterministic=False, tags=None, max_episode_steps=None):
self.id = id
# Evaluation parameters
self.reward_threshold = reward_threshold
# Environment properties
self.nondeterministic = nondeterministic
self.entry_point = entry_point
if tags is None:
tags = {}
self.tags = tags
tags['wrapper_config.TimeLimit.max_episode_steps'] = max_episode_steps
self.max_episode_steps = max_episode_steps
# We may make some of these other parameters public if they're
# useful.
match = env_id_re.search(id)
if not match:
raise error.Error('Attempted to register malformed environment ID: {}. (Currently all IDs must be of the form {}.)'.format(id, env_id_re.pattern))
self._env_name = match.group(1)
self._kwargs = {} if kwargs is None else kwargs
示例10: get_fields
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def get_fields(weight_save_name):
match = weight_save_re.search(weight_save_name)
if not match:
raise error.Error('Attempted to read a malformed weight save: {}. (Currently all weight saves must be of the form {}.)'.format(id,weight_save_re.pattern))
return match.group(1), match.group(2), int(match.group(3))
示例11: make
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def make(self):
"""Instantiates an instance of the environment with appropriate kwargs"""
if self._entry_point is None:
raise error.Error('Attempting to make deprecated env {}. (HINT: is there a newer registered version of this env?)'.format(self.id))
cls = load(self._entry_point)
env = cls(**self._kwargs)
# Make the enviroment aware of which spec it came from.
env.spec = self
env = env.build(extra_wrappers=self._wrappers)
return env
示例12: register
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def register(self, id, **kwargs):
# +-+--+-+-+-+ PATCHING --+-+-+-+-+-+
_self = gym.envs.registry
# +-+--+-+-+-+ /PATCHING --+-+-+-+-+-+
if id in _self.env_specs:
raise error.Error('Cannot re-register id: {}'.format(id))
_self.env_specs[id] = EnvSpec(id, **kwargs)
# >>>>>>>>> START changes >>>>>>>>>>>>>>>>>>>>>>>>
示例13: np_random
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def np_random(seed=None):
if seed is not None and not (isinstance(seed, integer_types) and 0 <= seed):
raise error.Error('Seed must be a non-negative integer or omitted, not {}'.format(seed))
seed = create_seed(seed)
rng = np.random.RandomState()
rng.seed(_int_list_from_bigint(hash_seed(seed)))
return rng, seed
示例14: _int_list_from_bigint
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def _int_list_from_bigint(bigint):
# Special case 0
if bigint < 0:
raise error.Error('Seed must be non-negative, not {}'.format(bigint))
elif bigint == 0:
return [0]
ints = []
while bigint > 0:
bigint, mod = divmod(bigint, 2 ** 32)
ints.append(mod)
return ints
示例15: test_invalid_seeds
# 需要導入模塊: from gym import error [as 別名]
# 或者: from gym.error import Error [as 別名]
def test_invalid_seeds():
for seed in [-1, 'test']:
try:
seeding.np_random(seed)
except error.Error:
pass
else:
assert False, 'Invalid seed {} passed validation'.format(seed)