[tune] Add support for function-based stopping condition (#5754)

This commit is contained in:
Ujval Misra
2019-09-23 18:39:00 -07:00
committed by Richard Liaw
parent b03147e7bf
commit a4659a8f8b
5 changed files with 65 additions and 5 deletions
+10 -1
View File
@@ -3,6 +3,7 @@ from __future__ import division
from __future__ import print_function
import copy
import inspect
import logging
import os
import six
@@ -87,11 +88,19 @@ class Experiment(object):
_raise_deprecation_note(
"sync_function", "sync_to_driver", soft=False)
stop = stop or {}
if not isinstance(stop, dict) and not callable(stop):
raise ValueError("Invalid stop criteria: {}. Must be a callable "
"or dict".format(stop))
if callable(stop) and len(inspect.getargspec(stop).args) != 2:
raise ValueError("Invalid stop criteria: {}. Callable criteria "
"must take exactly 2 parameters.".format(stop))
config = config or {}
run_identifier = Experiment._register_if_needed(run)
spec = {
"run": run_identifier,
"stop": stop or {},
"stop": stop,
"config": config,
"resources_per_trial": resources_per_trial,
"num_samples": num_samples,