-
Notifications
You must be signed in to change notification settings - Fork 10
/
experiment.py
112 lines (101 loc) · 4.05 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from .impl.cloud.rest_api import RestApi
from .impl.decorators import with_dataset
from a2ml.api.utils.decorators import error_handler, authenticated
from .impl.experiment import Experiment
from .impl.exceptions import AugerException
from a2ml.api.utils.formatter import print_table
from .credentials import Credentials
from .config import AugerConfig
class AugerExperiment(object):
def __init__(self, ctx):
self.ctx = ctx
self.credentials = Credentials(ctx).load()
self.ctx.rest_api = RestApi(
self.credentials.api_url, self.credentials.token)
@error_handler
@authenticated
@with_dataset
def list(self, dataset):
count = 0
for exp in iter(Experiment(self.ctx, dataset).list()):
self.ctx.log(exp.get('name'))
count += 1
self.ctx.log('%s Experiment(s) listed' % str(count))
return {'experiments': Experiment(self.ctx, dataset).list()}
@error_handler
@authenticated
@with_dataset
def start(self, dataset):
experiment_name = \
self.ctx.config.get('experiment/name', None)
experiment_name, session_id = \
Experiment(self.ctx, dataset, experiment_name).start()
AugerConfig(self.ctx).set_experiment(experiment_name, session_id)
return {'experiment_name': experiment_name, 'session_id': session_id}
@error_handler
@authenticated
@with_dataset
def stop(self, dataset, run_id = None):
name = self.ctx.config.get('experiment/name', None)
if name is None:
raise AugerException('Please specify Experiment name...')
if run_id is None:
run_id = self.ctx.config.get(
'experiment/experiment_session_id', None)
if Experiment(self.ctx, dataset, name).stop(run_id):
self.ctx.log('Search is stopped...')
else:
self.ctx.log('Search is not running. Stop is ignored.')
return {'stopped': name}
@error_handler
@authenticated
@with_dataset
def leaderboard(self, dataset, run_id = None):
name = self.ctx.config.get('experiment/name', None)
if name is None:
raise AugerException('Please specify Experiment name...')
if run_id is None:
run_id = self.ctx.config.get(
'experiment/experiment_session_id', None)
leaderboard, status, run_id = Experiment(
self.ctx, dataset, name).leaderboard(run_id)
if leaderboard is None:
raise AugerException('No leaderboard was found...')
self.ctx.log('Leaderboard for Run %s' % run_id)
print_table(self.ctx.log, leaderboard[::-1])
messages = {
'preprocess': 'Search is preprocessing data for training...',
'started': 'Search is in progress...',
'completed': 'Search is completed.',
'interrupted': 'Search was interrupted.',
'error': 'Search was finished with error.'
}
message = messages.get(status, None)
if message:
self.ctx.log(message)
else:
self.ctx.log('Search status is %s' % status)
result = {
'run_id': run_id,
'leaderboard': leaderboard,
'status': status,
'provider_status': status
}
if status == "error":
#TODO: get experiment session errors
result['error'] = error
result['error_details'] = error_details
return result
@error_handler
@authenticated
@with_dataset
def history(self, dataset):
name = self.ctx.config.get('experiment/name', None)
if name is None:
raise AugerException('Please specify Experiment name...')
for exp_run in iter(Experiment(self.ctx, dataset, name).history()):
self.ctx.log("run id: {}, start time: {}, status: {}".format(
exp_run.get('id'),
exp_run.get('model_settings').get('start_time'),
exp_run.get('status')))
return {'history': Experiment(self.ctx, dataset, name).history()}