paths.ts 1.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
 *  Manage experiment paths.
 *
 *  Ideally all path constants should be put here so other modules (especially training services)
 *  do not need to know file hierarchy of nni-experiments folder, which is an implicit undocumented protocol.
 **/

import assert from 'assert/strict';
import fs from 'fs';
13
import os from 'os';
14
15
16
17
18
19
20
import path from 'path';

import type { NniManagerArgs } from './arguments';

export interface NniPaths {
    readonly experimentRoot: string;
    readonly experimentsDirectory: string;
21
    readonly experimentsList: string;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    readonly logDirectory: string;  // contains nni manager and dispatcher log; trial logs are not here
    readonly nniManagerLog: string;
}

export function createPaths(args: NniManagerArgs): NniPaths {
    assert(
        path.isAbsolute(args.experimentsDirectory),
        `Command line arg --experiments-directory "${args.experimentsDirectory}" is not absoulte`
    );
    const experimentRoot = path.join(args.experimentsDirectory, args.experimentId);

    const logDirectory = path.join(experimentRoot, 'log');

    // TODO: move all `mkdir`s here
    fs.mkdirSync(logDirectory, { recursive: true });

    const nniManagerLog = path.join(logDirectory, 'nnimanager.log');

40
41
42
    // TODO: this should follow experiments directory config
    const experimentsList = path.join(os.homedir(), 'nni-experiments', '.experiment');

43
44
45
    return {
        experimentRoot,
        experimentsDirectory: args.experimentsDirectory,
46
        experimentsList,
47
48
49
50
        logDirectory,
        nniManagerLog,
    };
}