Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
add /experiment/imported-data & add verify condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Ning Shang committed Sep 21, 2020
1 parent 47a2587 commit e8b5ce9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/nni_manager/common/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ abstract class Manager {
public abstract getExperimentProfile(): Promise<ExperimentProfile>;
public abstract updateExperimentProfile(experimentProfile: ExperimentProfile, updateType: ProfileUpdateType): Promise<void>;
public abstract importData(data: string): Promise<void>;
public abstract getImportedData(): Promise<string[]>;
public abstract exportData(): Promise<string>;

public abstract addCustomizedTrialJob(hyperParams: string): Promise<number>;
Expand Down
4 changes: 4 additions & 0 deletions src/nni_manager/core/nnimanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class NNIManager implements Manager {
return this.dataStore.storeTrialJobEvent('IMPORT_DATA', '', data);
}

public getImportedData(): Promise<string[]> {
return this.dataStore.getImportedData();
}

public async exportData(): Promise<string> {
return this.dataStore.exportTrialHpConfigs();
}
Expand Down
11 changes: 11 additions & 0 deletions src/nni_manager/rest_server/restHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class NNIRestHandler {
this.getExperimentProfile(router);
this.updateExperimentProfile(router);
this.importData(router);
this.getImportedData(router);
this.startExperiment(router);
this.getTrialJobStatistics(router);
this.setClusterMetaData(router);
Expand Down Expand Up @@ -143,6 +144,16 @@ class NNIRestHandler {
});
}

private getImportedData(router: Router): void {
router.get('/experiment/imported-data', (req: Request, res: Response) => {
this.nniManager.getImportedData().then((importedData: string[]) => {
res.send(JSON.stringify(importedData));
}).catch((err: Error) => {
this.handleError(err, res);
});
});
}

private startExperiment(router: Router): void {
router.post('/experiment', expressJoi(ValidationSchemas.STARTEXPERIMENT), (req: Request, res: Response) => {
if (isNewExperiment()) {
Expand Down
4 changes: 4 additions & 0 deletions src/nni_manager/rest_server/test/mockedNNIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class MockedNNIManager extends Manager {
public importData(data: string): Promise<void> {
return Promise.resolve();
}
public getImportedData(): Promise<string[]> {
const ret: string[] = ["1", "2"];
return Promise.resolve(ret);
}
public async exportData(): Promise<string> {
const ret: string = '';
return Promise.resolve(ret);
Expand Down
1 change: 1 addition & 0 deletions test/nni_test/nnitest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
STATUS_URL = API_ROOT_URL + '/check-status'
TRIAL_JOBS_URL = API_ROOT_URL + '/trial-jobs'
METRICS_URL = API_ROOT_URL + '/metric-data'
GET_IMPORTED_DATA_URL = API_ROOT_URL + '/experiment/imported-data'

def read_last_line(file_name):
'''read last line of a file and return None if file not found'''
Expand Down
6 changes: 5 additions & 1 deletion test/nni_test/nnitest/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import json
import requests
from nnicli import Experiment
from utils import METRICS_URL
from nni_cmd.updater import load_search_space
from utils import METRICS_URL, GET_IMPORTED_DATA_URL


class ITValidator:
Expand Down Expand Up @@ -40,6 +41,9 @@ def __call__(self, rest_endpoint, experiment_dir, nni_source_dir, **kwargs):
proc = subprocess.run(['nnictl', 'experiment', 'import', exp_id, '-f', import_data_file_path])
assert proc.returncode == 0, \
'`nnictl experiment import {0} -f {1}` failed with code {2}'.format(exp_id, import_data_file_path, proc.returncode)
imported_data = requests.get(GET_IMPORTED_DATA_URL).json()
origin_data = load_search_space(import_data_file_path).replace(' ', '')
assert origin_data in imported_data

class MetricsValidator(ITValidator):
def __call__(self, rest_endpoint, experiment_dir, nni_source_dir, **kwargs):
Expand Down

0 comments on commit e8b5ce9

Please sign in to comment.