mtenv.wrappers package¶
Submodules¶
mtenv.wrappers.env_to_mtenv module¶
Wrapper to convert an environment into multitask environment.
-
class
mtenv.wrappers.env_to_mtenv.
EnvToMTEnv
(env: gym.core.Env, task_observation_space: gym.spaces.space.Space)[source]¶ Bases:
mtenv.core.MTEnv
Wrapper to convert an environment into a multitak environment.
- Parameters
env (Env) – Environment to wrap over.
task_observation_space (Space) – Task observation space for the resulting multitask environment.
-
close
() → Any[source]¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
get_task_obs
() → Union[str, int, float, numpy.ndarray][source]¶ Get the current value of task observation.
Environment returns task observation everytime we call step or reset. This function is useful when the user wants to access the task observation without acting in (or resetting) the environment.
- Returns
- Return type
TaskObsType
-
get_task_state
() → Any[source]¶ Return all the information needed to execute the current task again.
This function is useful when we want to set the environment to a previous task.
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
reset
(**kwargs: Dict[str, Any]) → Dict[str, Union[numpy.ndarray, str, int, float]][source]¶ Reset the environment to some initial state and return the observation in the new state.
The subclasses, extending this class, should ensure that the environment seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_env_seed_is_set().
- Returns
For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
ObsType
-
reset_task_state
() → None[source]¶ Sample a new task_state and set the environment to that task_state.
For more information on task_state, refer Task State.
-
sample_task_state
() → Any[source]¶ Sample a task_state.
task_state contains all the information that the environment needs to switch to any other task.
The subclasses, extending this class, should ensure that the task seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_task_seed_is_set().
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
seed
(seed: Optional[int] = None) → List[int][source]¶ Set the seed for the environment’s random number generator.
Invoke seed_task to set the seed for the task’s random number generator.
- Parameters
seed (Optional[int], optional) – Defaults to None.
- Returns
Returns the list of seeds used in the environment’s random number generator. The first value in the list should be the seed that should be passed to this method for reproducibility.
- Return type
List[int]
-
set_task_state
(task_state: Any) → None[source]¶ Reset the environment to a particular task.
task_state contains all the information that the environment needs to switch to any other task.
- Parameters
task_state (TaskStateType) – For more information on task_state, refer Task State.
-
property
spec
¶
-
step
(action: Union[str, int, float, numpy.ndarray]) → Tuple[Dict[str, Union[numpy.ndarray, str, int, float]], float, bool, Dict[str, Any]][source]¶ Execute the action in the environment.
- Parameters
action (ActionType) –
- Returns
Tuple of multitask observation, reward, done, and info. For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
StepReturnType
-
property
unwrapped
¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
mtenv.wrappers.multitask module¶
Wrapper to change the behaviour of an existing multitask environment.
-
class
mtenv.wrappers.multitask.
MultiTask
(env: mtenv.core.MTEnv)[source]¶ Bases:
mtenv.core.MTEnv
Wrapper to change the behaviour of an existing multitask environment
- Parameters
env (MTEnv) – Multitask environment to wrap over.
-
get_task_obs
() → Union[str, int, float, numpy.ndarray][source]¶ Get the current value of task observation.
Environment returns task observation everytime we call step or reset. This function is useful when the user wants to access the task observation without acting in (or resetting) the environment.
- Returns
- Return type
TaskObsType
-
get_task_state
() → Any[source]¶ Return all the information needed to execute the current task again.
This function is useful when we want to set the environment to a previous task.
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
reset
() → Dict[str, Union[numpy.ndarray, str, int, float]][source]¶ Reset the environment to some initial state and return the observation in the new state.
The subclasses, extending this class, should ensure that the environment seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_env_seed_is_set().
- Returns
For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
ObsType
-
reset_task_state
() → None[source]¶ Sample a new task_state and set the environment to that task_state.
For more information on task_state, refer Task State.
-
sample_task_state
() → Any[source]¶ Sample a task_state.
task_state contains all the information that the environment needs to switch to any other task.
The subclasses, extending this class, should ensure that the task seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_task_seed_is_set().
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
seed
(seed: Optional[int] = None) → List[int][source]¶ Set the seed for the environment’s random number generator.
Invoke seed_task to set the seed for the task’s random number generator.
- Parameters
seed (Optional[int], optional) – Defaults to None.
- Returns
Returns the list of seeds used in the environment’s random number generator. The first value in the list should be the seed that should be passed to this method for reproducibility.
- Return type
List[int]
-
seed_task
(seed: Optional[int] = None) → List[int][source]¶ Set the seed for the task’s random number generator.
Invoke seed to set the seed for the environment’s random number generator.
- Parameters
seed (Optional[int], optional) – Defaults to None.
- Returns
Returns the list of seeds used in the task’s random number generator. The first value in the list should be the seed that should be passed to this method for reproducibility.
- Return type
List[int]
-
set_task_state
(task_state: Any) → None[source]¶ Reset the environment to a particular task.
task_state contains all the information that the environment needs to switch to any other task.
- Parameters
task_state (TaskStateType) – For more information on task_state, refer Task State.
-
step
(action: Union[str, int, float, numpy.ndarray]) → Tuple[Dict[str, Union[numpy.ndarray, str, int, float]], float, bool, Dict[str, Any]][source]¶ Execute the action in the environment.
- Parameters
action (ActionType) –
- Returns
Tuple of multitask observation, reward, done, and info. For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
StepReturnType
mtenv.wrappers.ntasks module¶
Wrapper to fix the number of tasks in an existing multitask environment.
-
class
mtenv.wrappers.ntasks.
NTasks
(env: mtenv.core.MTEnv, n_tasks: int)[source]¶ Bases:
mtenv.wrappers.multitask.MultiTask
Wrapper to fix the number of tasks in an existing multitask environment to n_tasks.
Each task is sampled in this fixed set of n_tasks.
- Parameters
env (MTEnv) – Multitask environment to wrap over.
n_tasks (int) – Number of tasks to sample.
-
reset_task_state
() → None[source]¶ Sample a new task_state from the set of n_tasks tasks and set the environment to that task_state.
For more information on task_state, refer Task State.
-
sample_task_state
() → Any[source]¶ Sample a task_state from the set of n_tasks tasks.
task_state contains all the information that the environment needs to switch to any other task.
The subclasses, extending this class, should ensure that the task seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_task_seed_is_set().
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
mtenv.wrappers.ntasks_id module¶
Wrapper to fix the number of tasks in an existing multitask environment and return the id of the task as part of the observation.
-
class
mtenv.wrappers.ntasks_id.
NTasksId
(env: mtenv.core.MTEnv, n_tasks: int)[source]¶ Bases:
mtenv.wrappers.ntasks.NTasks
Wrapper to fix the number of tasks in an existing multitask environment to n_tasks.
Each task is sampled in this fixed set of n_tasks. The agent observes the id of the task.
- Parameters
env (MTEnv) – Multitask environment to wrap over.
n_tasks (int) – Number of tasks to sample.
-
get_task_obs
() → Any[source]¶ Get the current value of task observation.
Environment returns task observation everytime we call step or reset. This function is useful when the user wants to access the task observation without acting in (or resetting) the environment.
- Returns
- Return type
TaskObsType
-
get_task_state
() → Any[source]¶ Return all the information needed to execute the current task again.
This function is useful when we want to set the environment to a previous task.
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
reset
() → Dict[str, Union[numpy.ndarray, str, int, float]][source]¶ Reset the environment to some initial state and return the observation in the new state.
The subclasses, extending this class, should ensure that the environment seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_env_seed_is_set().
- Returns
For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
ObsType
-
sample_task_state
() → Any[source]¶ Sample a task_state from the set of n_tasks tasks.
task_state contains all the information that the environment needs to switch to any other task.
The subclasses, extending this class, should ensure that the task seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_task_seed_is_set().
- Returns
For more information on task_state, refer Task State.
- Return type
TaskStateType
-
set_task_state
(task_state: Any) → None[source]¶ Reset the environment to a particular task.
task_state contains all the information that the environment needs to switch to any other task.
- Parameters
task_state (TaskStateType) – For more information on task_state, refer Task State.
-
step
(action: Union[str, int, float, numpy.ndarray]) → Tuple[Dict[str, Union[numpy.ndarray, str, int, float]], float, bool, Dict[str, Any]][source]¶ Execute the action in the environment.
- Parameters
action (ActionType) –
- Returns
Tuple of multitask observation, reward, done, and info. For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
StepReturnType
mtenv.wrappers.sample_random_task module¶
Wrapper that samples a new task everytime the environment is reset.
-
class
mtenv.wrappers.sample_random_task.
SampleRandomTask
(env: mtenv.core.MTEnv)[source]¶ Bases:
mtenv.wrappers.multitask.MultiTask
Wrapper that samples a new task everytime the environment is reset.
- Parameters
env (MTEnv) – Multitask environment to wrap over.
-
reset
() → Dict[str, Union[numpy.ndarray, str, int, float]][source]¶ Reset the environment to some initial state and return the observation in the new state.
The subclasses, extending this class, should ensure that the environment seed is set (by calling seed(int)) before invoking this method (for reproducibility). It can be done by invoking self.assert_env_seed_is_set().
- Returns
For more information on multitask observation returned by the environment, refer MultiTask Observation.
- Return type
ObsType