Skip to content

Commit

Permalink
-fixing dashboards
Browse files Browse the repository at this point in the history
-fixing adresses
  • Loading branch information
nick-harder committed Sep 25, 2023
1 parent 35657be commit 157be69
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 165 deletions.
114 changes: 56 additions & 58 deletions assume/common/units_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,24 @@ async def add_unit(
"""
self.units[unit.id] = unit

if self.context.data_dict.get("learning_agent_addr") is None:
db_aid = self.context.data_dict.get("output_agent_id")
db_addr = self.context.data_dict.get("output_agent_addr")
if db_aid and db_addr:
# send unit data to db agent to store it
message = {
"context": "write_results",
"type": "store_units",
"data": self.units[unit.id].as_dict(),
}
await self.context.send_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content=message,
acl_metadata={
"sender_addr": self.context.addr,
"sender_id": self.context.aid,
},
)
db_aid = self.context.data_dict.get("output_agent_id")
db_addr = self.context.data_dict.get("output_agent_addr")
if db_aid and db_addr:
# send unit data to db agent to store it
message = {
"context": "write_results",
"type": "store_units",
"data": self.units[unit.id].as_dict(),
}
await self.context.send_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content=message,
acl_metadata={
"sender_addr": self.context.addr,
"sender_id": self.context.aid,
},
)

def participate(self, market: MarketConfig):
"""
Expand Down Expand Up @@ -236,30 +235,29 @@ def write_actual_dispatch(self):
filter(lambda x: x["end_time"] >= now, self.valid_orders)
)

if self.context.data_dict.get("learning_agent_addr") is None:
db_aid = self.context.data_dict.get("output_agent_id")
db_addr = self.context.data_dict.get("output_agent_addr")
if db_aid and db_addr:
db_aid = self.context.data_dict.get("output_agent_id")
db_addr = self.context.data_dict.get("output_agent_addr")
if db_aid and db_addr:
self.context.schedule_instant_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content={
"context": "write_results",
"type": "market_dispatch",
"data": market_dispatch,
},
)
if unit_dispatch_dfs:
unit_dispatch = pd.concat(unit_dispatch_dfs)
self.context.schedule_instant_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content={
"context": "write_results",
"type": "market_dispatch",
"data": market_dispatch,
"type": "unit_dispatch",
"data": unit_dispatch,
},
)
if unit_dispatch_dfs:
unit_dispatch = pd.concat(unit_dispatch_dfs)
self.context.schedule_instant_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content={
"context": "write_results",
"type": "unit_dispatch",
"data": unit_dispatch,
},
)

async def submit_bids(self, opening: OpeningMessage):
"""
Expand Down Expand Up @@ -397,19 +395,18 @@ def write_learning_to_output(self, start: datetime, marketconfig: MarketConfig):

output_agent_list.append(output_dict)

if self.context.data_dict.get("learning_agent_addr"):
db_aid = self.context.data_dict.get("output_agent_id")
db_addr = self.context.data_dict.get("output_agent_addr")
if db_aid and db_addr:
self.context.schedule_instant_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content={
"context": "write_results",
"type": "rl_learning_params",
"data": output_agent_list,
},
)
db_aid = self.context.data_dict.get("learning_output_agent_id")
db_addr = self.context.data_dict.get("learning_output_agent_addr")
if db_aid and db_addr:
self.context.schedule_instant_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
content={
"context": "write_results",
"type": "rl_learning_params",
"data": output_agent_list,
},
)

def write_to_learning(
self,
Expand Down Expand Up @@ -453,15 +450,16 @@ def write_to_learning(
learning_role_id = self.context.data_dict.get("learning_agent_id")
learning_role_addr = self.context.data_dict.get("learning_agent_addr")

self.context.schedule_instant_acl_message(
receiver_id=learning_role_id,
receiver_addr=learning_role_addr,
content={
"context": "rl_training",
"type": "replay_buffer",
"data": rl_agent_data,
},
)
if learning_role_id and learning_role_addr:
self.context.schedule_instant_acl_message(
receiver_id=learning_role_id,
receiver_addr=learning_role_addr,
content={
"context": "rl_training",
"type": "replay_buffer",
"data": rl_agent_data,
},
)

def write_learning_params(self, orderbook: Orderbook, marketconfig: MarketConfig):
"""
Expand Down
23 changes: 13 additions & 10 deletions assume/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,19 @@ def add_unit_operator(
self.unit_operators[id] = units_operator

# after creation of an agent - we set additional context params
unit_operator_agent._role_context.data_dict = {
"output_agent_addr": self.output_agent_addr[0],
"output_agent_id": self.output_agent_addr[1],
"learning_agent_addr": self.learning_agent_addr[0]
if self.learning_mode
else None,
"learning_agent_id": self.learning_agent_addr[1]
if self.learning_mode
else None,
}
unit_operator_agent._role_context.data_dict = {}
if self.learning_mode:
unit_operator_agent._role_context.data_dict = {
"learning_output_agent_addr": self.output_agent_addr[0],
"learning_output_agent_id": self.output_agent_addr[1],
"learning_agent_addr": self.learning_agent_addr[0],
"learning_agent_id": self.learning_agent_addr[1],
}
else:
unit_operator_agent._role_context.data_dict = {
"output_agent_addr": self.output_agent_addr[0],
"output_agent_id": self.output_agent_addr[1],
}

async def async_add_unit(
self,
Expand Down
Loading

0 comments on commit 157be69

Please sign in to comment.