API
alpyperl.BaseAnyLogicEnv
- class alpyperl.BaseAnyLogicEnv(env_config: dict = {'checkpoint_dir': './trained_policies', 'env_params': {}, 'exported_model_loc': './exported_model', 'run_exported_model': True, 'server_mode_on': False, 'show_terminals': False, 'verbose': False}, disable_env_checking: bool = True)[source]
The python class that contains the AnyLogic model connection and is in charge of retrieving the information required to be returned by OpenAI Gymnasium functions such as step and reset.
- __init__(env_config: dict = {'checkpoint_dir': './trained_policies', 'env_params': {}, 'exported_model_loc': './exported_model', 'run_exported_model': True, 'server_mode_on': False, 'show_terminals': False, 'verbose': False}, disable_env_checking: bool = True)[source]
Internal AnyLogic environment wrapper constructor
- Parameters:
env_config (dict) –
Environment configuration which includes:
'run_exported_model'
: In case you want to run an exported version of the model. Otherwise it will wait for the AnyLogic model to connect.'exported_model_loc'
: The location of the exported model folder.'show_terminals'
: This only applies if running an exported model and the user wants a terminal to be launched for every model instance (could be useful for debugging purposes).'server_mode_on'
: This is for internal use only. It is used to flag the AnyLogic model to not be launched when serving a trained policy.'verbose'
: To be activated in case DEBUG logger wants to be activated.'checkpoint_dir'
: The location of the checkpoint directory to store the action and observation spaces in case they are defined in the AnyLogic model. This is required mainly during policy evaluation.'env_params'
: The environment custom parameter values (e.g.,cartpole_mass
) as a dictionary
- step(action)[source]
[INTERNAL] Basic function for performing ‘steps’ in order for the simulation to move on. It requires an action as an input. This action can be of different types (including an array of values).
- reset(*, seed=None, options=None)[source]
[INTERNAL] Reset function will restart the AnyLogic model to its initial status and return the new initial state
alpyperl.create_custom_env
- alpyperl.create_custom_env(action_space, observation_space, env_config: dict | None = None)[source]
Create a custom environment by passing an action and observation
- Parameters:
action_space (gymnasium.spaces) – A valid action space: integer, double or an array of doubles
observation_space (gymnasium.spaces.Box) – A valid observation space as an array of doubles
env_config (dict) –
Environment configuration which includes:
'run_exported_model'
: In case you want to run an exported version of the model. Otherwise it will wait for the AnyLogic model to connect.'exported_model_loc'
: The location of the exported model folder.'show_terminals'
: This only applies if running an exported model and the user wants a terminal to be launched for every model instance (could be useful for debugging purposes).'server_mode_on'
: This is for internal use only. It is used to flag the AnyLogic model to not be launched when serving a trained policy.'verbose'
: To be activated in case DEBUG logger wants to be activated.'checkpoint_dir'
: The location of the checkpoint directory to store the action and observation spaces in case they are defined in the AnyLogic model. This is required mainly during policy evaluation.
- Returns:
Returns a class definition of your custom environment with the specified action and observation spaces
- Return type:
CustomEnv
alpyperl.serve.rllib.launch_policy_server
- alpyperl.serve.rllib.launch_policy_server(policy_config, env, env_config=None, trained_policy_loc='./"trained_policy"', host='0.0.0.0', port=3000)[source]
Launch server and host trained policy to allow requests. The server requires an observation in the form of an array and will return and action (type depends on action space)
- Parameters:
policy_config – It refers to the policy (also refered as RL algorithm) that will be trained. It must be an instance of rllib algorithms (check here for more information)
env (alpyperl.BaseAnyLogicEnv) – The environment or AnyLogic simulation that the policy will use to train against.
env_config (dict) – Any option that will be consumed by the environment. Options available are: TODO:
trained_policy_loc (str) – The location of the rllib trained policy. Be mindful that the rllib policy creates an aditional folder when calling
save
.checkpoint_dir = policy.save("./resources/trained_policies/cartpole_v0")
host (str) – The host ID to be used. Defaults to
localhost
or0.0.0.0
port (int) – The port the service will connect to. Defaults to
3000