datamllab / rlcard

Reinforcement Learning / AI Bots in Card (Poker) Games - Blackjack, Leduc, Texas, DouDizhu, Mahjong, UNO.
http://www.rlcard.org
MIT License
2.91k stars 630 forks source link

Array has inhomogeneous shape when trying to run the pettingzoo example #274

Open Sisyphus192 opened 1 year ago

Sisyphus192 commented 1 year ago

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 commented 1 year ago

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+.

daochenzha commented 1 year ago

@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.

JocyeI commented 1 year ago

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.

daochenzha commented 1 year ago

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

Sisyphus192 commented 1 year ago

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

JocyeI commented 1 year ago

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

Sisyphus192 commented 1 year ago

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?