()
CLI interface to bootstrap taining
CLI interface to bootstrap taining
CLI interface to bootstrap taining
def main():
    '''CLI interface to bootstrap taining'''
    parser = argparse.ArgumentParser(description="Playground Flags.")
    parser.add_argument("--game", default="pommerman", help="Game to choose.")
    parser.add_argument(
        "--config",
        default="PommeFFACompetition-v0",
        help="Configuration to execute. See env_ids in "
        "configs.py for options.")
    parser.add_argument(
        "--agents",
        default="tensorforce::ppo,test::agents.SimpleAgent,"
        "test::agents.SimpleAgent,test::agents.SimpleAgent",
        help="Comma delineated list of agent types and docker "
        "locations to run the agents.")
    parser.add_argument(
        "--agent_env_vars",
        help="Comma delineated list of agent environment vars "
        "to pass to Docker. This is only for the Docker Agent."
        " An example is '0:foo=bar:baz=lar,3:foo=lam', which "
        "would send two arguments to Docker Agent 0 and one to"
        " Docker Agent 3.",
        default="")
    parser.add_argument(
        "--record_pngs_dir",
        default=None,
        help="Directory to record the PNGs of the game. "
        "Doesn't record if None.")
    parser.add_argument(
        "--record_json_dir",
        default=None,
        help="Directory to record the JSON representations of "
        "the game. Doesn't record if None.")
    parser.add_argument(
        "--render",
        default=False,
        action='store_true',
        help="Whether to render or not. Defaults to False.")
    parser.add_argument(
        "--game_state_file",
        default=None,
        help="File from which to load game state. Defaults to "
        "None.")
    args = parser.parse_args()

    config = args.config
    record_pngs_dir = args.record_pngs_dir
    record_json_dir = args.record_json_dir
    agent_env_vars = args.agent_env_vars
    game_state_file = args.game_state_file

    # TODO: After https://github.com/MultiAgentLearning/playground/pull/40
    #       this is still missing the docker_env_dict parsing for the agents.
    agents = [
        helpers.make_agent_from_string(agent_string, agent_id + 1000)
        for agent_id, agent_string in enumerate(args.agents.split(","))
    ]

    env = make(config, agents, game_state_file)
    training_agent = None

    for agent in agents:
        if type(agent) == TensorForceAgent:
            training_agent = agent
            env.set_training_agent(agent.agent_id)
            break

    if args.record_pngs_dir:
        assert not os.path.isdir(args.record_pngs_dir)
        os.makedirs(args.record_pngs_dir)
    if args.record_json_dir:
        assert not os.path.isdir(args.record_json_dir)
        os.makedirs(args.record_json_dir)

    # Create a Proximal Policy Optimization agent
    agent = training_agent.initialize(env)

    atexit.register(functools.partial(clean_up_agents, agents))
    wrapped_env = WrappedEnv(env, visualize=args.render)
    runner = Runner(agent=agent, environment=wrapped_env)
    runner.run(episodes=10, max_episode_timesteps=2000)
    print("Stats: ", runner.episode_rewards, runner.episode_timesteps,
          runner.episode_times)

    try:
        runner.close()
    except AttributeError as e:
        pass
def main ( ) : parser = argparse . ArgumentParser ( description = "Playground Flags." ) parser . add_argument ( "--game" , default = "pommerman" , help = "Game to choose." ) parser . add_argument ( "--config" , default = "PommeFFACompetition-v0" , help = "Configuration to execute. See env_ids in " "configs.py for options." ) parser . add_argument ( "--agents" , default = "tensorforce::ppo,test::agents.SimpleAgent," "test::agents.SimpleAgent,test::agents.SimpleAgent" , help = "Comma delineated list of agent types and docker " "locations to run the agents." ) parser . add_argument ( "--agent_env_vars" , help = "Comma delineated list of agent environment vars " "to pass to Docker. This is only for the Docker Agent." " An example is '0:foo=bar:baz=lar,3:foo=lam', which " "would send two arguments to Docker Agent 0 and one to" " Docker Agent 3." , default = "" ) parser . add_argument ( "--record_pngs_dir" , default = None , help = "Directory to record the PNGs of the game. " "Doesn't record if None." ) parser . add_argument ( "--record_json_dir" , default = None , help = "Directory to record the JSON representations of " "the game. Doesn't record if None." ) parser . add_argument ( "--render" , default = False , action = 'store_true' , help = "Whether to render or not. Defaults to False." ) parser . add_argument ( "--game_state_file" , default = None , help = "File from which to load game state. Defaults to " "None." ) args = parser . parse_args ( ) config = args . config record_pngs_dir = args . record_pngs_dir record_json_dir = args . record_json_dir agent_env_vars = args . agent_env_vars game_state_file = args . game_state_file # TODO: After https://github.com/MultiAgentLearning/playground/pull/40 #       this is still missing the docker_env_dict parsing for the agents. agents = [ helpers . make_agent_from_string ( agent_string , agent_id + 1000 ) for agent_id , agent_string in enumerate ( args . agents . split ( "," ) ) ] env = make ( config , agents , game_state_file ) training_agent = None for agent in agents : if type ( agent ) == TensorForceAgent : training_agent = agent env . set_training_agent ( agent . agent_id ) break if args . record_pngs_dir : assert not os . path . isdir ( args . record_pngs_dir ) os . makedirs ( args . record_pngs_dir ) if args . record_json_dir : assert not os . path . isdir ( args . record_json_dir ) os . makedirs ( args . record_json_dir ) # Create a Proximal Policy Optimization agent agent = training_agent . initialize ( env ) atexit . register ( functools . partial ( clean_up_agents , agents ) ) wrapped_env = WrappedEnv ( env , visualize = args . render ) runner = Runner ( agent = agent , environment = wrapped_env ) runner . run ( episodes = 10 , max_episode_timesteps = 2000 ) print ( "Stats: " , runner . episode_rewards , runner . episode_timesteps , runner . episode_times ) try : runner . close ( ) except AttributeError as e : pass