in ts/nni_manager/core/nniDataStore.ts [279:363]
private getTrialJobsByReplayEvents(trialJobEvents: TrialJobEventRecord[]): Map<string, TrialJobInfo> {
this.log.debug('getTrialJobsByReplayEvents begin');
const map: Map<string, TrialJobInfo> = new Map();
const hParamIdMap: Map<string, Set<number>> = new Map();
// assume data is stored by time ASC order
for (const record of trialJobEvents) {
let jobInfo: TrialJobInfo | undefined;
if (record.trialJobId === undefined || record.trialJobId.length < 1) {
continue;
}
if (map.has(record.trialJobId)) {
jobInfo = map.get(record.trialJobId);
} else {
jobInfo = {
trialJobId: record.trialJobId,
status: this.getJobStatusByLatestEvent('UNKNOWN', record.event),
hyperParameters: []
};
}
if (!jobInfo) {
throw new Error('Empty JobInfo');
}
/* eslint-disable no-fallthrough */
switch (record.event) {
case 'RUNNING':
if (record.timestamp !== undefined) {
jobInfo.startTime = record.timestamp;
}
case 'WAITING':
if (record.logPath !== undefined) {
jobInfo.logPath = record.logPath;
}
// Initially assign WAITING timestamp as job's start time,
// If there is RUNNING state event, it will be updated as RUNNING state timestamp
if (jobInfo.startTime === undefined && record.timestamp !== undefined) {
jobInfo.startTime = record.timestamp;
}
break;
case 'SUCCEEDED':
case 'FAILED':
case 'USER_CANCELED':
case 'SYS_CANCELED':
case 'EARLY_STOPPED':
if (record.logPath !== undefined) {
jobInfo.logPath = record.logPath;
}
jobInfo.endTime = record.timestamp;
if (jobInfo.startTime === undefined && record.timestamp !== undefined) {
jobInfo.startTime = record.timestamp;
}
default:
}
/* eslint-enable no-fallthrough */
jobInfo.status = this.getJobStatusByLatestEvent(jobInfo.status, record.event);
if (record.data !== undefined && record.data.trim().length > 0) {
const newHParam: any = this.parseHyperParameter(record.data);
if (newHParam !== undefined) {
if (jobInfo.hyperParameters !== undefined) {
let hParamIds: Set<number> | undefined = hParamIdMap.get(jobInfo.trialJobId);
if (hParamIds === undefined) {
hParamIds = new Set();
}
if (!hParamIds.has(newHParam.parameter_index)) {
jobInfo.hyperParameters.push(JSON.stringify(newHParam));
hParamIds.add(newHParam.parameter_index);
hParamIdMap.set(jobInfo.trialJobId, hParamIds);
}
} else {
assert(false, 'jobInfo.hyperParameters is undefined');
}
}
}
if (record.sequenceId !== undefined && jobInfo.sequenceId === undefined) {
jobInfo.sequenceId = record.sequenceId;
}
jobInfo.message = record.message;
map.set(record.trialJobId, jobInfo);
}
this.log.debug('getTrialJobsByReplayEvents done');
return map;
}