mockedNNIManager.ts 6.02 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Deshui Yu's avatar
Deshui Yu committed
3
4
5
6
7
8
9
10
11
12

'use strict';

import { Deferred } from 'ts-deferred';
import { Provider } from 'typescript-ioc';

import { MetricDataRecord, MetricType, TrialJobInfo } from '../../common/datastore';
import { MethodNotImplementedError } from '../../common/errors';
import {
    ExperimentParams, ExperimentProfile, Manager, ProfileUpdateType,
13
    TrialJobStatistics, NNIManagerStatus
Deshui Yu's avatar
Deshui Yu committed
14
15
} from '../../common/manager';
import {
16
    TrialJobApplicationForm, TrialJobDetail, TrialJobStatus, LogType
Deshui Yu's avatar
Deshui Yu committed
17
18
19
20
21
22
23
} from '../../common/trainingService';

export const testManagerProvider: Provider = {
    get: (): Manager => { return new MockedNNIManager(); }
};

export class MockedNNIManager extends Manager {
24
25
    public getStatus(): NNIManagerStatus {
        return {
26
            status: 'RUNNING',
27
28
29
            errors: []
        }
    }
30
    public updateExperimentProfile(experimentProfile: ExperimentProfile, updateType: ProfileUpdateType): Promise<void> {
Deshui Yu's avatar
Deshui Yu committed
31
32
        return Promise.resolve();
    }
33
34
35
    public importData(data: string): Promise<void> {
        return Promise.resolve();
    }
36
37
38
39
    public getImportedData(): Promise<string[]> {
        const ret: string[] = ["1", "2"];
        return Promise.resolve(ret);
    }
40
41
42
43
    public async exportData(): Promise<string> {
        const ret: string = '';
        return Promise.resolve(ret);
    }
Deshui Yu's avatar
Deshui Yu committed
44
45
46
47
48
49
50
51
52
53
54
55
    public getTrialJobStatistics(): Promise<TrialJobStatistics[]> {
        const deferred: Deferred<TrialJobStatistics[]> = new Deferred<TrialJobStatistics[]>();
        deferred.resolve([{
            trialJobStatus: 'RUNNING',
            trialJobNumber: 2
        }, {
            trialJobStatus: 'FAILED',
            trialJobNumber: 1
        }]);

        return deferred.promise;
    }
56
57
    public addCustomizedTrialJob(hyperParams: string): Promise<number> {
        return Promise.resolve(99);
Deshui Yu's avatar
Deshui Yu committed
58
59
60
61
62
63
64
65
66
67
68
    }

    public resumeExperiment(): Promise<void> {
        return Promise.resolve();
    }

    public submitTrialJob(form: TrialJobApplicationForm): Promise<TrialJobDetail> {
        const deferred: Deferred<TrialJobDetail> = new Deferred<TrialJobDetail>();
        const jobDetail: TrialJobDetail = {
            id: '1234',
            status: 'RUNNING',
69
70
71
            submitTime: Date.now(),
            startTime: Date.now(),
            endTime: Date.now(),
Deshui Yu's avatar
Deshui Yu committed
72
73
74
75
            tags: ['test'],
            url: 'http://test',
            workingDirectory: '/tmp/mocked',
            form: {
76
77
                sequenceId: 0,
                hyperParameters: { value: '', index: 0 }
Deshui Yu's avatar
Deshui Yu committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
            }
        };
        deferred.resolve(jobDetail);

        return deferred.promise;
    }

    public cancelTrialJobByUser(trialJobId: string): Promise<void> {
        return Promise.resolve();
    }

    public getClusterMetadata(key: string): Promise<string> {
        return Promise.resolve('METAVALUE1');
    }

    public startExperiment(experimentParams: ExperimentParams): Promise<string> {
        return Promise.resolve('id-1234');
    }

    public setClusterMetadata(key: string, value: string): Promise<void> {
chicm-ms's avatar
chicm-ms committed
98
        return Promise.resolve();
Deshui Yu's avatar
Deshui Yu committed
99
100
    }

101
102
103
    public getTrialJob(trialJobId: string): Promise<TrialJobInfo> {
        const deferred: Deferred<TrialJobInfo> = new Deferred<TrialJobInfo>();
        const jobInfo: TrialJobInfo = {
J-shang's avatar
J-shang committed
104
            trialJobId: '1234',
Deshui Yu's avatar
Deshui Yu committed
105
            status: 'SUCCEEDED',
106
107
            startTime: Date.now(),
            endTime: Date.now()
Deshui Yu's avatar
Deshui Yu committed
108
        };
109
        deferred.resolve(jobInfo);
Deshui Yu's avatar
Deshui Yu committed
110
111
112

        return deferred.promise;
    }
113

Deshui Yu's avatar
Deshui Yu committed
114
115
116
    public stopExperiment(): Promise<void> {
        throw new MethodNotImplementedError();
    }
117
118
119
120
121
122
    public stopExperimentTopHalf(): Promise<void> {
        throw new MethodNotImplementedError();
    }
    public stopExperimentBottomHalf(): Promise<void> {
        throw new MethodNotImplementedError();
    }
Deshui Yu's avatar
Deshui Yu committed
123
124
125
    public getMetricData(trialJobId: string, metricType: MetricType): Promise<MetricDataRecord[]> {
        throw new MethodNotImplementedError();
    }
126
127
128
129
130
131
    public getMetricDataByRange(minSeqId: number, maxSeqId: number): Promise<MetricDataRecord[]> {
        throw new MethodNotImplementedError();
    }
    public getLatestMetricData(): Promise<MetricDataRecord[]> {
        throw new MethodNotImplementedError();
    }
132
133
134
    public getTrialLog(trialJobId: string, logType: LogType): Promise<string> {
        throw new MethodNotImplementedError();
    }
Deshui Yu's avatar
Deshui Yu committed
135
136
137
138
139
140
141
142
    public getExperimentProfile(): Promise<ExperimentProfile> {
        const profile: ExperimentProfile = {
            params: {
                authorName: 'test',
                experimentName: 'exp1',
                trialConcurrency: 2,
                maxExecDuration: 30,
                maxTrialNum: 3,
143
                trainingServicePlatform: 'local',
Deshui Yu's avatar
Deshui Yu committed
144
145
                searchSpace: '{lr: 0.01}',
                tuner: {
146
147
                    className: 'testTuner',
                    checkpointDir: ''
Deshui Yu's avatar
Deshui Yu committed
148
149
150
151
                }
            },
            id: '2345',
            execDuration: 0,
152
153
            startTime: Date.now(),
            endTime: Date.now(),
154
            nextSequenceId: 0,
Deshui Yu's avatar
Deshui Yu committed
155
156
157
158
159
160
161
            revision: 0
        };

        return Promise.resolve(profile);
    }
    public listTrialJobs(status?: TrialJobStatus): Promise<TrialJobInfo[]> {
        const job1: TrialJobInfo = {
J-shang's avatar
J-shang committed
162
            trialJobId: '1234',
Deshui Yu's avatar
Deshui Yu committed
163
            status: 'SUCCEEDED',
164
165
            startTime: Date.now(),
            endTime: Date.now(),
chicm-ms's avatar
chicm-ms committed
166
            finalMetricData: [{
chicm-ms's avatar
chicm-ms committed
167
168
169
170
171
172
                timestamp: 0,
                trialJobId: '3456',
                parameterId: '123',
                type: 'FINAL',
                sequence: 0,
                data: '0.2'
chicm-ms's avatar
chicm-ms committed
173
            }]
Deshui Yu's avatar
Deshui Yu committed
174
175
        };
        const job2: TrialJobInfo = {
J-shang's avatar
J-shang committed
176
            trialJobId: '3456',
Deshui Yu's avatar
Deshui Yu committed
177
            status: 'FAILED',
178
179
            startTime: Date.now(),
            endTime: Date.now(),
chicm-ms's avatar
chicm-ms committed
180
            finalMetricData: [{
chicm-ms's avatar
chicm-ms committed
181
182
183
184
185
186
                timestamp: 0,
                trialJobId: '3456',
                parameterId: '123',
                type: 'FINAL',
                sequence: 0,
                data: '0.2'
chicm-ms's avatar
chicm-ms committed
187
            }]
Deshui Yu's avatar
Deshui Yu committed
188
189
190
191
192
        };

        return Promise.resolve([job1, job2]);
    }
}