def test_basic(): env = DummyParEnv(base_obs, base_obs_space, base_act_spaces) env = supersuit.delay_observations_v0(env, 4) env = supersuit.dtype_v0(env, np.uint8) orig_obs = env.reset() for i in range(10): action = {agent: env.action_spaces[agent].sample() for agent in env.agents} obs, rew, done, info = env.step(action)
def unwrapped_check(env): # image observations if isinstance(env.observation_space, spaces.Box): if ((env.observation_space.low.shape == 3) and (env.observation_space.low == 0).all() and (len(env.observation_space.shape[2]) == 3) and (env.observation_space.high == 255).all()): env = max_observation_v0(env, 2) env = color_reduction_v0(env, mode="full") env = normalize_obs_v0(env) # box action spaces if isinstance(env.action_space, spaces.Box): env = clip_actions_v0(env) env = scale_actions_v0(env, 0.5) # stackable observations if isinstance(env.observation_space, spaces.Box) or isinstance( env.observation_space, spaces.Discrete): env = frame_stack_v1(env, 2) # not discrete and not multibinary observations if not isinstance(env.observation_space, spaces.Discrete) and not isinstance( env.observation_space, spaces.MultiBinary): env = dtype_v0(env, np.float16) env = flatten_v0(env) env = frame_skip_v0(env, 2) # everything else env = clip_reward_v0(env, lower_bound=-1, upper_bound=1) env = delay_observations_v0(env, 2) env = sticky_actions_v0(env, 0.5) env = nan_random_v0(env) env = nan_zeros_v0(env) assert env.unwrapped.__class__ == DummyEnv, f"Failed to unwrap {env}"
def unwrapped_check(env): env.reset() agents = env.agents if image_observation(env, agents): env = max_observation_v0(env, 2) env = color_reduction_v0(env, mode="full") env = normalize_obs_v0(env) if box_action(env, agents): env = clip_actions_v0(env) env = scale_actions_v0(env, 0.5) if observation_homogenizable(env, agents): env = pad_observations_v0(env) env = frame_stack_v1(env, 2) env = agent_indicator_v0(env) env = black_death_v3(env) if (not_dict_observation(env, agents) and not_discrete_observation(env, agents) and not_multibinary_observation(env, agents)): env = dtype_v0(env, np.float16) env = flatten_v0(env) env = frame_skip_v0(env, 2) if action_homogenizable(env, agents): env = pad_action_space_v0(env) env = clip_reward_v0(env, lower_bound=-1, upper_bound=1) env = delay_observations_v0(env, 2) env = sticky_actions_v0(env, 0.5) env = nan_random_v0(env) env = nan_zeros_v0(env) assert env.unwrapped.__class__ == DummyEnv, f"Failed to unwrap {env}"
wrappers = [ supersuit.color_reduction_v0(new_dummy(), "R"), supersuit.resize_v0(dtype_v0(new_dummy(), np.uint8), x_size=5, y_size=10), supersuit.resize_v0(dtype_v0(new_dummy(), np.uint8), x_size=5, y_size=10, linear_interp=True), supersuit.dtype_v0(new_dummy(), np.int32), supersuit.flatten_v0(new_dummy()), supersuit.reshape_v0(new_dummy(), (64, 3)), supersuit.normalize_obs_v0(new_dummy(), env_min=-1, env_max=5.0), supersuit.frame_stack_v1(new_dummy(), 8), supersuit.reward_lambda_v0(new_dummy(), lambda x: x / 10), supersuit.clip_reward_v0(new_dummy()), supersuit.clip_actions_v0(new_continuous_dummy()), supersuit.frame_skip_v0(new_dummy(), 4), supersuit.frame_skip_v0(new_dummy(), (4, 6)), supersuit.sticky_actions_v0(new_dummy(), 0.75), supersuit.delay_observations_v0(new_dummy(), 1), ] @pytest.mark.parametrize("env", wrappers) def test_basic_wrappers(env): env.seed(5) obs = env.reset() act_space = env.action_space obs_space = env.observation_space assert obs_space.contains(obs) assert obs.dtype == obs_space.dtype for i in range(10): env.step(act_space.sample())
np.float32), env_min=-1, env_max=5.0), supersuit.frame_stack_v1(knights_archers_zombies_v4.env(), 8), supersuit.pad_observations_v0(knights_archers_zombies_v4.env()), supersuit.pad_action_space_v0(knights_archers_zombies_v4.env()), supersuit.black_death_v0(knights_archers_zombies_v4.env()), supersuit.agent_indicator_v0(knights_archers_zombies_v4.env(), True), supersuit.agent_indicator_v0(knights_archers_zombies_v4.env(), False), supersuit.reward_lambda_v0(knights_archers_zombies_v4.env(), lambda x: x / 10), supersuit.clip_reward_v0(knights_archers_zombies_v4.env()), supersuit.clip_actions_v0(prison_v2.env(continuous=True)), supersuit.frame_skip_v0(knights_archers_zombies_v4.env(), 4), supersuit.sticky_actions_v0(knights_archers_zombies_v4.env(), 0.75), supersuit.delay_observations_v0(knights_archers_zombies_v4.env(), 3), ] @pytest.mark.parametrize("env", wrappers) def test_pettingzoo_aec_api(env): api_test.api_test(env) parallel_wrappers = [ supersuit.frame_stack_v1(knights_archers_zombies_v4.parallel_env(), 8), supersuit.reward_lambda_v0(knights_archers_zombies_v4.parallel_env(), lambda x: x / 10), supersuit.delay_observations_v0(knights_archers_zombies_v4.parallel_env(), 3), supersuit.color_reduction_v0(knights_archers_zombies_v4.parallel_env(),
supersuit.flatten_v0(generated_agents_parallel_v0.env()), supersuit.normalize_obs_v0( dtype_v0(generated_agents_parallel_v0.env(), np.float32), env_min=-1, env_max=5.0, ), supersuit.frame_stack_v1(generated_agents_parallel_v0.env(), 8), supersuit.reward_lambda_v0(generated_agents_parallel_v0.env(), lambda x: x / 10), supersuit.clip_reward_v0(generated_agents_parallel_v0.env()), supersuit.nan_noop_v0(generated_agents_parallel_v0.env(), 0), supersuit.nan_zeros_v0(generated_agents_parallel_v0.env()), supersuit.nan_random_v0(generated_agents_parallel_v0.env()), supersuit.frame_skip_v0(generated_agents_parallel_v0.env(), 4), supersuit.sticky_actions_v0(generated_agents_parallel_v0.env(), 0.75), supersuit.delay_observations_v0(generated_agents_parallel_v0.env(), 3), supersuit.max_observation_v0(generated_agents_parallel_v0.env(), 3), ] @pytest.mark.parametrize("env", wrappers) def test_pettingzoo_aec_api_par_gen(env): api_test(env, num_cycles=50) wrappers = [ supersuit.dtype_v0(generated_agents_env_v0.env(), np.int32), supersuit.flatten_v0(generated_agents_env_v0.env()), supersuit.normalize_obs_v0(dtype_v0(generated_agents_env_v0.env(), np.float32), env_min=-1,
supersuit.frame_stack_v1(combined_arms_v6.env(), 8), supersuit.pad_observations_v0(simple_world_comm_v2.env()), supersuit.pad_action_space_v0(simple_world_comm_v2.env()), supersuit.black_death_v3(combined_arms_v6.env()), supersuit.agent_indicator_v0(knights_archers_zombies_v10.env(), True), supersuit.agent_indicator_v0(knights_archers_zombies_v10.env(), False), supersuit.reward_lambda_v0(knights_archers_zombies_v10.env(), lambda x: x / 10), supersuit.clip_reward_v0(combined_arms_v6.env()), supersuit.nan_noop_v0(knights_archers_zombies_v10.env(), 0), supersuit.nan_zeros_v0(knights_archers_zombies_v10.env()), supersuit.nan_random_v0(chess_v5.env()), supersuit.nan_random_v0(knights_archers_zombies_v10.env()), supersuit.frame_skip_v0(combined_arms_v6.env(), 4), supersuit.sticky_actions_v0(combined_arms_v6.env(), 0.75), supersuit.delay_observations_v0(combined_arms_v6.env(), 3), supersuit.max_observation_v0(knights_archers_zombies_v10.env(), 3), ] @pytest.mark.parametrize("env", wrappers) def test_pettingzoo_aec_api(env): api_test(env) parallel_wrappers = [ supersuit.frame_stack_v1(combined_arms_v6.parallel_env(), 8), supersuit.frame_stack_v1(simple_push_v2.parallel_env(), 8), supersuit.reward_lambda_v0(combined_arms_v6.parallel_env(), lambda x: x / 10), supersuit.delay_observations_v0(combined_arms_v6.parallel_env(), 3),