Howto 11 - (RL) Wrap mlpro Environment class to gym environment

Ver. 1.0.3 (2022-03-21)

This module shows how to wrap mlpro’s Environment class to gym compatible.

Prerequisites

Please install the following packages to run this examples properly:

Results

The GridWorld environment will be wrapped to a gym environment. By making use of gym’s environment checker, we could confirm the success of the environment wrapping.

YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Instantiated
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Instantiated
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Operation mode set to 0
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Reset
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Reset
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Start processing action
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Actions of agent 0 = [3.415721893310547, -7.9934492111206055]
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment GridWorld: Action processing finished successfully
...

There will be several more lines of action processing logs due to the nature of the environment checker. When there is no detected failure, the environment is successfully wrapped.

Example Code

## -------------------------------------------------------------------------------------------------
## -- Project : MLPro - A Synoptic Framework for Standardized Machine Learning Tasks
## -- Package : mlpro
## -- Module  : Howto 11 - (RL) Wrap mlpro Environment class to gym environment 
## -------------------------------------------------------------------------------------------------
## -- History :
## -- yyyy-mm-dd  Ver.      Auth.    Description
## -- 2021-09-30  0.0.0     SY       Creation
## -- 2021-09-30  1.0.0     SY       Released first version
## -- 2021-10-04  1.0.1     DA       Minor fixes
## -- 2021-12-22  1.0.2     DA       Cleaned up a bit
## -- 2022-03-21  1.0.3     MRD      Use Gym Env Checker
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.0.3 (2022-03-21)

This module shows how to wrap mlpro's Environment class to gym compatible.
"""


from mlpro.wrappers.openai_gym import WrEnvMLPro2GYM
from mlpro.rl.pool.envs.gridworld import GridWorld
from gym.utils.env_checker import check_env



mlpro_env   = GridWorld(p_logging=True)
env         = WrEnvMLPro2GYM(mlpro_env, p_state_space=None, p_action_space=None)
check_env(env)