def assign_env(env_config):
    #print(env_config)
    print("worker index is {}".format(env_config.worker_index))
    if env_config.worker_index % 2 == 0:
        print('in even env')
        env = sonic_on_ray.make(game='Airstriker-Genesis', state='Level1')
    else:
        print('in odd env')
        env = sonic_on_ray.make(game='Airstriker-Genesis', state='Level1')

    return env
def assign_env(env_config):
    #print(env_config)
    print("worker index is {}".format(env_config.worker_index))
    if env_config.worker_index % 2 == 0:
        print('in even env')
        env = sonic_on_ray.make(game='BustAMove-Snes',
                                state='BustAMove.1pplay.Level10')
    else:
        print('in odd env')
        env = sonic_on_ray.make(game='BustAMove-Snes',
                                state='BustAMove.1pplay.Level40')

    return env
Beispiel #3
0
 def __init__(self, env_config):
     # pick actual env based on worker and env indexes
     #print("worker index is {}".format(env_config.worker_index))
     #print("testing vector_index {}".format(env_config.vector_index))
     #BustAMove.Challengeplay0
     challenge_level = env_config.worker_index % 5
     self.env = sonic_on_ray.make(game='BustAMove-Snes', state='BustAMove.Challengeplay{}'.format(challenge_level)) #BustAMove.1pplay.Level10
     self.action_space = self.env.action_space
     self.observation_space = self.env.observation_space
Beispiel #4
0
from ray.tune.registry import register_env
import sonic_on_ray
import random

env_name = 'bustamove_env'
# Note that the hyperparameters have been tuned for sonic, which can be used
# run by replacing the below function with:
#
#     register_env(env_name, lambda config: sonic_on_ray.make(
#                                game='SonicTheHedgehog-Genesis',
#                                state='GreenHillZone.Act1'))
#
# However, to try Sonic, you have to obtain the ROM yourself (see then
# instructions at https://github.com/openai/retro/blob/master/README.md).
register_env(
    env_name, lambda config: sonic_on_ray.make(game='ContraIII-Snes',
                                               state='level1.1player.easy'))
# env_name2 = 'bustamove_env2'
# register_env(env_name2,
#              lambda config: sonic_on_ray.make(game='BustAMove-Snes',
#                                               state='BustAMove.1pplay.Level1'))

ray.init()

run_experiments({
    'bustamove-ppo-random-search': {
        'run': 'PPO',
        'env': 'bustamove_env',
        'stop': {
            'timesteps_total': 200000
        },
        'repeat': 10,
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--save-checkpoint-dir',
                        help='Checkpoint dir',
                        default=None)
    parser.add_argument('--load-checkpoint',
                        help='Path to existing checkpoint created by _save',
                        default=None)
    parser.add_argument('--local', help='Use retro_contest.local.make')
    args = parser.parse_args()

    env_name = 'sonic_env'
    # Note that the hyperparameters have been tuned for sonic, which can be used

    if args.local:
        game = 'SonicTheHedgehog-Genesis'
        state = 'GreenHillZone.Act1'
        register_env(env_name,
                     lambda config: sonic_on_ray.make_local(game, state))

    else:
        register_env(env_name, lambda config: sonic_on_ray.make())

    ray.init()

    config = ppo.DEFAULT_CONFIG.copy()

    config.update({
        'timesteps_per_batch':
        40000,
        'min_steps_per_task':
        100,
        'num_workers':
        32,
        'gamma':
        0.99,
        'lambda':
        0.95,
        'clip_param':
        0.1,
        'num_sgd_iter':
        30,
        'sgd_batchsize':
        4096,
        'sgd_stepsize':
        5e-5,
        'use_gae':
        True,
        'horizon':
        4000,
        'devices': [
            '/gpu:0', '/gpu:1', '/gpu:2', '/gpu:3', '/gpu:4', '/gpu:5',
            '/gpu:6', 'gpu:7'
        ],
        'tf_session_args': {
            'gpu_options': {
                'allow_growth': True
            }
        }
    })

    alg = ppo.PPOAgent(config=config, env=env_name)
    print("Created a PSqO object")
    if args.load_checkpoint is not None:
        print("Trying to restore from checkpoint", args.load_checkpoint)
        alg.restore(args.load_checkpoint)
        print("Restored state from checkpoint:", args.load_checkpoint)

    #for i in range(10):
    while True:
        try:
            print("Starting to train")
            result = alg.train()
            print('result = {}'.format(result))

        except gre.GymRemoteError as e:
            print('exception', e)
Beispiel #6
0
#                                game='SonicTheHedgehog-Genesis',
#                                state='GreenHillZone.Act1'))
#
# However, to try Sonic, you have to obtain the ROM yourself (see then
# instructions at https://github.com/openai/retro/blob/master/README.md).
# register_env(env_name,
#              lambda config: sonic_on_ray.make(game='Airstriker-Genesis',
#                                               state='Level1'))

# register_env(env_name,
#              lambda config: sonic_on_ray.make(game='SonicTheHedgehog-Genesis',
#                                               state='GreenHillZone.Act1'))

register_env(
    env_name,
    lambda config: sonic_on_ray.make(game='BustAMove-Snes',
                                     state='BustAMove.1pplay.Level1'))

ray.init()

config = ppo.DEFAULT_CONFIG.copy()

config.update({
    #'timesteps_per_batch': 40000,
    'timesteps_per_batch': 8,
    #'min_steps_per_task': 100,
    #'num_workers': 32,
    'num_workers': 1,
    'gamma': 0.99,
    'lambda': 0.95,
    'clip_param': 0.1,
    'num_sgd_iter': 3,
Beispiel #7
0
if __name__ == '__main__':
    args = parser.parse_args()

    if not args.config:
        # Load configuration from file
        config_dir = os.path.dirname(args.checkpoint)
        config_path = os.path.join(config_dir, 'params.json')
        with open(config_path) as f:
            args.config = json.load(f)

    ray.init()

    env_name = 'sonic_env'
    register_env(
        env_name,
        lambda config: sonic_on_ray.make(game='SonicTheHedgehog-Genesis',
                                         state='GreenHillZone.Act1'))

    cls = get_agent_class(args.run)
    agent = cls(env=env_name, config=args.config)

    num_steps = int(args.steps)

    # This currently only works with PPO.
    env = agent.local_evaluator.env

    if args.out is not None:
        rollouts = []
    steps = 0
    while steps < (num_steps or steps + 1):
        if args.out is not None:
            rollout = []
Beispiel #8
0
import ray
from ray.rllib import ppo
from ray.tune.registry import register_env

env_name = 'sonic_env'
# Note that the hyperparameters have been tuned for sonic, which can be used
# run by replacing the below function with:
#
#     register_env(env_name, lambda config: sonic_on_ray.make(
#                                game='SonicTheHedgehog-Genesis',
#                                state='GreenHillZone.Act1'))
#
# However, to try Sonic, you have to obtain the ROM yourself (see then
# instructions at https://github.com/openai/retro/blob/master/README.md).
register_env(
    env_name, lambda config: sonic_on_ray.make(game='Airstriker-Genesis',
                                               state='Level1'))

ray.init()

config = ppo.DEFAULT_CONFIG.copy()

config.update({
    'timesteps_per_batch':
    40000,
    'min_steps_per_task':
    100,
    'num_workers':
    32,
    'gamma':
    0.99,
    'lambda':