本文整理汇总了Python中gym.spec方法的典型用法代码示例。如果您正苦于以下问题:Python gym.spec方法的具体用法?Python gym.spec怎么用?Python gym.spec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gym
的用法示例。
在下文中一共展示了gym.spec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def configure(self, n=1, pool_size=None, episode_limit=None):
self.n = n
self.envs = [self.spec.make() for _ in range(self.n)]
if pool_size is None:
pool_size = min(len(self.envs), multiprocessing.cpu_count() - 1)
pool_size = max(1, pool_size)
self.worker_n = []
m = int((self.n + pool_size - 1) / pool_size)
for i in range(0, self.n, m):
envs = self.envs[i:i+m]
self.worker_n.append(Worker(envs, i))
if episode_limit is not None:
self._episode_id.episode_limit = episode_limit
示例2: __init__
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def __init__(self, env, gym_core_id=None):
super(GymCoreAction, self).__init__(env)
if gym_core_id is None:
# self.spec is None while inside of the make, so we need
# to pass gym_core_id in explicitly there. This case will
# be hit when instantiating by hand.
gym_core_id = self.spec._kwargs['gym_core_id']
spec = gym.spec(gym_core_id)
raw_action_space = gym_core_action_space(gym_core_id)
self._actions = raw_action_space.actions
self.action_space = gym_spaces.Discrete(len(self._actions))
if spec._entry_point.startswith('gym.envs.atari:'):
self.key_state = translator.AtariKeyState(gym.make(gym_core_id))
else:
self.key_state = None
示例3: test_spec_from_gym_space_when_simplify_box_bounds_false
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_spec_from_gym_space_when_simplify_box_bounds_false(self):
# testing on gym.spaces.Dict which makes recursive calls to
# _spec_from_gym_space
box_space = gym.spaces.Box(-1.0, 1.0, (2,))
dict_space = gym.spaces.Dict({'box1': box_space, 'box2': box_space})
spec = gym_wrapper.spec_from_gym_space(
dict_space, simplify_box_bounds=False)
self.assertEqual((2,), spec['box1'].shape)
self.assertEqual((2,), spec['box2'].shape)
self.assertEqual(np.float32, spec['box1'].dtype)
self.assertEqual(np.float32, spec['box2'].dtype)
self.assertEqual('box1', spec['box1'].name)
self.assertEqual('box2', spec['box2'].name)
np.testing.assert_array_equal(np.array([-1, -1], dtype=np.int),
spec['box1'].minimum)
np.testing.assert_array_equal(np.array([1, 1], dtype=np.int),
spec['box1'].maximum)
np.testing.assert_array_equal(np.array([-1, -1], dtype=np.int),
spec['box2'].minimum)
np.testing.assert_array_equal(np.array([1, 1], dtype=np.int),
spec['box2'].maximum)
示例4: test_wrapped_cartpole_specs
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_wrapped_cartpole_specs(self):
# Note we use spec.make on gym envs to avoid getting a TimeLimit wrapper on
# the environment.
cartpole_env = gym.spec('CartPole-v1').make()
env = gym_wrapper.GymWrapper(cartpole_env)
action_spec = env.action_spec()
self.assertEqual((), action_spec.shape)
self.assertEqual(0, action_spec.minimum)
self.assertEqual(1, action_spec.maximum)
observation_spec = env.observation_spec()
self.assertEqual((4,), observation_spec.shape)
self.assertEqual(np.float32, observation_spec.dtype)
high = np.array([
4.8,
np.finfo(np.float32).max, 2 / 15.0 * math.pi,
np.finfo(np.float32).max
])
np.testing.assert_array_almost_equal(-high, observation_spec.minimum)
np.testing.assert_array_almost_equal(high, observation_spec.maximum)
示例5: test_limit_duration_wrapped_env_forwards_calls
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_limit_duration_wrapped_env_forwards_calls(self):
cartpole_env = gym.spec('CartPole-v1').make()
env = gym_wrapper.GymWrapper(cartpole_env)
env = wrappers.TimeLimit(env, 10)
action_spec = env.action_spec()
self.assertEqual((), action_spec.shape)
self.assertEqual(0, action_spec.minimum)
self.assertEqual(1, action_spec.maximum)
observation_spec = env.observation_spec()
self.assertEqual((4,), observation_spec.shape)
high = np.array([
4.8,
np.finfo(np.float32).max, 2 / 15.0 * math.pi,
np.finfo(np.float32).max
])
np.testing.assert_array_almost_equal(-high, observation_spec.minimum)
np.testing.assert_array_almost_equal(high, observation_spec.maximum)
示例6: test_with_varying_observation_specs
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_with_varying_observation_specs(
self, observation_keys, observation_shapes, observation_dtypes):
"""Vary the observation spec and step the environment."""
obs_spec = collections.OrderedDict()
for idx, key in enumerate(observation_keys):
obs_spec[key] = array_spec.ArraySpec(observation_shapes[idx],
observation_dtypes)
action_spec = array_spec.BoundedArraySpec((), np.int32, -10, 10)
env = random_py_environment.RandomPyEnvironment(
obs_spec, action_spec=action_spec)
env = wrappers.FlattenObservationsWrapper(env)
time_step = env.step(
array_spec.sample_bounded_spec(action_spec, np.random.RandomState()))
# Check that all observations returned from environment is packed into one
# dimension.
expected_shape = self._get_expected_shape(obs_spec, obs_spec.keys())
self.assertEqual(time_step.observation.shape, expected_shape)
self.assertEqual(
env.observation_spec(),
array_spec.ArraySpec(
shape=expected_shape,
dtype=observation_dtypes,
name='packed_observations'))
示例7: test_batch_env
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_batch_env(self):
"""Vary the observation spec and step the environment."""
obs_spec = collections.OrderedDict({
'obs1': array_spec.ArraySpec((1,), np.int32),
'obs2': array_spec.ArraySpec((2,), np.int32),
})
action_spec = array_spec.BoundedArraySpec((), np.int32, -10, 10)
# Generate a randomy py environment with batch size.
batch_size = 4
env = random_py_environment.RandomPyEnvironment(
obs_spec, action_spec=action_spec, batch_size=batch_size)
env = wrappers.FlattenObservationsWrapper(env)
time_step = env.step(
array_spec.sample_bounded_spec(action_spec, np.random.RandomState()))
expected_shape = self._get_expected_shape(obs_spec, obs_spec.keys())
self.assertEqual(time_step.observation.shape,
(batch_size, expected_shape[0]))
self.assertEqual(
env.observation_spec(),
array_spec.ArraySpec(
shape=expected_shape, dtype=np.int32, name='packed_observations'))
示例8: __init__
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def __init__(self, env_id):
self.worker_n = None
# Pull the relevant info from a transient env instance
self.spec = gym.spec(env_id)
env = self.spec.make()
current_metadata = self.metadata
self.metadata = env.metadata.copy()
self.metadata.update(current_metadata)
self.action_space = env.action_space
self.observation_space = env.observation_space
self.reward_range = env.reward_range
示例9: __init__
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def __init__(self, gym_core_id, fps=60, vnc_pixels=True):
super(GymCoreSyncEnv, self).__init__(gym_core_id, fps=fps)
# Metadata has already been cloned
self.metadata['semantics.async'] = False
self.gym_core_id = gym_core_id
self.vnc_pixels = vnc_pixels
if not vnc_pixels:
self._core_env = gym.spec(gym_core_id).make()
else:
self._core_env = None
示例10: WrappedGymCoreEnv
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def WrappedGymCoreEnv(gym_core_id, fps=None, rewarder_observation=False):
# Don't need to store the ID on the instance; it'll be retrieved
# directly from the spec
env = wrap(envs.VNCEnv(fps=fps))
if rewarder_observation:
env = GymCoreObservation(env, gym_core_id=gym_core_id)
return env
示例11: WrappedGymCoreSyncEnv
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def WrappedGymCoreSyncEnv(gym_core_id, fps=60, rewarder_observation=False):
spec = gym.spec(gym_core_id)
env = gym_core_sync.GymCoreSync(BlockingReset(wrap(envs.VNCEnv(fps=fps))))
if rewarder_observation:
env = GymCoreObservation(env, gym_core_id=gym_core_id)
elif spec._entry_point.startswith('gym.envs.atari:'):
env = CropAtari(env)
return env
示例12: test_nice_vnc_semantics_match
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def test_nice_vnc_semantics_match(spec, matcher, wrapper):
# Check that when running over VNC or using the raw environment,
# semantics match exactly.
gym.undo_logger_setup()
logging.getLogger().setLevel(logging.INFO)
spaces.seed(0)
vnc_env = spec.make()
if vnc_env.metadata.get('configure.required', False):
vnc_env.configure(remotes=1)
vnc_env = wrapper(vnc_env)
vnc_env = wrappers.Unvectorize(vnc_env)
env = gym.make(spec._kwargs['gym_core_id'])
env.seed(0)
vnc_env.seed(0)
# Check that reset observations work
reset(matcher, env, vnc_env, stage='initial reset')
# Check a full rollout
rollout(matcher, env, vnc_env, timestep_limit=50, stage='50 steps')
# Reset to start a new episode
reset(matcher, env, vnc_env, stage='reset to new episode')
# Check that a step into the next episode works
rollout(matcher, env, vnc_env, timestep_limit=1, stage='1 step in new episode')
# Make sure env can be reseeded
env.seed(1)
vnc_env.seed(1)
reset(matcher, env, vnc_env, 'reseeded reset')
rollout(matcher, env, vnc_env, timestep_limit=1, stage='reseeded step')
示例13: create_env
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def create_env(env_id, client_id, remotes, **kwargs):
spec = gym.spec(env_id)
if spec.tags.get('flashgames', False):
return create_flash_env(env_id, client_id, remotes, **kwargs)
elif spec.tags.get('atari', False) and spec.tags.get('vnc', False):
return create_vncatari_env(env_id, client_id, remotes, **kwargs)
else:
# Assume atari.
assert "." not in env_id # universe environments have dots in names.
return create_atari_env(env_id)
示例14: __init__
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def __init__(self, args, task_q, result_q, actor_id, monitor, pms, net_class):
multiprocessing.Process.__init__(self)
self.actor_id = actor_id
self.task_q = task_q
self.result_q = result_q
self.args = args
self.monitor = monitor
self.pms = pms
self.net_class = net_class
# pms.max_path_length = gym.spec(args.environment_name).timestep_limit
示例15: __init__
# 需要导入模块: import gym [as 别名]
# 或者: from gym import spec [as 别名]
def __init__(self, args, task_q, result_q, actor_id, monitor, pms, net_class, env_class):
multiprocessing.Process.__init__(self)
self.actor_id = actor_id
self.task_q = task_q
self.result_q = result_q
self.args = args
self.monitor = monitor
self.pms = pms
self.net_class = net_class
self.env_class = env_class
# pms.max_path_length = gym.spec(args.environment_name).timestep_limit