Skip to content

implemented neighboring agent discovery and agent to agent communication#114

Merged
craig8 merged 6 commits intodevelopfrom
agent_comm
Apr 13, 2023
Merged

implemented neighboring agent discovery and agent to agent communication#114
craig8 merged 6 commits intodevelopfrom
agent_comm

Conversation

@poorva1209
Copy link
Copy Markdown
Contributor

@poorva1209 poorva1209 commented Mar 27, 2023

Documentation to test in the distributed sample app PR: GRIDAPPSD/gridappsd-sample-distributed-app#6

Comment thread gridappsd/field_interface/__init__.py

self.app_id = agent_config['app_id']
self.description = agent_config['description']
self.agent_id = str(uuid.uuid4())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want a random id or do we want something sudo random so we can tell it's a distributed agent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 'da_[app_id]_[timestamp]'. Similar to instance id for centralized apps and services.

def subscribe_to_measurement(self):
if self.simulation_id is None:
self.downstream_message_bus.subscribe(f"fieldbus/{self.downstream_message_bus.id}", self.on_measurement)
self.downstream_message_bus.subscribe(f"/topic/goss.gridappsd.field.output.{self.downstream_message_bus.id}", self.on_measurement)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the topics t to build this topic rather than hard coding here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to be imported from topics.

def on_request(self, message_bus, headers:Dict, message):
raise NotImplementedError(f"{self.__class__.__name__} must be overriden in child class")

def get_registration_details(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration details should be a dataclass that can be returned/serialized as json rather than a dictionary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentRegitrationDetails dataclass added.

Comment thread gridappsd/field_interface/context.py Outdated
Comment thread gridappsd/field_interface/gridappsd_field_bus.py
Comment thread gridappsd/field_interface/gridappsd_field_bus.py
Comment thread gridappsd/field_interface/interfaces.py Outdated

@abstractmethod
def publish(self, data, topic: str = None):
def send(self, topic, data):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elsewhere we use topic message....which should it be?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to message.


@abstractmethod
def publish(self, data, topic: str = None):
def get_agent_response(self, agent_id, message, timeout):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstractmethods don't have implementation....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed abstract.

Comment thread gridappsd/topics.py Outdated
:return:
"""
assert message_bus_id, "message_bus_id cannot be empty"
return "{}.{}.{}.{}".format(BASE_FIELD_TOPIC, message_bus_id, app_id, agent_id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use f-string formatting...it is much easier to read.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return f"{BASE_FIELD_TOPIC}.{message_bus_id}.{app_id}.{agent_id}"

or use ".".join([BASE_FIELD_TOPIC, message_bus_id, app_id, agent_id])

Make sure the arguments are strings though or the above will fail.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. We do the same in all other functions so may have to change all . Will create another issue if needed.

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.

2 participants