From 66896865a33dfc49b3bcc37657b28a4e8b40c3f8 Mon Sep 17 00:00:00 2001 From: trevorhardy Date: Wed, 30 Oct 2024 17:23:44 -0700 Subject: [PATCH] Add error-handling for removing timing periods from the timing_config.json --- .../fundamental_timing/timing_fed.py | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/user_guide_examples/fundamental/fundamental_timing/timing_fed.py b/user_guide_examples/fundamental/fundamental_timing/timing_fed.py index 90599fe..2f8ea47 100644 --- a/user_guide_examples/fundamental/fundamental_timing/timing_fed.py +++ b/user_guide_examples/fundamental/fundamental_timing/timing_fed.py @@ -137,22 +137,30 @@ def destroy_federate(fed): # large times and need the publication to wake them up earlier. pub.publish(grant_time) - # Dummy execution time as specified in the timing config file - sleep_time = config[str(fednum)]["execution time"][str(int(grant_time))] - logger.debug(f"Sleeping for {sleep_time} seconds") - time.sleep(sleep_time) + try: + # Dummy execution time as specified in the timing config file + sleep_time = config[str(fednum)]["execution time"][str(int(grant_time))] + done = False + except: + # If the requested time is not in the timing config JSON, this + # federate is done + done = True + grant_time = 100000 + if not done: + logger.debug(f"Sleeping for {sleep_time} seconds") + time.sleep(sleep_time) - if config[str(fednum)]["max time request"]: - request_time = 100000 - else: - request_time = grant_time + period - request_wall_clock_time = time.monotonic() - reference_time - timing_log.append({"grant time": grant_time, - "grant wall clock time": grant_wall_clock_time, - "request time": request_time, - "request wall clock time": request_wall_clock_time}) - grant_time = fed.request_time(timing_log[-1]["request time"]) - grant_wall_clock_time = time.monotonic() - reference_time + if config[str(fednum)]["max time request"]: + request_time = 100000 + else: + request_time = grant_time + period + request_wall_clock_time = time.monotonic() - reference_time + timing_log.append({"grant time": grant_time, + "grant wall clock time": grant_wall_clock_time, + "request time": request_time, + "request wall clock time": request_wall_clock_time}) + grant_time = fed.request_time(timing_log[-1]["request time"]) + grant_wall_clock_time = time.monotonic() - reference_time # Cleaning up HELICS stuff once we've finished the co-simulation. destroy_federate(fed)