rlcard icon indicating copy to clipboard operation
rlcard copied to clipboard

Array has inhomogeneous shape when trying to run the pettingzoo example

Open Sisyphus192 opened this issue 2 years ago • 7 comments

Trying to run run_rl.py pettingzoo example and I get the following error:

poetry run python examples/run_rl.py --cuda 0
--> Running on the GPU

----------------------------------------
  timestep     |  0
  reward       |  3.8675
----------------------------------------

Logs saved in experiments/leduc_holdem_dqn_result/
Traceback (most recent call last):
  File "rlcard/examples/run_rl.py", line 162, in <module>
    train(args)
  File "rlcard/examples/run_rl.py", line 85, in train
    agent.feed(ts)
  File "rlcard/.venv/lib/python3.9/site-packages/rlcard/agents/pettingzoo_agents.py", line 34, in feed
    return super().feed(ts)
  File "rlcard/.venv/lib/python3.9/site-packages/rlcard/agents/dqn_agent.py", line 131, in feed
    self.train()
  File "rlcard/.venv/lib/python3.9/site-packages/rlcard/agents/dqn_agent.py", line 194, in train
    state_batch, action_batch, reward_batch, next_state_batch, legal_actions_batch, done_batch = self.memory.sample()
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (32,) + inhomogeneous part.

Sisyphus192 avatar Jan 10 '23 23:01 Sisyphus192

Ok, after some more testing this appears to be an issue with python 3.9+ The run_rl.py works fine on python 3.8, with latest versions of rl_card + pettingzoo

I had originally tested several combinations of versions of rl_card + pettingzoo in python 3.9, 3.10, and 3.11.

I don't know if this is a rl_card + pettingzoo compatibility issue with python 3.9+ or is coming from some changed behavior in torch in python 3.9+.

Sisyphus192 avatar Jan 11 '23 11:01 Sisyphus192

@Sisyphus192 Thanks for posting this. The update of Numpy causes this. I have just fixed the issue in the master branch. The PyPi version will also be updated soon.

daochenzha avatar Jan 13 '23 20:01 daochenzha

Hello, how to solve this problem when running code?

question: File "D:\lq_rlcard\rlcards\agents\dqn_agent.py", line 422, in sample return tuple(map(np.array, samples[:-1])) + (samples[-1],) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (32,) + inhomogeneous part.

JocyeI avatar Mar 07 '23 02:03 JocyeI

@Walhalla-Summary Could you provide more details about how to reproduce the results?

daochenzha avatar Mar 07 '23 06:03 daochenzha

@Walhalla-Summary What version of rlcard and numpy are you using?

Sisyphus192 avatar Mar 07 '23 17:03 Sisyphus192

@Sisyphus192 I use the latest version of rlcard, numpy=1.24, and Python version is 3.10

JocyeI avatar Mar 08 '23 00:03 JocyeI

I can't replicate this with rlcard's dqn_agent on python 3.10 and numpy 1.24. I suspect the issue lies with your changes to the dqn_agent, can you provide more details about how to reproduce this error?

Sisyphus192 avatar Mar 10 '23 20:03 Sisyphus192