Closed WangJuan6 closed 3 months ago
Sorry, I tried running the code for a while and I found I made a mistake: the environment reinitialization is not related to the value of Done.
When I run the code by python ding/example/ppo_with_complex_obs.py, the codes in the main function:
and
will initialize the environment. But, the code in
will also reinitialize the new environment. The new environments will used to train and evaluate algorithms. So, the increased memory overhead comes from the environment initialized in the main function.
I am not sure if my understanding is correct, but I hope it can be of help.
Thanks
For your case, you need to implement you custom env like a lazy_init
way. This form is just to set necessary member variables in __init__
method instead of init environment. And the real initialization happens in the reset
method. You can refer to the code here.
BTW, you can print(id(self))
in env to check whether a new env is launched or just a old env is reset.
Sorry, you mentioned it in the documentation, but I forgot. This problem has been solved, thank you so much.
Dear Author, I referenced the documentation to construct the custom environment, but this documentation does not specify how to define the
close
function. I define the close function simply by:This function will close the environment window.
When the done is True, it seems that this close function is not being called. Besides, the code in the following location:
reinitializes the environment, and a new window is opened. Since the old window is not closed, memory overhead is increased. I need to call the close function to close the old window to limit memory overhead. I am not sure if my understanding is correct. Can you help me to solve this problem? Thanks