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

Disable writing data during learning process #205

Merged
merged 6 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion assume/common/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ async def on_stop(self):
with self.db.begin() as db:
df.to_sql("kpis", self.db, if_exists="append", index=None)
except ProgrammingError as e:
# self.db.rollback() not working, no rollback function
logger.error(f"No scenario run Yet {e}")

def learning_queries(self):
Expand Down
12 changes: 6 additions & 6 deletions assume/common/units_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def add_unit(
"""
self.units[unit.id] = unit

if not self.context.data_dict.get("learning_mode"):
if self.context.data_dict.get("learning_agent_addr") is None:
nick-harder marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down Expand Up @@ -236,7 +236,7 @@ def write_actual_dispatch(self):
filter(lambda x: x["end_time"] >= now, self.valid_orders)
)

if not self.context.data_dict.get("learning_mode"):
if self.context.data_dict.get("learning_agent_addr") is None:
nick-harder marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down Expand Up @@ -397,7 +397,7 @@ def write_learning_to_output(self, start: datetime, marketconfig: MarketConfig):

output_agent_list.append(output_dict)

if self.context.data_dict.get("learning_mode"):
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")
nick-harder marked this conversation as resolved.
Show resolved Hide resolved
if db_aid and db_addr:
Expand All @@ -420,9 +420,6 @@ def write_to_learning(
device: str,
learning_unit_count: int,
):
learning_role_id = "learning_agent"
learning_role_addr = self.context.addr

all_observations = []
all_rewards = []
try:
Expand Down Expand Up @@ -453,6 +450,9 @@ def write_to_learning(
all_rewards = np.array(all_rewards)
rl_agent_data = (np.array(all_observations), all_actions, all_rewards)

learning_role_id = self.context.data_dict.get("learning_agent_id")
learning_role_addr = self.context.data_dict.get("learning_agent_addr")

nick-harder marked this conversation as resolved.
Show resolved Hide resolved
self.context.schedule_instant_acl_message(
receiver_id=learning_role_id,
receiver_addr=learning_role_addr,
Expand Down
32 changes: 14 additions & 18 deletions assume/markets/base_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,17 @@ async def store_order_book(self, orderbook: Orderbook):
:param orderbook: The order book to be stored
:type orderbook: Orderbook
"""
if self.context.data_dict.get("learning_mode"):
return

message = {
"context": "write_results",
"type": "store_order_book",
"sender": self.marketconfig.name,
"data": orderbook,
}

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:
message = {
"context": "write_results",
"type": "store_order_book",
"sender": self.marketconfig.name,
"data": orderbook,
}
await self.context.send_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
Expand All @@ -434,18 +432,16 @@ async def store_market_results(self, market_meta):
:type market_meta: any
"""

if self.context.data_dict.get("learning_mode"):
return

message = {
"context": "write_results",
"type": "store_market_results",
"sender": self.marketconfig.name,
"data": market_meta,
}
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:
message = {
"context": "write_results",
"type": "store_market_results",
"sender": self.marketconfig.name,
"data": market_meta,
}
await self.context.send_acl_message(
receiver_id=db_aid,
receiver_addr=db_addr,
Expand Down
21 changes: 16 additions & 5 deletions assume/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@
# if self.same_process:
# separate process does not support buffer and learning
if True:
rl_agent = RoleAgent(self.container, suggested_aid="learning_agent")
self.learning_agent_addr = (self.addr, "learning_agent")
rl_agent = RoleAgent(
self.container, suggested_aid=self.learning_agent_addr[1]
)
rl_agent.add_role(self.learning_role)
else:

Expand Down Expand Up @@ -213,7 +216,12 @@
unit_operator_agent._role_context.data_dict = {
"output_agent_addr": self.output_agent_addr[0],
"output_agent_id": self.output_agent_addr[1],
"learning_mode": self.learning_mode,
"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,
nick-harder marked this conversation as resolved.
Show resolved Hide resolved
}

async def async_add_unit(
Expand Down Expand Up @@ -304,9 +312,12 @@

# after creation of an agent - we set additional context params
market_operator_agent._role_context.data_dict = {
"output_agent_addr": self.output_agent_addr[0],
"output_agent_id": self.output_agent_addr[1],
"learning_mode": self.learning_mode,
"output_agent_addr": None

Check warning on line 315 in assume/world.py

View check run for this annotation

Codecov / codecov/patch

assume/world.py#L315

Added line #L315 was not covered by tests
if self.learning_mode
else self.output_agent_addr[0],
"output_agent_id": None
if self.learning_mode
else self.output_agent_addr[1],
}
self.market_operators[id] = market_operator_agent

Expand Down