Ejemplo n.º 1
0
def webui_nas(args):
    '''launch nas ui'''
    print_normal('Starting NAS UI...')
    try:
        entry_dir = get_nni_installation_path()
        entry_file = os.path.join(entry_dir, 'nasui', 'server.js')
        node_command = 'node'
        if sys.platform == 'win32':
            node_command = os.path.join(entry_dir[:-3], 'Scripts', 'node.exe')
        cmds = [
            node_command, '--max-old-space-size=4096', entry_file, '--port',
            str(args.port), '--logdir', args.logdir
        ]
        subprocess.run(cmds)
    except KeyboardInterrupt:
        pass
Ejemplo n.º 2
0
def start_rest_server(port,
                      platform,
                      mode,
                      config_file_name,
                      foreground=False,
                      experiment_id=None,
                      log_dir=None,
                      log_level=None):
    '''Run nni manager process'''
    if detect_port(port):
        print_error('Port %s is used by another process, please reset the port!\n' \
        'You could use \'nnictl create --help\' to get help information' % port)
        exit(1)

    if (platform != 'local') and detect_port(int(port) + 1):
        print_error('PAI mode need an additional adjacent port %d, and the port %d is used by another process!\n' \
        'You could set another port to start experiment!\n' \
        'You could use \'nnictl create --help\' to get help information' % ((int(port) + 1), (int(port) + 1)))
        exit(1)

    print_normal('Starting restful server...')

    entry_dir = get_nni_installation_path()
    if (not entry_dir) or (not os.path.exists(entry_dir)):
        print_error('Fail to find nni under python library')
        exit(1)
    entry_file = os.path.join(entry_dir, 'main.js')

    node_command = 'node'
    if sys.platform == 'win32':
        node_command = os.path.join(entry_dir[:-3], 'Scripts', 'node.exe')
    cmds = [
        node_command, '--max-old-space-size=4096', entry_file, '--port',
        str(port), '--mode', platform
    ]
    if mode == 'view':
        cmds += ['--start_mode', 'resume']
        cmds += ['--readonly', 'true']
    else:
        cmds += ['--start_mode', mode]
    if log_dir is not None:
        cmds += ['--log_dir', log_dir]
    if log_level is not None:
        cmds += ['--log_level', log_level]
    if mode in ['resume', 'view']:
        cmds += ['--experiment_id', experiment_id]
    if foreground:
        cmds += ['--foreground', 'true']
    stdout_full_path, stderr_full_path = get_log_path(config_file_name)
    with open(stdout_full_path,
              'a+') as stdout_file, open(stderr_full_path,
                                         'a+') as stderr_file:
        time_now = time.strftime('%Y-%m-%d %H:%M:%S',
                                 time.localtime(time.time()))
        #add time information in the header of log files
        log_header = LOG_HEADER % str(time_now)
        stdout_file.write(log_header)
        stderr_file.write(log_header)
        if sys.platform == 'win32':
            from subprocess import CREATE_NEW_PROCESS_GROUP
            if foreground:
                process = Popen(cmds,
                                cwd=entry_dir,
                                stdout=PIPE,
                                stderr=STDOUT,
                                creationflags=CREATE_NEW_PROCESS_GROUP)
            else:
                process = Popen(cmds,
                                cwd=entry_dir,
                                stdout=stdout_file,
                                stderr=stderr_file,
                                creationflags=CREATE_NEW_PROCESS_GROUP)
        else:
            if foreground:
                process = Popen(cmds, cwd=entry_dir, stdout=PIPE, stderr=PIPE)
            else:
                process = Popen(cmds,
                                cwd=entry_dir,
                                stdout=stdout_file,
                                stderr=stderr_file)
    return process, str(time_now)
Ejemplo n.º 3
0
def start_rest_server(
    port,
    platform,
    mode,
    config_file_name,
    foreground=False,
    experiment_id=None,
    log_dir=None,
    log_level=None,
):
    """Run nni manager process"""
    if detect_port(port):
        print_error(
            "Port %s is used by another process, please reset the port!\n"
            "You could use 'nnictl create --help' to get help information" % port
        )
        exit(1)

    if (platform != "local") and detect_port(int(port) + 1):
        print_error(
            "PAI mode need an additional adjacent port %d, and the port %d is used by another process!\n"
            "You could set another port to start experiment!\n"
            "You could use 'nnictl create --help' to get help information"
            % ((int(port) + 1), (int(port) + 1))
        )
        exit(1)

    print_normal("Starting restful server...")

    entry_dir = get_nni_installation_path()
    if (not entry_dir) or (not os.path.exists(entry_dir)):
        print_error("Fail to find nni under python library")
        exit(1)
    entry_file = os.path.join(entry_dir, "main.js")
    node_command = "node"
    if sys.platform == "win32":
        node_command = os.path.join(entry_dir[:-3], "Scripts", "node.exe")
    cmds = [
        node_command,
        "--max-old-space-size=4096",
        entry_file,
        "--port",
        str(port),
        "--mode",
        platform,
    ]
    if mode == "view":
        cmds += ["--start_mode", "resume"]
        cmds += ["--readonly", "true"]
    else:
        cmds += ["--start_mode", mode]
    if log_dir is not None:
        cmds += ["--log_dir", log_dir]
    if log_level is not None:
        cmds += ["--log_level", log_level]
    cmds += ["--experiment_id", experiment_id]
    if foreground:
        cmds += ["--foreground", "true"]
    stdout_full_path, stderr_full_path = get_log_path(config_file_name)
    with open(stdout_full_path, "a+") as stdout_file, open(
        stderr_full_path, "a+"
    ) as stderr_file:
        time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
        # add time information in the header of log files
        log_header = LOG_HEADER % str(time_now)
        stdout_file.write(log_header)
        stderr_file.write(log_header)
        if sys.platform == "win32":
            from subprocess import CREATE_NEW_PROCESS_GROUP

            if foreground:
                process = Popen(
                    cmds,
                    cwd=entry_dir,
                    stdout=PIPE,
                    stderr=STDOUT,
                    creationflags=CREATE_NEW_PROCESS_GROUP,
                )
            else:
                process = Popen(
                    cmds,
                    cwd=entry_dir,
                    stdout=stdout_file,
                    stderr=stderr_file,
                    creationflags=CREATE_NEW_PROCESS_GROUP,
                )
        else:
            if foreground:
                process = Popen(cmds, cwd=entry_dir, stdout=PIPE, stderr=PIPE)
            else:
                process = Popen(
                    cmds, cwd=entry_dir, stdout=stdout_file, stderr=stderr_file
                )
    return process, str(time_now)