@@ -89,6 +89,7 @@ def asha(
8989 maximum_resource : Union [int , float ] = 1.0 ,
9090 minimum_early_stopping_rate : int = 0 ,
9191 max_full_evaluations : Optional [int ] = None ,
92+ max_attempts : int = 100000 ,
9293) -> List [Individual ]:
9394 """Asynchronous Halving Algorithm by Li et al.
9495
@@ -115,6 +116,9 @@ def asha(
115116 max_full_evaluations: Optional[int] (default=None)
116117 Maximum number of individuals to evaluate on the max rung (i.e. on all data).
117118 If None, the algorithm will be run indefinitely.
119+ max_attempts: int (default=100000)
120+ Maximum number of attempts to generate a unique individual otherwise raise
121+ an error.
118122
119123 Returns
120124 -------
@@ -163,7 +167,18 @@ def get_job():
163167
164168 if start_candidates :
165169 return start_candidates .pop (), minimum_early_stopping_rate
166- return operations .individual (), minimum_early_stopping_rate
170+
171+ attempts = 0
172+ while (new_individual := operations .individual ()) and operations .is_evaluated (
173+ new_individual
174+ ):
175+ if attempts >= max_attempts :
176+ raise ValueError (
177+ "Maximum attempts reached while trying to generate a"
178+ "unique individual."
179+ )
180+ attempts += 1
181+ return new_individual , minimum_early_stopping_rate
167182
168183 try :
169184 with AsyncEvaluator () as async_ :
0 commit comments