本文整理匯總了Python中universe.wrappers.Unvectorize方法的典型用法代碼示例。如果您正苦於以下問題:Python wrappers.Unvectorize方法的具體用法?Python wrappers.Unvectorize怎麽用?Python wrappers.Unvectorize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類universe.wrappers
的用法示例。
在下文中一共展示了wrappers.Unvectorize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_flash_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_flash_env(env_id, client_id, remotes, **_):
env = gym.make(env_id)
env = Vision(env)
env = Logger(env)
env = BlockingReset(env)
reg = universe.runtime_spec('flashgames').server_registry
height = reg[env_id]["height"]
width = reg[env_id]["width"]
env = CropScreen(env, height, width, 84, 18)
env = FlashRescale(env)
keys = ['left', 'right', 'up', 'down', 'x']
env = DiscreteToFixedKeysVNCActions(env, keys)
env = EpisodeID(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
env.configure(fps=5.0, remotes=remotes, start_timeout=15 * 60, client_id=client_id,
vnc_driver='go', vnc_kwargs={
'encoding': 'tight', 'compress_level': 0,
'fine_quality_level': 50, 'subsample_level': 3})
return env
示例2: test_boundary_simple
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_boundary_simple():
env = gym.make('flashgames.DuskDrive-v0')
env = wrappers.Unvectorize(env)
env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
env.reset()
rewarder_client = get_rewarder_client(env)
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 1, 'done': False, 'info': {}}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 2, 'done': True, 'info': {}}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})
# We have reward of 3 for episode 1, and episode 2 should now be resetting
observation, reward, done, info = env.step([])
assert info['mask.masked.observation']
assert info['mask.masked.action']
assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (3, True, 'resetting', '2')
示例3: test_smoke
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_smoke(env_id):
"""Check that environments start up without errors and that we can extract rewards and observations"""
gym.undo_logger_setup()
logging.getLogger().setLevel(logging.INFO)
env = gym.make(env_id)
if env.metadata.get('configure.required', False):
if os.environ.get('FORCE_LATEST_UNIVERSE_DOCKER_RUNTIMES'): # Used to test universe-envs in CI
configure_with_latest_docker_runtime_tag(env)
else:
env.configure(remotes=1)
env = wrappers.Unvectorize(env)
env.reset()
_rollout(env, timestep_limit=60*30) # Check a rollout
示例4: create_vncatari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_vncatari_env(env_id, client_id, remotes, **_):
env = gym.make(env_id)
env = Vision(env)
env = Logger(env)
env = BlockingReset(env)
env = GymCoreAction(env)
env = AtariRescale42x42(env)
env = EpisodeID(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
logger.info('Connecting to remotes: %s', remotes)
fps = env.metadata['video.frames_per_second']
env.configure(remotes=remotes, start_timeout=15 * 60, fps=fps, client_id=client_id)
return env
示例5: create_atari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
env = gym.make(env_id)
env = Vectorize(env)
env = AtariRescale42x42(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
return env
示例6: create_atari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
env = gym.make(env_id)
if len(env.observation_space.shape) > 1:
print('Preprocessing env')
env = Vectorize(env)
env = AtariRescale42x42(env)
env = NormalizedEnv(env)
env = Unvectorize(env)
else:
print('No preprocessing because env is too small')
return env
示例7: test_vnc_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_vnc_env():
env = gym.make('flashgames.DuskDrive-v0')
env = wrappers.Unvectorize(env)
env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
env.reset()
rewarder_client = get_rewarder_client(env)
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})
observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
assert (observation, reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (None, 0, False, None, None)
rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})
observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
assert (observation, reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (None, 0, False, 'resetting', '1')
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 10, 'done': False, 'info': {}}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 15, 'done': False, 'info': {}}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.env.reward', {'reward': -3, 'done': False, 'info': {}}, {'episode_id': '1'})
observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
assert sorted(observation.keys()) == ['text', 'vision']
assert observation['text'] == []
assert observation['vision'].shape == (768, 1024, 3)
assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (22, False, 'running', '1')
assert info['stats.reward.count'] == 3
示例8: test_boundary_multiple
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_boundary_multiple():
env = gym.make('flashgames.DuskDrive-v0')
env = wrappers.Unvectorize(env)
env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
env.reset()
rewarder_client = get_rewarder_client(env)
# episode 2
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})
rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '2'})
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '2'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 2, 'done': True, 'info': {}}, {'episode_id': '2'})
# episode 3
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '3'})
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '3'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 3, 'done': True, 'info': {}}, {'episode_id': '3'})
# episode 4
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '4'})
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '4'})
rewarder_client._manual_recv('v0.env.reward', {'reward': 4, 'done': False, 'info': {}}, {'episode_id': '4'})
observation, reward, done, info = env.step([])
assert not info.get('mask.masked.observation')
assert not info.get('mask.masked.action')
assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (2, True, 'running', '4')
assert (info['env_status.complete.env_state'], info['env_status.complete.episode_id']) == ('running', '2')
observation, reward, done, info = env.step([])
assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (4, False, 'running', '4')
示例9: test_peek
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_peek():
env = gym.make('flashgames.DuskDrive-v0')
env = wrappers.Unvectorize(env)
env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
env.reset()
rewarder_client = get_rewarder_client(env)
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})
rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})
observation, reward, done, info = env.step([spaces.PeekReward])
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})
observation, reward, done, info = env.step([spaces.PeekReward])
assert info['mask.masked.observation']
assert info['mask.masked.action']
assert info['env_status.episode_id'] == '1'
assert info['env_status.env_state'] == 'resetting'
assert info['env_status.peek.episode_id'] == '2'
assert info['env_status.peek.env_state'] == 'resetting'
rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '2'})
observation, reward, done, info = env.step([spaces.PeekReward])
assert not info.get('mask.masked.observation')
assert not info.get('mask.masked.action')
assert info['env_status.episode_id'] == '1'
assert info['env_status.env_state'] == 'resetting'
assert info['env_status.peek.episode_id'] == '2'
assert info['env_status.peek.env_state'] == 'running'
示例10: make_environment
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def make_environment(name, **args):
"""Make an environment of a given name, possibly using extra arguments."""
env = environment_registry.get(name, Environment)
if name in environment_registry:
env = env(**args)
else:
env = env(name, **args)
if "atari.atari_env" in env.unwrapped.__module__:
to_dict = env.to_dict
env = Vectorize(env)
env = AtariRescale42x42(env)
env = Unvectorize(env)
env.to_dict = to_dict
return env
示例11: create_flash_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_flash_env(env_id, client_id, remotes, **_):
env = gym.make(env_id)
env = Vision(env)
env = Logger(env)
env = BlockingReset(env)
reg = universe.runtime_spec('flashgames').server_registry
height = reg[env_id]["height"]
width = reg[env_id]["width"]
env = CropScreen(env, height, width, 84, 18)
env = FlashRescale(env)
keys = ['left', 'right', 'up', 'down', 'x']
if env_id == 'flashgames.NeonRace-v0':
# Better key space for this game.
keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
logger.info('create_flash_env(%s): keys=%s', env_id, keys)
env = DiscreteToFixedKeysVNCActions(env, keys)
env = EpisodeID(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
env.configure(fps=5.0, remotes=remotes, start_timeout=15 * 60, client_id=client_id,
vnc_driver='go', vnc_kwargs={
'encoding': 'tight', 'compress_level': 0,
'fine_quality_level': 50, 'subsample_level': 3})
return env
示例12: create_atari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
env = gym.make(env_id)
if len(env.observation_space.shape) > 1:
env = Vectorize(env)
env = Unvectorize(env)
return env
# process each frame
示例13: create_mario
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_mario(env_id, client_id, envWrap=True, record=False, outdir=None,
noLifeReward=False, acRepeat=0, **_):
import ppaquette_gym_super_mario
from ppaquette_gym_super_mario import wrappers
if '-v' in env_id.lower():
env_id = 'ppaquette/' + env_id
else:
env_id = 'ppaquette/SuperMarioBros-1-1-v0' # shape: (224,256,3)=(h,w,c)
# Mario workaround: Simultaneously launching multiple vizdoom processes makes program stuck,
# so use the global lock in multi-threading/multi-processing
# see: https://github.com/ppaquette/gym-super-mario/tree/master/ppaquette_gym_super_mario
client_id = int(client_id)
time.sleep(client_id * 50)
env = gym.make(env_id)
modewrapper = wrappers.SetPlayingMode('algo')
acwrapper = wrappers.ToDiscrete()
env = modewrapper(acwrapper(env))
env = env_wrapper.MarioEnv(env)
if record and outdir is not None:
env = gym.wrappers.Monitor(env, outdir, force=True)
if envWrap:
frame_skip = acRepeat if acRepeat>0 else 6
fshape = (42, 42)
env.seed(None)
if noLifeReward:
env = env_wrapper.NoNegativeRewardEnv(env)
env = env_wrapper.BufferedObsEnv(env, skip=frame_skip, shape=fshape, maxFrames=False)
if frame_skip > 1:
env = env_wrapper.SkipEnv(env, skip=frame_skip)
elif noLifeReward:
env = env_wrapper.NoNegativeRewardEnv(env)
env = Vectorize(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
# env.close() # TODO: think about where to put env.close !
return env
示例14: create_atari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id, record=False, outdir=None, **_):
env = gym.make(env_id)
if record and outdir is not None:
env = gym.wrappers.Monitor(env, outdir, force=True)
env = Vectorize(env)
env = AtariRescale42x42(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
return env
示例15: create_atari_env
# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
env = gym.make(env_id)
env = Vectorize(env)
env = AtariRescale42x42(env)
env = DiagnosticsInfo(env)
env = Unvectorize(env)
env.runner = RunnerThread(env, 20)
return env