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

Commit 5133ff1

Browse files
author
Tanguy Pierre Louis Damart
committed
Add parameter names to the pickle files
1 parent 214ccf0 commit 5133ff1

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

bluepyopt/deapext/algorithms.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def eaAlphaMuPlusLambdaCheckpoint(
9494
cp_frequency=1,
9595
cp_filename=None,
9696
continue_cp=False,
97-
terminator=None):
97+
terminator=None,
98+
param_names=None):
9899
r"""This is the :math:`(~\alpha,\mu~,~\lambda)` evolutionary algorithm
99100
100101
Args:
@@ -111,8 +112,12 @@ def eaAlphaMuPlusLambdaCheckpoint(
111112
continue_cp(bool): whether to continue
112113
terminator (multiprocessing.Event): exit loop when is set.
113114
Not taken into account if None.
115+
param_names(list): names of the parameters optimized by the evaluator
114116
"""
115117

118+
if param_names is None:
119+
param_names = []
120+
116121
if cp_filename:
117122
cp_filename_tmp = cp_filename + '.tmp'
118123

@@ -178,7 +183,8 @@ def eaAlphaMuPlusLambdaCheckpoint(
178183
halloffame=halloffame,
179184
history=history,
180185
logbook=logbook,
181-
rndstate=random.getstate())
186+
rndstate=random.getstate(),
187+
param_names=param_names)
182188
pickle.dump(cp, open(cp_filename_tmp, "wb"))
183189
if os.path.isfile(cp_filename_tmp):
184190
shutil.copy(cp_filename_tmp, cp_filename)

bluepyopt/deapext/optimisations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ def run(self,
297297
stats.register("min", numpy.min)
298298
stats.register("max", numpy.max)
299299

300+
param_names = []
301+
if hasattr(self.evaluator, "param_names"):
302+
param_names = self.evaluator.param_names
303+
300304
pop, hof, log, history = algorithms.eaAlphaMuPlusLambdaCheckpoint(
301305
pop,
302306
self.toolbox,
@@ -309,7 +313,8 @@ def run(self,
309313
cp_frequency=cp_frequency,
310314
continue_cp=continue_cp,
311315
cp_filename=cp_filename,
312-
terminator=terminator)
316+
terminator=terminator,
317+
param_names=param_names)
313318

314319
# Update hall of fame
315320
self.hof = hof

bluepyopt/deapext/optimisationsCMA.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ def run(
297297

298298
pop = CMA_es.get_population(self.to_space)
299299

300+
param_names = []
301+
if hasattr(self.evaluator, "param_names"):
302+
param_names = self.evaluator.param_names
303+
300304
# Run until a termination criteria is met
301305
while utils.run_next_gen(CMA_es.active, terminator):
302306
logger.info("Generation {}".format(gen))
@@ -347,6 +351,7 @@ def run(
347351
rndstate=random.getstate(),
348352
np_rndstate=numpy.random.get_state(),
349353
CMA_es=CMA_es,
354+
param_names=param_names,
350355
)
351356
pickle.dump(cp, open(cp_filename_tmp, "wb"))
352357
if os.path.isfile(cp_filename_tmp):

0 commit comments

Comments
 (0)