mirror of
https://github.com/wassname/ray.git
synced 2026-07-10 02:41:07 +08:00
[tune] Cancel Experiment via Client (#7719)
* init cancel * testing * Update python/ray/tune/tests/test_tune_server.py Co-Authored-By: Richard Liaw <rliaw@berkeley.edu> * Apply suggestions from code review * Apply suggestions from code review * finished * set_finished Co-authored-by: ijrsvt <ian.rodney@gmail.com>
This commit is contained in:
@@ -35,15 +35,15 @@ class TuneClient:
|
||||
self._port_forward = port_forward
|
||||
self._path = "http://{}:{}".format(tune_address, port_forward)
|
||||
|
||||
def get_all_trials(self):
|
||||
def get_all_trials(self, timeout=None):
|
||||
"""Returns a list of all trials' information."""
|
||||
response = requests.get(urljoin(self._path, "trials"))
|
||||
response = requests.get(urljoin(self._path, "trials"), timeout=timeout)
|
||||
return self._deserialize(response)
|
||||
|
||||
def get_trial(self, trial_id):
|
||||
def get_trial(self, trial_id, timeout=None):
|
||||
"""Returns trial information by trial_id."""
|
||||
response = requests.get(
|
||||
urljoin(self._path, "trials/{}".format(trial_id)))
|
||||
urljoin(self._path, "trials/{}".format(trial_id)), timeout=timeout)
|
||||
return self._deserialize(response)
|
||||
|
||||
def add_trial(self, name, specification):
|
||||
@@ -58,6 +58,11 @@ class TuneClient:
|
||||
urljoin(self._path, "trials/{}".format(trial_id)))
|
||||
return self._deserialize(response)
|
||||
|
||||
def stop_experiment(self):
|
||||
"""Requests to stop the entire experiment."""
|
||||
response = requests.put(urljoin(self._path, "stop_experiment"))
|
||||
return self._deserialize(response)
|
||||
|
||||
@property
|
||||
def server_address(self):
|
||||
return self._tune_address
|
||||
@@ -137,17 +142,20 @@ def RunnerHandler(runner):
|
||||
response_code = 200
|
||||
message = ""
|
||||
try:
|
||||
result = self._get_trial_by_url(self.path)
|
||||
resource = {}
|
||||
if result:
|
||||
if isinstance(result, list):
|
||||
infos = [self._trial_info(t) for t in result]
|
||||
resource["trials"] = infos
|
||||
for t in result:
|
||||
|
||||
if self.path.endswith("stop_experiment"):
|
||||
runner.request_stop_experiment()
|
||||
trials = list(runner.get_trials())
|
||||
else:
|
||||
trials = self._get_trial_by_url(self.path)
|
||||
if trials:
|
||||
if not isinstance(trials, list):
|
||||
trials = [trials]
|
||||
for t in trials:
|
||||
runner.request_stop_trial(t)
|
||||
else:
|
||||
resource["trial"] = self._trial_info(result)
|
||||
runner.request_stop_trial(result)
|
||||
|
||||
resource["trials"] = [self._trial_info(t) for t in trials]
|
||||
message = json.dumps(resource)
|
||||
except TuneError as e:
|
||||
response_code = 404
|
||||
|
||||
Reference in New Issue
Block a user