Task Interface#

Each environment will define tasks in a different way. A “task” might be the environment seed, an intialization argument, or an entirely different subclass. The TaskEnv and TaskWrapper provides a simple interface to change the task of an environment.

A task wrapper defines allows an existing environment to change its task when reset() is called. It can be used to map tasks from the task space to actual environment configurations, or to add entirely new tasks to an environment. To write a custom task wrapper for an environment, simply subclass the TaskWrapper for gym environments or PettingZooTaskWrapper for pettingzoo environments. Syllabus includes a task wrappers for common use cases, as well as examples of task wrappers for specific environments.

Required Methods#

  • change_task(task) - Updates the environment configuration to play the provided task on the next episode.

    This gets called before the wrapper’s environment is reset.

If changing the task only requires you to edit properties of the environment, you can do so in the change_task() method. This is called before the internal environment’s reset() function when you pass a new_task to the wrapped environment’s reset(). If you need to perform more complex operations, you can also override the entire reset() method or other environment methods.

Optional features#

syllabus.core.task_interface.environment_task_env module#

class syllabus.core.task_interface.environment_task_env.TaskEnv(*args, **kwargs)#

Bases: Env

add_task(task)#
change_task(new_task)#

Changes the task of the existing environment to the new_task.

Each environment will implement tasks differently. The easiest system would be to call a function or set an instance variable to change the task.

Some environments may need to be reset or even reinitialized to change the task. If you need to reset or re-init the environment here, make sure to check that it is not in the middle of an episode to avoid unexpected behavior.

observation(observation)#

Adds the goal encoding to the observation. Override to add additional task-specific observations. Returns a modified observation. TODO: Complete this implementation and find way to support centralized encodings

reset(*args, **kwargs)#

Resets the environment to an initial internal state, returning an initial observation and info.

This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the seed parameter otherwise if the environment already has a random number generator and reset() is called with seed=None, the RNG is not reset.

Therefore, reset() should (in the typical use case) be called with a seed right after initialization and then never again.

For Custom environments, the first line of reset() should be super().reset(seed=seed) which implements the seeding correctly.

Changed in version v0.25: The return_info parameter was removed and now info is expected to be returned.

Parameters:
  • seed (optional int) – The seed that is used to initialize the environment’s PRNG (np_random). If the environment does not already have a PRNG and seed=None (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and seed=None is passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.

  • options (optional dict) – Additional information to specify how the environment is reset (optional, depending on the specific environment)

Returns:

Observation of the initial state. This will be an element of observation_space

(typically a numpy array) and is analogous to the observation returned by step().

info (dictionary): This dictionary contains auxiliary information complementing observation. It should be analogous to

the info returned by step().

Return type:

observation (ObsType)

step(action)#

Steps the environment with the given action. Unlike the typical Gym environment, this method should also add the {“task_completion”: self.task_completion()} key to the info dictionary to support curricula that rely on this metric.

syllabus.core.task_interface.reinit_task_wrapper module#

Task wrapper for NLE that can change tasks at reset using the NLE’s task definition format.

class syllabus.core.task_interface.reinit_task_wrapper.ReinitTaskWrapper(env: Env, env_fn: Callable, task_space: Space | None = None)#

Bases: TaskWrapper

This is a general wrapper for tasks defined as subclasses of a base environment.

This wrapper reinitializes the environment with the provided env function at the start of each episode. This is a simple, general solution to using Syllabus with tasks that need to be reinitialized, but it is inefficient. It’s likely that you can achieve better performance by using a more specialized wrapper.

change_task(new_task: Tuple | int | float)#

Change task by directly editing environment class.

This ensures that all instance variables are reset, not just the ones for the current task. We do this efficiently by keeping track of which reset functions have already been called, since very few tasks override reset. If new_task is provided, we change the task before calling the final reset.

decode_task(encoding)#

Override to convert element of the MultiDiscrete task space into format usable by the reinit env_fn. This is the identity function by default.

encode_task(task)#

Override to convert task description into an element of the MultiDiscrete task space. This is the identity function by default.

reset(new_task: Tuple | int | float | None = None, **kwargs)#

Resets the environment along with all available tasks, and change the current task.

step(action)#

Step through environment and update task completion.

syllabus.core.task_interface.subclass_task_wrapper module#

Task wrapper for NLE that can change tasks at reset using the NLE’s task definition format.

class syllabus.core.task_interface.subclass_task_wrapper.SubclassTaskWrapper(env: Env, task_subclasses: List[Env] | None = None, **env_init_kwargs)#

Bases: TaskWrapper

This is a general wrapper for tasks defined as subclasses of a base environment.

This wrapper reinitializes the environment with the provided env function at the start of each episode. This is a simple, general solution to using Syllabus with tasks that need to be reinitialized, but it is inefficient. It’s likely that you can achieve better performance by using a more specialized wrapper.

change_task(new_task: int)#

Change task by directly editing environment class.

This ensures that all instance variables are reset, not just the ones for the current task. We do this efficiently by keeping track of which reset functions have already been called, since very few tasks override reset. If new_task is provided, we change the task before calling the final reset.

property current_task#
reset(new_task: int | None = None, **kwargs)#

Resets the environment along with all available tasks, and change the current task.

step(action)#

Step through environment and update task completion.

syllabus.core.task_interface.task_wrapper module#

class syllabus.core.task_interface.task_wrapper.TaskWrapper(*args, **kwargs)#

Bases: Wrapper

add_task(task)#
change_task(new_task)#

Changes the task of the existing environment to the new_task.

Each environment will implement tasks differently. The easiest system would be to call a function or set an instance variable to change the task.

Some environments may need to be reset or even reinitialized to change the task. If you need to reset or re-init the environment here, make sure to check that it is not in the middle of an episode to avoid unexpected behavior.

observation(observation)#

Adds the goal encoding to the observation. Override to add additional task-specific observations. Returns a modified observation. TODO: Complete this implementation and find way to support centralized encodings

reset(*args, **kwargs)#

Uses the reset() of the env that can be overwritten to change the returned data.

step(action)#

Uses the step() of the env that can be overwritten to change the returned data.