repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
MAgent | MAgent-master/python/magent/builtin/tf_model/base.py | import os
import tensorflow as tf
from magent.model import BaseModel
class TFBaseModel(BaseModel):
"""base model for tensorflow model"""
def __init__(self, env, handle, name, subclass_name):
"""init a model
Parameters
----------
env: magent.Environment
handle: handle ... | 2,880 | 35.935897 | 120 | py |
MAgent | MAgent-master/python/magent/builtin/tf_model/a2c.py | """ advantage actor critic """
import os
import numpy as np
import tensorflow as tf
from .base import TFBaseModel
class AdvantageActorCritic(TFBaseModel):
def __init__(self, env, handle, name, learning_rate=1e-3,
batch_size=64, reward_decay=0.99, eval_obs=None,
train_freq=1, va... | 10,232 | 33.570946 | 108 | py |
MAgent | MAgent-master/python/magent/builtin/tf_model/drqn.py | """Deep recurrent Q network"""
import time
import os
import collections
import numpy as np
import tensorflow as tf
from .base import TFBaseModel
class DeepRecurrentQNetwork(TFBaseModel):
def __init__(self, env, handle, name,
batch_size=32, unroll_step=8, reward_decay=0.99, learning_rate=1e-4,
... | 24,180 | 40.54811 | 124 | py |
MAgent | MAgent-master/python/magent/builtin/tf_model/dqn.py | """Deep q network"""
import time
import numpy as np
import tensorflow as tf
from .base import TFBaseModel
from ..common import ReplayBuffer
class DeepQNetwork(TFBaseModel):
def __init__(self, env, handle, name,
batch_size=64, learning_rate=1e-4, reward_decay=0.99,
train_freq=1... | 16,266 | 40.286802 | 113 | py |
MAgent | MAgent-master/python/magent/builtin/tf_model/__init__.py | from .dqn import DeepQNetwork
from .drqn import DeepRecurrentQNetwork
from .a2c import AdvantageActorCritic
| 108 | 26.25 | 39 | py |
MAgent | MAgent-master/python/magent/builtin/config/double_attack.py | """
A cooperation game, tigers must attack a same deer simultaneously to get reward
"""
import magent
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"embedding_size": 10})
deer = cfg.register_agent_type(
... | 1,213 | 27.232558 | 79 | py |
MAgent | MAgent-master/python/magent/builtin/config/battle.py | """ battle of two armies """
import magent
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"minimap_mode": True})
cfg.set({"embedding_size": 10})
small = cfg.register_agent_type(
"small",
{'w... | 943 | 26.764706 | 96 | py |
MAgent | MAgent-master/python/magent/builtin/config/pursuit.py | import magent
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
predator = cfg.register_agent_type(
"predator",
{
'width': 2, 'length': 2, 'hp': 1, 'speed': 1,
'view_range': gw.CircleRang... | 904 | 25.617647 | 81 | py |
MAgent | MAgent-master/python/magent/builtin/config/__init__.py | 0 | 0 | 0 | py | |
MAgent | MAgent-master/python/magent/builtin/config/forest.py | """ tigers eat deer to get health point and reward"""
import magent
def get_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_size})
cfg.set({"embedding_size": 10})
deer = cfg.register_agent_type(
"deer",
{'width': 1, 'l... | 963 | 26.542857 | 76 | py |
MAgent | MAgent-master/python/magent/builtin/mx_model/base.py | import os
import mxnet as mx
from magent.utility import has_gpu
from magent.model import BaseModel
class MXBaseModel(BaseModel):
def __init__(self, env, handle, name, subclass_name):
"""init a model
Parameters
----------
env: magent.Environment
handle: handle (ctypes.c_in... | 1,779 | 25.567164 | 74 | py |
MAgent | MAgent-master/python/magent/builtin/mx_model/a2c.py | """advantage actor critic"""
import os
import time
import numpy as np
import mxnet as mx
from .base import MXBaseModel
class AdvantageActorCritic(MXBaseModel):
def __init__(self, env, handle, name, eval_obs=None,
batch_size=64, reward_decay=0.99, learning_rate=1e-3,
train_freq... | 10,630 | 34.674497 | 95 | py |
MAgent | MAgent-master/python/magent/builtin/mx_model/dqn.py | import time
import numpy as np
import mxnet as mx
from .base import MXBaseModel
from ..common import ReplayBuffer
from ...utility import has_gpu
class DeepQNetwork(MXBaseModel):
def __init__(self, env, handle, name,
batch_size=64, learning_rate=1e-4, reward_decay=0.99,
train_fr... | 15,724 | 39.424165 | 101 | py |
MAgent | MAgent-master/python/magent/builtin/mx_model/__init__.py | from .dqn import DeepQNetwork
from .a2c import AdvantageActorCritic
| 68 | 22 | 37 | py |
MAgent | MAgent-master/python/magent/builtin/rule_model/rush.py | """deprecated"""
import ctypes
import numpy as np
from magent.model import BaseModel
from magent.c_lib import _LIB, as_int32_c_array, as_float_c_array
class RushPredator(BaseModel):
def __init__(self, env, handle, attack_handle, *args, **kwargs):
BaseModel.__init__(self, env, handle)
self.attac... | 1,243 | 35.588235 | 81 | py |
MAgent | MAgent-master/python/magent/builtin/rule_model/rushgather.py | """gather agent, rush to food according to minimap"""
import numpy as np
from magent.model import BaseModel
from magent.c_lib import _LIB, as_int32_c_array, as_float_c_array
class RushGatherer(BaseModel):
def __init__(self, env, handle, *args, **kwargs):
BaseModel.__init__(self, env, handle)
se... | 1,105 | 33.5625 | 78 | py |
MAgent | MAgent-master/python/magent/builtin/rule_model/runaway.py | """deprecated"""
import numpy as np
from magent.model import BaseModel
from magent.c_lib import _LIB, as_int32_c_array, as_float_c_array
class RunawayPrey(BaseModel):
def __init__(self, env, handle, away_handle, *args, **kwargs):
BaseModel.__init__(self, env, handle)
self.away_channel = env.get... | 1,006 | 34.964286 | 95 | py |
MAgent | MAgent-master/python/magent/builtin/rule_model/random.py | """A random agent"""
import numpy as np
from magent.model import BaseModel
class RandomActor(BaseModel):
def __init__(self, env, handle, *args, **kwargs):
BaseModel.__init__(self, env, handle)
self.env = env
self.handle = handle
self.n_action = env.get_action_space(handle)[0]
... | 495 | 23.8 | 76 | py |
MAgent | MAgent-master/python/magent/builtin/rule_model/__init__.py | from .random import RandomActor
from .rush import RushPredator
from .runaway import RunawayPrey
from .rushgather import RushGatherer
| 133 | 25.8 | 36 | py |
MAgent | MAgent-master/python/magent/renderer/pygame_renderer.py | from __future__ import absolute_import
from __future__ import division
import math
import pygame
import numpy as np
from magent.renderer.base_renderer import BaseRenderer
from magent.renderer.server import BaseServer
class PyGameRenderer(BaseRenderer):
def __init__(self):
super(PyGameRenderer, self).__... | 18,209 | 46.298701 | 123 | py |
MAgent | MAgent-master/python/magent/renderer/base_renderer.py | from abc import ABCMeta, abstractmethod
class BaseRenderer:
__metaclass__ = ABCMeta
def __init__(self):
pass
@abstractmethod
def start(self, *args, **kwargs):
pass
| 200 | 14.461538 | 39 | py |
MAgent | MAgent-master/python/magent/renderer/__init__.py | from .base_renderer import BaseRenderer
from .pygame_renderer import PyGameRenderer
| 84 | 27.333333 | 43 | py |
MAgent | MAgent-master/python/magent/renderer/server/base_server.py | from abc import ABCMeta, abstractmethod
class BaseServer:
__metaclass__ = ABCMeta
@abstractmethod
def get_info(self):
pass
@abstractmethod
def get_data(self, frame_id, x_range, y_range):
pass
@abstractmethod
def add_agents(self, x, y, g):
pass
@abstr... | 778 | 18 | 57 | py |
MAgent | MAgent-master/python/magent/renderer/server/sample_server.py | from .base_server import BaseServer
class SampleServer(BaseServer):
def get_group_info(self):
return [[1, 1, 0, 0, 0]]
def get_static_info(self):
return {"walls": []}
def get_data(self, frame_id, x_range, y_range):
if frame_id == 0:
return {1: [10, 10, 0]}, [(1, 0, 0)... | 716 | 24.607143 | 51 | py |
MAgent | MAgent-master/python/magent/renderer/server/random_server.py | import random
from .base_server import BaseServer
class RandomServer(BaseServer):
def __init__(self, agent_number=1000, group_number=20, map_size=100, shape_range=3, speed=5, event_range=100):
self._data = {}
self._map_size = map_size
self._number = agent_number
for i in range(age... | 2,474 | 34.357143 | 114 | py |
MAgent | MAgent-master/python/magent/renderer/server/arrange_server.py | import time
import numpy as np
import random
import magent
from magent.builtin.tf_model import DeepQNetwork
from magent.renderer.server import BaseServer
from magent.utility import FontProvider
def remove_wall(d, cur_pos, wall_set, unit):
if d == 0:
for i in range(0, unit):
for j in range(0, ... | 12,054 | 31.319035 | 159 | py |
MAgent | MAgent-master/python/magent/renderer/server/battle_server.py | import math
import time
import matplotlib.pyplot as plt
import numpy as np
import magent
from magent.builtin.tf_model import DeepQNetwork
from magent.renderer.server import BaseServer
def load_config(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height": map_si... | 7,905 | 31.941667 | 112 | py |
MAgent | MAgent-master/python/magent/renderer/server/__init__.py | from .base_server import BaseServer
from .sample_server import SampleServer
from .random_server import RandomServer
from .battle_server import BattleServer
from .arrange_server import ArrangeServer
| 198 | 32.166667 | 41 | py |
MAgent | MAgent-master/scripts/plot_many.py | """plot curve from many log files"""
import sys
import matplotlib.pyplot as plt
import numpy as np
rec_filename = sys.argv[1]
plot_key = sys.argv[2]
list_col_index = int(sys.argv[3]) if len(sys.argv) > 3 else -1
silent = sys.argv[-1] == '--silent'
def parse_pair(item):
"""parse pair \tkey: value\t """
split... | 1,994 | 24.576923 | 71 | py |
MAgent | MAgent-master/scripts/plot_log.py | """plot general log file according to given indexes"""
import sys
import matplotlib.pyplot as plt
import numpy as np
filename = sys.argv[1]
data = []
with open(filename, 'r') as fin:
for line in fin.readlines():
items = line.split('\t')
row = []
for item in items[1:]:
t = ev... | 658 | 18.969697 | 54 | py |
MAgent | MAgent-master/scripts/plot_reward.py | """deprecated"""
import matplotlib.pyplot as plt
from matplotlib.colors import hsv_to_rgb
import numpy as np
import sys
filename = sys.argv[1]
data = []
with open(filename) as fin:
for i, row in enumerate(fin.readlines()):
row = eval(row)
data.append(row)
#if i > max_n:
# brea... | 785 | 19.684211 | 72 | py |
MAgent | MAgent-master/scripts/plot_heat.py | """plot a heatmap for tournament"""
import matplotlib.pyplot as plt
import numpy as np
def plot_heatmap(x, y, z):
x, y = np.meshgrid(y, x)
fig, ax = plt.subplots()
im = ax.pcolormesh(x, y, z)
fig.colorbar(im)
def smooth(data, alpha, beta=None):
beta = beta or alpha
for i in range(0, len(data))... | 1,558 | 22.621212 | 70 | py |
MAgent | MAgent-master/scripts/plot.py | """dynamic plot class"""
import matplotlib.pyplot as plt
class DynamicPlot:
def __init__(self, n):
self.x_data = []
self.y_datas = []
self.lines = []
plt.show()
axes = plt.gca()
for i in range(n):
self.y_datas.append([])
line, = axes.plo... | 1,093 | 23.863636 | 66 | py |
MAgent | MAgent-master/scripts/tournament.py | """let saved models to play tournament"""
import os
import numpy as np
import time
import re
import math
import magent
from magent.builtin.tf_model import DeepQNetwork
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def play(env, handles, models, map_size, leftID, rightID, eps=0.05):
env.reset()
# generate map
... | 4,484 | 30.363636 | 116 | py |
MAgent | MAgent-master/scripts/rename.py | """rename tensorflow models"""
import sys
import magent
from magent.builtin.tf_model import DeepQNetwork
env = magent.GridWorld("battle", map_size=125)
handles = env.get_handles()
rounds = eval(sys.argv[1])
for i in [rounds]:
model = DeepQNetwork(env, handles[0], "battle")
print("load %d" % i)
model.l... | 412 | 19.65 | 51 | py |
MAgent | MAgent-master/scripts/test/test_1m.py | """test one million random agents"""
import time
import magent
import os
import math
import argparse
from magent.builtin.rule_model import RandomActor
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def load_forest(map_size):
gw = magent.gridworld
cfg = gw.Config()
cfg.set({"map_width": map_size, "map_height"... | 4,111 | 30.630769 | 104 | py |
MAgent | MAgent-master/scripts/test/test_examples.py | """test examples"""
import os
import time
source = [
"examples/train_tiger.py",
"examples/train_pursuit.py",
"examples/train_gather.py",
"examples/train_battle.py",
"examples/train_single.py",
"examples/train_arrange.py",
"examples/train_multi.py",
]
def do_cmd(cmd):
tic = time.time(... | 667 | 18.085714 | 59 | py |
MAgent | MAgent-master/scripts/test/search.py | """do search task"""
import os
import sys
import argparse
import time
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
def do_task(task_item):
recorder = open(task_item["name"] + "-rec.out", "w")
for value in task_item["arg_value"]:
tmp_name = task_item["name"] + "-" + value
cmd = " ".join([task_ite... | 719 | 26.692308 | 85 | py |
MAgent | MAgent-master/scripts/test/test_against.py | """test baselines in battle against"""
from search import do_task
task = [
{
"name": "against",
"type": "single-search",
"prefix": "python examples/train_against.py --train --save_every 100 --n_round 500",
"arg_name": "--alg",
"arg_value": ["a2c", "drqn", "dqn"]
}
]
fo... | 496 | 21.590909 | 92 | py |
MAgent | MAgent-master/scripts/test/test_fps.py | """test fps"""
import os
import sys
import magent
import argparse
if len(sys.argv) < 2:
print("usage python test_fps.py max_gpu frame")
parser = argparse.ArgumentParser()
parser.add_argument("--max_gpu", type=int, default=0)
parser.add_argument("--frame", type=str, default='tf')
parser.add_argument("--name", ty... | 1,192 | 23.346939 | 117 | py |
MAgent | MAgent-master/scripts/test/test_tiger.py | """test baselines in double attack"""
from search import do_task
task = [
{
"name": "tiger",
"type": "single-search",
"prefix": "python examples/train_tiger.py --train --n_round 250",
"arg_name": "--alg",
"arg_value": ["dqn", "a2c", "drqn"]
}
]
for item in task:
do... | 463 | 21.095238 | 73 | py |
filtered-sliced-optimal-transport | filtered-sliced-optimal-transport-main/render_two_class_pointset.py | import numpy as np
import matplotlib.pyplot as plt
import sys
# Create data
colors = (0,0,0)
area = np.pi*3*4*4*4
x = np.zeros([65536]) # max size of the pointset to load
y = np.zeros([65536])
f = open(str(sys.argv[1]), "r")
u = 0
for t in f:
line = t.split()
x[int(u)] = float(line[0])
y[int(u... | 861 | 20.55 | 73 | py |
filtered-sliced-optimal-transport | filtered-sliced-optimal-transport-main/render_stippling.py | import numpy as np
import matplotlib.pyplot as plt
import sys
import os
import cv2 as cv
from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox
import matplotlib.image as mpimg
x = np.zeros([32*32*4*4*4*4])
y = np.zeros([32*32*4*4*4*4])
f = open(str(sys.argv[1]), "r")
area = int(np.pi*3*4... | 1,204 | 27.023256 | 107 | py |
filtered-sliced-optimal-transport | filtered-sliced-optimal-transport-main/render_progressive_pointset.py | import numpy as np
import matplotlib.pyplot as plt
import sys
# Create data
colors = (0,0,0)
area = np.pi*3*4*4*4
x = np.zeros([65536]) # max size of the pointset to load
y = np.zeros([65536])
f = open(str(sys.argv[1]), "r")
u = 0
for t in f:
line = t.split()
x[int(u)] = float(line[0])
y[int(u... | 1,055 | 22.466667 | 155 | py |
filtered-sliced-optimal-transport | filtered-sliced-optimal-transport-main/render_color_img.py | import numpy as np
import matplotlib.pyplot as plt
import sys
import cv2 as cv
# Create data
colors = (0,0,0)
area = int(np.pi*3*4*2*3*2*2)
x = np.zeros([65536])
y = np.zeros([65536])
f = open(str(sys.argv[1]), "r")
u = 0
for t in f:
line = t.split()
x[int(u)] = float(line[0])
y[int(u)] = fl... | 1,599 | 29.188679 | 159 | py |
mtenv | mtenv-main/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# type: ignore
import codecs
import os.path
import subprocess
from pathlib import Path
import setuptools
def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), "r") as fp:
... | 2,743 | 30.54023 | 98 | py |
mtenv | mtenv-main/noxfile.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# type: ignore
import base64
import os
from pathlib import Path
from typing import List, Set
import nox
from nox.sessions import Session
DEFAULT_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"]
PYTHON_VERSIONS = os.environ.get(
"NOX_PYTHON_VERS... | 5,746 | 31.653409 | 88 | py |
mtenv | mtenv-main/examples/wrapped_bandit.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List, Optional
from gym import spaces
from examples.bandit import BanditEnv # type: ignore[import]
from mtenv.utils import seeding
from mtenv.utils.types import TaskObsType, TaskStateType
from mtenv.wrappers.env_to_mtenv import... | 2,051 | 32.096774 | 90 | py |
mtenv | mtenv-main/examples/finite_mtenv_bandit.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Any, Dict, List, Optional
import numpy as np
from gym import spaces
from mtenv import MTEnv
from mtenv.utils import seeding
from mtenv.utils.types import ActionType, ObsType, StepReturnType
TaskStateType = int
class FiniteMTB... | 4,016 | 35.518182 | 102 | py |
mtenv | mtenv-main/examples/bandit.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List, Optional, Tuple
import numpy as np
from gym import spaces
from gym.core import Env
from mtenv.utils import seeding
from mtenv.utils.types import ActionType, DoneType, EnvObsType, InfoType, RewardType
StepReturnType = Tupl... | 1,632 | 27.649123 | 84 | py |
mtenv | mtenv-main/examples/mtenv_bandit.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import numpy as np
from gym import spaces
from mtenv import MTEnv
from mtenv.utils.types import ActionType, ObsType, StepReturnType, TaskStateType
class MTBanditEnv(MTEnv):
def __init__(self, n_arms: int):
super().__init__(
... | 2,186 | 29.802817 | 94 | py |
mtenv | mtenv-main/tests/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
| 71 | 35 | 70 | py |
mtenv | mtenv-main/tests/envs/registered_env_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import os
from copy import deepcopy
from pathlib import Path
from typing import Any, Dict, List, Tuple
import pytest
from mtenv import make
from mtenv.envs.registration import MultitaskEnvSpec, mtenv_registry
from tests.utils.utils import validat... | 2,599 | 33.666667 | 88 | py |
mtenv | mtenv-main/tests/envs/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
| 71 | 35 | 70 | py |
mtenv | mtenv-main/tests/examples/bandit_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from examples.bandit import BanditEnv # noqa: E402
from tests.utils.utils import validate_single_task_env
def get_valid_n_arms() -> List[int]:
return [1, 10, 100]
def get_invalid_n_arms() -> List[in... | 784 | 22.787879 | 70 | py |
mtenv | mtenv-main/tests/examples/wrapped_bandit_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from gym import spaces
from examples.bandit import BanditEnv # noqa: E402
from examples.wrapped_bandit import MTBanditWrapper # noqa: E402
from tests.utils.utils import validate_mtenv
def get_valid_n_arms(... | 1,043 | 25.769231 | 82 | py |
mtenv | mtenv-main/tests/examples/mtenv_bandit_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from examples.mtenv_bandit import MTBanditEnv # noqa: E402
from tests.utils.utils import validate_mtenv
def get_valid_n_arms() -> List[int]:
return [1, 10, 100]
def get_invalid_n_arms() -> List[int]:
... | 736 | 24.413793 | 70 | py |
mtenv | mtenv-main/tests/examples/finite_mtenv_bandit_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from examples.finite_mtenv_bandit import FiniteMTBanditEnv # noqa: E402
from tests.utils.utils import validate_mtenv
def get_valid_n_tasks_and_arms() -> List[int]:
return [(1, 2), (10, 20), (100, 200)]
... | 906 | 30.275862 | 75 | py |
mtenv | mtenv-main/tests/examples/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
| 71 | 35 | 70 | py |
mtenv | mtenv-main/tests/wrappers/ntasks_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from mtenv.envs.control.cartpole import MTCartPole
from mtenv.wrappers.ntasks import NTasks as NTasksWrapper
from tests.utils.utils import validate_mtenv
def get_valid_num_tasks() -> List[int]:
return ... | 865 | 24.470588 | 70 | py |
mtenv | mtenv-main/tests/wrappers/ntasks_id_test.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List
import pytest
from mtenv.envs.control.cartpole import MTCartPole
from mtenv.wrappers.ntasks_id import NTasksId as NTasksIdWrapper
from tests.utils.utils import validate_mtenv
def get_valid_num_tasks() -> List[int]:
... | 882 | 24.970588 | 70 | py |
mtenv | mtenv-main/tests/wrappers/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
| 71 | 35 | 70 | py |
mtenv | mtenv-main/tests/utils/utils.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Tuple
import gym
import numpy as np
from mtenv import MTEnv
from mtenv.utils.types import (
DoneType,
EnvObsType,
InfoType,
ObsType,
RewardType,
StepReturnType,
)
StepReturnTypeSingleEnv = Tuple[EnvObsT... | 1,854 | 25.5 | 75 | py |
mtenv | mtenv-main/mtenv/core.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Core API of MultiTask Environments for Reinforcement Learning."""
from abc import ABC, abstractmethod
from typing import List, Optional
from gym.core import Env
from gym.spaces.dict import Dict as DictSpace
from gym.spaces.space import Space
fro... | 7,251 | 33.046948 | 89 | py |
mtenv | mtenv-main/mtenv/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
__version__ = "1.0"
from mtenv.core import MTEnv # noqa: F401
from mtenv.envs.registration import make # noqa: F401
__all__ = ["MTEnv", "make"]
| 219 | 26.5 | 70 | py |
mtenv | mtenv-main/mtenv/envs/registration.py | # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
from typing import Any, Dict, Optional
from gym import error
from gym.core import Env
from gym.envs.registration import EnvRegistry, EnvSpec
class MultitaskEnvSpec(EnvSpec): # type: ignore[misc]
def __init__(
self,
id: st... | 2,823 | 31.45977 | 74 | py |
mtenv | mtenv-main/mtenv/envs/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from copy import deepcopy
from mtenv.envs.registration import register
# Control Task
# ----------------------------------------
register(
id="MT-CartPole-v0",
entry_point="mtenv.envs.control.cartpole:MTCartPole",
test_kwargs={
... | 3,190 | 24.528 | 112 | py |
mtenv | mtenv-main/mtenv/envs/control/cartpole.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import math
import numpy as np
from gym import logger, spaces
from mtenv import MTEnv
from mtenv.utils import seeding
"""
Classic cart-pole system implemented based on Rich Sutton et al.
Copied from http://incompleteideas.net/sutton/book/code/po... | 6,710 | 32.059113 | 218 | py |
mtenv | mtenv-main/mtenv/envs/control/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
import setuptools
from mtenv.utils.setup_utils import parse_dependency
env_name = "control"
path = Path(__file__).parent / "requirements.txt"
requirements = parse_dependency(path)
with (Path(__file__).parent / "README.md... | 812 | 27.034483 | 70 | py |
mtenv | mtenv-main/mtenv/envs/control/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from mtenv.envs.control.cartpole import CartPole, MTCartPole # noqa: F401
| 146 | 48 | 74 | py |
mtenv | mtenv-main/mtenv/envs/control/acrobot.py | # Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
import numpy as np
from gym import spaces
from numpy import cos, pi, sin
from mtenv import MTEnv
from mtenv.utils import seeding
__copyright__... | 10,088 | 29.480363 | 122 | py |
mtenv | mtenv-main/mtenv/envs/metaworld/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
import setuptools
from mtenv.utils.setup_utils import parse_dependency
env_name = "metaworld"
path = Path(__file__).parent / "requirements.txt"
requirements = parse_dependency(path)
with (Path(__file__).parent / "README... | 766 | 25.448276 | 70 | py |
mtenv | mtenv-main/mtenv/envs/metaworld/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/metaworld/env.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import random
from typing import Any, Callable, Dict, List, Optional, Tuple
import metaworld
from gym import Env
from mtenv import MTEnv
from mtenv.envs.metaworld.wrappers.normalized_env import ( # type: ignore[attr-defined]
NormalizedEnvWrap... | 7,359 | 36.171717 | 100 | py |
mtenv | mtenv-main/mtenv/envs/metaworld/wrappers/normalized_env.py | # This code is taken from: https://raw.githubusercontent.com/rlworkgroup/garage/af57bf9c6b10cd733cb0fa9bfe3abd0ba239fd6e/src/garage/envs/normalized_env.py
#
# """"An environment wrapper that normalizes action, observation and reward."""
# type: ignore
import gym
import gym.spaces
import gym.spaces.utils
import numpy as... | 5,977 | 34.164706 | 154 | py |
mtenv | mtenv-main/mtenv/envs/metaworld/wrappers/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/shared/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/shared/wrappers/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/shared/wrappers/multienv.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to (lazily) construct a multitask environment from a list of
constructors (list of functions to construct the environments)."""
from typing import Callable, List, Optional
from gym.core import Env
from gym.spaces.discrete import Dis... | 3,850 | 37.89899 | 94 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/dmc_env.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Any, Dict
import gym
from gym.core import Env
from gym.envs.registration import register
from mtenv.envs.hipbmdp.wrappers import framestack, sticky_observation
def _build_env(
domain_name: str,
task_name: str,
seed... | 3,821 | 31.948276 | 83 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
import setuptools
from mtenv.utils.setup_utils import parse_dependency
env_name = "hipbmdp"
path = Path(__file__).parent / "requirements.txt"
requirements = parse_dependency(path)
with (Path(__file__).parent / "README.m... | 764 | 25.37931 | 70 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/hipbmdp/env.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Any, Callable, Dict, List
from gym.core import Env
from mtenv import MTEnv
from mtenv.envs.hipbmdp import dmc_env
from mtenv.envs.shared.wrappers.multienv import MultiEnvWrapper
EnvBuilderType = Callable[[], Env]
TaskStateType ... | 2,727 | 32.268293 | 84 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/wrappers/framestack.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to stack observations for single task environments."""
from collections import deque
import gym
import numpy as np
from mtenv.utils.types import ActionType, EnvStepReturnType
class FrameStack(gym.Wrapper): # type: ignore[misc]
#... | 1,554 | 31.395833 | 74 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/wrappers/dmc_wrapper.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Any, Dict, Optional
import dmc2gym
import numpy as np
from dmc2gym.wrappers import DMCWrapper as BaseDMCWrapper
from gym import spaces
import local_dm_control_suite as local_dmc_suite
class DMCWrapper(BaseDMCWrapper):
def... | 2,634 | 31.530864 | 85 | py |
mtenv | mtenv-main/mtenv/envs/hipbmdp/wrappers/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/hipbmdp/wrappers/sticky_observation.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to enable sitcky observations for single task environments."""
# type: ignore
import random
from collections import deque
import gym
class StickyObservation(gym.Wrapper):
def __init__(self, env: gym.Env, sticky_probability: float, ... | 2,110 | 36.035088 | 91 | py |
mtenv | mtenv-main/mtenv/envs/mpte/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
import setuptools
from mtenv.utils.setup_utils import parse_dependency
env_name = "mpte"
path = Path(__file__).parent / "requirements.txt"
requirements = parse_dependency(path)
with (Path(__file__).parent / "README.md").... | 737 | 25.357143 | 70 | py |
mtenv | mtenv-main/mtenv/envs/mpte/two_goal_maze_env.py | # Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
import copy
import math
from typing import Any, Dict, List, Optional, Tuple, Union
import numpy as np
from gym import spaces
from gym.spaces.box... | 11,245 | 31.69186 | 122 | py |
mtenv | mtenv-main/mtenv/envs/mpte/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/envs/tabular_mdp/tmdp.py | # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import scipy.special
from gym import spaces
from gym.utils import seeding
from mtenv import MTEnv
clas... | 3,884 | 30.844262 | 155 | py |
mtenv | mtenv-main/mtenv/envs/tabular_mdp/setup.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
import setuptools
from mtenv.utils.setup_utils import parse_dependency
env_name = "tabular_mdp"
path = Path(__file__).parent / "requirements.txt"
requirements = parse_dependency(path)
setuptools.setup(
name=env_name... | 726 | 25.925926 | 70 | py |
mtenv | mtenv-main/mtenv/envs/tabular_mdp/__init__.py | 0 | 0 | 0 | py | |
mtenv | mtenv-main/mtenv/wrappers/sample_random_task.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper that samples a new task everytime the environment is reset."""
from mtenv import MTEnv
from mtenv.utils.types import ObsType
from mtenv.wrappers.multitask import MultiTask
class SampleRandomTask(MultiTask):
def __init__(self, env: ... | 639 | 26.826087 | 73 | py |
mtenv | mtenv-main/mtenv/wrappers/ntasks_id.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to fix the number of tasks in an existing multitask environment
and return the id of the task as part of the observation."""
from gym.spaces import Dict as DictSpace
from gym.spaces import Discrete
from mtenv import MTEnv
from mtenv.uti... | 2,410 | 34.455882 | 94 | py |
mtenv | mtenv-main/mtenv/wrappers/multitask.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to change the behaviour of an existing multitask environment."""
from typing import List, Optional
from numpy.random import RandomState
from mtenv import MTEnv
from mtenv.utils import seeding
from mtenv.utils.types import (
ActionT... | 2,261 | 31.314286 | 81 | py |
mtenv | mtenv-main/mtenv/wrappers/ntasks.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to fix the number of tasks in an existing multitask environment."""
from typing import List
from mtenv import MTEnv
from mtenv.utils.types import TaskStateType
from mtenv.wrappers.multitask import MultiTask
class NTasks(MultiTask):
... | 2,223 | 36.694915 | 94 | py |
mtenv | mtenv-main/mtenv/wrappers/__init__.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from mtenv.wrappers.ntasks import NTasks # noqa: F401
from mtenv.wrappers.ntasks_id import NTasksId # noqa: F401
from mtenv.wrappers.sample_random_task import SampleRandomTask # noqa: F401
| 263 | 51.8 | 76 | py |
mtenv | mtenv-main/mtenv/wrappers/env_to_mtenv.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
"""Wrapper to convert an environment into multitask environment."""
from typing import Any, Dict, List, Optional
from gym.core import Env
from gym.spaces.space import Space
from mtenv import MTEnv
from mtenv.utils import seeding
from mtenv.utils.t... | 3,253 | 28.581818 | 78 | py |
mtenv | mtenv-main/mtenv/utils/setup_utils.py | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from pathlib import Path
from typing import List
def parse_dependency(filepath: Path) -> List[str]:
"""Parse python dependencies from a file.
The list of dependencies is used by `setup.py` files. Lines starting
with "#" are ingored (u... | 877 | 27.322581 | 72 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.