@@ -181,15 +181,6 @@ class DefaultWorker:
181181 worker_id : str
182182 """The id of the worker."""
183183
184- worker_cumulative_eval_count : int = 0
185- """The number of evaluations done by this worker."""
186-
187- worker_cumulative_eval_cost : float = 0.0
188- """The cost of the evaluations done by this worker."""
189-
190- worker_cumulative_evaluation_time_seconds : float = 0.0
191- """The time spent evaluating configurations by this worker."""
192-
193184 _GRACE : ClassVar = FS_SYNC_GRACE_BASE
194185
195186 @classmethod
@@ -251,46 +242,13 @@ def _check_worker_local_settings(
251242 raise WorkerRaiseError (msg ) from error_from_this_worker
252243 return msg
253244
254- if (
255- self .settings .max_evaluations_for_worker is not None
256- and self .worker_cumulative_eval_count
257- >= self .settings .max_evaluations_for_worker
258- ):
259- return (
260- "Worker has reached the maximum number of evaluations it is allowed to do"
261- f" as given by `{ self .settings .max_evaluations_for_worker = } `."
262- "\n To allow more evaluations, increase this value or use a different"
263- " stopping criterion."
264- )
265-
266- if (
267- self .settings .max_cost_for_worker is not None
268- and self .worker_cumulative_eval_cost >= self .settings .max_cost_for_worker
269- ):
270- return (
271- "Worker has reached the maximum cost it is allowed to spend"
272- f" which is given by `{ self .settings .max_cost_for_worker = } `."
273- f" This worker has spend '{ self .worker_cumulative_eval_cost } '."
274- "\n To allow more evaluations, increase this value or use a different"
275- " stopping criterion."
276- )
277-
278- if self .settings .max_wallclock_time_for_worker_seconds is not None and (
245+ if self .settings .max_wallclock_time_seconds is not None and (
279246 time .monotonic () - time_monotonic_start
280- >= self .settings .max_wallclock_time_for_worker_seconds
247+ >= self .settings .max_wallclock_time_seconds
281248 ):
282249 return (
283250 "Worker has reached the maximum wallclock time it is allowed to spend"
284- f", given by `{ self .settings .max_wallclock_time_for_worker_seconds = } `."
285- )
286-
287- if self .settings .max_evaluation_time_for_worker_seconds is not None and (
288- self .worker_cumulative_evaluation_time_seconds
289- >= self .settings .max_evaluation_time_for_worker_seconds
290- ):
291- return (
292- "Worker has reached the maximum evaluation time it is allowed to spend"
293- f", given by `{ self .settings .max_evaluation_time_for_worker_seconds = } `."
251+ f", given by `{ self .settings .max_wallclock_time_seconds = } `."
294252 )
295253
296254 return False
@@ -328,23 +286,30 @@ def _check_global_stopping_criterion(
328286 self ,
329287 trials : Mapping [str , Trial ],
330288 ) -> str | Literal [False ]:
289+ # worker related stopping criterion
290+ worker_trials = {
291+ _id : trial
292+ for _id , trial in trials .items ()
293+ if trial .metadata .evaluating_worker_id == self .worker_id
294+ }
331295 if self .settings .evaluations_to_spend is not None :
332296 if self .settings .include_in_progress_evaluations_towards_maximum :
333297 count = sum (
334298 1
335- for _ , trial in trials .items ()
336- if trial .metadata .state
337- not in (Trial .State .PENDING , Trial .State .SUBMITTED )
299+ for _ , trial in worker_trials .items ()
300+ if trial .metadata .state != Trial .State .PENDING
338301 )
339302 else :
340303 # This indicates they have completed.
341- count = sum (1 for _ , trial in trials .items () if trial .report is not None )
304+ count = sum (
305+ 1 for _ , trial in worker_trials .items () if trial .report is not None
306+ )
342307
343308 if count >= self .settings .evaluations_to_spend :
344309 return (
345- "The total number of evaluations has reached the maximum allowed of"
346- f" `{ self .settings .evaluations_to_spend = } `."
347- " To allow more evaluations, increase this value or use a different"
310+ "Worker has reached the maximum number of evaluations it is allowed "
311+ f" to do as given by `{ self .settings .evaluations_to_spend = } `."
312+ "\n To allow more evaluations, increase this value or use a different"
348313 " stopping criterion."
349314 )
350315
@@ -354,7 +319,7 @@ def _check_global_stopping_criterion(
354319 fidelity_name = next (iter (self .optimizer .space .fidelities .keys ()))
355320 count = sum (
356321 trial .config [fidelity_name ]
357- for _ , trial in trials .items ()
322+ for _ , trial in worker_trials .items ()
358323 if trial .report is not None and trial .config [fidelity_name ] is not None
359324 )
360325 if count >= self .settings .fidelities_to_spend :
@@ -368,20 +333,22 @@ def _check_global_stopping_criterion(
368333 if self .settings .cost_to_spend is not None :
369334 cost = sum (
370335 trial .report .cost
371- for _ , trial in trials .items ()
336+ for _ , trial in worker_trials .items ()
372337 if trial .report is not None and trial .report .cost is not None
373338 )
374339 if cost >= self .settings .cost_to_spend :
375340 return (
376- f"The maximum cost `{ self .settings .cost_to_spend = } ` has been"
377- " reached by all of the evaluated trials. To allow more evaluations,"
378- " increase this value or use a different stopping criterion."
341+ "Worker has reached the maximum cost it is allowed to spend"
342+ f" which is given by `{ self .settings .cost_to_spend = } `."
343+ f" This worker has spend '{ cost } '."
344+ "\n To allow more evaluations, increase this value or use a different"
345+ " stopping criterion."
379346 )
380347
381348 if self .settings .max_evaluation_time_total_seconds is not None :
382349 time_spent = sum (
383350 trial .report .evaluation_duration
384- for _ , trial in trials .items ()
351+ for _ , trial in worker_trials .items ()
385352 if trial .report is not None
386353 if trial .report .evaluation_duration is not None
387354 )
@@ -658,13 +625,6 @@ def run(self) -> None: # noqa: C901, PLR0912, PLR0915
658625 evaluation_fn = self .evaluation_fn ,
659626 default_report_values = self .settings .default_report_values ,
660627 )
661- evaluation_duration = evaluated_trial .metadata .evaluation_duration
662- assert (evaluation_duration is not None ) | (report is None )
663- self .worker_cumulative_evaluation_time_seconds += (
664- evaluation_duration if evaluation_duration else 0
665- )
666-
667- self .worker_cumulative_eval_count += 1
668628
669629 if report is None :
670630 logger .info (
@@ -681,9 +641,6 @@ def run(self) -> None: # noqa: C901, PLR0912, PLR0915
681641 evaluated_trial .metadata .state ,
682642 )
683643
684- if report .cost is not None :
685- self .worker_cumulative_eval_cost += report .cost
686-
687644 if report .err is not None :
688645 logger .error (
689646 f"Error during evaluation of '{ evaluated_trial .id } '"
@@ -960,7 +917,6 @@ def _launch_runtime( # noqa: PLR0913
960917 overwrite_optimization_dir : bool ,
961918 evaluations_to_spend : int | None ,
962919 fidelities_to_spend : int | float | None ,
963- max_evaluations_for_worker : int | None ,
964920 sample_batch_size : int | None ,
965921 worker_id : str | None = None ,
966922) -> None :
@@ -1034,11 +990,8 @@ def _launch_runtime( # noqa: PLR0913
1034990 not continue_until_max_evaluation_completed
1035991 ),
1036992 cost_to_spend = cost_to_spend ,
1037- max_evaluations_for_worker = max_evaluations_for_worker ,
1038993 max_evaluation_time_total_seconds = None , # TODO: User can't specify yet
1039- max_wallclock_time_for_worker_seconds = None , # TODO: User can't specify yet
1040- max_evaluation_time_for_worker_seconds = None , # TODO: User can't specify yet
1041- max_cost_for_worker = None , # TODO: User can't specify yet
994+ max_wallclock_time_seconds = None , # TODO: User can't specify yet
1042995 )
1043996
1044997 # HACK: Due to nfs file-systems, locking with the default `flock()` is not reliable.
0 commit comments