nnictl.py 8.85 KB
Newer Older
Deshui Yu's avatar
Deshui Yu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


import argparse
from .launcher import create_experiment, resume_experiment
from .updater import update_searchspace, update_concurrency, update_duration
from .nnictl_utils import *
QuanluZhang's avatar
QuanluZhang committed
26
from .package_management import *
goooxu's avatar
goooxu committed
27
from .constants import *
Deshui Yu's avatar
Deshui Yu committed
28
29

def nni_help_info(*args):
30
    print('please run "nnictl {positional argument} --help" to see nnictl guidance')
Deshui Yu's avatar
Deshui Yu committed
31
32
33

def parse_args():
    '''Definite the arguments users need to follow and input'''
34
    parser = argparse.ArgumentParser(prog='nnictl', description='use nnictl command to control nni experiments')
Deshui Yu's avatar
Deshui Yu committed
35
36
37
38
39
40
41
42
    parser.set_defaults(func=nni_help_info)

    # create subparsers for args with sub values
    subparsers = parser.add_subparsers()

    # parse start command
    parser_start = subparsers.add_parser('create', help='create a new experiment')
    parser_start.add_argument('--config', '-c', required=True, dest='config', help='the path of yaml config file')
goooxu's avatar
goooxu committed
43
    parser_start.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
44
45
46
47
48
49
    parser_start.set_defaults(func=create_experiment)

    # parse resume command
    parser_resume = subparsers.add_parser('resume', help='resume a new experiment')
    parser_resume.add_argument('--experiment', '-e', dest='id', help='ID of the experiment you want to resume')
    parser_resume.add_argument('--manager', '-m', default='nnimanager', dest='manager')
goooxu's avatar
goooxu committed
50
    parser_resume.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
51
52
53
54
55
56
57
    parser_resume.set_defaults(func=resume_experiment)

    # parse update command
    parser_updater = subparsers.add_parser('update', help='update the experiment')
    #add subparsers for parser_updater
    parser_updater_subparsers = parser_updater.add_subparsers()
    parser_updater_searchspace = parser_updater_subparsers.add_parser('searchspace', help='update searchspace')
goooxu's avatar
goooxu committed
58
    parser_updater_searchspace.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
59
60
    parser_updater_searchspace.add_argument('--filename', '-f', required=True)
    parser_updater_searchspace.set_defaults(func=update_searchspace)
goooxu's avatar
goooxu committed
61
62
63
64
65
66
67
68
    parser_updater_concurrency = parser_updater_subparsers.add_parser('concurrency', help='update concurrency')
    parser_updater_concurrency.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
    parser_updater_concurrency.add_argument('--value', '-v', required=True)
    parser_updater_concurrency.set_defaults(func=update_concurrency)
    parser_updater_duration = parser_updater_subparsers.add_parser('duration', help='update duration')
    parser_updater_duration.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
    parser_updater_duration.add_argument('--value', '-v', required=True)
    parser_updater_duration.set_defaults(func=update_duration)
Deshui Yu's avatar
Deshui Yu committed
69
70
71

    #parse stop command
    parser_stop = subparsers.add_parser('stop', help='stop the experiment')
