openai gym env.P, AttributeError 'TimeLimit' object has no attribute 'P'

我只是一个虾纸丫 提交于 2019-12-11 03:25:57

问题


I'm currently reading Hands-On Reinforcement Learning with Python by Sudharsan Ravichandiran and on one of the first examples I run into this AttributeError:

AttributeError 'TimeLimit' object has no attribute 'P'

raised by the following line:

for next_sr in env.P[state][action]: 

I can't find any documentation regarding env.P, but I found a similar example written in python2 here: https://gym.openai.com/evaluations/eval_48sirBRSRAapMjotYzjb6w/

I suppose env.P is part of an outdated library (even if the the book was published on June 2018 and the incriminated code is in python3), so how can i replace it?


回答1:


Try to unwrap the env first by adding this

env = env.unwrapped




回答2:


Try this,

for next_sr in env.env.P[state][action]:

Note the extra 'env' at start

For general use, try

>>> dir(class_name)

this will give list of member function.




回答3:


If you are using a recent version of OpenAI Gym, the solution proposed in this github issue link worked for me.

As explained in the github issue, monitoring in the latest version of gym been replaced by wrappers, therefore monitoring will not work with the latest gym. To reimplement monitoring in a recent version of Gym, chang the code that resembles :

    env.monitor.start('cartpole-hill/', force=True)

to

    env = gym.wrappers.Monitor(env,directory='cartpole-hill/',force=True,write_upon_reset=True)


来源:https://stackoverflow.com/questions/52040325/openai-gym-env-p-attributeerror-timelimit-object-has-no-attribute-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!