<filename>OpenAI/baselines/ppo1/run_Pendulum-v0.py
#!/usr/bin/env python

from baselines.common import set_global_seeds, tf_util as U
from baselines import bench
import gym, logging
from baselines import logger

def train(env_id, num_timesteps, seed):
    from baselines.ppo1 import mlp_policy, pposgd_simple
    U.make_session(num_cpu=1).__enter__()
    set_global_seeds(seed)

    env = gym.make(env_id)

    def policy_fn(name, ob_space, ac_space):
        return mlp_policy.MlpPolicy(name=name, ob_space=ob_space, ac_space=ac_space, hid_size=64, num_hid_layers=2)
    
    env = bench.Monitor(env, "monitor.json")
    env.seed(seed)
    gym.logger.setLevel(logging.WARN)
    pposgd_simple.learn(env, policy_fn,
            max_timesteps=num_timesteps,
            timesteps_per_batch=2048,
            clip_param=0.2, entcoeff=0.0,
            optim_epochs=10, optim_stepsize=3e-4, optim_batchsize=64,
            gamma=0.95, lam=0.1,
            schedule='linear'
            )
    env.close()

def main():
    env_name = 'Pendulum-v0'
    train(env_name, num_timesteps=5e5, seed=0)

if __name__ == '__main__':
    main()


<filename>OpenAI/baselines/ppo1/run_Pendulum-v0.py
#!/usr/bin/env python

from baselines.common import set_global_seeds, tf_util as U
from baselines import bench
import gym, logging
from baselines import logger

def train(env_id, num_timesteps, seed):
    from baselines.ppo1 import mlp_policy, pposgd_simple
    U.make_session(num_cpu=1).__enter__()
    set_global_seeds(seed)

    env = gym.make(env_id)

    def policy_fn(name, ob_space, ac_space):
        return mlp_policy.MlpPolicy(name=name, ob_space=ob_space, ac_space=ac_space, hid_size=64, num_hid_layers=2)
    
    env = bench.Monitor(env, "monitor.json")
    env.seed(seed)
    gym.logger.setLevel(logging.WARN)
    pposgd_simple.learn(env, policy_fn,
            max_timesteps=num_timesteps,
            timesteps_per_batch=2048,
            clip_param=0.2, entcoeff=0.0,
            optim_epochs=10, optim_stepsize=3e-4, optim_batchsize=64,
            gamma=0.95, lam=0.1,
            schedule='linear'
            )
    env.close()

def main():
    env_name = 'Pendulum-v0'
    train(env_name, num_timesteps=5e5, seed=0)

if __name__ == '__main__':
    main()


#!/usr/bin/env python