def make_env(i): env = gym.make(args.env) env = MultiMonitor(env, os.path.join(out_path, 'mon{:d}'.format(i)), allow_early_resets=True) env.seed(args.seed + 10 * i) return env
def test_multi_monitor(): """Smoke test for MultiMonitor.""" env = gym.make("aprl/IteratedMatchingPennies-v0") env.seed(42) with tempfile.TemporaryDirectory(prefix="test_multi_mon") as d: env = MultiMonitor(env, filename=os.path.join(d, "test")) for eps in range(5): env.reset() done = False while not done: a = env.action_space.sample() _, _, done, info = env.step(a) epinfo = info["episode"] assert set(epinfo.keys()) == {"r", "r0", "r1", "l", "t"}
def test_multi_monitor(): """Smoke test for MultiMonitor.""" env = gym.make('aprl/IteratedMatchingPennies-v0') env.seed(42) with tempfile.TemporaryDirectory(prefix='test_multi_mon') as d: env = MultiMonitor(env, filename=os.path.join(d, 'test')) for eps in range(5): env.reset() done = False while not done: a = env.action_space.sample() _, _, done, info = env.step(a) epinfo = info['episode'] assert set(epinfo.keys()) == {'r', 'r0', 'r1', 'l', 't'}
def make_env(env_name, seed, i, out_dir, our_idx=None, pre_wrapper=None, post_wrapper=None, agent_wrappers=None): multi_env = gym.make(env_name) if agent_wrappers is not None: for agent_id in agent_wrappers: multi_env.agents[agent_id] = agent_wrappers[agent_id]( multi_env.agents[agent_id]) if pre_wrapper is not None: multi_env = pre_wrapper(multi_env) if not isinstance(multi_env, MultiAgentEnv): multi_env = SingleToMulti(multi_env) multi_env.seed(seed + i) if out_dir is not None: mon_dir = osp.join(out_dir, 'mon') os.makedirs(mon_dir, exist_ok=True) multi_env = MultiMonitor(multi_env, osp.join(mon_dir, 'log{}'.format(i)), our_idx) if post_wrapper is not None: multi_env = post_wrapper(multi_env) return multi_env
def make_env( env_name, seed, i, out_dir, our_idx=None, pre_wrappers=None, post_wrappers=None, agent_wrappers=None, ): multi_env = gym.make(env_name) if agent_wrappers is not None: for agent_id in agent_wrappers: multi_env.agents[agent_id] = agent_wrappers[agent_id]( multi_env.agents[agent_id]) multi_env = _apply_wrappers(pre_wrappers, multi_env) if not hasattr(multi_env, "num_agents"): multi_env = SingleToMulti(multi_env) if out_dir is not None: mon_dir = osp.join(out_dir, "mon") os.makedirs(mon_dir, exist_ok=True) multi_env = MultiMonitor(multi_env, osp.join(mon_dir, "log{}".format(i)), our_idx) multi_env = _apply_wrappers(post_wrappers, multi_env) multi_env.seed(seed + i) return multi_env