def test_arena_config(mock_yaml): arena_config = ArenaConfig(" ") assert len(arena_config.arenas) == 3 arena_config_proto = arena_config.to_proto() assert len(arena_config_proto.arenas) == 3
def test_reset_arena_config(mock_communicator, mock_launcher, mock_byte_channel, mock_yaml): mock_communicator.return_value = MockCommunicator(discrete_action=True, visual_inputs=0, num_agents=2, vec_obs_size=2) arena_config = ArenaConfig(" ") env = AnimalAIEnvironment( file_name=" ", n_arenas=2, arenas_configurations=arena_config, ) mock_byte_channel.assert_called_once() bytes_arg = bytes( arena_config.to_proto().SerializeToString(deterministic=True)) # we cannot call assert_called_with mock_byte_channel.assert_called_with(bytes_arg) batched_step_result = env.get_step_result("RealFakeBrain") spec = env.get_agent_group_spec("RealFakeBrain") env.close() assert isinstance(batched_step_result, BatchedStepResult) assert len(spec.observation_shapes) == len(batched_step_result.obs) n_agents = batched_step_result.n_agents() for shape, obs in zip(spec.observation_shapes, batched_step_result.obs): assert (n_agents, ) + shape == obs.shape
def reset(self, arenas_configurations: ArenaConfig = None) -> None: if arenas_configurations: arenas_configurations_proto = arenas_configurations.to_proto() arenas_configurations_proto_string = arenas_configurations_proto.SerializeToString( deterministic=True) self.arenas_parameters_side_channel.send_raw_data( bytearray(arenas_configurations_proto_string)) try: super().reset() except UnityTimeOutException as timeoutException: if self.play: pass else: raise timeoutException