goooxu's avatar
goooxu committed
72
    parser_stop.add_argument('--port', '-p', required=True, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
73
74
75
76
77
78
79
    parser_stop.set_defaults(func=stop_experiment)

    #parse trial command
    parser_trial = subparsers.add_parser('trial', help='get trial information')
    #add subparsers for parser_trial
    parser_trial_subparsers = parser_trial.add_subparsers()
    parser_trial_ls = parser_trial_subparsers.add_parser('ls', help='list trial jobs')
goooxu's avatar
goooxu committed
80
    parser_trial_ls.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
81
82
    parser_trial_ls.set_defaults(func=trial_ls)
    parser_trial_kill = parser_trial_subparsers.add_parser('kill', help='kill trial jobs')
goooxu's avatar
goooxu committed
83
    parser_trial_kill.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
84
85
86
87
88
89
90
    parser_trial_kill.add_argument('--trialid', '-t', required=True, dest='trialid', help='the id of trial to be killed')
    parser_trial_kill.set_defaults(func=trial_kill)

    #parse experiment command
    parser_experiment = subparsers.add_parser('experiment', help='get experiment information')
    #add subparsers for parser_experiment
    parser_experiment_subparsers = parser_experiment.add_subparsers()
91
    parser_experiment_show = parser_experiment_subparsers.add_parser('show', help='show the information of experiment')
goooxu's avatar
goooxu committed
92
    parser_experiment_show.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
93
    parser_experiment_show.set_defaults(func=list_experiment)
94
    parser_experiment_status = parser_experiment_subparsers.add_parser('status', help='show the status of experiment')
goooxu's avatar
goooxu committed
95
    parser_experiment_status.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
96
    parser_experiment_status.set_defaults(func=experiment_status)
Deshui Yu's avatar
Deshui Yu committed
97
98
99
100

    #parse config command
    parser_config = subparsers.add_parser('config', help='get config information')
    parser_config_subparsers = parser_config.add_subparsers()
101
    parser_config_show = parser_config_subparsers.add_parser('show', help='show the information of config')
goooxu's avatar
goooxu committed
102
    parser_config_show.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
103
    parser_config_show.set_defaults(func=get_config)
Deshui Yu's avatar
Deshui Yu committed
104
105
106

    #parse log command
    parser_log = subparsers.add_parser('log', help='get log information')
QuanluZhang's avatar
QuanluZhang committed
107
    # add subparsers for parser_log
Deshui Yu's avatar
Deshui Yu committed
108
109
    parser_log_subparsers = parser_log.add_subparsers()
    parser_log_stdout = parser_log_subparsers.add_parser('stdout', help='get stdout information')
goooxu's avatar
goooxu committed
110
    parser_log_stdout.add_argument('--port', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
111
112
    parser_log_stdout.add_argument('--tail', '-T', dest='tail', type=int, help='get tail -100 content of stdout')
    parser_log_stdout.add_argument('--head', '-H', dest='head', type=int, help='get head -100 content of stdout')
goooxu's avatar
goooxu committed
113
    parser_log_stdout.add_argument('--path', action='store_true', default=False, help='get the path of stdout file')
Deshui Yu's avatar
Deshui Yu committed
114
115
    parser_log_stdout.set_defaults(func=log_stdout)
    parser_log_stderr = parser_log_subparsers.add_parser('stderr', help='get stderr information')
goooxu's avatar
goooxu committed
116
    parser_log_stderr.add_argument('--port', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
Deshui Yu's avatar
Deshui Yu committed
117
118
    parser_log_stderr.add_argument('--tail', '-T', dest='tail', type=int, help='get tail -100 content of stderr')
    parser_log_stderr.add_argument('--head', '-H', dest='head', type=int, help='get head -100 content of stderr')
goooxu's avatar
goooxu committed
119
    parser_log_stderr.add_argument('--path', action='store_true', default=False, help='get the path of stderr file')
Deshui Yu's avatar
Deshui Yu committed
120
    parser_log_stderr.set_defaults(func=log_stderr)
121
    parser_log_trial = parser_log_subparsers.add_parser('trial', help='get trial log path')
goooxu's avatar
goooxu committed
122
    parser_log_trial.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', help='the port of restful server')
123
124
125
    parser_log_trial.add_argument('--id', '-I', dest='id', help='find trial log path by id')
    parser_log_trial.set_defaults(func=log_trial)

Deshui Yu's avatar
Deshui Yu committed
126

QuanluZhang's avatar
QuanluZhang committed
127
128
129
130
131
132
133
134
135
136
137
    #parse package command
    parser_package = subparsers.add_parser('package', help='control nni tuner and assessor packages')
    # add subparsers for parser_package
    parser_package_subparsers = parser_package.add_subparsers()
    parser_package_install = parser_package_subparsers.add_parser('install', help='install packages')
    parser_package_install.add_argument('--name', '-n', dest='name', help='package name to be installed')
    parser_package_install.set_defaults(func=package_install)
    parser_package_show = parser_package_subparsers.add_parser('show', help='show the information of packages')
    parser_package_show.set_defaults(func=package_show)


Deshui Yu's avatar
Deshui Yu committed
138
139
140
141
142
    args = parser.parse_args()
    args.func(args)

if __name__ == '__main__':
    parse_args()