Base Env Class

class xuance.environment.utils.base.RawEnvironment(*args, **kwargs)[source]

Bases: ABC

A base class for new environment.

The following attributes are necessary when creating a new environment:
  • self.env: the environment object;

  • self.observation_space: the observation space of the agent;

  • self.action_space: the action space of the agent;

  • self.max_episode_steps: the maximum steps for one episode of the environment in XuanCe.

avail_actions()[source]

Returns a boolean mask indicating which actions are available for each agent.

abstractmethod close()[source]

Closes the environment.

abstractmethod render(*args, **kwargs)[source]

Renders the environment.

Returns:

The images used to visualize the environment.

Return type:

rgb_images (np.ndarray or list)

abstractmethod reset(**kwargs)[source]

Resets the environment with kwargs.

Returns:

The initial observations of the agent. info (dict): The information about the environment.

Return type:

observation (np.ndarray or list)

abstractmethod step(action)[source]

Steps through the environment with action.

Parameters:

action (np.ndarray or list) – The action to be executed.

Returns:

The next step observation after executing action. reward (np.ndarray or list): The reward returned by the environment. terminated(np.ndarray or list): A bool value that indicates if the environment should be terminated. truncated(np.ndarray or list): A bool value that indicates if the environment should be truncated. info (dict): The information about the environment.

Return type:

observation (np.ndarray or list)

class xuance.environment.utils.base.RawMultiAgentEnv(*args, **kwargs)[source]

Bases: ABC

A base class for multi-agent environment.

The following attributes are necessary when creating a new multi-agent environment in XuanCe:
  • self.env: the environment object;

  • self.observation_space: the observation space of the agent;

  • self.action_space: the action space of the agent;

  • self.agents: a list of all agents’ ids;

  • self.num_agents: the number of total agents in the environment;

  • self.groups: a list of groups. Each group contains agents’ ids with a same role;

  • self.num_groups: the number of groups of the environment, default is 1;

  • self.max_episode_steps: the maximum steps for one episode of the environment.

agent_mask()[source]

Returns boolean mask variables indicating which agents are currently alive.

avail_actions()[source]

Returns a boolean mask indicating which actions are available for each agent.

abstractmethod close()[source]

Closes the environment.

get_env_info() Dict[str, Any][source]
get_groups_info() Dict[str, Any][source]
abstractmethod render(*args, **kwargs)[source]

Renders the environment.

Returns:

The images used to visualize the environment.

Return type:

rgb_images (np.ndarray or list)

abstractmethod reset(**kwargs)[source]

Resets the environment with kwargs.

Returns:

The initial observations of the agent. info (MultiAgentDict): The information about the environment.

Return type:

observation (MultiAgentDict)

state()[source]

Returns the global state of the environment.

abstractmethod step(action_dict: Dict[Any, Any]) Tuple[Dict[Any, Any], Dict[Any, Any], Dict[Any, Any], bool, Dict[Any, Any]][source]

Steps through the environment with action.

Parameters:

action_dict (MultiAgentDict) – A dict that contains all agents’ actions.

Returns:

The next step observations after executing actions. reward (MultiAgentDict): The rewards returned by the environment. terminated(MultiAgentDict): A dict of bool values that indicates if the environment should be terminated. truncated(bool): A bool value that indicates if the environment should be truncated. info (MultiAgentDict): The information about the environment.

Return type:

observation (MultiAgentDict)