google-deepmind / concordia

A library for generative social simulation
Apache License 2.0
497 stars 96 forks source link

KeyError: 'agent_name' when concurrent_externalities=False #68

Closed austinmw closed 1 month ago

austinmw commented 2 months ago

I am running into what appears to be a deadlock issue in the calendar.ipynb example. I tried to set concurrent_externalities=False, but then hit another error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[20], [line 4](vscode-notebook-cell:?execution_count=20&line=4)
      [2](vscode-notebook-cell:?execution_count=20&line=2) episode_length = 12  # @param {type: 'integer'}
      [3](vscode-notebook-cell:?execution_count=20&line=3) for _ in range(episode_length):
----> [4](vscode-notebook-cell:?execution_count=20&line=4)   env.step()

File ~/Desktop/concordia/concordia/environment/game_master.py:381, in GameMaster.step(self, active_players, action_spec)
    [379](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:379) for player in players:
    [380](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:380)   print(f'Stepping player {player.name}')
--> [381](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:381)   step_player_fn(player)
    [382](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:382)   if not self._players_act_simultaneously:
    [383](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:383)     self._clock.advance()

File ~/Desktop/concordia/concordia/environment/game_master.py:369, in GameMaster.step.<locals>.<lambda>(player)
    [366](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:366)   override_action_spec = action_spec
    [368](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:368) print('Stepping players')
--> [369](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:369) step_player_fn = lambda player: self._step_player(
    [370](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:370)     player=player, action_spec=override_action_spec
    [371](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:371) )
    [373](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:373) if self._randomise_initiative:
    [374](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:374)   random.shuffle(players)

File ~/Desktop/concordia/concordia/environment/game_master.py:339, in GameMaster._step_player(self, player, action_spec)
    [336](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:336) action = player.act(action_spec_this_time)
    [337](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:337) print('Got action from player:', action)
--> [339](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:339) self.update_from_player(action_attempt=action, player_name=player.name)

File ~/Desktop/concordia/concordia/environment/game_master.py:275, in GameMaster.update_from_player(self, player_name, action_attempt)
    [273](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:273)   for externality in self._components.values():
    [274](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:274)     print(f'Running update_after_event for {externality.name()}')
--> [275](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:275)     externality.update_after_event(event_statement)
    [277](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:277) self._last_chain = prompt
    [279](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:279) print('Updating log for all components')

File ~/Desktop/concordia/examples/phone/../../examples/phone/components/triggering.py:135, in SceneTriggeringComponent.update_after_event(self, event_statement)
    [133](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:133) player = self._get_player_using_phone(event_statement)
    [134](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:134) if player is not None:
--> [135](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:135)   self._run_phone_scene(player)
    [136](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:136) print('SceneTriggeringComponent: Finished updating after event')

File ~/Desktop/concordia/examples/phone/../../examples/phone/components/triggering.py:121, in SceneTriggeringComponent._run_phone_scene(self, player)
    [119](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:119) with self._clock.higher_gear():
    [120](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:120)   print('Running phone_scene.run_episode()')
--> [121](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:121)   scene_output = phone_scene.run_episode()
    [123](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:123) print('Getting events from phone scene...')
    [124](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/examples/phone/components/triggering.py:124) for event in scene_output:

File ~/Desktop/concordia/concordia/environment/game_master.py:390, in GameMaster.run_episode(self, max_steps)
    [388](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:388) print('Running episode')
    [389](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:389) for _ in range(max_steps):
--> [390](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:390)   self.step()
    [391](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:391)   for comp in self._components.values():
    [392](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:392)     if comp.terminate_episode():

File ~/Desktop/concordia/concordia/environment/game_master.py:381, in GameMaster.step(self, active_players, action_spec)
    [379](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:379) for player in players:
    [380](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:380)   print(f'Stepping player {player.name}')
--> [381](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:381)   step_player_fn(player)
    [382](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:382)   if not self._players_act_simultaneously:
    [383](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:383)     self._clock.advance()

File ~/Desktop/concordia/concordia/environment/game_master.py:369, in GameMaster.step.<locals>.<lambda>(player)
    [366](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:366)   override_action_spec = action_spec
    [368](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:368) print('Stepping players')
--> [369](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:369) step_player_fn = lambda player: self._step_player(
    [370](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:370)     player=player, action_spec=override_action_spec
    [371](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:371) )
    [373](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:373) if self._randomise_initiative:
    [374](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:374)   random.shuffle(players)

File ~/Desktop/concordia/concordia/environment/game_master.py:336, in GameMaster._step_player(self, player, action_spec)
    [333](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:333)   action_spec_this_time = self._action_spec
    [335](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:335) print('Getting action from player')
--> [336](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:336) action = player.act(action_spec_this_time)
    [337](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:337) print('Got action from player:', action)
    [339](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/environment/game_master.py:339) self.update_from_player(action_attempt=action, player_name=player.name)

File ~/Desktop/concordia/concordia/agents/basic_agent.py:186, in BasicAgent.act(self, action_spec)
    [180](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:180) context_of_action = '\n'.join([
    [181](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:181)     f'{self.state()}',
    [182](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:182) ])
    [184](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:184) prompt.statement(context_of_action)
--> [186](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:186) call_to_action = action_spec.call_to_action.format(
    [187](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:187)     name=self._agent_name,
    [188](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:188)     timedelta=helper_functions.timedelta_to_readable_str(
    [189](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:189)         self._clock.get_step_size()
    [190](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:190)     ),
    [191](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:191) )
    [192](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:192) output = ''
    [194](https://file+.vscode-resource.vscode-cdn.net/Users/austinwelch/Desktop/concordia/examples/phone/~/Desktop/concordia/concordia/agents/basic_agent.py:194) if action_spec.output_type == entity.OutputType.FREE:

KeyError: 'agent_name'
duenez commented 1 month ago

This should be fixed at head. Feel free to reopen if you re-download head and this persists.

austinmw commented 1 month ago

Thanks!