def create_registry(): reg = UnityEnvRegistry() entry = RemoteRegistryEntry( BASIC_ID, 0.0, "Description", "https://storage.googleapis.com/mlagents-test-environments/1.0.0/linux/Basic.zip", "https://storage.googleapis.com/mlagents-test-environments/1.0.0/darwin/Basic.zip", "https://storage.googleapis.com/mlagents-test-environments/1.0.0/windows/Basic.zip", ) reg.register(entry) return reg
def __init__( self, environment_filename=None, worker_id=0, retro=True, timeout_wait=30, realtime_mode=False, config=None, greyscale=False, ): """ Arguments: environment_filename: The file path to the Unity executable. Does not require the extension. docker_training: Whether this is running within a docker environment and should use a virtual frame buffer (xvfb). worker_id: The index of the worker in the case where multiple environments are running. Each environment reserves port (5005 + worker_id) for communication with the Unity executable. retro: Resize visual observation to 84x84 (int8) and flattens action space. timeout_wait: Time for python interface to wait for environment to connect. realtime_mode: Whether to render the environment window image and run environment at realtime. """ self.reset_parameters = EnvironmentParametersChannel() self.engine_config = EngineConfigurationChannel() if environment_filename is None: registry = UnityEnvRegistry() registry.register_from_yaml(self._REGISTRY_YAML) self._env = registry["ObstacleTower"].make( worker_id=worker_id, timeout_wait=timeout_wait, side_channels=[self.reset_parameters, self.engine_config]) else: self._env = UnityEnvironment( environment_filename, worker_id, timeout_wait=timeout_wait, side_channels=[self.reset_parameters, self.engine_config], ) if realtime_mode: self.engine_config.set_configuration_parameters(time_scale=1.0) else: self.engine_config.set_configuration_parameters(time_scale=20.0) self._env.reset() behavior_name = list(self._env.behavior_specs)[0] split_name = behavior_name.split("-v") if len(split_name) == 2 and split_name[0] == "ObstacleTowerAgent": self.name, self.version = split_name else: raise UnityGymException( "Attempting to launch non-Obstacle Tower environment") if self.version not in self.ALLOWED_VERSIONS: raise UnityGymException( "Invalid Obstacle Tower version. Your build is v" + self.version + " but only the following versions are compatible with this gym: " + str(self.ALLOWED_VERSIONS)) self.visual_obs = None self._current_state = None self._n_agents = None self._flattener = None self._greyscale = greyscale # Environment reset parameters self._seed = None self._floor = None self.realtime_mode = realtime_mode self.game_over = False # Hidden flag used by Atari environments to determine if the game is over self.retro = retro if config != None: self.config = config else: self.config = None flatten_branched = self.retro uint8_visual = self.retro # Check behavior configuration if len(self._env.behavior_specs) != 1: raise UnityGymException( "There can only be one agent in this environment " "if it is wrapped in a gym.") self.behavior_name = behavior_name behavior_spec = self._env.behavior_specs[behavior_name] if len(behavior_spec) < 2: raise UnityGymException( "Environment provides too few observations.") self.uint8_visual = uint8_visual # Check for number of agents in scene. initial_info, terminal_info = self._env.get_steps(behavior_name) self._check_agents(len(initial_info)) # Set observation and action spaces if len(behavior_spec.action_shape) == 1: self._action_space = spaces.Discrete(behavior_spec.action_shape[0]) else: if flatten_branched: self._flattener = ActionFlattener(behavior_spec.action_shape) self._action_space = self._flattener.action_space else: self._action_space = spaces.MultiDiscrete( behavior_spec.action_shape) if self._greyscale: depth = 1 else: depth = 3 image_space_max = 1.0 image_space_dtype = np.float32 camera_height = behavior_spec.observation_shapes[0][0] camera_width = behavior_spec.observation_shapes[0][1] if self.retro: image_space_max = 255 image_space_dtype = np.uint8 camera_height = 84 camera_width = 84 image_space = spaces.Box( 0, image_space_max, dtype=image_space_dtype, shape=(camera_height, camera_width, depth), ) if self.retro: self._observation_space = image_space else: max_float = np.finfo(np.float32).max keys_space = spaces.Discrete(5) time_remaining_space = spaces.Box(low=0.0, high=max_float, shape=(1, ), dtype=np.float32) floor_space = spaces.Discrete(9999) self._observation_space = spaces.Tuple( (image_space, keys_space, time_remaining_space, floor_space))