Skip to content

Commit

Permalink
fix using gym mujoco
Browse files Browse the repository at this point in the history
  • Loading branch information
dementrock committed Oct 22, 2016
1 parent 7e7f0e7 commit 7b3a6ad
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
69 changes: 69 additions & 0 deletions examples/cluster_gym_mujoco_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.normalized_env import normalize
from sandbox.rocky.tf.envs.base import TfEnv
from sandbox.rocky.tf.policies.gaussian_mlp_policy import GaussianMLPPolicy
from sandbox.rocky.tf.algos.trpo import TRPO
from rllab.misc.instrument import stub, run_experiment_lite
from rllab.envs.gym_env import GymEnv
import sys

stub(globals())

from rllab.misc.instrument import VariantGenerator, variant


class VG(VariantGenerator):

@variant
def step_size(self):
return [0.01, 0.05, 0.1]

@variant
def seed(self):
return [1, 11, 21, 31, 41]

variants = VG().variants()

for v in variants:

env = TfEnv(normalize(GymEnv('HalfCheetah-v1', record_video=False, record_log=False)))

policy = GaussianMLPPolicy(
env_spec=env.spec,
# The neural network policy should have two hidden layers, each with 32 hidden units.
hidden_sizes=(32, 32),
name="policy"
)

baseline = LinearFeatureBaseline(env_spec=env.spec)

algo = TRPO(
env=env,
policy=policy,
baseline=baseline,
batch_size=4000,
max_path_length=100,
n_itr=40,
discount=0.99,
step_size=v["step_size"],
# Uncomment both lines (this and the plot parameter below) to enable plotting
# plot=True,
)

run_experiment_lite(
algo.train(),
exp_prefix="first_exp",
# Number of parallel workers for sampling
n_parallel=1,
# Only keep the snapshot parameters for the last iteration
snapshot_mode="last",
# Specifies the seed for the experiment. If this is not provided, a random seed
# will be used
seed=v["seed"],
# mode="local",
mode="ec2",
variant=v,
# plot=True,
# terminate_machine=False,
)
sys.exit()
17 changes: 17 additions & 0 deletions rllab/misc/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,20 @@ def launch_ec2(params_list, exp_prefix, docker_image, code_full_path,
sio.write("""
die() { status=$1; shift; echo "FATAL: $*"; exit $status; }
""")

sio.write("""
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`"
""")
sio.write("""
aws ec2 create-tags --resources $EC2_INSTANCE_ID --tags Key=Name,Value={exp_name} --region {aws_region}
""".format(exp_name=params_list[0].get("exp_name"), aws_region=config.AWS_REGION_NAME))
if config.LABEL:
sio.write("""
aws ec2 create-tags --resources $EC2_INSTANCE_ID --tags Key=owner,Value={label} --region {aws_region}
""".format(label=config.LABEL, aws_region=config.AWS_REGION_NAME))
sio.write("""
aws ec2 create-tags --resources $EC2_INSTANCE_ID --tags Key=exp_prefix,Value={exp_prefix} --region {aws_region}
""".format(exp_prefix=exp_prefix, aws_region=config.AWS_REGION_NAME))
sio.write("""
service docker start
""")
Expand All @@ -732,6 +740,10 @@ def launch_ec2(params_list, exp_prefix, docker_image, code_full_path,
aws s3 cp --recursive {code_full_path} {local_code_path} --region {aws_region}
""".format(code_full_path=code_full_path, local_code_path=config.DOCKER_CODE_DIR,
aws_region=config.AWS_REGION_NAME))
s3_mujoco_key_path = config.AWS_CODE_SYNC_S3_PATH + '/.mujoco/'
sio.write("""
aws s3 cp --recursive {} {} --region {}
""".format(s3_mujoco_key_path, config.MUJOCO_KEY_PATH, config.AWS_REGION_NAME))
sio.write("""
cd {local_code_path}
""".format(local_code_path=config.DOCKER_CODE_DIR))
Expand Down Expand Up @@ -922,12 +934,17 @@ def s3_sync_code(config, dry=False):

upload_cmd = ["aws", "s3", "cp", file_path, remote_path]

mujoco_key_cmd = [
"aws", "s3", "sync", config.MUJOCO_KEY_PATH, "{}/.mujoco/".format(base)]

print(" ".join(tar_cmd))
print(" ".join(upload_cmd))
print(" ".join(mujoco_key_cmd))

if not dry:
subprocess.check_call(tar_cmd)
subprocess.check_call(upload_cmd)
subprocess.check_call(mujoco_key_cmd)

S3_CODE_PATH = remote_path
return remote_path
Expand Down

0 comments on commit 7b3a6ad

Please sign in to comment.