cambrian.utils.wrappers

Wrappers for the MjCambrianEnv. Used during training.

Classes

MjCambrianSingleAgentEnvWrapper

Wrapper around the MjCambrianEnv that acts as if there is a single agent.

MjCambrianPettingZooEnvWrapper

Wrapper around the MjCambrianEnv that acts as if there is a single agent, where

MjCambrianConstantActionWrapper

This wrapper will apply a constant action at specific indices of the action

MjCambrianTorchToNumpyWrapper

Wraps a torch-based environment to convert inputs and outputs to NumPy arrays.

Functions

make_wrapped_env(config, wrappers[, seed])

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 wrapper action_space is used.

observation_space[source]

Return the Env observation_space unless overwritten then the wrapper observation_space is used.

reset(*args, **kwargs)[source]

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

step(action)[source]

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

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 the env that can be overwritten to change the returned data.

step(action)[source]

Uses the step() of the env 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.

step(action)[source]

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

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

reset(*, seed=None, options=None)[source]

Resets the environment returning numpy-based observations and info.

Parameters:
  • seed – The seed for resetting the environment

  • options – The options for resetting the environment

Returns:

The numpy-based observation and extra info

render()[source]

Renders the environment returning a numpy-based image.

Returns:

The numpy-based image

make_wrapped_env(config, wrappers, seed=None, **kwargs)[source]

Utility function for creating a MjCambrianEnv.