Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
#!/usr/bin/env python3
from gym.core import Env
class MetaEnv(Env):
Interface for l2l envs. Environments have a certain number of task specific parameters that uniquely
identify the environment. Tasks are then a dictionary with the names of these parameters as keys and the
values of these parameters as values. Environments must then implement functions to get, set and sample tasks.
The flow is then
env = EnvClass()
tasks = env.sample_tasks(num_tasks)
for task in tasks:
# *training code here*
Adapted from Tristan Deleu and Jonas Rothfuss' implementations.
def __init__(self, task=None):
super(MetaEnv, self).__init__()
if task is None:
task = self.sample_tasks(1)[0]
def sample_tasks(self, num_tasks):
Samples num_tasks tasks for training or evaluation.
How the tasks are sampled determines the task distribution.
num_tasks (int) - number of tasks to sample
tasks ([dict]) - returns a list of num_tasks tasks. Tasks are
dictionaries of task specific parameters. A
minimal example for num_tasks = 1 is [{'goal': value}].
raise NotImplementedError
def set_task(self, task):
Sets the task specific parameters defined in task.
task (dict) - A dictionary of task specific parameters and
their values.
self._task = task
def get_task(self):
Returns the current task.
(task) - Dictionary of task specific parameters and their
current values.
return self._task