Skip to content

Commit

Permalink
improve learning if db is None (#513)
Browse files Browse the repository at this point in the history
do not try to access self.db if we do not have a db_uri defined

closes #512
  • Loading branch information
maurerle authored Dec 9, 2024
1 parent 7457a21 commit 5aa8a5c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions assume/common/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def delete_similar_runs(self):
"""
Deletes all similar runs from the database based on the simulation ID. This ensures that we overwrite simulations results when restarting one. Please note that a simulation which you also want to keep need to be assigned anew ID.
"""
if self.db_uri is None:
return
query = text("select distinct simulation from rl_params")

try:
Expand Down Expand Up @@ -684,9 +686,11 @@ def get_sum_reward(self):
query = text(
f"select unit, SUM(reward) FROM rl_params where simulation='{self.simulation_id}' GROUP BY unit"
)
if self.db is not None:
with self.db.begin() as db:
rewards_by_unit = db.execute(query).fetchall()
if self.db is None:
return []

with self.db.begin() as db:
rewards_by_unit = db.execute(query).fetchall()

# convert into a numpy array
rewards_by_unit = [r[1] for r in rewards_by_unit]
Expand Down

0 comments on commit 5aa8a5c

Please sign in to comment.