environment

class nett.Environment(config: str | NETTConfig, executable_path: str, display: int = 0, base_port: int = 5004, record_chamber: bool = False, record_agent: bool = False, recording_frames: int = 1000)

Represents the environment where the agent lives.

The environment is the source of all input data streams to train the brain of the agent. It accepts a Unity Executable and wraps it around as a Gym environment by leveraging the UnityEnvironment class from the mlagents_envs library.

It provides a convenient interface for interacting with the Unity environment and includes methods for initializing the environment, rendering frames, taking steps, resetting the environment, and logging messages.

Parameters:
  • config (str | NETTConfig) – The configuration for the environment. It can be either a string representing the name of a pre-defined configuration, or an instance of the NETTConfig class.

  • executable_path (str) – The path to the Unity executable file.

  • display (int, optional) – The display number to use for the Unity environment. Defaults to 0.

  • base_port (int, optional) – The base port number to use for communication with the Unity environment. Defaults to 5004.

  • record_chamber (bool, optional) – Whether to record the chamber. Defaults to False.

  • record_agent (bool, optional) – Whether to record the agent. Defaults to False.

  • recording_frames (int, optional) – The number of frames to record. Defaults to 1000.

Raises:

ValueError – If the configuration is not a valid string or an instance of NETTConfig.

Example

>>> from nett import Environment
>>> env = Environment(config="identityandview", executable_path="path/to/executable")
initialize(mode: str, **kwargs) None

Initializes the environment with the given mode and arguments.

Parameters:
  • mode (str) – The mode to set the environment for training or testing or both.

  • **kwargs – The arguments to pass to the environment.

log(msg: str) None

Logs a message to the environment.

Parameters:

msg (str) – The message to log.

render(mode='rgb_array') ndarray

Renders the current frame of the environment.

Parameters:

mode (str, optional) – The mode to render the frame in. Defaults to “rgb_array”.

Returns:

The rendered frame of the environment.

Return type:

numpy.ndarray

reset(seed: int | None = None, **kwargs) None | list[ndarray] | ndarray

Resets the environment with the given seed and arguments.

Parameters:
  • seed (int, optional) – The seed to use for the environment. Defaults to None.

  • **kwargs – The arguments to pass to the environment.

Returns:

The initial state of the environment.

Return type:

numpy.ndarray

step(action: list[Any]) tuple[ndarray, float, bool, dict]

Takes a step in the environment with the given action.

Parameters:

action (list[Any]) – The action to take in the environment.

Returns:

A tuple containing the next state, reward, done flag, and info dictionary.

Return type:

tuple[numpy.ndarray, float, bool, dict]