syllabus.tests package#

Submodules#

syllabus.tests.determinism module#

syllabus.tests.determinism.compare_episodes(make_env, task1, task2, verbose=0)[source]#
syllabus.tests.determinism.compare_episodes_gymnasium(make_env, task1, task2, verbose=0)[source]#
syllabus.tests.determinism.compare_episodes_pettingzoo(make_env, task1, task2, verbose=0)[source]#
syllabus.tests.determinism.compare_obs(obs1, obs2)[source]#
syllabus.tests.determinism.print_if_verbose(verbose, *args, **kwargs)[source]#
syllabus.tests.determinism.test_determinism(make_env, num_episodes=10, verbose=0)[source]#

syllabus.tests.sync_test_curriculum module#

class syllabus.tests.sync_test_curriculum.SyncTestCurriculum(num_envs, num_episodes, *curriculum_args, **curriculum_kwargs)[source]#

Bases: SequentialCurriculum

Base class and API for defining curricula to interface with Gym environments.

REQUIRES_CENTRAL_UPDATES = False#
REQUIRES_STEP_UPDATES = True#
get_stats()[source]#
property requires_step_updates: bool#

Returns whether the curriculum requires step updates from the environment.

Returns:

True if the curriculum requires step updates, False otherwise

sample(k: int = 1) List | Any[source]#

Choose the next k tasks from the list.

update_on_episode(episode_return, length, task, progress, env_id=None) None[source]#

Update the curriculum with episode results from the environment.

Parameters:
  • episode_return – Episodic return

  • length – Length of the episode

  • task – Task for which the episode was completed

  • progress – Progress toward completion or success rate of the given task. 1.0 or True typically indicates a complete task.

  • env_id – Environment identifier

update_on_step(task, obs, rew, term, trunc, info, progress, env_id=None) None[source]#

Update the curriculum with the current step results from the environment.

Parameters:
  • obs – Observation from the environment

  • rew – Reward from the environment

  • term – True if the episode ended on this step, False otherwise

  • trunc – True if the episode was truncated on this step, False otherwise

  • info – Extra information from the environment

  • progress – Progress toward completion or success rate of the given task. 1.0 or True typically indicates a complete task.

  • env_id – Environment identifier

Raises:

NotImplementedError

update_on_step_batch(step_results, env_id=None)[source]#

Update the curriculum with a batch of step results from the environment.

This method can be overridden to provide a more efficient implementation. It is used as a convenience function and to optimize the multiprocessing message passing throughput.

Parameters:
  • step_results – List of step results

  • env_id – Environment identifier

syllabus.tests.sync_test_env module#

class syllabus.tests.sync_test_env.PettingZooSyncTestEnv(num_episodes, num_steps=100)[source]#

Bases: PettingZooTaskEnv

action_space(agent)[source]#

Takes in agent and returns the action space for that agent.

MUST return the same value for the same agent name

Default implementation is to return the action_spaces dict

reset(new_task=None)[source]#

Resets the environment.

And returns a dictionary of observations (keyed by the agent name)

step(action)[source]#

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.

class syllabus.tests.sync_test_env.SyncTestEnv(num_episodes, num_steps=100)[source]#

Bases: TaskEnv

reset(new_task=None)[source]#

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) and the read-only attribute np_random_seed. 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 and the env’s np_random_seed will not be altered. 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)[source]#

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.tests.utils module#

class syllabus.tests.utils.ExtractDictObservation(env: Env, filter_key: str | None = None)[source]#

Bases: ObservationWrapper, RecordConstructorArgs

Extract space from Dict observation space by the key.

observation(observation)[source]#

Returns a modified observation.

Parameters:

observation – The env observation

Returns:

The modified observation

reset(**kwargs)[source]#

Modifies the env after calling reset(), returning a modified observation using self.observation().

syllabus.tests.utils.create_cartpole_env(*args, sync_type=None, env_args=(), env_kwargs={}, wrap=False, **kwargs)[source]#
syllabus.tests.utils.create_gymnasium_synctest_env(*args, sync_type=None, env_args=(), env_kwargs={}, **kwargs)[source]#
syllabus.tests.utils.create_minigrid_env(*args, sync_type=None, env_args=(), env_kwargs={}, **kwargs)[source]#
syllabus.tests.utils.create_nethack_env(*args, sync_type=None, env_args=(), env_kwargs={}, wrap=False, **kwargs)[source]#
syllabus.tests.utils.create_pettingzoo_synctest_env(*args, sync_type=None, env_args=(), env_kwargs={}, **kwargs)[source]#
syllabus.tests.utils.create_pistonball_env(*args, sync_type=None, env_args=(), env_kwargs={}, **kwargs)[source]#
syllabus.tests.utils.create_procgen_env(*args, sync_type=None, env_args=(), env_kwargs={}, wrap=False, **kwargs)[source]#
syllabus.tests.utils.create_simpletag_env(*args, sync_type=None, env_args=(), env_kwargs={}, **kwargs)[source]#
syllabus.tests.utils.evaluate_random_policy(make_env, num_episodes=100, seeds=None)[source]#
syllabus.tests.utils.evaluate_random_policy_gymnasium(make_env, num_episodes=100, seeds=None)[source]#
syllabus.tests.utils.evaluate_random_policy_pettingzoo(make_env, num_episodes=100, seeds=None)[source]#
syllabus.tests.utils.get_test_actions(x)[source]#
syllabus.tests.utils.get_test_values(x)[source]#
syllabus.tests.utils.run_episode(env, new_task=None, curriculum=None, env_id=0)[source]#
syllabus.tests.utils.run_episodes(env_fn, env_args, env_kwargs, curriculum=None, num_episodes=10, env_id=0)[source]#

Run multiple episodes of the environment.

syllabus.tests.utils.run_episodes_queue(env_fn, env_args, env_kwargs, curriculum_components, sync=True, num_episodes=10, buffer_size=1, env_id=0)[source]#
syllabus.tests.utils.run_gymnasium_episode(env, new_task=None, curriculum=None, env_id=0)[source]#

Run a single episode of the environment.

syllabus.tests.utils.run_native_multiprocess(env_fn, env_args=(), env_kwargs={}, curriculum=None, num_envs=2, num_episodes=10, buffer_size=2)[source]#
syllabus.tests.utils.run_native_vecenv(env_fn, env_args=(), env_kwargs={}, curriculum=None, num_envs=2, num_episodes=10)[source]#
syllabus.tests.utils.run_pettingzoo_episode(env, new_task=None, curriculum=None, env_id=0)[source]#

Run a single episode of the environment.

syllabus.tests.utils.run_ray_multiprocess(env_fn, env_args=(), env_kwargs={}, curriculum=None, num_envs=2, num_episodes=10)[source]#
syllabus.tests.utils.run_set_length(env, curriculum=None, episodes=None, steps=None, env_id=0, env_outputs=None)[source]#

Run environment for a set number of episodes or steps.

syllabus.tests.utils.run_single_process(env_fn, env_args=(), env_kwargs={}, curriculum=None, num_envs=2, num_episodes=10)[source]#

Module contents#