From cb11769cb1374380f73ff75d646617ddb9b6f2eb Mon Sep 17 00:00:00 2001 From: Nathan Petersen Date: Sun, 18 Feb 2024 11:45:57 -0600 Subject: [PATCH 1/2] Handle UnpicklingError for loading archive --- mach_opt/mach_opt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mach_opt/mach_opt.py b/mach_opt/mach_opt.py index 2eeed2f8..fc41e25b 100644 --- a/mach_opt/mach_opt.py +++ b/mach_opt/mach_opt.py @@ -313,6 +313,8 @@ def load_from_archive(self): yield pickle.load(f) # use generator except EOFError: break + except pickle.UnpicklingError: + break def save_designer(self, designer): """ Save designer used in optimization""" From 6ec523c9960869dfcf644e5394f6f91019b8524a Mon Sep 17 00:00:00 2001 From: Nathan Petersen Date: Wed, 28 Feb 2024 10:43:29 -0600 Subject: [PATCH 2/2] Add comments to code --- mach_opt/mach_opt.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mach_opt/mach_opt.py b/mach_opt/mach_opt.py index fc41e25b..8dd8c7a7 100644 --- a/mach_opt/mach_opt.py +++ b/mach_opt/mach_opt.py @@ -307,14 +307,20 @@ def save_to_archive(self, x, design, full_results, objs): def load_from_archive(self): """ Load data from Pickle optimization archive """ - with open(self.archive_filepath, 'rb') as f: - while 1: + with open(self.archive_filepath, "rb") as f: + while True: try: - yield pickle.load(f) # use generator + # Use generator: each yield returns + # a single design from the archive + yield pickle.load(f) except EOFError: + # After we read and return the + # full archive, stop and return break except pickle.UnpicklingError: - break + # If there is an issue with the archive file, + # this occurs so it can keep trying + continue def save_designer(self, designer): """ Save designer used in optimization"""