".github/vscode:/vscode.git/clone" did not exist on "e4956c813f84c9aaf076043c8d84451c1f8160ba"
trainingService.ts 3.92 KB
Newer Older
Deshui Yu's avatar
Deshui Yu committed
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
/**
 * Copyright (c) Microsoft Corporation
 * All rights reserved.
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

'use strict';

/**
 * define TrialJobStatus
 */
type TrialJobStatus = 'UNKNOWN' | 'WAITING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'USER_CANCELED' | 'SYS_CANCELED';
type JobType = 'TRIAL' | 'HOST';

interface TrainingServiceMetadata {
    readonly key: string;
    readonly value: string;
}

/**
 * define JobApplicationForm
 */
interface JobApplicationForm {
    readonly jobType: JobType;
}

chicm-ms's avatar
chicm-ms committed
40
41
42
43
44
interface HyperParameters {
    readonly value: string;
    readonly index: number;
}

Deshui Yu's avatar
Deshui Yu committed
45
46
47
48
/**
 * define TrialJobApplicationForm
 */
interface TrialJobApplicationForm extends JobApplicationForm {
chicm-ms's avatar
chicm-ms committed
49
    readonly hyperParameters: HyperParameters;
Deshui Yu's avatar
Deshui Yu committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
}

/**
 * define HostJobApplicationForm
 */
interface HostJobApplicationForm extends JobApplicationForm {
    readonly host: string;
    readonly cmd: string;
}

/**
 * define TrialJobDetail
 */
interface TrialJobDetail {
    readonly id: string;
    readonly status: TrialJobStatus;
66
67
68
    readonly submitTime: number;
    readonly startTime?: number;
    readonly endTime?: number;
Deshui Yu's avatar
Deshui Yu committed
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
    readonly tags?: string[];
    readonly url?: string;
    readonly workingDirectory: string;
    readonly form: JobApplicationForm;
}

interface HostJobDetail {
    readonly id: string;
    readonly status: string;
}

/**
 * define TrialJobMetric
 */
interface TrialJobMetric {
    readonly id: string;
    readonly data: string;
}

/**
 * define TrainingServiceError
 */
class TrainingServiceError extends Error {
    private errCode: number;

    constructor(errorCode: number, errorMessage: string) {
        super(errorMessage);
        this.errCode = errorCode;
    }

    get errorCode(): number {
        return this.errCode;
    }
}

/**
 * define TrainingService
 */
abstract class TrainingService {
    public abstract listTrialJobs(): Promise<TrialJobDetail[]>;
    public abstract getTrialJob(trialJobId: string): Promise<TrialJobDetail>;
    public abstract addTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
    public abstract removeTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
    public abstract submitTrialJob(form: JobApplicationForm): Promise<TrialJobDetail>;
113
114
    public abstract updateTrialJob(trialJobId: string, form: JobApplicationForm): Promise<TrialJobDetail>;
    public abstract get isMultiPhaseJobSupported(): boolean;
Deshui Yu's avatar
Deshui Yu committed
115
116
117
118
119
120
121
122
123
    public abstract cancelTrialJob(trialJobId: string): Promise<void>;
    public abstract setClusterMetadata(key: string, value: string): Promise<void>;
    public abstract getClusterMetadata(key: string): Promise<string>;
    public abstract cleanUp(): Promise<void>;
    public abstract run(): Promise<void>;
}

export {
    TrainingService, TrainingServiceError, TrialJobStatus, TrialJobApplicationForm,
chicm-ms's avatar
chicm-ms committed
124
    TrainingServiceMetadata, TrialJobDetail, TrialJobMetric, HyperParameters,
Deshui Yu's avatar
Deshui Yu committed
125
126
    HostJobApplicationForm, JobApplicationForm, JobType
};