<filename>maml_examples/oldLaunchers/trpo_r7dof.py
from sandbox.rocky.tf.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.normalized_env import normalize
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import ConjugateGradientOptimizer
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import FiniteDifferenceHvp
from sandbox.rocky.tf.policies.gaussian_mlp_policy import GaussianMLPPolicy
from sandbox.rocky.tf.envs.base import TfEnv
from rllab.misc.instrument import stub, run_experiment_lite
from rllab.envs.mujoco.half_cheetah_env_rand import HalfCheetahEnvRand
from maml_examples.r7dof_env_oracle import Reacher7DofMultitaskEnvOracle
from maml_examples.r7dof_env_vision_oracle import Reacher7DofVisionEnvOracle
from maml_examples.r7dof_vars import EXPERT_TRAJ_LOCATION_DICT, ENV_OPTIONS, R7DOF_GOALS_LOCATION, \
    default_r7dof_env_option
import pickle

#from rllab.envs.gym_env import GymEnv
#from gym.envs.mujoco import mujoco_env
import tensorflow as tf
from rllab.misc.mujoco_render import pusher

from rllab.misc.instrument import VariantGenerator, variant

import glob
import random
local = True

DOCKER_CODE_DIR = "/root/code/rllab/"
LOCAL_CODE_DIR = '/home/rosen/maml_rl/'
if local:
    DOCKER_CODE_DIR = LOCAL_CODE_DIR
    mode = 'local'
else:
    mode = 'ec2'

class VG(VariantGenerator):
    @variant
    def seed(self):
        # 1003 is pretraining policy 3.
        return [1000]
        #return range(1,101) #102)


variants = VG().variants()

env_option = default_r7dof_env_option

def run_task(v):
    env = TfEnv(normalize(Reacher7DofVisionEnvOracle(distractors=True)))
    # policy = GaussianMLPPolicy(
    #    name="policy",
    #    env_spec=env.spec,
    #    hidden_nonlinearity=tf.nn.relu,
    #    hidden_sizes=(256, 256),
    # )
    baseline = LinearFeatureBaseline(env_spec=env.spec)
    algo = TRPO(
        env=env,
        # policy=policy,
        policy=None,
        load_policy='/home/rosen/maml_rl/data/local/R7DOF-ET-E3.3/R7DOF_ET_E3.3_2018_08_27_16_39_26_0001/itr_-20.pkl',  # if you want to use this you need to comment out the definition of policy above
        baseline=baseline,
        batch_size=100*30,  # 400 * 200 we divide this by #envs on every iteration
        batch_size_expert_traj=2000*30,
        max_path_length=30,
        start_itr=-1,
        n_itr=5,  # actually last iteration number, not total iterations
        discount=0.99,
        step_size=0.01,  # 0.01
        force_batch_sampler=True,
        # optimizer=ConjugateGradientOptimizer(hvp_approach=FiniteDifferenceHvp(base_eps=1e-5)),
        action_noise_train=0.0,
        action_noise_test=0.0,
        make_video=True,
        save_img_obs=True,
        save_expert_traj_dir=EXPERT_TRAJ_LOCATION_DICT[env_option+".local_vision_2distr"],
        goals_pool_to_load=EXPERT_TRAJ_LOCATION_DICT[env_option+".local_vision_2distr"]+"goals_pool.pkl",
    )
    algo.train()

for v in variants:

    run_experiment_lite(
        #algo.train(),
        run_task,
        # Number of parallel workers for sampling
        n_parallel=1, #10,
        # Only keep the snapshot parameters for the last iteration
        snapshot_mode="gap",
        snapshot_gap=20,
        exp_prefix='R7DOF_ET_E3.3',
        python_command='python3',
        # Specifies the seed for the experiment. If this is not provided, a random seed
        # will be used
        seed=79,
        variant=v,
        # mode="ec2",
        # mode="local_docker",
        mode='local',
        sync_s3_pkl=True,
        # plot=True,
    )


