From 35acb98d7a2741c288cee67108b960eb78cd2978 Mon Sep 17 00:00:00 2001 From: didi <84363704+didiforgithub@users.noreply.github.com> Date: Mon, 21 Oct 2024 23:26:26 +0800 Subject: [PATCH] Update optimizer.py --- examples/aflow/scripts/optimizer.py | 33 +++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/aflow/scripts/optimizer.py b/examples/aflow/scripts/optimizer.py index d73be574f..3d98adbde 100644 --- a/examples/aflow/scripts/optimizer.py +++ b/examples/aflow/scripts/optimizer.py @@ -82,26 +82,23 @@ class Optimizer: retry_count = 0 max_retries = 1 - - score = loop.run_until_complete(self._optimize_graph()) + while retry_count < max_retries: + try: + score = loop.run_until_complete(self._optimize_graph()) + break + except Exception as e: + retry_count += 1 + logger.info(f"Error occurred: {e}. Retrying... (Attempt {retry_count}/{max_retries})") + if retry_count == max_retries: + logger.info("Max retries reached. Moving to next round.") + score = None - # while retry_count < max_retries: - # try: - # score = loop.run_until_complete(self._optimize_graph()) - # break - # except Exception as e: - # retry_count += 1 - # logger.info(f"Error occurred: {e}. Retrying... (Attempt {retry_count}/{max_retries})") - # if retry_count == max_retries: - # logger.info("Max retries reached. Moving to next round.") - # score = None + wait_time = 5 * retry_count + time.sleep(wait_time) - # wait_time = 5 * retry_count - # time.sleep(wait_time) - - # if retry_count < max_retries: - # loop = asyncio.new_event_loop() - # asyncio.set_event_loop(loop) + if retry_count < max_retries: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) self.round += 1 logger.info(f"Score for round {self.round}: {score}")