From 5aa8a5c053b54284d61fe5a61f776d150e53d2fc Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Mon, 9 Dec 2024 14:05:05 +0100 Subject: [PATCH] improve learning if db is None (#513) do not try to access self.db if we do not have a db_uri defined closes #512 --- assume/common/outputs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/assume/common/outputs.py b/assume/common/outputs.py index c4b38936..0dc4310d 100644 --- a/assume/common/outputs.py +++ b/assume/common/outputs.py @@ -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: @@ -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]