Example TaskWrappers#

This directory includes a couple examples of task wrappers for different environments to help you get started with creating the task interface for your environment.

syllabus.examples.task_wrappers.cartpole_task_wrapper module#

class syllabus.examples.task_wrappers.cartpole_task_wrapper.CartPoleTaskWrapper(env)#

Bases: TaskWrapper

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.

reset(*args, **kwargs)#

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

syllabus.examples.task_wrappers.minigrid_task_wrapper module#

Task wrapper that can select a new MiniGrid task on reset.

class syllabus.examples.task_wrappers.minigrid_task_wrapper.MinigridTaskWrapper(env: Env)#

Bases: TaskWrapper

This wrapper allows you to change the task of an NLE environment.

change_task(new_task: int)#

Change task by directly editing environment class.

Ignores requests for unknown tasks or task changes outside of a reset.

observation(obs)#

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(new_task=None, **kwargs)#

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

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.

step(action)#

Step through environment and update task completion.

syllabus.examples.task_wrappers.minihack_task_wrapper module#

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

class syllabus.examples.task_wrappers.minihack_task_wrapper.MinihackTaskWrapper(env: Env)#

Bases: TaskWrapper

This wrapper simply changes the seed of a Minigrid environment.

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

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

syllabus.examples.task_wrappers.nethack_task_wrapper module#

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

class syllabus.examples.task_wrappers.nethack_task_wrapper.NethackTaskWrapper(env: Env, tasks: List[NLE] | None = None, use_provided_tasks: bool = True)#

Bases: TaskWrapper

This wrapper allows you to change the task of an NLE environment.

This wrapper was designed to meet two goals.
  1. Allow us to change the task of the NLE environment at the start of an episode

  2. Allow us to use the predefined NLE task definitions without copying/modifying their code. This makes it easier to integrate with other work on nethack tasks or curricula.

Each task is defined as a subclass of the NLE, so you need to cast and reinitialize the environment to change its task. This wrapper manipulates the __class__ property to achieve this, but does so in a safe way. Specifically, we ensure that the instance variables needed for each task are available and reset at the start of the episode regardless of which task is active.

change_task(new_task: int)#

Change task by directly editing environment class.

Ignores requests for unknown tasks or task changes outside of a reset.

observation(observation)#

Parses current inventory and new items gained this timestep from the observation. Returns a modified observation.

reset(new_task=None, **kwargs)#

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

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.

step(action)#

Step through environment and update task completion.

syllabus.examples.task_wrappers.procgen_task_wrapper module#

class syllabus.examples.task_wrappers.procgen_task_wrapper.ProcgenTaskWrapper(env: Env, seed=0)#

Bases: TaskWrapper

This wrapper allows you to change the task of an NLE environment.

change_task(new_task: int)#

Change task by directly editing environment class.

Ignores requests for unknown tasks or task changes outside of a reset.

observation(obs)#

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(new_task=None, **kwargs)#

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

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.

seed(seed)#
step(action)#

Step through environment and update task completion.

Module contents#