airboxlab / rllib-energyplus

Simple EnergyPlus environments for control optimization using reinforcement learning
MIT License
39 stars 8 forks source link

FAIL serialization #12

Closed hermmanhender closed 1 year ago

hermmanhender commented 1 year ago

Hello! I have tried to modify the run.py file to be able to build the algorithm and be able to train it directly with RLlib (ie without using Tune). When I run the command algo=config.build() it tells me that it is not serializable. With the help of ray.util.inspect_serializability I have obtained the following message:

==================================================== ==============
Checking Serializability of <class '__main__.EnergyPlusEnv'>
==================================================== ==============
!!! FAIL serialization: no default __reduce__ due to non-trivial __cinit__
     Serializing '__enter__' <function Env.__enter__ at 0x7f0420dbef80>...
     Serializing '__exit__' <function Env.__exit__ at 0x7f0420dbf010>...
     Serializing '__init__' <function EnergyPlusEnv.__init__ at 0x7f0306bd70a0>...
     Serializing '__str__' <function Env.__str__ at 0x7f0420dbeef0>...
     Serializing '_compute_reward' <function EnergyPlusEnv._compute_reward at 0x7f0306bd72e0>...
     Serializing 'close' <function Env.close at 0x7f0420dbecb0>...
     Serializing 'get_wrapper_attr' <function Env.get_wrapper_attr at 0x7f0420dbf0a0>...
     Serializing 'render' <function EnergyPlusEnv.render at 0x7f0306bd7250>...
     Serializing 'reset' <function EnergyPlusEnv.reset at 0x7f0306bd7130>...
     !!! FAIL serialization: no default __reduce__ due to non-trivial __cinit__
     Detected 4 global variables. Checking serializability...
         Serializing 'Queue' <class 'queue.Queue'>...
         Serializing 'EnergyPlusRunner' <class '__main__.EnergyPlusRunner'>...
         !!! FAIL serialization: no default __reduce__ due to non-trivial __cinit__
             Serializing '__init__' <function EnergyPlusRunner.__init__ at 0x7f0306bd69e0>...
             Serializing '_collect_obs' <function EnergyPlusRunner._collect_obs at 0x7f0306bd6cb0>...
             Serializing '_flush_queues' <function EnergyPlusRunner._flush_queues at 0x7f0306bd6ef0>...
             Serializing '_init_callback' <function EnergyPlusRunner._init_callback at 0x7f0306bd6dd0>...
             Serializing '_init_handles' <function EnergyPlusRunner._init_handles at 0x7f0306bd6e60>...
             !!! FAIL serialization: no default __reduce__ due to non-trivial __cinit__
             Serializing '_collect_obs' <function EnergyPlusRunner._collect_obs at 0x7f0306bd6cb0>...
     Serializing '_compute_reward' <function EnergyPlusEnv._compute_reward at 0x7f0306bd72e0>...
==================================================== ==============
Variable:

FailTuple(_init_handles [obj=<function EnergyPlusRunner._init_handles at 0x7f0306bd6e60>, parent=<class '__main__.EnergyPlusRunner'>])

was found to be non-serializable. There may be multiple other undetected variables that were non-serializable.
Consider either removing the instantiation/imports of these variables or moving the instantiation into the scope of the function/class.
==================================================== ==============
Check https://docs.ray.io/en/master/ray-core/objects/serialization.html#troubleshooting for more information.
If you have any suggestions on how to improve this error message, please reach out to the Ray developers on github.com/ray-project/ray/issues/
==================================================== ==============
(False,
  {FailTuple(_init_handles [obj=<function EnergyPlusRunner._init_handles at 0x7f0306bd6e60>, parent=<class '__main__.EnergyPlusRunner'>])})

This is a mistake? How can I fix it? Thank you

antoine-galataud commented 1 year ago

Hi @hermmanhender and thank you for reporting this issue.

I've tested in the base code the following:

ray.util.inspect_serializability(EnergyPlusEnv({}))
ray.util.inspect_serializability(EnergyPlusRunner(1, {}, Queue(), Queue()))

and it passes ok.

The output of ray serialization inspector indicates the issue stands in EnergyPlusRunner._init_handles(). Have you checked specifically this method? You can also share that portion of your code if you want me to have a look.

hermmanhender commented 1 year ago

Thanks for the response! I've checked the method. In that portion of code I didn't change anything of the original file. I implemented the code in Colab and I found that the exit() function in EnergyPlusRunner._init_handles() and exit() function in EnergyPlusEnv.step() are the issues in the serilization. I commented these lines and the function was good.

Probably is a Colab issue with exit() function.