Search is not available for this dataset
repo stringlengths 2 152 ⌀ | file stringlengths 15 239 | code stringlengths 0 58.4M | file_length int64 0 58.4M | avg_line_length float64 0 1.81M | max_line_length int64 0 12.7M | extension_type stringclasses 364
values |
|---|---|---|---|---|---|---|
mopo | mopo-master/run.sh | mopo run_local examples.development --config=examples.config.halfcheetah.off_policy --gpus=1 --trial-gpus=1 --checkpoint-frequency=50
| 134 | 66.5 | 133 | sh |
mopo | mopo-master/setup.py | from distutils.core import setup
from setuptools import find_packages
setup(
name='mopo',
packages=find_packages(),
version='0.0.1',
description='Model-based Offline Policy Optimization',
long_description=open('./README.md').read(),
author='Tianhe Yu',
author_email='tianheyu@cs.stanford.eu'... | 604 | 25.304348 | 61 | py |
mopo | mopo-master/environment/gpu-env.yml | ## copy of https://github.com/rail-berkeley/softlearning/blob/master/environment.yml
name: mopo
channels:
- defaults
- conda-forge
dependencies:
- python=3.6.5
- pip>=18.0
- conda>=4.5.9
- patchelf=0.9
- pip:
- -r requirements.txt
| 236 | 15.928571 | 84 | yml |
mopo | mopo-master/examples/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/examples/instrument.py | """Functions for instrumenting and running softlearning examples.
This package contains functions, which allow seamless runs of examples in
different modes (e.g. locally, in google compute engine, or ec2).
There are two types of functions in this file:
1. run_example_* methods, which run the experiments by invoking
... | 12,982 | 32.722078 | 83 | py |
mopo | mopo-master/examples/utils.py | import multiprocessing
import argparse
from distutils.util import strtobool
import json
from ray.tune import sample_from
import softlearning.algorithms.utils as alg_utils
import softlearning.environments.utils as env_utils
from softlearning.misc.utils import datetimestamp
DEFAULT_UNIVERSE = 'gym'
DEFAULT_DOMAIN = '... | 9,350 | 29.558824 | 80 | py |
mopo | mopo-master/examples/config/__init__.py | params = {
'type': 'MOPO',
'universe': 'gym',
'domain': 'Hopper',
'task': 'v2',
'log_dir': '~/ray_mopo/',
'exp_name': 'defaults',
'kwargs': {
'epoch_length': 1000,
'train_every_n_steps': 1,
'n_train_repeat': 2, #20,
'eval_render_mode': None,
'eval_n_... | 1,061 | 25.55 | 72 | py |
mopo | mopo-master/examples/config/d4rl/base.py | base_params = {
'type': 'MOPO',
'universe': 'gym',
'log_dir': './ray_mopo/', # Specify where to write log files here
'kwargs': {
'epoch_length': 1000,
'train_every_n_steps': 1,
'n_train_repeat': 1,
'eval_render_mode': None,
'eval_n_episodes': 10,
'eval_d... | 700 | 23.172414 | 69 | py |
mopo | mopo-master/examples/config/d4rl/base_mopo.py | from copy import deepcopy
from .base import base_params
mopo_params = deepcopy(base_params)
mopo_params['kwargs'].update({
'separate_mean_var': True,
'penalty_learned_var': True,
}) | 190 | 22.875 | 35 | py |
mopo | mopo-master/examples/config/d4rl/halfcheetah_medium.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'halfcheetah',
'task': 'medium-v0',
'exp_name': 'halfcheetah_medium'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/halfcheetah-medium-v0',
'pool_load_max_size': 10**6,
'rollout_length': ... | 350 | 24.071429 | 51 | py |
mopo | mopo-master/examples/config/d4rl/halfcheetah_medium_expert.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'halfcheetah',
'task': 'medium-expert-v0',
'exp_name': 'halfcheetah_medium_expert'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/halfcheetah-medium-expert-v0',
'pool_load_max_size': 2 * 10**... | 375 | 25.857143 | 58 | py |
mopo | mopo-master/examples/config/d4rl/halfcheetah_mixed.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'halfcheetah',
'task': 'medium-replay-v0',
'exp_name': 'halfcheetah_medium_replay'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/halfcheetah-medium-replay-v0',
'pool_load_max_size': 101000,
... | 372 | 25.642857 | 58 | py |
mopo | mopo-master/examples/config/d4rl/halfcheetah_random.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'halfcheetah',
'task': 'random-v0',
'exp_name': 'halfcheetah_random'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/halfcheetah-random-v0',
'pool_load_max_size': 10**6,
'rollout_length': ... | 350 | 24.071429 | 51 | py |
mopo | mopo-master/examples/config/d4rl/hopper_medium.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'hopper',
'task': 'medium-v0',
'exp_name': 'hopper_medium'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/hopper-medium-v0',
'pool_load_max_size': 10**6,
'rollout_length': 5,
'penalty... | 335 | 23 | 46 | py |
mopo | mopo-master/examples/config/d4rl/hopper_medium_expert.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'hopper',
'task': 'medium-expert-v0',
'exp_name': 'hopper_medium_expert'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/hopper-medium-expert-v0',
'pool_load_max_size': 2 * 10**6,
'rollout... | 360 | 24.785714 | 53 | py |
mopo | mopo-master/examples/config/d4rl/hopper_mixed.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'hopper',
'task': 'medium-replay-v0',
'exp_name': 'hopper_medium_replay'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/hopper-mixed-v0',
'pool_load_max_size': 200920,
'rollout_length': 5... | 350 | 24.071429 | 45 | py |
mopo | mopo-master/examples/config/d4rl/hopper_random.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'hopper',
'task': 'random-v0',
'exp_name': 'hopper_random'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/hopper-random-v0',
'pool_load_max_size': 10**6,
'rollout_length': 5,
'penalty... | 335 | 23 | 46 | py |
mopo | mopo-master/examples/config/d4rl/walker2d_medium.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'walker2d',
'task': 'medium-v0',
'exp_name': 'walker2d_medium'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/walker2d-medium-v0',
'pool_load_max_size': 10**6,
'rollout_length': 5,
'p... | 341 | 23.428571 | 48 | py |
mopo | mopo-master/examples/config/d4rl/walker2d_medium_expert.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'walker2d',
'task': 'medium-expert-v0',
'exp_name': 'walker2d_medium_expert'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/walker2d-medium-expert-v0',
'pool_load_max_size': 2 * 10**6,
'r... | 366 | 25.214286 | 55 | py |
mopo | mopo-master/examples/config/d4rl/walker2d_mixed.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'walker2d',
'task': 'medium-replay-v0',
'exp_name': 'walker2d_medium_replay'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/walker2d-medium-replay-v0',
'pool_load_max_size': 100930,
'roll... | 363 | 25 | 55 | py |
mopo | mopo-master/examples/config/d4rl/walker2d_random.py | from .base_mopo import mopo_params, deepcopy
params = deepcopy(mopo_params)
params.update({
'domain': 'walker2d',
'task': 'random-v0',
'exp_name': 'walker2d_random'
})
params['kwargs'].update({
'pool_load_path': 'd4rl/walker2d-random-v0',
'pool_load_max_size': 10**6,
'rollout_length': 1,
'p... | 341 | 23.428571 | 48 | py |
mopo | mopo-master/examples/development/__init__.py | """Provides functions that are utilized by the command line interface.
In particular, the examples are exposed to the command line interface
(defined in `softlearning.scripts.console_scripts`) through the
`get_trainable_class`, `get_variant_spec`, and `get_parser` functions.
"""
def get_trainable_class(*args, **kwar... | 1,254 | 30.375 | 79 | py |
mopo | mopo-master/examples/development/base.py | from ray import tune
import numpy as np
import pdb
from softlearning.misc.utils import get_git_rev, deep_update
M = 256
REPARAMETERIZE = True
NUM_COUPLING_LAYERS = 2
GAUSSIAN_POLICY_PARAMS_BASE = {
'type': 'GaussianPolicy',
'kwargs': {
'hidden_layer_sizes': (M, M),
'squash': True,
}
}
G... | 8,771 | 27.760656 | 84 | py |
mopo | mopo-master/examples/development/main.py | import os
import copy
import glob
import pickle
import sys
import pdb
import tensorflow as tf
from ray import tune
from softlearning.environments.utils import get_environment_from_params
from softlearning.algorithms.utils import get_algorithm_from_variant
from softlearning.policies.utils import get_policy_from_varian... | 8,680 | 35.783898 | 80 | py |
mopo | mopo-master/examples/development/simulate_policy.py | import argparse
from distutils.util import strtobool
import json
import os
import pickle
import numpy as np
import tensorflow as tf
from softlearning.environments.utils import get_environment_from_params
from softlearning.policies.utils import get_policy_from_variant
from softlearning.samplers import rollouts
def p... | 2,833 | 31.953488 | 76 | py |
mopo | mopo-master/examples/development/simulate_policy_with_state.py | import argparse
from distutils.util import strtobool
import json
import os
import pickle
import numpy as np
import tensorflow as tf
import pdb
from softlearning.environments.utils import get_environment_from_params
from softlearning.policies.utils import get_policy_from_variant
# from softlearning.samplers import rol... | 4,998 | 30.24375 | 88 | py |
mopo | mopo-master/examples/development/variants.py | from ray import tune
import numpy as np
from softlearning.misc.utils import get_git_rev, deep_update
M = 256
REPARAMETERIZE = True
NUM_COUPLING_LAYERS = 2
GAUSSIAN_POLICY_PARAMS_BASE = {
'type': 'GaussianPolicy',
'kwargs': {
'hidden_layer_sizes': (M, M),
'squash': True,
}
}
GAUSSIAN_POL... | 10,800 | 28.113208 | 74 | py |
mopo | mopo-master/mopo/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/algorithms/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/algorithms/mopo.py | ## adapted from https://github.com/rail-berkeley/softlearning/blob/master/softlearning/algorithms/sac.py
import os
import math
import pickle
from collections import OrderedDict
from numbers import Number
from itertools import count
import gtimer as gt
import pdb
import numpy as np
import tensorflow as tf
from tensorf... | 29,127 | 36.248082 | 143 | py |
mopo | mopo-master/mopo/env/__init__.py | import sys
from .ant import AntEnv
from .humanoid import HumanoidEnv
env_overwrite = {'Ant': AntEnv, 'Humanoid': HumanoidEnv}
sys.modules[__name__] = env_overwrite | 166 | 19.875 | 56 | py |
mopo | mopo-master/mopo/env/ant.py | import numpy as np
from gym import utils
from gym.envs.mujoco import mujoco_env
class AntEnv(mujoco_env.MujocoEnv, utils.EzPickle):
# def __init__(self, goal=15.0/180*np.pi):
def __init__(self, goal=30.0/180*np.pi):
self._goal = goal
mujoco_env.MujocoEnv.__init__(self, 'ant.xml', 5)
uti... | 2,407 | 37.83871 | 92 | py |
mopo | mopo-master/mopo/env/humanoid.py | import numpy as np
from gym.envs.mujoco import mujoco_env
from gym import utils
def mass_center(model, sim):
mass = np.expand_dims(model.body_mass, 1)
xpos = sim.data.xipos
return (np.sum(mass * xpos, 0) / np.sum(mass))[0]
class HumanoidEnv(mujoco_env.MujocoEnv, utils.EzPickle):
def __init__(self):
... | 2,151 | 38.851852 | 170 | py |
mopo | mopo-master/mopo/models/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/models/bnn.py | from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import os
import time
import pdb
import itertools
from collections import OrderedDict
import tensorflow as tf
import numpy as np
from tqdm import trange
from scipy.io import savemat, loadmat
from mopo.models.... | 32,165 | 45.348703 | 156 | py |
mopo | mopo-master/mopo/models/constructor.py | import numpy as np
import tensorflow as tf
import pdb
from mopo.models.fc import FC
from mopo.models.bnn import BNN
def construct_model(obs_dim=11, act_dim=3, rew_dim=1, hidden_dim=200, num_networks=7,
num_elites=5, session=None, model_type='mlp', separate_mean_var=False,
name=None, load_dir=None, determini... | 2,344 | 36.822581 | 123 | py |
mopo | mopo-master/mopo/models/fake_env.py | import numpy as np
import tensorflow as tf
import pdb
class FakeEnv:
def __init__(self, model, config,
penalty_coeff=0.,
penalty_learned_var=False,
penalty_learned_var_random=False):
self.model = model
self.config = config
self.penalty_coeff =... | 6,073 | 40.040541 | 127 | py |
mopo | mopo-master/mopo/models/fc.py | from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import numpy as np
import tensorflow as tf
from .utils import spectral_norm
import pdb
class FC:
"""Represents a fully-connected layer in a network.
"""
_activations = {
None: tf.identity... | 9,634 | 34.164234 | 114 | py |
mopo | mopo-master/mopo/models/utils.py | from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
import tensorflow as tf
import numpy as np
def get_required_argument(dotmap, key, message, default=None):
val = dotmap.get(key, default)
if val is default:
raise ValueError(message)
return ... | 3,815 | 28.129771 | 106 | py |
mopo | mopo-master/mopo/off_policy/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/off_policy/loader.py | import os
import glob
import pickle
import gzip
import pdb
import numpy as np
def restore_pool(replay_pool, experiment_root, max_size, save_path=None):
if 'd4rl' in experiment_root:
restore_pool_d4rl(replay_pool, experiment_root[5:])
else:
assert os.path.exists(experiment_root)
if os.pa... | 4,882 | 37.448819 | 148 | py |
mopo | mopo-master/mopo/parallel/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/parallel/parallel_env.py | import gym
import mujoco_py as mjc
import pdb
from mopo.parallel.parallel_hopper import ParallelHopperEnv
if __name__ == '__main__':
N = 10
env = ParallelHopperEnv()
# env = gym.make('Hopper-v2')
# sim = env.unwrapped.sim
# pool = mjc.MjSimPool.create_from_sim(sim, N)
pdb.set_trace() | 295 | 18.733333 | 59 | py |
mopo | mopo-master/mopo/parallel/parallel_hopper.py | import os
from os import path
import numpy as np
from gym import utils
from gym.envs.mujoco import mujoco_env
from gym.envs.mujoco.mujoco_env import convert_observation_to_space
import mujoco_py as mjc
import pdb
class ParallelMujocoEnv(mujoco_env.MujocoEnv):
"""Superclass for all MuJoCo environments.
"""
... | 6,455 | 34.668508 | 96 | py |
mopo | mopo-master/mopo/parallel/test.py | import numpy as np
import time
import gym
# import mujoco_py as mjc
import pdb
from mopo.parallel.parallel_hopper import ParallelHopperEnv
N = 10000
horizon = 1
env = gym.make('Hopper-v2')
parallel = ParallelHopperEnv(N)
env.reset()
t0_p = time.time()
obs = parallel.reset()
vec_qpos_init, vec_qvel_init = parallel.v... | 1,297 | 21.37931 | 73 | py |
mopo | mopo-master/mopo/scripts/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/mopo/scripts/console_scripts.py | import click
@click.group(invoke_without_command=True)
@click.argument("data_path", required=True, nargs=1)
@click.argument('kwargs', nargs=-1)
def cli(data_path, kwargs):
from viskit.frontend import main
main()
def main():
return cli()
if __name__ == "__main__":
main()
| 291 | 17.25 | 52 | py |
mopo | mopo-master/mopo/scripts/train_model_offline.py | import gym
import d4rl
import numpy as np
import tensorflow as tf
from mopo.models.constructor import construct_model, format_samples_for_training
def model_name(args):
name = f'{args.env}-{args.quality}'
if args.separate_mean_var:
name += '_smv'
name += f'_{args.seed}'
return name
def main... | 2,177 | 38.6 | 97 | py |
mopo | mopo-master/mopo/static/__init__.py | import sys
import os
import importlib
import pdb
def import_fns(path, file, fns_name='StaticFns'):
full_path = os.path.join(path, file)
import_path = full_path.replace('/', '.')
module = importlib.import_module(import_path)
fns = getattr(module, fns_name)
return fns
cwd = 'mopo/static'
files = os.listdir(cwd)
#... | 598 | 22.038462 | 62 | py |
mopo | mopo-master/mopo/static/ant.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
x = next_obs[:, 0]
not_done = np.isfinite(next_obs).all(axis=-1) \
* (x >= 0.2) \
* (x <= 1.0)
... | 385 | 21.705882 | 75 | py |
mopo | mopo-master/mopo/static/antangle.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
x = next_obs[:, 0]
not_done = np.isfinite(next_obs).all(axis=-1) \
* (x >= 0.2) \
* (x <= 1.0)
... | 385 | 21.705882 | 75 | py |
mopo | mopo-master/mopo/static/halfcheetah.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
@staticmethod
def recompute_reward_f... | 535 | 27.210526 | 86 | py |
mopo | mopo-master/mopo/static/halfcheetahjump.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
| 275 | 22 | 75 | py |
mopo | mopo-master/mopo/static/halfcheetahvel.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
@staticmethod
def recompute_reward_f... | 535 | 27.210526 | 86 | py |
mopo | mopo-master/mopo/static/halfcheetahveljump.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
| 275 | 22 | 75 | py |
mopo | mopo-master/mopo/static/hopper.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
height = next_obs[:, 0]
angle = next_obs[:, 1]
not_done = np.isfinite(next_obs).all(axis=-1) \
* n... | 518 | 26.315789 | 75 | py |
mopo | mopo-master/mopo/static/humanoid.py | import sys
import numpy as np
import pdb
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
z = next_obs[:,0]
done = (z < 1.0) + (z > 2.0)
done = done[:,None]
return done | 310 | 19.733333 | 75 | py |
mopo | mopo-master/mopo/static/pendulum.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.zeros((len(obs), 1))
return done
| 236 | 20.545455 | 75 | py |
mopo | mopo-master/mopo/static/point2denv.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
| 275 | 22 | 75 | py |
mopo | mopo-master/mopo/static/point2dwallenv.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
done = np.array([False]).repeat(len(obs))
done = done[:,None]
return done
| 275 | 22 | 75 | py |
mopo | mopo-master/mopo/static/walker2d.py | import numpy as np
class StaticFns:
@staticmethod
def termination_fn(obs, act, next_obs):
assert len(obs.shape) == len(next_obs.shape) == len(act.shape) == 2
height = next_obs[:, 0]
angle = next_obs[:, 1]
not_done = (height > 0.8) \
* (height < 2.0) \
... | 464 | 24.833333 | 75 | py |
mopo | mopo-master/mopo/utils/__init__.py | # from .filesystem import *
# from .launcher import * | 53 | 26 | 27 | py |
mopo | mopo-master/mopo/utils/filesystem.py | import os
def mkdir(path):
if not os.path.exists(path):
os.mkdir(path) | 74 | 14 | 29 | py |
mopo | mopo-master/mopo/utils/logging.py | import time
import math
import pdb
class Progress:
def __init__(self, total, name = 'Progress', ncol=3, max_length=20, indent=0, line_width=100, speed_update_freq=100):
self.total = total
self.name = name
self.ncol = ncol
self.max_length = max_length
self.indent = indent
self.line_width = line_width
se... | 4,127 | 22.454545 | 118 | py |
mopo | mopo-master/mopo/utils/visualization.py | import io
import math
import numpy as np
import cv2
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pdb
def plot_trajectories(writer, label, epoch, env_traj, model_traj, means, stds):
state_dim = env_traj[0].size
model_states = [[obs[s] for obs in model_traj] for s in range(stat... | 4,294 | 30.580882 | 126 | py |
mopo | mopo-master/mopo/utils/writer.py | import io
import numpy as np
import cv2
import pdb
import matplotlib
matplotlib.use('Agg')
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import tensorboardX as tbx
class Writer():
def __init__(self, log_dir):
self.log_dir = log_dir
self._write... | 1,941 | 27.558824 | 84 | py |
mopo | mopo-master/softlearning/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/softlearning.md | # Softlearning
Softlearning is a deep reinforcement learning toolbox for training maximum entropy policies in continuous domains. The implementation is fairly thin and primarily optimized for our own development purposes. It utilizes the tf.keras modules for most of the model classes (e.g. policies and value functions... | 9,055 | 46.166667 | 672 | md |
mopo | mopo-master/softlearning/algorithms/__init__.py | from .sql import SQL
from .sac import SAC
| 42 | 13.333333 | 20 | py |
mopo | mopo-master/softlearning/algorithms/rl_algorithm.py | import abc
from collections import OrderedDict
from itertools import count
import gtimer as gt
import math
import os
import pdb
import tensorflow as tf
import numpy as np
from softlearning.samplers import rollouts
from softlearning.misc.utils import save_video
class RLAlgorithm(tf.contrib.checkpoint.Checkpointable)... | 12,728 | 34.066116 | 129 | py |
mopo | mopo-master/softlearning/algorithms/sac.py | from collections import OrderedDict
from numbers import Number
import numpy as np
import tensorflow as tf
from tensorflow.python.training import training_util
from .rl_algorithm import RLAlgorithm
def td_target(reward, discount, next_value):
return reward + discount * next_value
class SAC(RLAlgorithm):
""... | 14,507 | 32.897196 | 80 | py |
mopo | mopo-master/softlearning/algorithms/sql.py | from collections import OrderedDict
import numpy as np
import tensorflow as tf
from softlearning.misc.kernel import adaptive_isotropic_gaussian_kernel
from .rl_algorithm import RLAlgorithm
EPS = 1e-6
def assert_shape(tensor, expected_shape):
tensor_shape = tensor.shape.as_list()
assert len(tensor_shape) =... | 16,532 | 35.098253 | 86 | py |
mopo | mopo-master/softlearning/algorithms/utils.py | from copy import deepcopy
def create_SAC_algorithm(variant, *args, **kwargs):
from .sac import SAC
algorithm = SAC(*args, **kwargs)
return algorithm
def create_SQL_algorithm(variant, *args, **kwargs):
from .sql import SQL
algorithm = SQL(*args, **kwargs)
return algorithm
def create_MVE_... | 1,142 | 21.411765 | 59 | py |
mopo | mopo-master/softlearning/distributions/__init__.py | from .real_nvp_flow import ConditionalRealNVPFlow
| 50 | 24.5 | 49 | py |
mopo | mopo-master/softlearning/distributions/real_nvp_flow.py | """RealNVP bijector flow."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from tensorflow_probability import bijectors
import numpy as np
__all__ = [
"ConditionalRealNVPFlow",
]
def _use_static_shape(input_tensor, ndims):
... | 9,321 | 37.204918 | 88 | py |
mopo | mopo-master/softlearning/distributions/squash_bijector.py | import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
class SquashBijector(tfp.bijectors.Bijector):
def __init__(self, validate_args=False, name="tanh"):
super(SquashBijector, self).__init__(
forward_min_event_ndims=0,
validate_args=validate_args,
... | 555 | 25.47619 | 62 | py |
mopo | mopo-master/softlearning/environments/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/environments/helpers.py | import numpy as np
def random_point_in_circle(angle_range=(0, 2*np.pi), radius=(0, 25)):
angle = np.random.uniform(*angle_range)
radius = radius if np.isscalar(radius) else np.random.uniform(*radius)
x, y = np.cos(angle) * radius, np.sin(angle) * radius
point = np.array([x, y])
return point
| 314 | 30.5 | 74 | py |
mopo | mopo-master/softlearning/environments/utils.py | from .adapters.gym_adapter import (
GYM_ENVIRONMENTS,
GymAdapter,
)
import mopo.env as env_overwrite
import pdb
ENVIRONMENTS = {
'gym': GYM_ENVIRONMENTS,
}
ADAPTERS = {
'gym': GymAdapter,
}
def get_environment(universe, domain, task, environment_params):
if domain in env_overwrite:
prin... | 913 | 25.114286 | 96 | py |
mopo | mopo-master/softlearning/environments/adapters/__init__.py | """Module that provides adapters between SoftlearningEnv and other universes"""
| 80 | 39.5 | 79 | py |
mopo | mopo-master/softlearning/environments/adapters/gym_adapter.py | """Implements a GymAdapter that converts Gym envs into SoftlearningEnv."""
import numpy as np
import copy
import gym
from gym import spaces, wrappers
import d4rl
from .softlearning_env import SoftlearningEnv
from softlearning.environments.gym import register_environments
from softlearning.environments.gym.wrappers im... | 6,372 | 32.719577 | 83 | py |
mopo | mopo-master/softlearning/environments/adapters/softlearning_env.py | """Implements the SoftlearningEnv that is usable in softlearning algorithms."""
from abc import ABCMeta, abstractmethod
from collections import defaultdict
import numpy as np
from serializable import Serializable
class SoftlearningEnv(Serializable, metaclass=ABCMeta):
"""The abstract Softlearning environment cl... | 8,575 | 33.167331 | 123 | py |
mopo | mopo-master/softlearning/environments/dm_control/__init__.py | """Custom DeepMind Control Suite environments.
Every class inside this module should extend a dm_control.suite.Task class. The
# file structure should be similar to dm_control's file structure.
"""
| 199 | 32.333333 | 79 | py |
mopo | mopo-master/softlearning/environments/gym/__init__.py | """Custom Gym environments.
Every class inside this module should extend a gym.Env class. The file
structure should be similar to gym.envs file structure, e.g. if you're
implementing a mujoco env, you would implement it under gym.mujoco submodule.
"""
import gym
import numpy as np
CUSTOM_GYM_ENVIRONMENTS_PATH = __p... | 5,116 | 28.073864 | 78 | py |
mopo | mopo-master/softlearning/environments/gym/multi_goal.py | import numpy as np
import matplotlib.pyplot as plt
from gym.utils import EzPickle
from gym import spaces
from gym.envs.mujoco.mujoco_env import MujocoEnv
class MultiGoalEnv(MujocoEnv, EzPickle):
"""
Move a 2D point mass to one of the goal positions. Cost is the distance to
the closest goal.
State: p... | 6,005 | 28.880597 | 78 | py |
mopo | mopo-master/softlearning/environments/gym/mujoco/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/environments/gym/mujoco/image_pusher_2d.py | import numpy as np
from softlearning.environments.helpers import random_point_in_circle
from .pusher_2d import Pusher2dEnv
class ImagePusher2dEnv(Pusher2dEnv):
def __init__(self, image_shape, *args, **kwargs):
self._Serializable__initialize(locals())
self.image_shape = image_shape
Pusher2... | 4,952 | 33.395833 | 78 | py |
mopo | mopo-master/softlearning/environments/gym/mujoco/pusher_2d.py | import os.path as osp
import numpy as np
from gym.envs.mujoco.mujoco_env import MujocoEnv
from serializable import Serializable
from softlearning.misc.utils import PROJECT_PATH
from softlearning.environments.helpers import random_point_in_circle
class Pusher2dEnv(Serializable, MujocoEnv):
"""Two-dimensional Pu... | 9,093 | 35.376 | 81 | py |
mopo | mopo-master/softlearning/environments/gym/robotics/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/environments/gym/wrappers/__init__.py | from .normalize_action import NormalizeActionWrapper
| 53 | 26 | 52 | py |
mopo | mopo-master/softlearning/environments/gym/wrappers/normalize_action.py | import gym
from gym import spaces
import numpy as np
__all__ = ['NormalizeActionWrapper']
class NormalizeActionWrapper(gym.ActionWrapper):
"""Rescale the action space of the environment."""
def action(self, action):
if not isinstance(self.env.action_space, spaces.Box):
return action
... | 685 | 23.5 | 73 | py |
mopo | mopo-master/softlearning/misc/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/misc/kernel.py | from distutils.version import LooseVersion
import numpy as np
import tensorflow as tf
def adaptive_isotropic_gaussian_kernel(xs, ys, h_min=1e-3):
"""Gaussian kernel with dynamic bandwidth.
The bandwidth is adjusted dynamically to match median_distance / log(Kx).
See [2] for more information.
Args:
... | 2,718 | 35.743243 | 80 | py |
mopo | mopo-master/softlearning/misc/plotter.py | import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
class QFPolicyPlotter:
def __init__(self, Q, policy, obs_lst, default_action, n_samples):
self._Q = Q
self._policy = policy
self._obs_lst = obs_lst
self._default_action = np.array(default_action)
sel... | 2,428 | 30.960526 | 74 | py |
mopo | mopo-master/softlearning/misc/utils.py | import collections
import datetime
import os
import random
import tensorflow as tf
import numpy as np
PROJECT_PATH = os.path.dirname(
os.path.realpath(os.path.join(__file__, '..', '..')))
DEFAULT_SNAPSHOT_MODE = 'none'
DEFAULT_SNAPSHOT_GAP = 1000
def initialize_tf_variables(session, only_uninitialized=True):... | 4,054 | 24.030864 | 78 | py |
mopo | mopo-master/softlearning/models/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/models/feedforward.py | import tensorflow as tf
from softlearning.utils.keras import PicklableKerasModel
def feedforward_model(input_shapes,
output_size,
hidden_layer_sizes,
activation='relu',
output_activation='linear',
preproces... | 1,265 | 26.521739 | 68 | py |
mopo | mopo-master/softlearning/models/utils.py | def build_metric_learner_from_variant(variant, env, evaluation_data):
sampler_params = variant['sampler_params']
metric_learner_params = variant['metric_learner_params']
metric_learner_params.update({
'observation_shape': env.observation_space.shape,
'max_distance': sampler_params['kwargs'][... | 547 | 33.25 | 69 | py |
mopo | mopo-master/softlearning/policies/__init__.py | 0 | 0 | 0 | py | |
mopo | mopo-master/softlearning/policies/base_policy.py | from contextlib import contextmanager
from collections import OrderedDict
import numpy as np
from serializable import Serializable
class BasePolicy(Serializable):
def __init__(self):
self._deterministic = False
def reset(self):
"""Reset and clean the policy."""
raise NotImplementedEr... | 3,426 | 33.616162 | 79 | py |