def make_env(env_name): if env_name == "pistonball": env = pistonball_v0.parallel_env(max_frames=100) env = supersuit.resize_v0(env, 16, 16) env = supersuit.dtype_v0(env, np.float32) env = supersuit.normalize_obs_v0(env) return supersuit.flatten_v0(env) if env_name == "KAZ": env = knights_archers_zombies_v2.parallel_env(max_frames=100) env = supersuit.resize_v0(env, 32, 32) env = supersuit.dtype_v0(env, np.float32) env = supersuit.normalize_obs_v0(env) return supersuit.flatten_v0(env) if env_name == "pursuit": env = pursuit_v1.parallel_env(max_frames=100) env = supersuit.resize_v0(env, 32, 32) return supersuit.flatten_v0(env) elif env_name == "waterworld": return waterworld_v1.parallel_env(max_frames=100) elif env_name == "multiwalker": return multiwalker_v3.parallel_env(max_frames=100) else: raise RuntimeError("bad environment name")
def env_creator(args): env = env_constr.env( ) #killable_knights=False, killable_archers=False) resize_size = 84 if model == None else 32 env = supersuit.resize_v0(env, resize_size, resize_size, linear_interp=True) env = supersuit.color_reduction_v0(env) env = supersuit.pad_action_space_v0(env) env = supersuit.pad_observations_v0(env) # env = supersuit.frame_stack_v0(env,2) env = supersuit.dtype_v0(env, np.float32) env = supersuit.normalize_obs_v0(env) if model == "MLPModelV2": env = supersuit.flatten_v0(env) env = PettingZooEnv(env) return env
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}"
def new_continuous_dummy(): base_act_spaces = Box(low=np.float32(0.0), high=np.float32(10.0), shape=[3]) return DummyEnv(base_obs, base_obs_space, base_act_spaces) def new_dummy(): return DummyEnv(base_obs, base_obs_space, base_act_spaces) 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 = simple_world_comm_v2.parallel_env() wrapped_env = pad_action_space_v0(_env) parallel_test.parallel_play_test(wrapped_env) wrappers = [ supersuit.color_reduction_v0(knights_archers_zombies_v4.env(), "R"), supersuit.resize_v0(dtype_v0(knights_archers_zombies_v4.env(), np.uint8), x_size=5, y_size=10), supersuit.resize_v0(dtype_v0(knights_archers_zombies_v4.env(), np.uint8), x_size=5, y_size=10, linear_interp=True), supersuit.dtype_v0(knights_archers_zombies_v4.env(), np.int32), supersuit.flatten_v0(knights_archers_zombies_v4.env()), supersuit.reshape_v0(knights_archers_zombies_v4.env(), (512 * 512, 3)), supersuit.normalize_obs_v0(dtype_v0(knights_archers_zombies_v4.env(), 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)),
def env_creator(args): env = game_env.env() env = flatten_v0(env) return env
def env_creator(args): env = game_env.env() if env_name == 'curriculum': env = cyclically_expansive_learning(env, [(0,1*8), (10000000,2*8), (30000000,3*8), (50000000,8*8)]) env = flatten_v0(env) return env
import numpy as np from pettingzoo.test import api_test, seed_test, parallel_test from pettingzoo.test.example_envs import ( generated_agents_parallel_v0, generated_agents_env_v0, ) import supersuit from supersuit import dtype_v0 import pytest wrappers = [ supersuit.dtype_v0(generated_agents_parallel_v0.env(), np.int32), 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), ]