schola.core.env.ScholaEnv
class schola.core.env.ScholaEnv(unreal_connection, verbosity=0, environment_start_timeout=45)
: Bases: object
A Gym-Like Environment that wraps a connection to the Unreal Engine, running the Schola Plugin for Unreal.
Parameters: : - unreal_connection (UnrealConnection) – The connection to the Unreal Engine.
- verbosity (int, default=0) – The verbosity level for the environment.
- environment_start_timeout (int, default=45) – The time to wait for the environment to start in seconds.
unreal_connection : The connection to the Unreal Engine.
Type: : UnrealConnection
gym_stub : The gRPC stub for the Gym Service.
Type: : gym_grpc.GymServiceStub
ids : A nested list of all the environments and their active agents.
Type: : List[List[int]]
agent_display_names : A list of mappings from the id to the display names for each agent in each environment.
obs_defns : The observation space definitions for each agent in each environment.
Type: : Dict[int,Dict[int,DictSpace]]
action_defns : The action space definitions for each agent in each environment.
Type: : Dict[int,Dict[int,DictSpace]]
steps : The number of steps taken in the current episode of the environment.
Type: : int
next_action : The next action to be taken by each agent in each environment.
Type: : Dict[int,Dict[int,Any]], optional
Raises: : - NoEnvironmentsException – If there are no environment definitions.
- NoAgentsException – If there are no agents defined for any environment.
Parameters: : - unreal_connection (UnrealConnection)
Methods
__init__ (unreal_connection[, verbosity, …]) | |
close () | Closes the connection to the Unreal Engine and cleans up any resources. |
get_action_space (env_id, agent_id) | Get the action space for a specific environment and agent. |
get_obs_space (env_id, agent_id) | Get the observation space for a specific environment and agent. |
hard_reset ([env_ids, seeds, options]) | Perform a hard reset on the environment. |
poll () | Polls the environment for the current state. |
send_actions (action) | Send Actions to all agents and environments. |
soft_reset ([ids]) | Soft reset the environment, by waiting for Unreal to rself reset and send a Post Reset State to python. |
Attributes
num_agents | Return the total number of agents in the environment. |
num_envs | Return the number of environments. |
__init__(unreal_connection, verbosity=0, environment_start_timeout=45) : Parameters: : - unreal_connection (UnrealConnection)
close() : Closes the connection to the Unreal Engine and cleans up any resources. It is safe to call this method multiple times.
See also
gymnasium.Env.close
: The equivalent operation in gymnasium
Return type: : None
get_action_space(env_id, agent_id) : Get the action space for a specific environment and agent.
Parameters: : - env_id (int) – The ID of the environment.
- agent_id (int) – The ID of the agent.
Returns: : The action space for the specified environment and agent.
Return type: : DictSpace
get_obs_space(env_id, agent_id) : Get the observation space for a specific environment and agent.
Parameters: : - env_id (int) – The ID of the environment.
- agent_id (int) – The ID of the agent.
Returns: : The observation space for the specified environment and agent.
Return type: : DictSpace
hard_reset(env_ids=None, seeds=None, options=None) : Perform a hard reset on the environment.
Parameters: : - env_ids (Optional*[List[int]**]*) – A list of environment IDs to reset. If None, all environments will be reset. Default is None.
- seeds (Union*[None,* List*[int]**,* int]) – The seeds to use for random number generation. If an int is provided, it will be used as the seed for all environments. If a list of ints is provided, each environment will be assigned a seed from the list. Default is None.
- options (Union*[List[Dict[str,str]],* Dict*[str,str]**,* None*]*) – The options to set for each environment. If a list of dictionaries is provided, each environment will be assigned the corresponding dictionary of options. If a single dictionary is provided, all environments will be assigned the same options. Default is None.
Returns: : A list of environment IDs that were reset.
Return type: : List
Raises: : - AssertionError – If the number of seeds provided, is not zero or one, and does not match the number of environments.
- AssertionError – If the number of options dictionaries provided, is not zero or one, does not match the number of environments.
Notes
- If seeds are provided, the environment will be seeded with the specified values.
- If options are provided, the environment will be configured with the specified options.
See also
gymnasium.Env.reset
: The equivalent operation in gymnasium
property num_agents*: int* : Return the total number of agents in the environment.
Returns: : The total number of agents.
Return type: : int
property num_envs*: int* : Return the number of environments. :returns: The number of environments. :rtype: int
poll() : Polls the environment for the current state.
Returns: : - observations (EnvAgentIdDict[Dict[str,Any]]) – A dictionary, keyed by the environment and agent Id, containing the observations for each agent.
- rewards (EnvAgentIdDict[float]) – A dictionary, keyed by the environment and agent Id, containing the reward for each agent.
- terminateds (EnvAgentIdDict[bool]) – A dictionary, keyed by the environment and agent Id, containing the termination flag for each agent.
- truncateds (EnvAgentIdDict[bool]) – A dictionary, keyed by the environment and agent Id, containing the truncation flag for each agent.
- infos (EnvAgentIdDict[Dict[str,str]]]:) – A dictionary, keyed by the environment and agent Id, containing the information dictionary for each agent.
Return type: : Tuple[Dict[int, Dict[int, Dict[str, Any]]], Dict[int, Dict[int, float]], Dict[int, Dict[int, bool]], Dict[int, Dict[int, bool]], Dict[int, Dict[int, Dict[str, str]]]]
send_actions(action) : Send Actions to all agents and environments.
Parameters: : action (EnvAgentIdDict*[Dict[str,Any]**]*) – A dictionary, keyed by the environment and agent Id, containing the actions for all active environments and agents.
Return type: : None
Notes
The actions are not sent to Unreal until Poll is called.
See also
poll
: Where the actions are actually sent to unreal
soft_reset(ids=None) : Soft reset the environment, by waiting for Unreal to rself reset and send a Post Reset State to python.
Parameters: : ids (List*[str]**,* optional) – A list of environment IDs to reset. If not provided or set to None, all environment IDs will be reset.
Returns: : - observations (EnvAgentIdDict[Dict[str,Any]]) – A dictionary, keyed by the environment and agent Id, containing the observations of the agents in the environments immediately following a reset
- infos (EnvAgentIdDict[Dict[str,str]]) – A dictionary, keyed by the environment and agent Id, containing the infos of the agents in the environment
Return type: : Tuple[Dict[int, Dict[int, Dict[str, Any]]], Dict[int, Dict[int, Dict[str, str]]]]