def __init__(
      self,
      config: Config,
      model: language_model.LanguageModel,
      embedder: Callable[[str], np.ndarray],
  ):
    """Initialize the simulation object.

    This simulation differentiates between game masters and entities. Game
    masters are responsible for creating the world state and resolving events.
    Entities are passive agents that react to the world state. Game masters are
    a kind of entity and both are interchangeable once instantiated. However,
    there is one critical difference in how they are configured which we
    implement here in this file. The difference is that game masters are
    configured with references to all entities, but entities are never
    given references to other entities or game masters.

    Args:
      config: the config to use.
      model: the language model to use.
      embedder: the sentence transformer to use.
    """
    self._config = config
    self._model = model
    self._embedder = embedder
    self._environment = sequential.Sequential()

    self.game_masters = []
    self.entities = []

    initializer_game_master_configs = []
    non_initializer_game_master_configs = []
    entity_configs = []

    all_data = self._config.instances
    game_masters_data = [entity_cfg for entity_cfg in all_data
                         if entity_cfg.role == Role.GAME_MASTER]
    entities_data = [entity_cfg for entity_cfg in all_data
                     if entity_cfg.role == Role.ENTITY]
    initializers_data = [entity_cfg for entity_cfg in all_data
                         if entity_cfg.role == Role.INITIALIZER]

    # Create a copy of each prefab using the params specified in its instance.
    for config in game_masters_data + entities_data + initializers_data:
      # Deep copy the prefab to avoid modifying the original prefab.
      entity_config = copy.deepcopy(self._config.prefabs[config.prefab])
      entity_config.params = config.params

      if config.role == "game_master":
        non_initializer_game_master_configs.append(entity_config)
      elif config.role == "initializer":
        initializer_game_master_configs.append(entity_config)
      else:
        entity_configs.append(entity_config)

    game_master_configs = (initializer_game_master_configs +
                           non_initializer_game_master_configs)

    # All game masters share the same memory bank.
    self.game_master_memory_bank = associative_memory.AssociativeMemoryBank(
        sentence_embedder=embedder,
    )

    # Build all entities.
    for entity_config in entity_configs:
      # Each entity gets their own memory bank, not shared with other entities.
      memory_bank = associative_memory.AssociativeMemoryBank(
          sentence_embedder=embedder,
      )
      entity = entity_config.build(model=model,
                                   memory_bank=memory_bank)
      self.entities.append(entity)
    for game_master_config in game_master_configs:
      # Pass references to entities to all game masters, but never pass entities
      # to non-game-master entities.
      game_master_config.entities = self.entities
      # Pass a reference to the shared memory bank to all game masters.
      game_master = game_master_config.build(
          model=model, memory_bank=self.game_master_memory_bank)
      self.game_masters.append(game_master)
Initialize the simulation object.

    This simulation differentiates between game masters and entities. Game
    masters are responsible for creating the world state and resolving events.
    Entities are passive agents that react to the world state. Game masters are
    a kind of entity and both are interchangeable once instantiated. However,
    there is one critical difference in how they are configured which we
    implement here in this file. The difference is that game masters are
    configured with references to all entities, but entities are never
    given references to other entities or game masters.

    Args:
      config: the config to use.
      model: the language model to use.
      embedder: the sentence transformer to use.
    
concordia/prefabs/simulation/generic.py