<filename>maml_examples/oldLaunchers/trpo_r7dof.py
from sandbox.rocky.tf.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.normalized_env import normalize
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import ConjugateGradientOptimizer
from sandbox.rocky.tf.optimizers.conjugate_gradient_optimizer import FiniteDifferenceHvp
from sandbox.rocky.tf.policies.gaussian_mlp_policy import GaussianMLPPolicy
from sandbox.rocky.tf.envs.base import TfEnv
from rllab.misc.instrument import stub, run_experiment_lite
from rllab.envs.mujoco.half_cheetah_env_rand import HalfCheetahEnvRand
from maml_examples.r7dof_env_oracle import Reacher7DofMultitaskEnvOracle
from maml_examples.r7dof_env_vision_oracle import Reacher7DofVisionEnvOracle
from maml_examples.r7dof_vars import EXPERT_TRAJ_LOCATION_DICT, ENV_OPTIONS, R7DOF_GOALS_LOCATION, \
    default_r7dof_env_option
import pickle

#from rllab.envs.gym_env import GymEnv
#from gym.envs.mujoco import mujoco_env
import tensorflow as tf
from rllab.misc.mujoco_render import pusher

from rllab.misc.instrument import VariantGenerator, variant

import glob
import random
local = True

DOCKER_CODE_DIR = "/root/code/rllab/"
LOCAL_CODE_DIR = '/home/rosen/maml_rl/'
if local:
    DOCKER_CODE_DIR = LOCAL_CODE_DIR
    mode = 'local'
else:
    mode = 'ec2'

class VG(VariantGenerator):
    @variant
    def seed(self):
        # 1003 is pretraining policy 3.
        return [1000]
        #return range(1,101) #102)


variants = VG().variants()

env_option = default_r7dof_env_option

def run_task(v):
    env = TfEnv(normalize(Reacher7DofVisionEnvOracle(distractors=True)))
    # policy = GaussianMLPPolicy(
    #    name="policy",
    #    env_spec=env.spec,
    #    hidden_nonlinearity=tf.nn.relu,
    #    hidden_sizes=(256, 256),
    # )
    baseline = LinearFeatureBaseline(env_spec=env.spec)
    algo = TRPO(
        env=env,
        # policy=policy,
        policy=None,
        load_policy='/home/rosen/maml_rl/data/local/R7DOF-ET-E3.3/R7DOF_ET_E3.3_2018_08_27_16_39_26_0001/itr_-20.pkl',  # if you want to use this you need to comment out the definition of policy above
        baseline=baseline,
        batch_size=100*30,  # 400 * 200 we divide this by #envs on every iteration
        batch_size_expert_traj=2000*30,
        max_path_length=30,
        start_itr=-1,
        n_itr=5,  # actually last iteration number, not total iterations
        discount=0.99,
        step_size=0.01,  # 0.01
        force_batch_sampler=True,
        # optimizer=ConjugateGradientOptimizer(hvp_approach=FiniteDifferenceHvp(base_eps=1e-5)),
        action_noise_train=0.0,
        action_noise_test=0.0,
        make_video=True,
        save_img_obs=True,
        save_expert_traj_dir=EXPERT_TRAJ_LOCATION_DICT[env_option+".local_vision_2distr"],
        goals_pool_to_load=EXPERT_TRAJ_LOCATION_DICT[env_option+".local_vision_2distr"]+"goals_pool.pkl",
    )
    algo.train()

for v in variants:

    run_experiment_lite(
        #algo.train(),
        run_task,
        # Number of parallel workers for sampling
        n_parallel=1, #10,
        # Only keep the snapshot parameters for the last iteration
        snapshot_mode="gap",
        snapshot_gap=20,
        exp_prefix='R7DOF_ET_E3.3',
        python_command='python3',
        # Specifies the seed for the experiment. If this is not provided, a random seed
        # will be used
        seed=79,
        variant=v,
        # mode="ec2",
        # mode="local_docker",
        mode='local',
        sync_s3_pkl=True,
        # plot=True,
    )


#from rllab.envs.gym_env import GymEnv #from gym.envs.mujoco import mujoco_env # 1003 is pretraining policy 3. #return range(1,101) #102) # policy = GaussianMLPPolicy( #    name="policy", #    env_spec=env.spec, #    hidden_nonlinearity=tf.nn.relu, #    hidden_sizes=(256, 256), # ) # policy=policy, # if you want to use this you need to comment out the definition of policy above # 400 * 200 we divide this by #envs on every iteration # actually last iteration number, not total iterations # 0.01 # optimizer=ConjugateGradientOptimizer(hvp_approach=FiniteDifferenceHvp(base_eps=1e-5)), #algo.train(), # Number of parallel workers for sampling #10, # Only keep the snapshot parameters for the last iteration # Specifies the seed for the experiment. If this is not provided, a random seed # will be used # mode="ec2", # mode="local_docker", # plot=True,