Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit e05b26e

Browse files
author
Jaquier Aurélien Tristan
committed
revert opening/closing pickle file at each generation
1 parent 3a28ef9 commit e05b26e

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

bluepyopt/deapext/algorithms.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def eaAlphaMuPlusLambdaCheckpoint(
123123

124124
if continue_cp:
125125
# A file name has been given, then load the data from the file
126-
with open(cp_filename, "rb") as f:
127-
cp = pickle.load(f)
126+
cp = pickle.load(open(cp_filename, "rb"))
128127
population = cp["population"]
129128
parents = cp["parents"]
130129
start_gen = cp["generation"]
@@ -186,8 +185,7 @@ def eaAlphaMuPlusLambdaCheckpoint(
186185
logbook=logbook,
187186
rndstate=random.getstate(),
188187
param_names=param_names)
189-
with open(cp_filename_tmp, "wb") as f:
190-
pickle.dump(cp, f)
188+
pickle.dump(cp, open(cp_filename_tmp, "wb"))
191189
if os.path.isfile(cp_filename_tmp):
192190
shutil.copy(cp_filename_tmp, cp_filename)
193191
logger.debug('Wrote checkpoint to %s', cp_filename)

bluepyopt/deapext/optimisationsCMA.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ def run(
265265
if continue_cp:
266266

267267
# A file name has been given, then load the data from the file
268-
with open(cp_filename, "rb") as f:
269-
cp = pickle.load(f)
268+
cp = pickle.load(open(cp_filename, "rb"))
270269
gen = cp["generation"]
271270
self.hof = cp["halloffame"]
272271
logbook = cp["logbook"]
@@ -362,8 +361,7 @@ def run(
362361
CMA_es=CMA_es,
363362
param_names=param_names,
364363
)
365-
with open(cp_filename_tmp, "wb") as f:
366-
pickle.dump(cp, f)
364+
pickle.dump(cp, open(cp_filename_tmp, "wb"))
367365
if os.path.isfile(cp_filename_tmp):
368366
shutil.copy(cp_filename_tmp, cp_filename)
369367
logger.debug("Wrote checkpoint to %s", cp_filename)

0 commit comments

Comments
 (0)