Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequenceId to TrialJobInfo (#283) #47

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions src/nni_manager/common/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface TrialJobEventRecord {
readonly event: TrialJobEvent;
readonly data?: string;
readonly logPath?: string;
readonly sequenceId?: number;
}

interface MetricData {
Expand All @@ -59,6 +60,7 @@ interface MetricDataRecord {

interface TrialJobInfo {
id: string;
sequenceId?: number;
status: TrialJobStatus;
startTime?: number;
endTime?: number;
Expand All @@ -73,7 +75,8 @@ abstract class DataStore {
public abstract close(): Promise<void>;
public abstract storeExperimentProfile(experimentProfile: ExperimentProfile): Promise<void>;
public abstract getExperimentProfile(experimentId: string): Promise<ExperimentProfile>;
public abstract storeTrialJobEvent(event: TrialJobEvent, trialJobId: string, data?: string, logPath?: string): Promise<void>;
public abstract storeTrialJobEvent(
event: TrialJobEvent, trialJobId: string, hyperParameter?: string, jobDetail?: TrialJobDetail): Promise<void>;
public abstract getTrialJobStatistics(): Promise<TrialJobStatistics[]>;
public abstract listTrialJobs(status?: TrialJobStatus): Promise<TrialJobInfo[]>;
public abstract getTrialJob(trialJobId: string): Promise<TrialJobInfo>;
Expand All @@ -87,7 +90,8 @@ abstract class Database {
public abstract storeExperimentProfile(experimentProfile: ExperimentProfile): Promise<void>;
public abstract queryExperimentProfile(experimentId: string, revision?: number): Promise<ExperimentProfile[]>;
public abstract queryLatestExperimentProfile(experimentId: string): Promise<ExperimentProfile>;
public abstract storeTrialJobEvent(event: TrialJobEvent, trialJobId: string, data?: string, logPath?: string): Promise<void>;
public abstract storeTrialJobEvent(
event: TrialJobEvent, trialJobId: string, hyperParameter?: string, jobDetail?: TrialJobDetail): Promise<void>;
public abstract queryTrialJobEvent(trialJobId?: string, event?: TrialJobEvent): Promise<TrialJobEventRecord[]>;
public abstract storeMetricData(trialJobId: string, data: string): Promise<void>;
public abstract queryMetricData(trialJobId?: string, type?: MetricType): Promise<MetricDataRecord[]>;
Expand Down
12 changes: 8 additions & 4 deletions src/nni_manager/core/nniDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { NNIError } from '../common/errors';
import { getExperimentId, isNewExperiment } from '../common/experimentStartupInfo';
import { getLogger, Logger } from '../common/log';
import { ExperimentProfile, TrialJobStatistics } from '../common/manager';
import { TrialJobStatus } from '../common/trainingService';
import { TrialJobDetail, TrialJobStatus } from '../common/trainingService';
import { getDefaultDatabaseDir, mkDirP } from '../common/utils';

class NNIDataStore implements DataStore {
Expand Down Expand Up @@ -83,10 +83,11 @@ class NNIDataStore implements DataStore {
return this.db.queryLatestExperimentProfile(experimentId);
}

public storeTrialJobEvent(event: TrialJobEvent, trialJobId: string, data?: string, logPath?: string): Promise<void> {
this.log.debug(`storeTrialJobEvent: event: ${event}, data: ${data}, logpath: ${logPath}`);
public storeTrialJobEvent(
event: TrialJobEvent, trialJobId: string, hyperParameter?: string, jobDetail?: TrialJobDetail): Promise<void> {
this.log.debug(`storeTrialJobEvent: event: ${event}, data: ${hyperParameter}, jobDetail: ${JSON.stringify(jobDetail)}`);

return this.db.storeTrialJobEvent(event, trialJobId, data, logPath).catch(
return this.db.storeTrialJobEvent(event, trialJobId, hyperParameter, jobDetail).catch(
(err: Error) => {
throw new NNIError('Datastore error', `Datastore error: ${err.message}`, err);
}
Expand Down Expand Up @@ -281,6 +282,9 @@ class NNIDataStore implements DataStore {
assert(false, 'jobInfo.hyperParameters is undefined');
}
}
if (record.sequenceId !== undefined && jobInfo.sequenceId === undefined) {
jobInfo.sequenceId = record.sequenceId;
}
map.set(record.trialJobId, jobInfo);
}

Expand Down
4 changes: 2 additions & 2 deletions src/nni_manager/core/nnimanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class NNIManager implements Manager {
const oldTrialJobDetail: TrialJobDetail | undefined = this.trialJobs.get(trialJobId);
if (oldTrialJobDetail !== undefined && oldTrialJobDetail.status !== trialJobDetail.status) {
this.trialJobs.set(trialJobId, Object.assign({}, trialJobDetail));
await this.dataStore.storeTrialJobEvent(trialJobDetail.status, trialJobDetail.id, undefined, trialJobDetail.url);
await this.dataStore.storeTrialJobEvent(trialJobDetail.status, trialJobDetail.id, undefined, trialJobDetail);
}
switch (trialJobDetail.status) {
case 'SUCCEEDED':
Expand Down Expand Up @@ -461,7 +461,7 @@ class NNIManager implements Manager {
const trialJobDetailSnapshot: TrialJobDetail | undefined = this.trialJobs.get(trialJobDetail.id);
if (trialJobDetailSnapshot != undefined) {
await this.dataStore.storeTrialJobEvent(
trialJobDetailSnapshot.status, trialJobDetailSnapshot.id, hyperParams, trialJobDetailSnapshot.url);
trialJobDetailSnapshot.status, trialJobDetailSnapshot.id, hyperParams, trialJobDetailSnapshot);
} else {
assert(false, `undefined trialJobDetail in trialJobs: ${trialJobDetail.id}`);
}
Expand Down
20 changes: 14 additions & 6 deletions src/nni_manager/core/sqlDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import {
TrialJobEventRecord
} from '../common/datastore';
import { ExperimentProfile } from '../common/manager';
import { TrialJobDetail } from '../common/trainingService';

/* tslint:disable:no-any */

const createTables: string = `
create table TrialJobEvent (timestamp integer, trialJobId text, event text, data text, logPath text);
create table TrialJobEvent (timestamp integer, trialJobId text, event text, data text, logPath text, sequenceId integer);
create index TrialJobEvent_trialJobId on TrialJobEvent(trialJobId);
create index TrialJobEvent_event on TrialJobEvent(event);

Expand All @@ -51,6 +52,7 @@ create table ExperimentProfile (
execDuration integer,
startTime integer,
endTime integer,
logDir text,
revision integer);
create index ExperimentProfile_id on ExperimentProfile(id);
`;
Expand All @@ -62,6 +64,7 @@ function loadExperimentProfile(row: any): ExperimentProfile {
execDuration: row.execDuration,
startTime: row.startTime === null ? undefined : row.startTime,
endTime: row.endTime === null ? undefined : row.endTime,
logDir: row.logDir === null ? undefined : row.logDir,
revision: row.revision
};
}
Expand All @@ -72,7 +75,8 @@ function loadTrialJobEvent(row: any): TrialJobEventRecord {
trialJobId: row.trialJobId,
event: row.event,
data: row.data === null ? undefined : row.data,
logPath: row.logPath === null ? undefined : row.logPath
logPath: row.logPath === null ? undefined : row.logPath,
sequenceId: row.sequenceId === null ? undefined : row.sequenceId
};
}

Expand Down Expand Up @@ -127,13 +131,14 @@ class SqlDB implements Database {
}

public storeExperimentProfile(exp: ExperimentProfile): Promise<void> {
const sql: string = 'insert into ExperimentProfile values (?,?,?,?,?,?)';
const sql: string = 'insert into ExperimentProfile values (?,?,?,?,?,?,?)';
const args: any[] = [
JSON.stringify(exp.params),
exp.id,
exp.execDuration,
exp.startTime === undefined ? null : exp.startTime,
exp.endTime === undefined ? null : exp.endTime,
exp.logDir === undefined ? null : exp.logDir,
exp.revision
];

Expand Down Expand Up @@ -168,9 +173,12 @@ class SqlDB implements Database {
return profiles[0];
}

public storeTrialJobEvent(event: TrialJobEvent, trialJobId: string, data?: string, logPath?: string): Promise<void> {
const sql: string = 'insert into TrialJobEvent values (?,?,?,?,?)';
const args: any[] = [Date.now(), trialJobId, event, data, logPath];
public storeTrialJobEvent(
event: TrialJobEvent, trialJobId: string, hyperParameter?: string, jobDetail?: TrialJobDetail): Promise<void> {
const sql: string = 'insert into TrialJobEvent values (?,?,?,?,?,?)';
const logPath: string | undefined = jobDetail === undefined ? undefined : jobDetail.url;
const sequenceId: number | undefined = jobDetail === undefined ? undefined : jobDetail.sequenceId;
const args: any[] = [Date.now(), trialJobId, event, hyperParameter, logPath, sequenceId];

const deferred: Deferred<void> = new Deferred<void>();
this.db.run(sql, args, (err: Error | null) => { this.resolve(deferred, err); });
Expand Down