Skip to content

Commit

Permalink
Refactor experiment ID generation and enhance logging in ExpArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
recursix committed Nov 2, 2024
1 parent 44cc745 commit 160167f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions browsergym/experiments/src/browsergym/experiments/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ class ExpArgs:
save_screenshot: bool = True
save_som: bool = False

def __post_init__(self):
self.exp_id = str(uuid.uuid4().hex)
def make_id(self):
"""Create a unique id for the experiment."""
if self.exp_id is None:
self.exp_id = str(uuid.uuid4())

def prepare(self, exp_root):
"""Prepare the experiment directory and save the experiment arguments.
Expand All @@ -170,6 +172,8 @@ def prepare(self, exp_root):
if self.exp_dir is not None:
_move_old_exp(self.exp_dir)

self.make_id()

self.exp_date = datetime.now()
self._make_dir(exp_root)

Expand Down Expand Up @@ -259,6 +263,7 @@ def run(self):

logger.warning(err_msg + "\n" + stack_trace)
if _is_debugging() and self.enable_debug:
logger.warning("Debug mode is enabled. Raising the error.")
raise

finally:
Expand All @@ -277,6 +282,7 @@ def run(self):
):
e = KeyboardInterrupt("Early termination??")
err_msg = f"Exception uncaught by agent or environment in task {self.env_args.task_name}.\n{type(e).__name__}:\n{e}"
logger.info(f"Saving summary info.")
_save_summary_info(episode_info, self.exp_dir, err_msg, stack_trace)
except Exception as e:
logger.error(f"Error while saving summary info in the finally block: {e}")
Expand Down

0 comments on commit 160167f

Please sign in to comment.