semitable / lb-foraging

Level-based Foraging (LBF): A multi-agent environment for RL
MIT License
151 stars 64 forks source link

Error , not valid action #4

Closed shark939393 closed 2 years ago

shark939393 commented 2 years ago

hello I am trying to execute the code , but when I compile it returns me this error raise ValueError("%r is not a valid %s" % (value, cls.name)) ValueError: (5, 4) is not a valid Action

my env is " env = gym.make("Foraging-10x10-2p-5f-v1") "

Did I set it wrong?

thank you for all

semitable commented 2 years ago

Hi,

Can you include the code that raises this error?

shark939393 commented 2 years ago

UserWarning: WARN: Box bound precision lowered by casting to float32 "Box bound precision lowered by casting to {}".format(self.dtype) Traceback (most recent call last): File "lbforaging.py", line 57, in main(args.times, args.render) File "lbforaging.py", line 45, in main _game_loop(env, render) File "lbforaging.py", line 28, in _gameloop nobs, nreward, ndone, = env.step(actions) File "/home/maicmania/PycharmProjects/mySmartWasteMARL/venv/lib/python3.6/site-packages/gym/wrappers/order_enforcing.py", line 11, in step observation, reward, done, info = self.env.step(action) File "/home/maicmania/PycharmProjects/mySmartWasteMARL/lbforaging/foraging/environment.py", line 414, in step for p, a in zip(self.players, actions) File "/home/maicmania/PycharmProjects/mySmartWasteMARL/lbforaging/foraging/environment.py", line 414, in for p, a in zip(self.players, actions) File "/usr/lib/python3.6/enum.py", line 293, in call return cls.new(cls, value) File "/usr/lib/python3.6/enum.py", line 535, in new return cls.missing(value) File "/usr/lib/python3.6/enum.py", line 548, in missing raise ValueError("%r is not a valid %s" % (value, cls.name)) ValueError: (3, 1) is not a valid Action

   26             for i, player in enumerate(env.players):
   27               actions.append(env.action_space.sample())
   28               nobs, nreward, ndone, _ = env.step(actions)

  44             for episode in range(game_count):
  45                   _game_loop(env, render)

  57      main(args.times, args.render)

my env is env = gym.make("Foraging-10x10-2p-5f-v1")

and init file is left the same as the one I downloaded from the repository

thanks for your reply.

semitable commented 2 years ago

You might be using an older version of lbforaging.py..? In the master branch, the step looks like:

actions = env.action_space.sample()
nobs, nreward, ndone, _ = env.step(actions)
...

Essentially you don't need the actions.append( or the loop over the players. You just need to step using env.step(env.action_space.sample())

shark939393 commented 2 years ago

OK thank you very much, but so now it gives me error

UserWarning: WARN: Box bound precision lowered by casting to float32 "Box bound precision lowered by casting to {}".format(self.dtype) [0, 0.2857142857142857] [0, 0.2857142857142857]

and I don’t know what it’s about, thank you so much anyway

semitable commented 2 years ago

Looks like it's just a warning. Shouldn't cause any issues.

shark939393 commented 2 years ago

ok thank you so much

shark939393 commented 2 years ago

excuse another question, how do I start the simulation? I get a Gui with the apple? which file should I run?

semitable commented 2 years ago

You need an agent that can make actions given the environment observation. Training/making such an agent is outside the scope of this repo but we do our best to have a similar API to OpenAI's Gym. You'd just need to run env.step(_ACTIONS_) and then env.render() to see the simulation. But to find the actions you'd need something outside this repo (e.g. a DQN implementation?).

shark939393 commented 2 years ago

ah ok , I thought you could simulate and see agents in the environment as in the gif where agents eat apples

semitable commented 2 years ago

Yes, you actually can. You still need to select the actions though. I am not sure what the exact question is? :) Have you tried python lbforaging.py --render? lbforaging.py is in the root directory. It might be what you are looking for.

shark939393 commented 2 years ago

Oh yes, thank you for all