Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agent communication wrapper. #1881

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

Gamenot
Copy link
Collaborator

@Gamenot Gamenot commented Feb 22, 2023

Still WIP.

See #1839 for context.

New plan

Message format is like:

class Header(NamedTuple):
   channel: str
   sender: str
   sender_type: str
   cc: Set[str]
   bcc: Set[str]
   format: str

class Message(NamedTuple):
   content: Any

Use idea is the following:

def filter_useless(transmissions):
   for header, msg in transmissions:
      if header.sender in ("parked_agent", "broken_stoplight"):
         continue
      if header.sender_type in ("advertisement",):
         continue
      yield header, msg

class GossiperAgent:
   def __init__(self, id_, filter, friends):
      self._filter = filter
      self._id = id_
      self._friends = friends

   def act(self, observation):
      out_transmissions = []
      for header, msg in filter(observation["transmissions"]):
         if not {self._id, "__all__"}.intersection(header["cc"] | header["bcc"]):
            continue
         if header.channel == "position_request":
            out_transmissions.append((
               Header(
                  channel="position",
                  sender=self._id,
                  sender_type="ad_vehicle",
                  cc={header.sender},
                  bcc={*self.friends},
                  format="position",
               )._as_dict(), # optimize this later
               Message(
                  content=obs.ego_vehicle_state.position,
               )._as_dict(), # optimize this later
            ))
         ...
      ...
      action = policy.select_action(observation)
      return (base_action, out_transmissions)

# for now
env = MessagePasser(
   hiwayv1env,
   max_message_bytes=MESSAGE_BYTES,
   message_config={
      "gossiper0": (
         V2XTransmitter(bands=Bands.ALL, range=100, available_channels=["position_request", "position"]),
         V2XReceiver(bands=Bands.ALL, aliases=["tim"], blacklist_channels=["self_control"]),
      ),
      ...
   },
)
gossiper_agent = GossiperAgent("gossiper0", filter=filter_useless, friends={"schemer", "gossiper1"})
oblivious_gossiper_agent = GossiperAgent("gossiper1", filter=filter_all, friends={"schemer"})
schemer_agent = SchemerAgent("schemer")

# then just the standard gym interface with no modifications
obs, info = env.reset()
for ...:
   actions = {agent_id: agent.act(obs[agent_id]) for agent_id, agent in agents}
   obs, reward, term, trunc, info = env.step(actions)

@Gamenot Gamenot self-assigned this Feb 22, 2023
@Gamenot Gamenot requested review from Adaickalavan and removed request for Adaickalavan February 24, 2023 17:49
@Gamenot Gamenot force-pushed the tucker/add_agent_communication branch from e9a22c0 to f6355a6 Compare March 1, 2023 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant