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

Commit 60ac638

Browse files
author
Tanguy Damart
committed
Added two exceptions for issues frequently met.
1 parent f8b3b01 commit 60ac638

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

bluepyopt/deapext/optimisations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ def setup_deap(self):
160160

161161
# Number of parameters
162162
IND_SIZE = len(self.evaluator.params)
163+
164+
if IND_SIZE == 0:
165+
raise Exception(
166+
"Length of evaluator.params is zero. At least one "
167+
"non-fix parameter is neededto run an optimization."
168+
)
163169

164170
# Bounds for the parameters
165171
LOWER = []

bluepyopt/deapext/optimisationsCMA.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ def __init__(
9191
self.hof = hof
9292
if self.hof is None:
9393
self.hof = deap.tools.HallOfFame(10)
94-
95-
self.fitness_reduce = fitness_reduce
94+
95+
if offspring_size < 2:
96+
raise Exception("offspring_size has to be at least 2.")
9697
self.offspring_size = offspring_size
98+
99+
self.fitness_reduce = fitness_reduce
97100
self.centroids = centroids
98101
self.sigma = sigma
99102

@@ -293,8 +296,10 @@ def run(
293296
lbounds=self.lbounds, ubounds=self.ubounds
294297
)
295298
logger.debug(
296-
"Number of individuals outside of bounds: {} ({:.2f}%)" +
297-
"".format(n_out, 100.0 * n_out / len(CMA_es.population))
299+
"Number of individuals outside of bounds: {} ({:.2f}%)".format(
300+
n_out,
301+
100.0 * n_out / len(CMA_es.population)
302+
)
298303
)
299304

300305
# Get all the individuals in the original space for evaluation

bluepyopt/tests/test_deapext/test_optimisationsCMA.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ def test_optimisationsCMA_run():
3333
optimiser = bluepyopt.deapext.optimisationsCMA.DEAPOptimisationCMA
3434
optimisation = optimiser(evaluator=evaluator, centroids=[x])
3535
pop, hof, log, hist = optimisation.run(max_ngen=2)
36-
raised = False
37-
nt.assert_equal(raised, False)

0 commit comments

Comments
 (0)