def WrappedLabCoreSyncEnv(lab_core_id, fps=60, rewarder_observation=False): spec = lab.spec(lab_core_id) env = lab_core_sync.LabCoreSync(BlockingReset(wrap(envs.VNCEnv(fps=fps)))) if rewarder_observation: env = LabCoreObservation(env, lab_core_id=lab_core_id) elif spec._entry_point.startswith('lab.envs.atari:'): env = CropAtari(env) return env
def create_env(env_id, client_id, remotes, **kwargs): spec = lab.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 # institute environments have dots in names. return create_atari_env(env_id)
def __init__(self, lab_core_id, fps=60, vnc_pixels=True): super(LabCoreSyncEnv, self).__init__(lab_core_id, fps=fps) # Metadata has already been cloned self.metadata['semantics.async'] = False self.lab_core_id = lab_core_id self.vnc_pixels = vnc_pixels if not vnc_pixels: self._core_env = lab.spec(lab_core_id).make() else: self._core_env = None
def __init__(self, env_id): self.worker_n = None # Pull the relevant info from a transient env instance self.spec = lab.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
def __init__(self, env, lab_core_id=None): super(LabCoreObservation, self).__init__(env) if lab_core_id is None: # self.spec is None while inside of the make, so we need # to pass lab_core_id in explicitly there. This case will # be hit when instantiating by hand. lab_core_id = self.spec._kwargs['lab_core_id'] self._reward_n = None self._done_n = None self._info_n = None self._lab_core_env = lab.spec(lab_core_id).make()
def __init__(self, env, lab_core_id=None): super(LabCoreAction, self).__init__(env) if lab_core_id is None: # self.spec is None while inside of the make, so we need # to pass lab_core_id in explicitly there. This case will # be hit when instantiating by hand. lab_core_id = self.spec._kwargs['lab_core_id'] spec = lab.spec(lab_core_id) raw_action_space = lab_core_action_space(lab_core_id) self._actions = raw_action_space.actions self.action_space = lab_spaces.Discrete(len(self._actions)) if spec._entry_point.startswith('lab.envs.atari:'): self.key_state = translator.AtariKeyState(lab.make(lab_core_id)) else: self.key_state = None
def lab_core_action_space(lab_core_id): spec = lab.spec(lab_core_id) if spec.id == 'CartPole-v0': return spaces.Hardcoded([[spaces.KeyEvent.by_name('left', down=True)], [spaces.KeyEvent.by_name('left', down=False)]]) elif spec._entry_point.startswith('lab.envs.atari:'): actions = [] env = spec.make() for action in env.unwrapped.get_action_meanings(): z = 'FIRE' in action left = 'LEFT' in action right = 'RIGHT' in action up = 'UP' in action down = 'DOWN' in action translated = atari_vnc(up=up, down=down, left=left, right=right, z=z) actions.append(translated) return spaces.Hardcoded(actions) else: raise error.Error('Unsupported env type: {}'.format(spec.id))
assert vnc_info['stats.reward.count'] == 1 matcher.assert_match(obs, vnc_obs, { 'reward': reward, 'done': done }, stage=stage) count += 1 if done or (timestep_limit is not None and count >= timestep_limit): break # TODO: we should have auto-env spinup specs = [ (lab.spec('lab-core.PongDeterministicSync-v3'), AtariMatcher(), atari_vnc_wrapper), (lab.spec('lab-core.PitfallDeterministicSync-v3'), AtariMatcher(), atari_vnc_wrapper), # This test is still broken. Looks like we're not piping the seed # to the CartPole env behind VNC # (lab.spec('lab-core.CartPoleLowDSync-v0'), CartPoleLowDMatcher()) ] @pytest.mark.parametrize("spec,matcher,wrapper", specs) def test_nice_vnc_semantics_match(spec, matcher, wrapper): # Check that when running over VNC or using the raw environment, # semantics match exactly. lab.undo_logger_setup()