Closed nosound2 closed 2 years ago
Looking into this. I've recently repro'd this same error in my own training here are there too.
Same, I'm getting them mostly when I train versus a model (as opposed to the default Agent()
). I will look into it too, I'll be happy to test a fix if anyone has one too.
Random thoughts. This doesn't happen too often, which seems to indicate that it isn't some generic error about a cell
being None
. Could it be something about the map's edge (city tile is on the edge with one or two missing neighbors)? I'll keep looking and maybe instrument some logs about tile coordinate to check this.
Edit: after surrounding the part with try/except AttributeError
, I got the error AttributeError: 'NoneType' object has no attribute 'adjacent_city_tiles' thing: 7 11
(it reads as cell.pos.x=7, cell.pos.y=11
) so it's not as straightforward as a "city on the edge" problem unfortunately.
Now it's weird, since I only had this issue when training versus another PPO I was assuming the issue was coming from the opponent and not the bot undergoing training.
By surrounding with try/except
:
obs[observation_index + 6] = min(
c.fuel / (c.get_light_upkeep() * 200.0),
1.0
)
and printing the mode train
or inference
of the bot in the except
. It turned out that it's from the bot in training. This try/except
did not cause a crash.
As this was running a crash was caused by:
Traceback (most recent call last):
File "examples/train.py", line 240, in <module>
train(local_args)
File "examples/train.py", line 190, in train
callback=checkpoint_callback) # 20M steps
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/ppo/ppo.py", line 310, in learn
reset_num_timesteps=reset_num_timesteps,
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 237, in learn
continue_training = self.collect_rollouts(self.env, callback, self.rollout_buffer, n_rollout_steps=self.n_steps)
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 178, in collect_rollouts
new_obs, rewards, dones, infos = env.step(clipped_actions)
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 162, in step
return self.step_wait()
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 44, in step_wait
self.actions[env_idx]
File "/opt/conda/lib/python3.7/site-packages/stable_baselines3/common/monitor.py", line 90, in step
observation, reward, done, info = self.env.step(action)
File "/opt/conda/lib/python3.7/site-packages/luxai2021-0.1.0-py3.7.egg/luxai2021/env/lux_env.py", line 60, in step
(unit, city_tile, team, is_new_turn) = next(self.match_generator)
File "/opt/conda/lib/python3.7/site-packages/luxai2021-0.1.0-py3.7.egg/luxai2021/game/match_controller.py", line 142, in run_to_next_observation
if city_tile.can_act():
AttributeError: 'NoneType' object has no attribute 'can_act'
Different location but same cause as OP posed, a cell.city_tile
is None
.
@nosound2 Have you tried to trigger the error after the fixes you introduced in your PR? The shared cargo for the first 2 workers could have caused it. One worker collecting resource filling both workers cargo followed by a city tile creation = crash: invalid city tiles and such.
I will try today and report here. Edit: same bug :(
I've met the issue too. seems it's actually coming from deleting a city when two city tile have been built on the same cell. I wanted to propose a PR but don't have the rights. whoever is interested can look at the file in attachment.
add some checks on the SpawnCityAction in game.validate_command() as advised by author, using the original src/Game/index.ts as model add a class MatchWarn as suggested by original implementation fix an access to game.game.state -> game.state should fix issues: #63 and #102 not formally tested with unit tests. run successfully with python 3.9
@Willyam42 good point :+1: You can make a PR though and be listed as a contributor! Fork the repo -> clone locally -> make branch with changes -> push -> open PR against the original repo (should be the default option).
Thanks for the tip @royerk I've sent the PR. I hope it will be reviewed properly as it hasn't been unit tested and I'm not too familiar with python...
Thanks @Willyam42 for the fix! Merged it. Closing this issue finally :)
Hello, I encountered the following error while training,
cell.city_tile
isNone
.