-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Support experiment view #1524
Support experiment view #1524
Changes from 16 commits
704b50e
5b0034e
8fe2588
4b566aa
4b8c222
44634b1
8f3dd22
bf3388c
bc7a7fd
9fae194
479daea
2ea7ae5
e7ee998
9ad744d
4e9a44a
3ffa6ee
c43c21a
530ec8d
b3a22e4
be70a11
7035590
cfea562
79f2240
13418ba
15fc510
1850834
5237202
6e3ea85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,9 @@ import { Database, DataStore, MetricData, MetricDataRecord, MetricType, | |
TrialJobEvent, TrialJobEventRecord, TrialJobInfo, HyperParameterFormat, | ||
ExportedDataFormat } from '../common/datastore'; | ||
import { NNIError } from '../common/errors'; | ||
import { getExperimentId, isNewExperiment } from '../common/experimentStartupInfo'; | ||
import { getExperimentId, getExperimentMode } from '../common/experimentStartupInfo'; | ||
import { getLogger, Logger } from '../common/log'; | ||
import { ExperimentProfile, TrialJobStatistics } from '../common/manager'; | ||
import { ExperimentProfile, TrialJobStatistics, ExperimentStartUpMode } from '../common/manager'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the new import not used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
import { TrialJobDetail, TrialJobStatus } from '../common/trainingService'; | ||
import { getDefaultDatabaseDir, mkDirP } from '../common/utils'; | ||
|
||
|
@@ -47,7 +47,7 @@ class NNIDataStore implements DataStore { | |
|
||
// TODO support specify database dir | ||
const databaseDir: string = getDefaultDatabaseDir(); | ||
if(isNewExperiment()) { | ||
if(getExperimentMode() === ExperimentStartUpMode.NEW) { | ||
mkDirP(databaseDir).then(() => { | ||
this.db.init(true, databaseDir).then(() => { | ||
this.log.info('Datastore initialization done'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,9 @@ import * as path from 'path'; | |
import * as component from '../common/component'; | ||
import { DataStore, MetricDataRecord, TrialJobInfo } from '../common/datastore'; | ||
import { NNIError, NNIErrorNames } from '../common/errors'; | ||
import { isNewExperiment } from '../common/experimentStartupInfo'; | ||
import { getExperimentMode } from '../common/experimentStartupInfo'; | ||
import { getLogger, Logger } from '../common/log'; | ||
import { ExperimentProfile, Manager, TrialJobStatistics} from '../common/manager'; | ||
import { ExperimentProfile, Manager, TrialJobStatistics, ExperimentStartUpMode } from '../common/manager'; | ||
import { ValidationSchemas } from './restValidationSchemas'; | ||
import { NNIRestServer } from './nniRestServer'; | ||
import { getVersion } from '../common/utils'; | ||
|
@@ -139,11 +139,18 @@ class NNIRestHandler { | |
|
||
private updateExperimentProfile(router: Router): void { | ||
router.put('/experiment', expressJoi(ValidationSchemas.UPDATEEXPERIMENT), (req: Request, res: Response) => { | ||
this.nniManager.updateExperimentProfile(req.body, req.query.update_type).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
let experimentMode: string = getExperimentMode(); | ||
if( experimentMode !== ExperimentStartUpMode.VIEW) { | ||
this.nniManager.updateExperimentProfile(req.body, req.query.update_type).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
} else { | ||
let message = `Could not update experiment in view mode!`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lvybriage could webui correctly handle this message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, send 400 code back. |
||
this.log.warning(message); | ||
res.send(message); | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -159,7 +166,8 @@ class NNIRestHandler { | |
|
||
private startExperiment(router: Router): void { | ||
router.post('/experiment', expressJoi(ValidationSchemas.STARTEXPERIMENT), (req: Request, res: Response) => { | ||
if (isNewExperiment()) { | ||
let experimentMode: string = getExperimentMode(); | ||
if (experimentMode === ExperimentStartUpMode.NEW) { | ||
this.nniManager.startExperiment(req.body).then((eid: string) => { | ||
res.send({ | ||
experiment_id: eid | ||
|
@@ -168,13 +176,20 @@ class NNIRestHandler { | |
// Start experiment is a step of initialization, so any exception thrown is a fatal | ||
this.handle_error(err, res); | ||
}); | ||
} else { | ||
} else if (experimentMode === ExperimentStartUpMode.RESUME){ | ||
this.nniManager.resumeExperiment().then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
// Resume experiment is a step of initialization, so any exception thrown is a fatal | ||
this.handle_error(err, res); | ||
}); | ||
} else if (experimentMode === ExperimentStartUpMode.VIEW){ | ||
this.nniManager.viewExperiment().then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
// View experiment is a step of initialization, so any exception thrown is a fatal | ||
this.handle_error(err, res); | ||
}); | ||
} | ||
}); | ||
} | ||
|
@@ -193,18 +208,26 @@ class NNIRestHandler { | |
router.put( | ||
'/experiment/cluster-metadata', expressJoi(ValidationSchemas.SETCLUSTERMETADATA), | ||
async (req: Request, res: Response) => { | ||
// tslint:disable-next-line:no-any | ||
const metadata: any = req.body; | ||
const keys: string[] = Object.keys(metadata); | ||
try { | ||
for (const key of keys) { | ||
await this.nniManager.setClusterMetadata(key, JSON.stringify(metadata[key])); | ||
let experimentMode: string = getExperimentMode(); | ||
if(experimentMode !== ExperimentStartUpMode.VIEW) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. white space There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
// tslint:disable-next-line:no-any | ||
const metadata: any = req.body; | ||
const keys: string[] = Object.keys(metadata); | ||
try { | ||
for (const key of keys) { | ||
await this.nniManager.setClusterMetadata(key, JSON.stringify(metadata[key])); | ||
} | ||
res.send(); | ||
} catch (err) { | ||
// setClusterMetata is a step of initialization, so any exception thrown is a fatal | ||
this.handle_error(NNIError.FromError(err), res, true); | ||
} | ||
res.send(); | ||
} catch (err) { | ||
// setClusterMetata is a step of initialization, so any exception thrown is a fatal | ||
this.handle_error(NNIError.FromError(err), res, true); | ||
} else { | ||
let message = `Could not set cluster-metadata in view mode!`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does nnictl handle this error message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, nnictl handles this error message |
||
this.log.warning(message); | ||
res.send(message); | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
@@ -234,21 +257,36 @@ class NNIRestHandler { | |
|
||
private addTrialJob(router: Router): void { | ||
router.post('/trial-jobs', async (req: Request, res: Response) => { | ||
this.nniManager.addCustomizedTrialJob(JSON.stringify(req.body)).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
let experimentMode: string = getExperimentMode(); | ||
if(experimentMode !== ExperimentStartUpMode.VIEW) { | ||
this.nniManager.addCustomizedTrialJob(JSON.stringify(req.body)).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
} else { | ||
let message = `Could not add customized trial in view mode!`; | ||
QuanluZhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.log.warning(message); | ||
res.send(message); | ||
} | ||
}); | ||
} | ||
|
||
private cancelTrialJob(router: Router): void { | ||
router.delete('/trial-jobs/:id', async (req: Request, res: Response) => { | ||
this.nniManager.cancelTrialJobByUser(req.params.id).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
let experimentMode: string = getExperimentMode(); | ||
if(experimentMode !== ExperimentStartUpMode.VIEW) { | ||
this.nniManager.cancelTrialJobByUser(req.params.id).then(() => { | ||
res.send(); | ||
}).catch((err: Error) => { | ||
this.handle_error(err, res); | ||
}); | ||
} else { | ||
let message = `Could not delete trial job in view mode!`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
this.log.warning(message); | ||
res.send(message); | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this import necessary? it seems not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.