Howto 12 - (RL) Wrap mlpro Environment class to petting zoo environment

Ver. 1.0.3 (2021-12-03)

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

Prerequisites

Please install the following packages to run this examples properly:

Results

The Bulk Good Laboratory Plant (BGLP) environment will be wrapped to a petting zoo compliant environment.

YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment BGLP: Instantiated
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment BGLP: Instantiated
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment BGLP: Operation mode set to 0
YYYY-MM-DD  HH:MM:SS.SSSSSS  I  Environment BGLP: Reset
Starting API test
...
Passed API test
test completed

There are several lines of action processing logs due to the API tests- When there is no detected failure, the completed test message will be printed.

Example Code

## -------------------------------------------------------------------------------------------------
## -- Project : MLPro - A Synoptic Framework for Standardized Machine Learning Tasks
## -- Package : mlpro
## -- Module  : Howto 12 - (RL) Wrap mlpro Environment class to petting zoo environment
## -------------------------------------------------------------------------------------------------
## -- History :
## -- yyyy-mm-dd  Ver.      Auth.    Description
## -- 2021-10-02  0.0.0     SY       Creation
## -- 2021-10-02  1.0.0     SY       Released first version
## -- 2021-10-04  1.0.1     DA       Minor fix
## -- 2021-11-15  1.0.2     DA       Refactoring
## -- 2021-12-03  1.0.3     DA       Refactoring
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.0.3 (2021-12-03)

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


from mlpro.bf.math import *
from mlpro.rl.models import *
from mlpro.wrappers.pettingzoo import WrEnvMLPro2PZoo
from mlpro.rl.pool.envs.bglp import BGLP
import random

from pettingzoo.test import api_test

mlpro_env   = BGLP(p_logging=Mode.C_LOG_ALL)
env         = WrEnvMLPro2PZoo(mlpro_env, p_num_agents=5, p_state_space=None, p_action_space=None).pzoo_env
try:
    api_test(env, num_cycles=10, verbose_progress=False)
    print("test completed")
    assert True
except:
    print("test failed")  
    assert False