cambrian.utils.wrappers¶
Wrappers for the MjCambrianEnv. Used during training.
Classes¶
Wrapper around the MjCambrianEnv that acts as if there is a single agent. |
|
Wrapper around the MjCambrianEnv that acts as if there is a single agent, where |
|
This wrapper will apply a constant action at specific indices of the action |
|
Wraps a torch-based environment to convert inputs and outputs to NumPy arrays. |
Functions¶
|
Utility function for creating a MjCambrianEnv. |
Module Contents¶
- class MjCambrianSingleAgentEnvWrapper(env, *, agent_name=None, combine_rewards=True, combine_terminated=True, combine_truncated=True)[source]¶
Bases:
gymnasium.Wrapper
Wrapper around the MjCambrianEnv that acts as if there is a single agent.
Will replace all multi-agent methods to just use the first agent.
- Keyword Arguments:
agent_name – The name of the agent to use. If not provided, the first agent will be used.
- action_space[source]¶
Return the
Env
action_space
unless overwritten then the wrapperaction_space
is used.
- observation_space[source]¶
Return the
Env
observation_space
unless overwritten then the wrapperobservation_space
is used.
- class MjCambrianPettingZooEnvWrapper(env)[source]¶
Bases:
gymnasium.Wrapper
Wrapper around the MjCambrianEnv that acts as if there is a single agent, where in actuality, there’s multi-agents.
SB3 doesn’t support Dict action spaces, so this wrapper will flatten the action into a single space. The observation can be a dict; however, nested dicts are not allowed.
- reset(*args, **kwargs)[source]¶
Uses the
reset()
of theenv
that can be overwritten to change the returned data.
- step(action)[source]¶
Uses the
step()
of theenv
that can be overwritten to change the returned data.
- property observation_space: gymnasium.spaces.Dict[source]¶
SB3 doesn’t support nested Dict observation spaces, so we’ll flatten it. If each agent has a Dict observation space, we’ll flatten it into a single observation where the key in the dict is the agent name and the original space name.
- property action_space: gymnasium.spaces.Box[source]¶
The only gym.Space that SB3 supports that’s continuous for the action space is a Box. We can assume each agent’s action space is a Box, so we’ll flatten each action space into one Box for the environment.
- Assumptions:
All agents have the same number of actions
All actions have the same shape
All actions are continuous
All actions are normalized between -1 and 1
- class MjCambrianConstantActionWrapper(env, constant_actions)[source]¶
Bases:
gymnasium.Wrapper
This wrapper will apply a constant action at specific indices of the action space.
- Parameters:
constant_actions – A dictionary where the keys are the indices of the action space and the values are the constant actions to apply.
- class MjCambrianTorchToNumpyWrapper(env, *, convert_action=False)[source]¶
Bases:
gymnasium.Wrapper
Wraps a torch-based environment to convert inputs and outputs to NumPy arrays.
- step(actions)[source]¶
Using a numpy-based action that is converted to torch to be used by the environment.
- Parameters:
action – A numpy-based action
- Returns:
The numpy-based observation, reward, termination, truncation, and extra info