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

Fix multiphase datastore problem #125

Merged
merged 5 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nni_manager/common/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ExperimentProfile, TrialJobStatistics } from './manager';
import { TrialJobDetail, TrialJobStatus } from './trainingService';

type TrialJobEvent = TrialJobStatus | 'USER_TO_CANCEL' | 'ADD_CUSTOMIZED' | 'ADD_HYPERPARAMETER';
type MetricType = 'PERIODICAL' | 'FINAL' | 'CUSTOM';
type MetricType = 'PERIODICAL' | 'FINAL' | 'CUSTOM' | 'REQUEST_PARAMETER';

interface ExperimentProfileRecord {
readonly timestamp: number;
Expand Down
36 changes: 31 additions & 5 deletions src/nni_manager/core/nniDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as component from '../common/component';
import { Database, DataStore, MetricData, MetricDataRecord, MetricType,
TrialJobEvent, TrialJobEventRecord, TrialJobInfo } from '../common/datastore';
import { isNewExperiment } from '../common/experimentStartupInfo';
import { getExperimentId } from '../common/experimentStartupInfo';
import { getLogger, Logger } from '../common/log';
import { ExperimentProfile, TrialJobStatistics } from '../common/manager';
import { TrialJobStatus } from '../common/trainingService';
Expand All @@ -35,6 +36,7 @@ class NNIDataStore implements DataStore {
private db: Database = component.get(Database);
private log: Logger = getLogger();
private initTask!: Deferred<void>;
private multiPhase: boolean | undefined;

public init(): Promise<void> {
if (this.initTask !== undefined) {
Expand Down Expand Up @@ -112,14 +114,18 @@ class NNIDataStore implements DataStore {
}

public async getTrialJob(trialJobId: string): Promise<TrialJobInfo> {
const trialJobs = await this.queryTrialJobs(undefined, trialJobId);
const trialJobs: TrialJobInfo[] = await this.queryTrialJobs(undefined, trialJobId);

return trialJobs[0];
}

public async storeMetricData(trialJobId: string, data: string): Promise<void> {
this.log.debug(`storeMetricData: trialJobId: ${trialJobId}, data: ${data}`);
const metrics = JSON.parse(data) as MetricData;
const metrics: MetricData = JSON.parse(data);
if (metrics.type === 'REQUEST_PARAMETER') {

return;
}
assert(trialJobId === metrics.trial_job_id);
await this.db.storeMetricData(trialJobId, JSON.stringify({
trialJobId: metrics.trial_job_id,
Expand Down Expand Up @@ -161,11 +167,31 @@ class NNIDataStore implements DataStore {

private async getFinalMetricData(trialJobId: string): Promise<any> {
const metrics: MetricDataRecord[] = await this.getMetricData(trialJobId, 'FINAL');
assert(metrics.length <= 1);
if (metrics.length === 1) {

const multiPhase: boolean | undefined = await this.isMultiPhase();

if (multiPhase) {
if (metrics.length > 0) {
return metrics[metrics.length - 1];
} else {
return undefined;
}
} else {
assert(metrics.length <= 1);
chicm-ms marked this conversation as resolved.
Show resolved Hide resolved

return metrics[0];
}
}

private async isMultiPhase(): Promise<boolean|undefined> {
if (this.multiPhase === undefined) {
this.multiPhase = (await this.getExperimentProfile(getExperimentId())).params.multiPhase;
}

if (this.multiPhase !== undefined) {
chicm-ms marked this conversation as resolved.
Show resolved Hide resolved
return this.multiPhase;
} else {
return undefined;
assert(false, 'Failed to retrieve multiPhase flag');
}
}

Expand Down