schola.core.env.ScholaEnv
Class Definition
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.
Raises:
NoEnvironmentsException
– If there are no environment definitionsNoAgentsException
– If there are no agents defined for any environment
Parameters
unreal_connection
Type: UnrealConnection
The connection to the Unreal Engine.
verbosity
Type: int
Default: 0
The verbosity level for the environment.
environment_start_timeout
Type: int
Default: 45
The time to wait for the environment to start in seconds.
Attributes
unreal_connection
Type: UnrealConnection
The connection to the Unreal Engine.
gym_stub
Type: gym_grpc.GymServiceStub
The gRPC stub for the Gym Service.
ids
Type: List[List[int]]
A nested list of all the environments and their active agents.
agent_display_names
Type: List[Dict[int, str]]
A list of mappings from the id to the display names for each agent in each environment.
obs_defns
Type: Dict[int, Dict[int, DictSpace]]
The observation space definitions for each agent in each environment.
action_defns
Type: Dict[int, Dict[int, DictSpace]]
The action space definitions for each agent in each environment.
steps
Type: int
The number of steps taken in the current episode of the environment.
next_action
Type: Dict[int, Dict[int, Any]]
, optional
The next action to be taken by each agent in each environment.
Properties
num_agents
Type: int
(property)
Return the total number of agents in the environment.
Returns: The total number of agents.
Return type: int
num_envs
Type: int
(property)
Return the number of environments.
Returns: The number of environments.
Return type: int
Methods
__init__
__init__(unreal_connection, verbosity=0, environment_start_timeout=45)
Parameters:
- unreal_connection (
UnrealConnection
) - verbosity (
int
) - environment_start_timeout (
int
)
close
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
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
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
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 environmentsAssertionError
– If the number of options dictionaries provided, is not zero or one, does not match the number of environments
See also: gymnasium.Env.reset
– The equivalent operation in gymnasium
poll
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
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
See also: poll
– Where the actions are actually sent to unreal
soft_reset
soft_reset(ids=None)
Soft reset the environment, by waiting for Unreal to self 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]]]]