Skip to content
Snippets Groups Projects
Commit 3b9d4ecd authored by Aritz's avatar Aritz
Browse files

Changing install procedure

parent 9fb5a187
No related branches found
No related tags found
No related merge requests found
Showing
with 18 additions and 345 deletions
......@@ -13,24 +13,15 @@ The code works on top of [Metaworld-v1](https://github.com/rlworkgroup/metaworld
<h3>MT-10-R results
<img src="/uploads/c743460c60cddf1bb099ecae3ea6365d/MT10.gif" width="80%" /> </h3>
# Running the experimentation
# Installation and Experimentation
It is recommended to use the conda environment provided with the code (`mujoco36.yml`) for ease:
A-MFEA-RL depends on Metaworld and [MuJoco](https://github.com/openai/mujoco-py) (license required). To automatically install conda environment and Metaworld run:
```bash
conda env create -f mujoco36.yml
conda activate mujoco36
chmod +x install.sh
./install.sh
```
A-MFEA-RL depends on Metaworld and [MuJoco](https://github.com/openai/mujoco-py) (license required). To install Metaworld please run:
```bash
cd a-mfea-rl/metaworld
pip install -e .
pip install ray
```
In order to run experiments:
The experimentation can be reproduced running:
```bash
python3 exp.py -exp INT -t INT -p STR -r INT
```
......
name: mujoco36
name: envPrueba
channels:
- defaults
dependencies:
......@@ -25,15 +25,15 @@ dependencies:
- beautifulsoup4==4.9.2
- google==3.0.0
- grpcio==1.32.0
- multidict==4.7.6
- opt-einsum==3.3.0
- prometheus-client==0.8.0
- psutil==5.7.2
- pyrsistent==0.17.3
- ray==1.0.0
- redis==3.4.1
- soupsieve==2.0.1
- tensorflow==1.14.0
- theano==1.0.5
- typing-extensions==3.7.4.3
- urllib3==1.25.10
- yarl==1.6.0
prefix: /home/aritz/.anaconda3/envs/envPrueba
......@@ -10,7 +10,7 @@ from utils.callback import callback_function as cb
from utils.utils import load_compressed_pickle as lp
from pickle import dump as pdump
PATH_TO_METAWORLD_FILE = './metaworld/envs/mujoco/sawyer_xyz/sawyer_xyz_env.py'
PATH_TO_METAWORLD_FILE = './metaworld/metaworld/envs/mujoco/sawyer_xyz/sawyer_xyz_env.py'
PATH_TO_FIXED = './exp_type/sawyer_xyz_env_fixed.py'
PATH_TO_RANDOM = './exp_type/sawyer_xyz_env_random.py'
......
# Import conda environment
conda env create -f amfearl.yml
conda activate amfearl
# Clone and install Metaworld
git clone https://github.com/rlworkgroup/metaworld
cd metaworld
pip install -e .
"""Proposal for a simple, understandable MetaWorld API."""
import abc
import pickle
from collections import OrderedDict
from typing import List, NamedTuple, Type
import metaworld.envs.mujoco.env_dict as _env_dict
import numpy as np
EnvName = str
class Task(NamedTuple):
"""All data necessary to describe a single MDP.
Should be passed into a MetaWorldEnv's set_task method.
"""
env_name: EnvName
data: bytes # Contains env parameters like random_init and *a* goal
class MetaWorldEnv:
"""Environment that requires a task before use.
Takes no arguments to its constructor, and raises an exception if used
before `set_task` is called.
"""
def set_task(self, task: Task) -> None:
"""Set the task.
Raises:
ValueError: If task.env_name is different from the current task.
"""
class Benchmark(abc.ABC):
"""A Benchmark.
When used to evaluate an algorithm, only a single instance should be used.
"""
@abc.abstractmethod
def __init__(self):
pass
@property
def train_classes(self) -> 'OrderedDict[EnvName, Type]':
"""Get all of the environment classes used for training."""
return self._train_classes
@property
def test_classes(self) -> 'OrderedDict[EnvName, Type]':
"""Get all of the environment classes used for testing."""
return self._test_classes
@property
def train_tasks(self) -> List[Task]:
"""Get all of the training tasks for this benchmark."""
return self._train_tasks
@property
def test_tasks(self) -> List[Task]:
"""Get all of the test tasks for this benchmark."""
return self._test_tasks
_ML_OVERRIDE = dict(partially_observable=True)
_MT_OVERRIDE = dict(partially_observable=False)
_N_GOALS = 50
def _encode_task(env_name, data):
return Task(env_name=env_name, data=pickle.dumps(data))
def _make_tasks(classes, args_kwargs, kwargs_override):
tasks = []
for (env_name, args) in args_kwargs.items():
assert len(args['args']) == 0
env_cls = classes[env_name]
env = env_cls()
env._freeze_rand_vec = False
env._set_task_called = True
rand_vecs = []
kwargs = args['kwargs'].copy()
del kwargs['task_id']
env._set_task_inner(**kwargs)
for _ in range(_N_GOALS):
env.reset()
rand_vecs.append(env._last_rand_vec)
unique_task_rand_vecs = np.unique(np.array(rand_vecs), axis=0)
assert unique_task_rand_vecs.shape[0] == _N_GOALS
env.close()
for rand_vec in rand_vecs:
kwargs = args['kwargs'].copy()
del kwargs['task_id']
kwargs.update(dict(rand_vec=rand_vec, env_cls=env_cls))
kwargs.update(kwargs_override)
tasks.append(_encode_task(env_name, kwargs))
return tasks
def _ml1_env_names():
key_train = _env_dict.HARD_MODE_ARGS_KWARGS['train']
key_test = _env_dict.HARD_MODE_ARGS_KWARGS['test']
tasks = sum([list(key_train)], list(key_test))
assert len(tasks) == 50
return tasks
class ML1(Benchmark):
ENV_NAMES = _ml1_env_names()
def __init__(self, env_name):
super().__init__()
try:
cls = _env_dict.HARD_MODE_CLS_DICT['train'][env_name]
args_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['train'][env_name]
except KeyError:
cls = _env_dict.HARD_MODE_CLS_DICT['test'][env_name]
args_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['test'][env_name]
self._train_classes = OrderedDict([(env_name, cls)])
self._test_classes = self._train_classes
self._train_ = OrderedDict([(env_name, cls)])
self._train_tasks = _make_tasks(self._train_classes,
{env_name: args_kwargs},
_ML_OVERRIDE)
self._test_tasks = _make_tasks(self._test_classes,
{env_name: args_kwargs},
_ML_OVERRIDE)
class MT1(Benchmark):
ENV_NAMES = _ml1_env_names()
def __init__(self, env_name):
super().__init__()
try:
cls = _env_dict.HARD_MODE_CLS_DICT['train'][env_name]
args_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['train'][env_name]
except KeyError:
cls = _env_dict.HARD_MODE_CLS_DICT['test'][env_name]
args_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['test'][env_name]
self._train_classes = OrderedDict([(env_name, cls)])
self._test_classes = OrderedDict()
self._train_ = OrderedDict([(env_name, cls)])
self._train_tasks = _make_tasks(self._train_classes,
{env_name: args_kwargs},
_MT_OVERRIDE)
self._test_tasks = []
class ML10(Benchmark):
def __init__(self):
super().__init__()
self._train_classes = _env_dict.MEDIUM_MODE_CLS_DICT['train']
self._test_classes = _env_dict.MEDIUM_MODE_CLS_DICT['test']
train_kwargs = _env_dict.medium_mode_train_args_kwargs
self._train_tasks = _make_tasks(self._train_classes,
train_kwargs,
_ML_OVERRIDE)
test_kwargs = _env_dict.medium_mode_test_args_kwargs
self._test_tasks = _make_tasks(self._test_classes,
test_kwargs,
_ML_OVERRIDE)
class ML45(Benchmark):
def __init__(self):
super().__init__()
self._train_classes = _env_dict.HARD_MODE_CLS_DICT['train']
self._test_classes = _env_dict.HARD_MODE_CLS_DICT['test']
train_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['train']
self._train_tasks = _make_tasks(self._train_classes,
train_kwargs,
_ML_OVERRIDE)
self._test_tasks = _make_tasks(self._test_classes,
_env_dict.HARD_MODE_ARGS_KWARGS['test'],
_ML_OVERRIDE)
class MT10(Benchmark):
def __init__(self):
super().__init__()
self._train_classes = _env_dict.EASY_MODE_CLS_DICT
self._test_classes = OrderedDict()
train_kwargs = _env_dict.EASY_MODE_ARGS_KWARGS
self._train_tasks = _make_tasks(self._train_classes,
train_kwargs,
_MT_OVERRIDE)
self._test_tasks = []
class MT50(Benchmark):
def __init__(self):
super().__init__()
self._train_classes = _env_dict.HARD_MODE_CLS_DICT['train'].copy()
# We're going to modify it, so make a copy
train_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['train'].copy()
test_kwargs = _env_dict.HARD_MODE_ARGS_KWARGS['test']
for (env_name, cls) in _env_dict.HARD_MODE_CLS_DICT['test'].items():
assert env_name not in self._train_classes
assert env_name not in train_kwargs
self._train_classes[env_name] = cls
train_kwargs[env_name] = test_kwargs[env_name]
self._test_classes = OrderedDict()
self._train_tasks = _make_tasks(self._train_classes,
train_kwargs,
_MT_OVERRIDE)
self._test_tasks = []
import os
ENV_ASSET_DIR_V1 = os.path.join(os.path.dirname(__file__), 'assets_v1')
ENV_ASSET_DIR_V2 = os.path.join(os.path.dirname(__file__), 'assets_v2')
def full_v1_path_for(file_name):
return os.path.join(ENV_ASSET_DIR_V1, file_name)
def full_v2_path_for(file_name):
return os.path.join(ENV_ASSET_DIR_V2, file_name)
<!-- Taken from openai gym -->
<!-- Cheetah Model
The state space is populated with joints in the order that they are
defined in this file. The actuators also operate on joints.
State-Space (name/joint/parameter):
- rootx slider position (m)
- rootz slider position (m)
- rooty hinge angle (rad)
- bthigh hinge angle (rad)
- bshin hinge angle (rad)
- bfoot hinge angle (rad)
- fthigh hinge angle (rad)
- fshin hinge angle (rad)
- ffoot hinge angle (rad)
- rootx slider velocity (m/s)
- rootz slider velocity (m/s)
- rooty hinge angular velocity (rad/s)
- bthigh hinge angular velocity (rad/s)
- bshin hinge angular velocity (rad/s)
- bfoot hinge angular velocity (rad/s)
- fthigh hinge angular velocity (rad/s)
- fshin hinge angular velocity (rad/s)
- ffoot hinge angular velocity (rad/s)
Actuators (name/actuator/parameter):
- bthigh hinge torque (N m)
- bshin hinge torque (N m)
- bfoot hinge torque (N m)
- fthigh hinge torque (N m)
- fshin hinge torque (N m)
- ffoot hinge torque (N m)
-->
<mujoco model="cheetah">
<compiler angle="radian" coordinate="local" inertiafromgeom="true" settotalmass="14"/>
<default>
<joint armature=".1" damping=".01" limited="true" solimplimit="0 .8 .03" solreflimit=".02 1" stiffness="8"/>
<geom conaffinity="0" condim="3" contype="1" friction=".4 .1 .1" rgba="0.8 0.6 .4 1" solimp="0.0 0.8 0.01" solref="0.02 1"/>
<motor ctrllimited="true" ctrlrange="-1 1"/>
</default>
<size nstack="300000" nuser_geom="1"/>
<option gravity="0 0 -9.81" timestep="0.01"/>
<asset>
<texture builtin="gradient" height="100" rgb1="1 1 1" rgb2="0 0 0" type="skybox" width="100"/>
<texture builtin="flat" height="1278" mark="cross" markrgb="1 1 1" name="texgeom" random="0.01" rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" type="cube" width="127"/>
<texture builtin="checker" height="100" name="texplane" rgb1="0 0 0" rgb2="0.8 0.8 0.8" type="2d" width="100"/>
<material name="MatPlane" reflectance="0.5" shininess="1" specular="1" texrepeat="60 60" texture="texplane"/>
<material name="geom" texture="texgeom" texuniform="true"/>
</asset>
<worldbody>
<light cutoff="100" diffuse="1 1 1" dir="-0 0 -1.3" directional="true" exponent="1" pos="0 0 1.3" specular=".1 .1 .1"/>
<geom conaffinity="1" condim="3" material="MatPlane" name="floor" pos="0 0 0" rgba="0.8 0.9 0.8 1" size="40 40 40" type="plane"/>
<body name="torso" pos="0 0 .7">
<camera name="track" mode="trackcom" pos="0 -3 0.3" xyaxes="1 0 0 0 0 1"/>
<joint armature="0" axis="1 0 0" damping="0" limited="false" name="rootx" pos="0 0 0" stiffness="0" type="slide"/>
<joint armature="0" axis="0 0 1" damping="0" limited="false" name="rootz" pos="0 0 0" stiffness="0" type="slide"/>
<joint armature="0" axis="0 1 0" damping="0" limited="false" name="rooty" pos="0 0 0" stiffness="0" type="hinge"/>
<geom fromto="-.5 0 0 .5 0 0" name="torso" size="0.046" type="capsule"/>
<geom axisangle="0 1 0 .87" name="head" pos=".6 0 .1" size="0.046 .15" type="capsule"/>
<!-- <site name='tip' pos='.15 0 .11'/>-->
<body name="bthigh" pos="-.5 0 0">
<joint axis="0 1 0" damping="6" name="bthigh" pos="0 0 0" range="-.52 1.05" stiffness="240" type="hinge"/>
<geom axisangle="0 1 0 -3.8" name="bthigh" pos=".1 0 -.13" size="0.046 .145" type="capsule"/>
<body name="bshin" pos=".16 0 -.25">
<joint axis="0 1 0" damping="4.5" name="bshin" pos="0 0 0" range="-.785 .785" stiffness="180" type="hinge"/>
<geom axisangle="0 1 0 -2.03" name="bshin" pos="-.14 0 -.07" rgba="0.9 0.6 0.6 1" size="0.046 .15" type="capsule"/>
<body name="bfoot" pos="-.28 0 -.14">
<joint axis="0 1 0" damping="3" name="bfoot" pos="0 0 0" range="-.4 .785" stiffness="120" type="hinge"/>
<geom axisangle="0 1 0 -.27" name="bfoot" pos=".03 0 -.097" rgba="0.9 0.6 0.6 1" size="0.046 .094" type="capsule"/>
</body>
</body>
</body>
<body name="fthigh" pos=".5 0 0">
<joint axis="0 1 0" damping="4.5" name="fthigh" pos="0 0 0" range="-1 .7" stiffness="180" type="hinge"/>
<geom axisangle="0 1 0 .52" name="fthigh" pos="-.07 0 -.12" size="0.046 .133" type="capsule"/>
<body name="fshin" pos="-.14 0 -.24">
<joint axis="0 1 0" damping="3" name="fshin" pos="0 0 0" range="-1.2 .87" stiffness="120" type="hinge"/>
<geom axisangle="0 1 0 -.6" name="fshin" pos=".065 0 -.09" rgba="0.9 0.6 0.6 1" size="0.046 .106" type="capsule"/>
<body name="ffoot" pos=".13 0 -.18">
<joint axis="0 1 0" damping="1.5" name="ffoot" pos="0 0 0" range="-.5 .5" stiffness="60" type="hinge"/>
<geom axisangle="0 1 0 -.6" name="ffoot" pos=".045 0 -.07" rgba="0.9 0.6 0.6 1" size="0.046 .07" type="capsule"/>
</body>
</body>
</body>
</body>
</worldbody>
<actuator>
<motor gear="120" joint="bthigh" name="bthigh"/>
<motor gear="90" joint="bshin" name="bshin"/>
<motor gear="60" joint="bfoot" name="bfoot"/>
<motor gear="120" joint="fthigh" name="fthigh"/>
<motor gear="60" joint="fshin" name="fshin"/>
<motor gear="30" joint="ffoot" name="ffoot"/>
</actuator>
</mujoco>
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment