ElegantRL
ElegantRL copied to clipboard
list(map()) bug
注意到在PR#202中为了加快速度,将list()
替换成[]
,但是将所有的list(map())
都替换成了[map()]
,例如AgentBase.py第282行:
traj_list1 = [map(list, zip(*traj_list))] # state, reward, done, action, noise
这不会引起迭代展开,而是生成了单个元素的list对象,如下:
>>> list(map(list, zip(*((1,2,3),(4,5,6)))))
[[1, 4], [2, 5], [3, 6]]
>>> [map(list, zip(*((1,2,3),(4,5,6))))]
[<map object at 0x7f96184ec910>]
非常感谢您的反馈!! 这两天我们陆续收到了 多个反馈,正努力修复。 这个 PR 接收得 有点快; 另一方面,也是因为 缺少 优良的Unit Tests....补课补课。
注意到在PR#202中为了加快速度,将
list()
替换成[]
,但是将所有的list(map())
都替换成了[map()]
,例如AgentBase.py第282行:traj_list1 = [map(list, zip(*traj_list))] # state, reward, done, action, noise
这不会引起迭代展开,而是生成了单个元素的list对象,如下:
>>> list(map(list, zip(*((1,2,3),(4,5,6))))) [[1, 4], [2, 5], [3, 6]] >>> [map(list, zip(*((1,2,3),(4,5,6))))] [<map object at 0x7f96184ec910>]
非常感谢您的反馈!! 这两天我们陆续收到了 多个反馈,正努力修复。 这个 PR 接收得 有点快; 另一方面,也是因为 缺少 优良的Unit Tests....补课补课。
Same problem, when will it be solved?
I have tried changing [] to list() in the line on AgentBase.py:
traj_list1 = list(map(list, zip(*traj_list)))
It doesn't work either.
It gives error in this notebook
把所有[map]
换成list(map)
就可解决。map()
生成的是一个可迭代对象(iterable),直接放进方括号[]得到的list也只能迭代使用,而不能通过index索引,后面的代码用的index索引,所以报错。
@jimmydengpeng Thank you for your contribution. I have replaced this
traj_list1 = [map(list, zip(*traj_list))] # state, reward, done, action, noise
with this
traj_list1 = list(map(list, zip(*traj_list))) # state, reward, done, action, noise
Same error
289 traj_state = torch.stack(traj_list1[0])
290 traj_action = torch.stack(traj_list1[3])
291
TypeError: stack(): argument 'tensors' (position 1) must be tuple of Tensors, not map
@sboal94 Do you install elegantrl with -e flag? traj_list1[0] is a map style. It seems that the modification doesn't work.
just replace states, rewards, masks, actions = [torch.cat(item, dim=0) for item in traj_items]
with [states, rewards, masks, actions] = traj_list
since the samples are already shaped.
The follow Pull request fix this bug ↓ Fix bug for vec env and agentbase init https://github.com/AI4Finance-Foundation/ElegantRL/pull/248
just replace
states, rewards, masks, actions = [torch.cat(item, dim=0) for item in traj_items]
with[states, rewards, masks, actions] = traj_list
since the samples are already shaped.
Thanks very much!