Unverified Commit 632df3ea authored by Yuge Zhang's avatar Yuge Zhang Committed by GitHub
Browse files

Use sphinx-argparse to generate nnictl reference (#4561)

parent 95338ef0
......@@ -10,6 +10,6 @@ pytest-azurepipelines
pytest-cov
rstcheck
sphinx
sphinx-argparse
sphinx-argparse-nni >= 0.4.0
sphinx-gallery
git+https://github.com/bashtage/sphinx-material.git
.. role:: raw-html(raw)
:format: html
nnictl
======
Introduction
------------
**nnictl** is a command line tool, which can be used to control experiments, such as start/stop/resume an experiment, start/stop NNIBoard, etc.
Commands
--------
nnictl support commands:
* `nnictl create <#create>`__
* `nnictl resume <#resume>`__
* `nnictl view <#view>`__
* `nnictl stop <#stop>`__
* `nnictl update <#update>`__
* `nnictl trial <#trial>`__
* `nnictl top <#top>`__
* `nnictl experiment <#experiment>`__
* `nnictl platform <#platform>`__
* `nnictl config <#config>`__
* `nnictl log <#log>`__
* `nnictl webui <#webui>`__
* `nnictl algo <#algo>`__
* `nnictl ss_gen <#ss_gen>`__
* `nnictl --version <#version>`__
Manage an experiment
^^^^^^^^^^^^^^^^^^^^
:raw-html:`<a name="create"></a>`
nnictl create
^^^^^^^^^^^^^
*
Description
You can use this command to create a new experiment, using the configuration specified in config file.
After this command is successfully done, the context will be set as this experiment, which means the following command you issued is associated with this experiment, unless you explicitly changes the context(not supported yet).
*
Usage
.. code-block:: bash
nnictl create [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - --config, -c
- True
-
- YAML configure file of the experiment
* - --port, -p
- False
-
- the port of restful server
* - --debug, -d
- False
-
- set debug mode
* - --foreground, -f
- False
-
- set foreground mode, print log content to terminal
*
Examples
..
create a new experiment with the default port: 8080
.. code-block:: bash
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml
..
create a new experiment with specified port 8088
.. code-block:: bash
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml --port 8088
..
create a new experiment with specified port 8088 and debug mode
.. code-block:: bash
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml --port 8088 --debug
Note:
.. code-block:: text
Debug mode will disable version check function in Trialkeeper.
:raw-html:`<a name="resume"></a>`
nnictl resume
^^^^^^^^^^^^^
*
Description
You can use this command to resume a stopped experiment.
*
Usage
.. code-block:: bash
nnictl resume [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- True
-
- The id of the experiment you want to resume
* - --port, -p
- False
-
- Rest port of the experiment you want to resume
* - --debug, -d
- False
-
- set debug mode
* - --foreground, -f
- False
-
- set foreground mode, print log content to terminal
* - --experiment_dir, -e
- False
-
- Resume experiment from external folder, specify the full path of experiment folder
*
Example
..
resume an experiment with specified port 8088
.. code-block:: bash
nnictl resume [experiment_id] --port 8088
:raw-html:`<a name="view"></a>`
nnictl view
^^^^^^^^^^^
*
Description
You can use this command to view a stopped experiment.
*
Usage
.. code-block:: bash
nnictl view [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- True
-
- The id of the experiment you want to view
* - --port, -p
- False
-
- Rest port of the experiment you want to view
* - --experiment_dir, -e
- False
-
- View experiment from external folder, specify the full path of experiment folder
*
Example
..
view an experiment with specified port 8088
.. code-block:: bash
nnictl view [experiment_id] --port 8088
:raw-html:`<a name="stop"></a>`
nnictl stop
^^^^^^^^^^^
*
Description
You can use this command to stop a running experiment or multiple experiments.
*
Usage
.. code-block:: bash
nnictl stop [Options]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- The id of the experiment you want to stop
* - --port, -p
- False
-
- Rest port of the experiment you want to stop
* - --all, -a
- False
-
- Stop all of experiments
*
Details & Examples
#.
If there is no id specified, and there is an experiment running, stop the running experiment, or print error message.
.. code-block:: bash
nnictl stop
#.
If there is an id specified, and the id matches the running experiment, nnictl will stop the corresponding experiment, or will print error message.
.. code-block:: bash
nnictl stop [experiment_id]
#.
If there is a port specified, and an experiment is running on that port, the experiment will be stopped.
.. code-block:: bash
nnictl stop --port 8080
#.
Users could use 'nnictl stop --all' to stop all experiments.
.. code-block:: bash
nnictl stop --all
#.
If the id ends with \*, nnictl will stop all experiments whose ids matchs the regular.
#. If the id does not exist but match the prefix of an experiment id, nnictl will stop the matched experiment.
#. If the id does not exist but match multiple prefix of the experiment ids, nnictl will give id information.
:raw-html:`<a name="update"></a>`
nnictl update
^^^^^^^^^^^^^
*
**nnictl update searchspace**
*
Description
You can use this command to update an experiment's search space.
*
Usage
.. code-block:: bash
nnictl update searchspace [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --filename, -f
- True
-
- the file storing your new search space
*
Example
``update experiment's new search space with file dir 'examples/trials/mnist-pytorch/search_space.json'``
.. code-block:: bash
nnictl update searchspace [experiment_id] --filename examples/trials/mnist-pytorch/search_space.json
*
**nnictl update concurrency**
*
Description
You can use this command to update an experiment's concurrency.
*
Usage
.. code-block:: bash
nnictl update concurrency [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --value, -v
- True
-
- the number of allowed concurrent trials
*
Example
..
update experiment's concurrency
.. code-block:: bash
nnictl update concurrency [experiment_id] --value [concurrency_number]
*
**nnictl update duration**
*
Description
You can use this command to update an experiment's duration.
*
Usage
.. code-block:: bash
nnictl update duration [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --value, -v
- True
-
- Strings like '1m' for one minute or '2h' for two hours. SUFFIX may be 's' for seconds, 'm' for minutes, 'h' for hours or 'd' for days.
*
Example
..
update experiment's duration
.. code-block:: bash
nnictl update duration [experiment_id] --value [duration]
*
**nnictl update trialnum**
*
Description
You can use this command to update an experiment's maxtrialnum.
*
Usage
.. code-block:: bash
nnictl update trialnum [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --value, -v
- True
-
- the new number of maxtrialnum you want to set
*
Example
..
update experiment's trial num
.. code-block:: bash
nnictl update trialnum [experiment_id] --value [trial_num]
:raw-html:`<a name="trial"></a>`
nnictl trial
^^^^^^^^^^^^
*
**nnictl trial ls**
*
Description
You can use this command to show trial's information. Note that if ``head`` or ``tail`` is set, only complete trials will be listed.
*
Usage
.. code-block:: bash
nnictl trial ls
nnictl trial ls --head 10
nnictl trial ls --tail 10
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --head
- False
-
- the number of items to be listed with the highest default metric
* - --tail
- False
-
- the number of items to be listed with the lowest default metric
*
**nnictl trial kill**
*
Description
You can use this command to kill a trial job.
*
Usage
.. code-block:: bash
nnictl trial kill [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- Experiment ID of the trial
* - --trial_id, -T
- True
-
- ID of the trial you want to kill.
*
Example
..
kill trail job
.. code-block:: bash
nnictl trial kill [experiment_id] --trial_id [trial_id]
:raw-html:`<a name="top"></a>`
nnictl top
^^^^^^^^^^
*
Description
Monitor all of running experiments.
*
Usage
.. code-block:: bash
nnictl top
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --time, -t
- False
-
- The interval to update the experiment status, the unit of time is second, and the default value is 3 second.
:raw-html:`<a name="experiment"></a>`
Manage experiment information
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*
**nnictl experiment show**
*
Description
Show the information of experiment.
*
Usage
.. code-block:: bash
nnictl experiment show
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
*
**nnictl experiment status**
*
Description
Show the status of experiment.
*
Usage
.. code-block:: bash
nnictl experiment status
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
*
**nnictl experiment list**
*
Description
Show the information of all the (running) experiments.
*
Usage
.. code-block:: bash
nnictl experiment list [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - --all
- False
-
- list all of experiments
*
**nnictl experiment delete**
*
Description
Delete one or all experiments, it includes log, result, environment information and cache. It uses to delete useless experiment result, or save disk space.
*
Usage
.. code-block:: bash
nnictl experiment delete [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment
* - --all
- False
-
- delete all of experiments
*
**nnictl experiment export**
*
Description
You can use this command to export reward & hyper-parameter of trial jobs to a csv file.
*
Usage
.. code-block:: bash
nnictl experiment export [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment
* - --filename, -f
- True
-
- File path of the output file
* - --type
- True
-
- Type of output file, only support "csv" and "json"
* - --intermediate, -i
- False
-
- Are intermediate results included
*
Examples
..
export all trial data in an experiment as json format
.. code-block:: bash
nnictl experiment export [experiment_id] --filename [file_path] --type json --intermediate
*
**nnictl experiment import**
*
Description
You can use this command to import several prior or supplementary trial hyperparameters & results for NNI hyperparameter tuning. The data are fed to the tuning algorithm (e.g., tuner or advisor).
*
Usage
.. code-block:: bash
nnictl experiment import [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- The id of the experiment you want to import data into
* - --filename, -f
- True
-
- a file with data you want to import in json format
*
Details
NNI supports users to import their own data, please express the data in the correct format. An example is shown below:
.. code-block:: json
[
{"parameter": {"x": 0.5, "y": 0.9}, "value": 0.03},
{"parameter": {"x": 0.4, "y": 0.8}, "value": 0.05},
{"parameter": {"x": 0.3, "y": 0.7}, "value": 0.04}
]
Every element in the top level list is a sample. For our built-in tuners/advisors, each sample should have at least two keys: ``parameter`` and ``value``. The ``parameter`` must match this experiment's search space, that is, all the keys (or hyperparameters) in ``parameter`` must match the keys in the search space. Otherwise, tuner/advisor may have unpredictable behavior. ``Value`` should follow the same rule of the input in ``nni.report_final_result``\ , that is, either a number or a dict with a key named ``default``. For your customized tuner/advisor, the file could have any json content depending on how you implement the corresponding methods (e.g., ``import_data``\ ).
You also can use `nnictl experiment export <#export>`__ to export a valid json file including previous experiment trial hyperparameters and results.
Currently, following tuner and advisor support import data:
.. code-block:: yaml
builtinTunerName: TPE, Anneal, GridSearch, MetisTuner
builtinAdvisorName: BOHB
*If you want to import data to BOHB advisor, user are suggested to add "TRIAL_BUDGET" in parameter as NNI do, otherwise, BOHB will use max_budget as "TRIAL_BUDGET". Here is an example:*
.. code-block:: json
[
{"parameter": {"x": 0.5, "y": 0.9, "TRIAL_BUDGET": 27}, "value": 0.03}
]
*
Examples
..
import data to a running experiment
.. code-block:: bash
nnictl experiment import [experiment_id] -f experiment_data.json
*
**nnictl experiment save**
*
Description
Save nni experiment metadata and code data.
*
Usage
.. code-block:: bash
nnictl experiment save [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- True
-
- The id of the experiment you want to save
* - --path, -p
- False
-
- the folder path to store nni experiment data, default current working directory
* - --saveCodeDir, -s
- False
-
- save codeDir data of the experiment, default False
*
Examples
..
save an expeirment
.. code-block:: bash
nnictl experiment save [experiment_id] --saveCodeDir
*
**nnictl experiment load**
*
Description
Load an nni experiment.
*
Usage
.. code-block:: bash
nnictl experiment load [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - --path, -p
- True
-
- the file path of nni package
* - --codeDir, -c
- True
-
- the path of codeDir for loaded experiment, this path will also put the code in the loaded experiment package
* - --logDir, -l
- False
-
- the path of logDir for loaded experiment
* - --searchSpacePath, -s
- True
-
- the path of search space file for loaded experiment, this path contains file name. Default in $codeDir/search_space.json
*
Examples
..
load an expeirment
.. code-block:: bash
nnictl experiment load --path [path] --codeDir [codeDir]
:raw-html:`<a name="platform"></a>`
Manage platform information
^^^^^^^^^^^^^^^^^^^^^^^^^^^
*
**nnictl platform clean**
*
Description
It uses to clean up disk on a target platform. The provided YAML file includes the information of target platform, and it follows the same schema as the NNI configuration file.
*
Note
if the target platform is being used by other users, it may cause unexpected errors to others.
*
Usage
.. code-block:: bash
nnictl platform clean [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - --config
- True
-
- the path of yaml config file used when create an experiment
:raw-html:`<a name="config"></a>`
nnictl config show
^^^^^^^^^^^^^^^^^^
*
Description
Display the current context information.
*
Usage
.. code-block:: bash
nnictl config show
:raw-html:`<a name="log"></a>`
Manage log
^^^^^^^^^^
*
**nnictl log stdout**
*
Description
Show the stdout log content.
*
Usage
.. code-block:: bash
nnictl log stdout [options]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --head, -h
- False
-
- show head lines of stdout
* - --tail, -t
- False
-
- show tail lines of stdout
* - --path, -p
- False
-
- show the path of stdout file
*
Example
..
Show the tail of stdout log content
.. code-block:: bash
nnictl log stdout [experiment_id] --tail [lines_number]
*
**nnictl log stderr**
*
Description
Show the stderr log content.
*
Usage
.. code-block:: bash
nnictl log stderr [options]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- ID of the experiment you want to set
* - --head, -h
- False
-
- show head lines of stderr
* - --tail, -t
- False
-
- show tail lines of stderr
* - --path, -p
- False
-
- show the path of stderr file
*
**nnictl log trial**
*
Description
Show trial log path.
*
Usage
.. code-block:: bash
nnictl log trial [options]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- Experiment ID of the trial
* - --trial_id, -T
- False
-
- ID of the trial to be found the log path, required when id is not empty.
:raw-html:`<a name="webui"></a>`
Manage webui
^^^^^^^^^^^^
*
**nnictl webui url**
*
Description
Show an experiment's webui url
*
Usage
.. code-block:: bash
nnictl webui url [options]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - id
- False
-
- Experiment ID
:raw-html:`<a name="algo"></a>`
Manage builtin algorithms
^^^^^^^^^^^^^^^^^^^^^^^^^
*
**nnictl algo register**
*
Description
Register customized algorithms as builtin tuner/assessor/advisor.
*
Usage
.. code-block:: bash
nnictl algo register --meta <path_to_meta_file>
``<path_to_meta_file>`` is the path to the meta data file in yml format, which has following keys:
*
``algoType``: type of algorithms, could be one of ``tuner``, ``assessor``, ``advisor``
*
``builtinName``: builtin name used in experiment configuration file
*
``className``: tuner class name, including its module name, for example: ``demo_tuner.DemoTuner``
*
``classArgsValidator``: class args validator class name, including its module name, for example: ``demo_tuner.MyClassArgsValidator``
*
Example
..
Install a customized tuner in nni examples
.. code-block:: bash
cd nni/examples/tuners/customized_tuner
python3 setup.py develop
nnictl algo register --meta meta_file.yml
*
**nnictl algo show**
*
Description
Show the detailed information of specified registered algorithms.
*
Usage
.. code-block:: bash
nnictl algo show <builtinName>
*
Example
.. code-block:: bash
nnictl algo show SMAC
*
**nnictl package list**
*
Description
List the registered builtin algorithms.
*
Usage
.. code-block:: bash
nnictl algo list
*
Example
.. code-block:: bash
nnictl algo list
*
**nnictl algo unregister**
*
Description
Unregister a registered customized builtin algorithms. The NNI provided builtin algorithms can not be unregistered.
*
Usage
.. code-block:: bash
nnictl algo unregister <builtinName>
*
Example
.. code-block:: bash
nnictl algo unregister demotuner
:raw-html:`<a name="ss_gen"></a>`
Generate search space
^^^^^^^^^^^^^^^^^^^^^
*
**nnictl ss_gen**
*
Description
Generate search space from user trial code which uses NNI NAS APIs.
*
Usage
.. code-block:: bash
nnictl ss_gen [OPTIONS]
*
Options
.. list-table::
:header-rows: 1
:widths: auto
* - Name, shorthand
- Required
- Default
- Description
* - --trial_command
- True
-
- The command of the trial code
* - --trial_dir
- False
- ./
- The directory of the trial code
* - --file
- False
- nni_auto_gen_search_space.json
- The file for storing generated search space
*
Example
..
Generate a search space
.. code-block:: bash
nnictl ss_gen --trial_command="python3 mnist.py" --trial_dir=./ --file=ss.json
:raw-html:`<a name="version"></a>`
Check NNI version
^^^^^^^^^^^^^^^^^
*
**nnictl --version**
*
Description
Describe the current version of NNI installed.
*
Usage
.. code-block:: bash
nnictl --version
......@@ -196,7 +196,7 @@ Change ``python3`` to ``python`` of the ``trialCommand`` field in the **config_d
nnictl create --config nni\examples\trials\mnist-pytorch\config_detailed.yml
.. Note:: ``nnictl`` is a command line tool that can be used to control experiments, such as start/stop/resume an experiment, start/stop NNIBoard, etc. Click :doc:`here <Nnictl>` for more usage of ``nnictl``.
.. Note:: ``nnictl`` is a command line tool that can be used to control experiments, such as start/stop/resume an experiment, start/stop NNIBoard, etc. Click :doc:`here <../reference/nnictl>` for more usage of ``nnictl``.
Wait for the message ``INFO: Successfully started experiment!`` in the command line. This message indicates that your experiment has been successfully started. And this is what we expect to get:
......
.. de9c05c0da9751f920113d0b169494a2
.. 90b7c298df11d68ba419a1feaf453cfc
快速入门
==========
......@@ -198,7 +198,7 @@ Windows
nnictl create --config nni\examples\trials\mnist-pytorch\config_detailed.yml
.. Note:: ``nnictl`` 是一个命令行工具,用来控制 NNI experiment,如启动、停止、继续 experiment,启动、停止 NNIBoard 等等。 点击 :doc:`这里 <Nnictl>` 查看 ``nnictl`` 的更多用法。
.. Note:: ``nnictl`` 是一个命令行工具,用来控制 NNI experiment,如启动、停止、继续 experiment,启动、停止 NNIBoard 等等。 点击 :doc:`这里 <../reference/nnictl>` 查看 ``nnictl`` 的更多用法。
在命令行中等待输出 ``INFO: Successfully started experiment!`` 。 此消息表明实验已成功启动。 期望的输出如下:
......
......@@ -45,7 +45,7 @@ extensions = [
'sphinx_gallery.gen_gallery',
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinxarg.ext',
'sphinxarg4nni.ext',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
......
......@@ -4,7 +4,7 @@ References
.. toctree::
:maxdepth: 2
nnictl Commands <Tutorial/Nnictl>
nnictl Commands <reference/nnictl>
Experiment Configuration <reference/experiment_config>
Experiment Configuration (legacy) <Tutorial/ExperimentConfig>
Search Space <Tutorial/SearchSpaceSpec>
......
nnictl
======
.. argparse::
:module: nni.tools.nnictl.nnictl
:func: get_parser
:prog: nnictl
.. 5f17887878bae5d51cf177a1c995c003
.. 19ce4f2ee1d3c4f1be277ab09ba40092
参考
==================
......@@ -6,7 +6,7 @@
.. toctree::
:maxdepth: 2
nnictl 命令 <Tutorial/Nnictl>
nnictl 命令 <reference/nnictl>
Experiment 配置 <reference/experiment_config>
Experiment 配置(遗产) <Tutorial/ExperimentConfig>
搜索空间<Tutorial/SearchSpaceSpec>
......
......@@ -15,7 +15,6 @@ from typing import Optional, Tuple, List, Any
import colorama
import nni_node # pylint: disable=wrong-import-order, import-error
import nni.runtime.protocol
from .config import ExperimentConfig
......@@ -128,6 +127,7 @@ def start_experiment(action, exp_id, config, port, debug, run_mode, url_prefix):
return proc
def _start_rest_server(nni_manager_args, run_mode) -> Tuple[int, Popen]:
import nni_node
node_dir = Path(nni_node.__path__[0])
node = str(node_dir / ('node.exe' if sys.platform == 'win32' else 'node'))
main_js = str(node_dir / 'main.js')
......@@ -224,6 +224,7 @@ def _start_rest_server_retiarii(config: ExperimentConfig, port: int, debug: bool
args['start_mode'] = 'resume'
args['readonly'] = 'true'
import nni_node
node_dir = Path(nni_node.__path__[0])
node = str(node_dir / ('node.exe' if sys.platform == 'win32' else 'node'))
main_js = str(node_dir / 'main.js')
......
......@@ -5,8 +5,6 @@ import os
from jupyter_core.paths import jupyter_config_dir, jupyter_data_dir
import nni_node
def _get_jupyter_lab_version():
try:
import jupyterlab
......@@ -33,10 +31,17 @@ _v2_backend_config_content = {
}
}
_frontend_src = Path(nni_node.__path__[0], 'jupyter-extension')
_frontend_dst = Path(jupyter_data_dir(), 'labextensions', 'nni-jupyter-extension')
_import_nni_node_failed = False
try:
import nni_node
_frontend_src = Path(nni_node.__path__[0], 'jupyter-extension')
_frontend_dst = Path(jupyter_data_dir(), 'labextensions', 'nni-jupyter-extension')
except ImportError:
_import_nni_node_failed = True
def install():
if _import_nni_node_failed:
raise ImportError('Import `nni_node` failed. nni is not properly installed.')
_backend_config_file.parent.mkdir(parents=True, exist_ok=True)
_backend_config_file.write_text(json.dumps(_backend_config_content))
......@@ -55,6 +60,8 @@ def install():
shutil.copytree(_frontend_src, _frontend_dst)
def uninstall():
if _import_nni_node_failed:
raise ImportError('Import `nni_node` failed. nni is not properly installed.')
_backend_config_file.unlink()
if jupyter_lab_major_version == '2':
_v2_backend_config_file.unlink()
......
......@@ -14,7 +14,6 @@ from subprocess import Popen, check_call, CalledProcessError, PIPE, STDOUT
from nni.experiment.config import ExperimentConfig, convert
from nni.tools.annotation import expand_annotations, generate_search_space
from nni.tools.package_utils.tuner_factory import get_builtin_module_class_name
import nni_node # pylint: disable=import-error, wrong-import-order
from .launcher_utils import validate_all_content
from .rest_utils import rest_put, rest_post, check_rest_server, check_response
from .url_utils import cluster_metadata_url, experiment_url, get_local_urls, set_prefix_url
......@@ -58,6 +57,7 @@ def start_rest_server(port, platform, mode, experiment_id, foreground=False, log
print_normal('Starting restful server...')
import nni_node
entry_dir = nni_node.__path__[0]
if (not entry_dir) or (not os.path.exists(entry_dir)):
print_error('Fail to find nni under python library')
......
......@@ -10,20 +10,178 @@ from .common_utils import print_error
from .launcher import create_experiment, resume_experiment, view_experiment
from .updater import update_searchspace, update_concurrency, update_duration, update_trialnum, import_data
from .nnictl_utils import stop_experiment, trial_ls, trial_kill, list_experiment, experiment_status,\
log_trial, experiment_clean, platform_clean, experiment_list, \
monitor_experiment, export_trials_data, trial_codegen, webui_url, \
get_config, log_stdout, log_stderr, search_space_auto_gen, \
save_experiment, load_experiment
log_trial, experiment_clean, platform_clean, experiment_list, \
monitor_experiment, export_trials_data, trial_codegen, webui_url, \
get_config, log_stdout, log_stderr, search_space_auto_gen, \
save_experiment, load_experiment
from .algo_management import algo_reg, algo_unreg, algo_show, algo_list
from .constants import DEFAULT_REST_PORT
from .import ts_management
init(autoreset=True)
_NNICTL_CREATE_HELP = '''
You can use this command to create a new experiment, using the configuration specified in config file.
After this command is successfully done, the context will be set as this experiment,
which means the following command you issued is associated with this experiment,
unless you explicitly change the context (not supported yet).
Examples:
* Create a new experiment with the default port 8080: ::
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml
* Create a new experiment with specified port 8088: ::
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml --port 8088
* Create a new experiment with specified port 8088 and debug mode: ::
nnictl create --config nni/examples/trials/mnist-pytorch/config.yml --port 8088 --debug
.. note:: Debug mode will disable version check function in ``trial_keeper``.
'''
_NNICTL_RESUME_HELP = '''
You can use this command to resume a stopped experiment.
Example: resume an experiment with specified port 8088. ::
nnictl resume [experiment_id] --port 8088
'''
_NNICTL_UPDATE_SEARCH_SPACE_HELP = '''
You can use this command to update an experiment's search space.
Example: update experiment's new search space with file dir `examples/trials/mnist-pytorch/search_space.json`. ::
nnictl update searchspace [experiment_id] --filename examples/trials/mnist-pytorch/search_space.json
'''
_NNICTL_STOP_HELP = '''
You can use this command to stop a running experiment or multiple experiments.
Details & Examples:
* If there is no id specified, and there is an experiment running, stop the running experiment, or print error message. ::
nnictl stop
* If there is an id specified, and the id matches the running experiment, nnictl will stop the corresponding experiment,
or will print error message. ::
nnictl stop [experiment_id]
* If there is a port specified, and an experiment is running on that port, the experiment will be stopped. ::
nnictl stop --port 8080
* Users could use ``nnictl stop --all`` to stop all experiments.
* If the id ends with ``*``, nnictl will stop all experiments whose ids matchs the regular.
* If the id does not exist but match the prefix of an experiment id, nnictl will stop the matched experiment.
* If the id does not exist but match multiple prefix of the experiment ids, nnictl will give id information.
'''
_NNICTL_TRIAL_LS_HELP = '''
You can use this command to show trials in an experiment.
.. note:: If ``head`` or ``tail`` is set, only complete trials will be listed.
'''
_NNICTL_EXPERIMENT_IMPORT_HELP = '''
You can use this command to import several prior or supplementary trial hyperparameters & results for NNI hyperparameter tuning.
The data are fed to the tuning algorithm (e.g., tuner or advisor).
NNI supports users to import their own data, please express the data in the correct format. An example is shown below:
.. code-block:: json
[
{"parameter": {"x": 0.5, "y": 0.9}, "value": 0.03},
{"parameter": {"x": 0.4, "y": 0.8}, "value": 0.05},
{"parameter": {"x": 0.3, "y": 0.7}, "value": 0.04}
]
Every element in the top level list is a sample.
For our built-in tuners/advisors, each sample should have at least two keys: ``parameter`` and ``value``.
The ``parameter`` must match this experiment's search space, that is,
all the keys (or hyperparameters) in ``parameter`` must match the keys in the search space.
Otherwise, tuner/advisor may have unpredictable behavior.
``value`` should follow the same rule of the input in ``nni.report_final_result``,
that is, either a number or a dict with a key named ``default``.
For your customized tuner/advisor, the file could have any json content depending on
how you implement the corresponding methods (e.g., ``import_data``).
You also can use `nnictl experiment export <#nnictl-experiment-export>`__ to export a valid json file
including previous experiment trial hyperparameters and results.
Currently, the following tuners/advisors support import data:
* TPE
* Anneal
* GridSearch
* MetisTuner
* BOHB
.. note::
If you want to import data to BOHB advisor, user are suggested to add ``TRIAL_BUDGET`` in parameter as NNI do,
otherwise, BOHB will use max_budget as ``TRIAL_BUDGET``. Here is an example:
.. code-block:: json
[
{"parameter": {"x": 0.5, "y": 0.9, "TRIAL_BUDGET": 27}, "value": 0.03}
]
'''
_NNICTL_EXPERIMENT_EXPORT_HELP = '''
Export results for trial jobs in an experiment as json format.
Example: ::
nnictl experiment export [experiment_id] --filename [file_path] --type json --intermediate
.. note::
Import/export are used to deal with trial jobs in a structured format.
If you are looking for ways to dump the whole experiment and continue running it on another machine, save/load might intrigue you.
'''
_NNICTL_PLATFORM_CLEAN_HELP = '''
Clean up disk on a target platform. The provided YAML file includes the information of target platform,
and it follows the same schema as the NNI configuration file.
.. note:: If the target platform is being used by other users, it may cause unexpected errors to others.
'''
_NNICTL_ALGO_REGISTER_HELP = '''
Register algorithms so that it can be used like a built-in algorithm.
``META_PATH`` is the path to the meta data file in yml format, which has following keys:
* ``algoType``: type of algorithms, could be one of ``tuner``, ``assessor``, ``advisor``.
* ``builtinName``: builtin name used in experiment configuration file.
* ``className``: tuner class name, including its module name, for example: ``demo_tuner.DemoTuner``.
* ``classArgsValidator``: class args validator class name, including its module name, for example: ``demo_tuner.MyClassArgsValidator``.
Example: install a customized tuner in nni examples.
.. code-block:: bash
cd nni/examples/tuners/customized_tuner
python3 setup.py develop
nnictl algo register -m meta_file.yml
'''
if os.environ.get('COVERAGE_PROCESS_START'):
import coverage
coverage.process_startup()
def nni_info(*args):
if args[0].version:
try:
......@@ -31,269 +189,320 @@ def nni_info(*args):
except pkg_resources.ResolutionError:
print_error('Get version failed, please use `pip3 list | grep nni` to check nni version!')
else:
print('please run "nnictl {positional argument} --help" to see nnictl guidance')
print('Please run "nnictl {positional argument} --help" to see nnictl guidance.')
def parse_args():
def get_parser():
logging.getLogger().setLevel(logging.ERROR)
'''Definite the arguments users need to follow and input'''
parser = argparse.ArgumentParser(prog='nnictl', description='use nnictl command to control nni experiments')
parser.add_argument('--version', '-v', action='store_true')
parser = argparse.ArgumentParser(
prog='nnictl',
description='**nnictl** is a command line tool, used to control experiments, '
'such as start/stop/resume an experiment, start/stop WebUI, etc.')
parser.add_argument('--version', '-v', action='store_true', help='Describe the current version of NNI installed')
parser.set_defaults(func=nni_info)
# create subparsers for args with sub values
subparsers = parser.add_subparsers()
# parse the command of auto generating search space
parser_start = subparsers.add_parser('ss_gen', help='automatically generate search space file from trial code')
parser_start.add_argument('--trial_command', '-t', required=True, dest='trial_command', help='the command for running trial code')
parser_start.add_argument('--trial_dir', '-d', default='./', dest='trial_dir', help='the directory for running the command')
parser_start.add_argument('--file', '-f', default='nni_auto_gen_search_space.json', dest='file', help='the path of search space file')
parser_start.set_defaults(func=search_space_auto_gen)
# 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')
parser_start.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='the port of restful server')
parser_start.add_argument('--debug', '-d', action='store_true', help=' set debug mode')
parser_start.add_argument('--url_prefix', '-u', dest='url_prefix', help=' set prefix url')
parser_start.add_argument('--foreground', '-f', action='store_true', help=' set foreground mode, print log content to terminal')
parser_start = subparsers.add_parser('create', description='Create a new experiment.', help=_NNICTL_CREATE_HELP)
parser_start.add_argument('--config', '-c', required=True, dest='config', help='Path to YAML configuration file of the experiment')
parser_start.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='The port of restful server')
parser_start.add_argument('--debug', '-d', action='store_true', help='Set debug mode')
parser_start.add_argument('--url_prefix', '-u', dest='url_prefix', help='Set prefix url')
parser_start.add_argument('--foreground', '-f', action='store_true', help='Set foreground mode, print log content to terminal')
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('id', help='The id of the experiment you want to resume')
parser_resume.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='the port of restful server')
parser_resume.add_argument('--debug', '-d', action='store_true', help=' set debug mode')
parser_resume.add_argument('--foreground', '-f', action='store_true', help=' set foreground mode, print log content to terminal')
parser_resume.add_argument('--experiment_dir', '-e', help='resume experiment from external folder, specify the full path of ' \
'experiment folder')
parser_resume = subparsers.add_parser('resume', description='Resume an experiment.', help=_NNICTL_RESUME_HELP)
parser_resume.add_argument('id', help='The ID of the experiment you want to resume')
parser_resume.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='The port of restful server')
parser_resume.add_argument('--debug', '-d', action='store_true', help='Set debug mode')
parser_resume.add_argument('--foreground', '-f', action='store_true', help='Set foreground mode, print log content to terminal')
parser_resume.add_argument('--experiment_dir', '-e',
help='Resume experiment from external folder, specify the full path of experiment folder')
parser_resume.set_defaults(func=resume_experiment)
# parse view command
parser_view = subparsers.add_parser('view', help='view a stopped experiment')
parser_view.add_argument('id', help='The id of the experiment you want to view')
parser_view.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='the port of restful server')
parser_view.add_argument('--experiment_dir', '-e', help='view experiment from external folder, specify the full path of ' \
'experiment folder')
parser_view = subparsers.add_parser('view', description='View a stopped experiment.')
parser_view.add_argument('id', help='The ID of the experiment you want to view')
parser_view.add_argument('--port', '-p', default=DEFAULT_REST_PORT, dest='port', type=int, help='The port of restful server')
parser_view.add_argument('--experiment_dir', '-e',
help='View experiment from external folder, specify the full path of experiment folder')
parser_view.set_defaults(func=view_experiment)
# parse update command
parser_updater = subparsers.add_parser('update', help='update the experiment')
#add subparsers for parser_updater
parser_updater = subparsers.add_parser('update', description='Update the configuration of an 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')
parser_updater_searchspace.add_argument('id', nargs='?', help='the id of experiment')
parser_updater_searchspace.add_argument('--filename', '-f', required=True)
parser_updater_searchspace = parser_updater_subparsers.add_parser(
'searchspace', description='Update the search space of an experiment.', help=_NNICTL_UPDATE_SEARCH_SPACE_HELP
)
parser_updater_searchspace.add_argument('id', nargs='?', help='ID of the experiment you want to set')
parser_updater_searchspace.add_argument('--filename', '-f', required=True, help='Path to new search space file')
parser_updater_searchspace.set_defaults(func=update_searchspace)
parser_updater_concurrency = parser_updater_subparsers.add_parser('concurrency', help='update concurrency')
parser_updater_concurrency.add_argument('id', nargs='?', help='the id of experiment')
parser_updater_concurrency.add_argument('--value', '-v', required=True)
parser_updater_concurrency = parser_updater_subparsers.add_parser(
'concurrency', description='Update the concurrency of an experiment.'
)
parser_updater_concurrency.add_argument('id', nargs='?', help='ID of the experiment you want to set')
parser_updater_concurrency.add_argument('--value', '-v', required=True, help='The number of allowed concurrent trials')
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('id', nargs='?', help='the id of experiment')
parser_updater_duration.add_argument('--value', '-v', required=True, help='the unit of time should in {\'s\', \'m\', \'h\', \'d\'}')
parser_updater_duration = parser_updater_subparsers.add_parser(
'duration', description="Update an experiment's maximum allowed duration."
)
parser_updater_duration.add_argument('id', nargs='?', help='ID of the experiment you want to set')
parser_updater_duration.add_argument(
'--value', '-v', required=True,
help="Strings like '1m' for one minute or '2h' for two hours. SUFFIX may be 's' for seconds, "
"'m' for minutes, 'h' for hours or 'd' for days."
)
parser_updater_duration.set_defaults(func=update_duration)
parser_updater_trialnum = parser_updater_subparsers.add_parser('trialnum', help='update maxtrialnum')
parser_updater_trialnum.add_argument('id', nargs='?', help='the id of experiment')
parser_updater_trialnum.add_argument('--value', '-v', required=True)
parser_updater_trialnum = parser_updater_subparsers.add_parser(
'trialnum', description="Update an experiment's maximum trial number."
)
parser_updater_trialnum.add_argument('id', nargs='?', help='ID of the experiment you want to set')
parser_updater_trialnum.add_argument('--value', '-v', required=True, help='The new number of maxtrialnum you want to set')
parser_updater_trialnum.set_defaults(func=update_trialnum)
#parse stop command
parser_stop = subparsers.add_parser('stop', help='stop the experiment')
parser_stop.add_argument('id', nargs='?', help='the id of experiment, use \'all\' to stop all running experiments')
parser_stop.add_argument('--port', '-p', dest='port', type=int, help='the port of restful server')
parser_stop.add_argument('--all', '-a', action='store_true', help='stop all of experiments')
# parse stop command
parser_stop = subparsers.add_parser('stop', help=_NNICTL_STOP_HELP)
parser_stop.add_argument('id', nargs='?', help='Experiment ID you want to stop')
parser_stop.add_argument('--port', '-p', dest='port', type=int, help='The port of restful server you want to stop')
parser_stop.add_argument('--all', '-a', action='store_true', help='Stop all the experiments')
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
# parse trial command
parser_trial = subparsers.add_parser('trial', description='Get information of trials.')
# 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')
parser_trial_ls.add_argument('id', nargs='?', help='the id of experiment')
parser_trial_ls.add_argument('--head', type=int, help='list the highest experiments on the default metric')
parser_trial_ls.add_argument('--tail', type=int, help='list the lowest experiments on the default metric')
parser_trial_ls = parser_trial_subparsers.add_parser('ls', description='List trial jobs in one experiment.', help=_NNICTL_TRIAL_LS_HELP)
parser_trial_ls.add_argument('id', nargs='?', help='Experiment ID')
parser_trial_ls.add_argument('--head', type=int, help='The number of items to be listed with the highest default metric')
parser_trial_ls.add_argument('--tail', type=int, help='The number of items to be listed with the lowest default metric')
parser_trial_ls.set_defaults(func=trial_ls)
parser_trial_kill = parser_trial_subparsers.add_parser('kill', help='kill trial jobs')
parser_trial_kill.add_argument('id', nargs='?', help='the id of experiment')
parser_trial_kill.add_argument('--trial_id', '-T', required=True, dest='trial_id', help='the id of trial to be killed')
parser_trial_kill = parser_trial_subparsers.add_parser('kill', description='Kill a trial job.')
parser_trial_kill.add_argument('id', nargs='?', help='Experiment ID')
parser_trial_kill.add_argument('--trial_id', '-T', required=True, dest='trial_id', help='The ID of trial to be killed')
parser_trial_kill.set_defaults(func=trial_kill)
parser_trial_codegen = parser_trial_subparsers.add_parser('codegen', help='generate trial code for a specific trial')
parser_trial_codegen.add_argument('id', nargs='?', help='the id of experiment')
parser_trial_codegen.add_argument('--trial_id', '-T', required=True, dest='trial_id', help='the id of trial to do code generation')
parser_trial_codegen = parser_trial_subparsers.add_parser(
'codegen', description='Generate trial code for a specific trial. Useful in annotation mode.'
)
parser_trial_codegen.add_argument('id', nargs='?', help='Experiment ID')
parser_trial_codegen.add_argument('--trial_id', '-T', required=True, dest='trial_id', help='The ID of trial to do code generation')
parser_trial_codegen.set_defaults(func=trial_codegen)
#parse experiment command
parser_experiment = subparsers.add_parser('experiment', help='get experiment information')
#add subparsers for parser_experiment
# parse experiment command
parser_experiment = subparsers.add_parser('experiment', description='Get information of, or operate on experiments.')
# add subparsers for parser_experiment
parser_experiment_subparsers = parser_experiment.add_subparsers()
parser_experiment_show = parser_experiment_subparsers.add_parser('show', help='show the information of experiment')
parser_experiment_show.add_argument('id', nargs='?', help='the id of experiment')
parser_experiment_show = parser_experiment_subparsers.add_parser('show', description='Show the information of experiment.')
parser_experiment_show.add_argument('id', nargs='?', help='Experiment ID')
parser_experiment_show.set_defaults(func=list_experiment)
parser_experiment_status = parser_experiment_subparsers.add_parser('status', help='show the status of experiment')
parser_experiment_status.add_argument('id', nargs='?', help='the id of experiment')
parser_experiment_status = parser_experiment_subparsers.add_parser('status', description='Show the status of experiment.')
parser_experiment_status.add_argument('id', nargs='?', help='Experiment ID')
parser_experiment_status.set_defaults(func=experiment_status)
parser_experiment_list = parser_experiment_subparsers.add_parser('list', help='list all of running experiment ids')
parser_experiment_list.add_argument('--all', action='store_true', default=False, help='list all of experiments')
parser_experiment_list = parser_experiment_subparsers.add_parser(
'list', description='Show the information of all the (running) experiments.'
)
parser_experiment_list.add_argument('--all', action='store_true', default=False, help='List all of experiments')
parser_experiment_list.set_defaults(func=experiment_list)
parser_experiment_clean = parser_experiment_subparsers.add_parser('delete', help='clean up the experiment data')
parser_experiment_clean.add_argument('id', nargs='?', help='the id of experiment')
parser_experiment_clean.add_argument('--all', action='store_true', default=False, help='delete all of experiments')
parser_experiment_clean = parser_experiment_subparsers.add_parser(
'delete',
description='Delete one or all experiments, it includes log, result, environment information and cache. '
'It can be used to delete useless experiment result, or save disk space.'
)
parser_experiment_clean.add_argument('id', nargs='?', help='Experiment ID')
parser_experiment_clean.add_argument('--all', action='store_true', default=False, help='Delete all of experiments')
parser_experiment_clean.set_defaults(func=experiment_clean)
#import tuning data
parser_import_data = parser_experiment_subparsers.add_parser('import', help='import additional data')
parser_import_data.add_argument('id', nargs='?', help='the id of experiment')
parser_import_data.add_argument('--filename', '-f', required=True)
# import tuning data
parser_import_data = parser_experiment_subparsers.add_parser(
'import', description='Import additional tuning data into an experiment.', help=_NNICTL_EXPERIMENT_IMPORT_HELP
)
parser_import_data.add_argument('id', nargs='?', help='Experiment ID')
parser_import_data.add_argument('--filename', '-f', required=True, help='A file with data you want to import in json format')
parser_import_data.set_defaults(func=import_data)
#export trial data
parser_trial_export = parser_experiment_subparsers.add_parser('export', help='export trial job results to csv or json')
parser_trial_export.add_argument('id', nargs='?', help='the id of experiment')
parser_trial_export.add_argument('--type', '-t', choices=['json', 'csv'], required=True, dest='type', help='target file type')
parser_trial_export.add_argument('--filename', '-f', required=True, dest='path', help='target file path')
# export trial data
parser_trial_export = parser_experiment_subparsers.add_parser(
'export', description='Export trial job results.', help=_NNICTL_EXPERIMENT_EXPORT_HELP
)
parser_trial_export.add_argument('id', nargs='?', help='Experiment ID')
parser_trial_export.add_argument('--type', '-t', choices=['json', 'csv'], required=True, dest='type', help='Target file type')
parser_trial_export.add_argument('--filename', '-f', required=True, dest='path', help='File path of the output file')
parser_trial_export.add_argument('--intermediate', '-i', action='store_true',
default=False, help='are intermediate results included')
default=False, help='Whether intermediate results are included')
parser_trial_export.set_defaults(func=export_trials_data)
#save an NNI experiment
parser_save_experiment = parser_experiment_subparsers.add_parser('save', help='save an experiment')
parser_save_experiment.add_argument('id', nargs='?', help='the id of experiment')
parser_save_experiment.add_argument('--path', '-p', required=False, help='the folder path to store nni experiment data, \
default current working directory')
parser_save_experiment.add_argument('--saveCodeDir', '-s', action='store_true', default=False, help='save codeDir data \
of the experiment')
# save an NNI experiment
parser_save_experiment = parser_experiment_subparsers.add_parser(
'save', description='Dump the metadata and code data of an experiment into a package.'
)
parser_save_experiment.add_argument('id', nargs='?', help='Experiment ID')
parser_save_experiment.add_argument('--path', '-p', required=False,
help='The folder to store nni experiment data. Default: current working directory.')
parser_save_experiment.add_argument('--saveCodeDir', '-s', action='store_true', default=False,
help='Copy code directory into the saved package.')
parser_save_experiment.set_defaults(func=save_experiment)
#load an NNI experiment
parser_load_experiment = parser_experiment_subparsers.add_parser('load', help='load an experiment')
parser_load_experiment.add_argument('--path', '-p', required=True, help='the path of nni package file')
parser_load_experiment.add_argument('--codeDir', '-c', required=True, help='the path of codeDir for loaded experiment, \
this path will also put the code in the loaded experiment package')
parser_load_experiment.add_argument('--logDir', '-l', required=False, help='the path of logDir for loaded experiment')
parser_load_experiment.add_argument('--searchSpacePath', '-s', required=False, help='the path of search space file for \
loaded experiment, this path contains file name. Default in $codeDir/search_space.json')
# load an NNI experiment
parser_load_experiment = parser_experiment_subparsers.add_parser('load', description='Load an experiment dumped with ``save`` command.')
parser_load_experiment.add_argument('--path', '-p', required=True, help='Path to the packaged experiment.')
parser_load_experiment.add_argument('--codeDir', '-c', required=True,
help='Where to put the code for the loaded experiment. Code in the package will be unzipped here.')
parser_load_experiment.add_argument('--logDir', '-l', required=False,
help='Path to ``logDir`` for the loaded experiment')
parser_load_experiment.add_argument('--searchSpacePath', '-s', required=False,
help='The file path (not folder) to put the search space file for the loaded experiment. '
'Default: ``$codeDir/search_space.json``')
parser_load_experiment.set_defaults(func=load_experiment)
#parse platform command
parser_platform = subparsers.add_parser('platform', help='get platform information')
#add subparsers for parser_platform
# parse platform command
parser_platform = subparsers.add_parser('platform')
# add subparsers for parser_platform
parser_platform_subparsers = parser_platform.add_subparsers()
parser_platform_clean = parser_platform_subparsers.add_parser('clean', help='clean up the platform data')
parser_platform_clean.add_argument('--config', '-c', required=True, dest='config', help='the path of yaml config file')
parser_platform_clean = parser_platform_subparsers.add_parser(
'clean', description='Clean up the specified platform.', help=_NNICTL_PLATFORM_CLEAN_HELP
)
parser_platform_clean.add_argument(
'--config', '-c', required=True, dest='config',
help='Path to yaml config file used when creating an experiment on that platform.'
)
parser_platform_clean.set_defaults(func=platform_clean)
#TODO:finish webui function
#parse board command
parser_webui = subparsers.add_parser('webui', help='get web ui information')
#add subparsers for parser_board
# TODO:finish webui function
# parse board command
parser_webui = subparsers.add_parser('webui')
# add subparsers for parser_board
parser_webui_subparsers = parser_webui.add_subparsers()
parser_webui_url = parser_webui_subparsers.add_parser('url', help='show the url of web ui')
parser_webui_url.add_argument('id', nargs='?', help='the id of experiment')
parser_webui_url = parser_webui_subparsers.add_parser('url', description="Show an experiment's webui url.")
parser_webui_url.add_argument('id', nargs='?', help='Experiment ID')
parser_webui_url.set_defaults(func=webui_url)
#parse config command
parser_config = subparsers.add_parser('config', help='get config information')
# parse config command
parser_config = subparsers.add_parser('config')
parser_config_subparsers = parser_config.add_subparsers()
parser_config_show = parser_config_subparsers.add_parser('show', help='show the information of config')
parser_config_show.add_argument('id', nargs='?', help='the id of experiment')
parser_config_show = parser_config_subparsers.add_parser('show', description='Show the config of an experiment.')
parser_config_show.add_argument('id', nargs='?', help='Experiment ID')
parser_config_show.set_defaults(func=get_config)
#parse log command
parser_log = subparsers.add_parser('log', help='get log information')
# parse log command
parser_log = subparsers.add_parser('log', description='Manage logs.')
# add subparsers for parser_log
parser_log_subparsers = parser_log.add_subparsers()
parser_log_stdout = parser_log_subparsers.add_parser('stdout', help='get stdout information')
parser_log_stdout.add_argument('id', nargs='?', help='the id of experiment')
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')
parser_log_stdout.add_argument('--path', action='store_true', default=False, help='get the path of stdout file')
parser_log_stdout = parser_log_subparsers.add_parser('stdout', description='Show the stdout log content.')
parser_log_stdout.add_argument('id', nargs='?', help='Experiment ID')
parser_log_stdout.add_argument('--tail', '-T', dest='tail', type=int, help='Show tail lines of stdout')
parser_log_stdout.add_argument('--head', '-H', dest='head', type=int, help='Show head lines of stdout')
parser_log_stdout.add_argument('--path', action='store_true', default=False, help='Get the path of stdout file')
parser_log_stdout.set_defaults(func=log_stdout)
parser_log_stderr = parser_log_subparsers.add_parser('stderr', help='get stderr information')
parser_log_stderr.add_argument('id', nargs='?', help='the id of experiment')
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')
parser_log_stderr.add_argument('--path', action='store_true', default=False, help='get the path of stderr file')
parser_log_stderr = parser_log_subparsers.add_parser('stderr', description='Show the stderr log content.')
parser_log_stderr.add_argument('id', nargs='?', help='Experiment ID')
parser_log_stderr.add_argument('--tail', '-T', dest='tail', type=int, help='Show tail lines of stderr')
parser_log_stderr.add_argument('--head', '-H', dest='head', type=int, help='Show head lines of stderr')
parser_log_stderr.add_argument('--path', action='store_true', default=False, help='Get the path of stderr file')
parser_log_stderr.set_defaults(func=log_stderr)
parser_log_trial = parser_log_subparsers.add_parser('trial', help='get trial log path')
parser_log_trial.add_argument('id', nargs='?', help='the id of experiment')
parser_log_trial.add_argument('--trial_id', '-T', dest='trial_id', help='find trial log path by id')
parser_log_trial = parser_log_subparsers.add_parser('trial', description='Show trial log path.')
parser_log_trial.add_argument('id', nargs='?', help='Experiment ID')
parser_log_trial.add_argument('--trial_id', '-T', dest='trial_id',
help='Trial ID to find the log path, required when experiment ID is set')
parser_log_trial.set_defaults(func=log_trial)
#parse algo command
parser_algo = subparsers.add_parser('algo', help='control nni builtin tuner, assessor and advisor algorithms')
# parse algo command
parser_algo = subparsers.add_parser('algo', description='Manage algorithms.')
# add subparsers for parser_algo
parser_algo_subparsers = parser_algo.add_subparsers()
parser_algo_reg = parser_algo_subparsers.add_parser(
'register',
aliases=('reg',),
help='''register algorithms as nni builtin algorithm, for example:
nnictl reg --meta_path <path_to_meta_file>
where <path_to_meta_file> is the path to a meta data in yml format,
reference the nni document and examples/tuners/customized_tuner example
for the format of the yml file.'''
description='Register customized algorithms as builtin tuner/assessor/advisor.',
help=_NNICTL_ALGO_REGISTER_HELP
)
parser_algo_reg.add_argument('--meta_path', '-m', dest='meta_path', help='path to the meta file', required=True)
parser_algo_reg.add_argument('--meta_path', '-m', dest='meta_path', help='Path to the meta file', required=True)
parser_algo_reg.set_defaults(func=algo_reg)
parser_algo_unreg = parser_algo_subparsers.add_parser('unregister', aliases=('unreg',), help='unregister algorithm')
parser_algo_unreg.add_argument('name', nargs=1, help='builtin name of the algorithm')
parser_algo_unreg = parser_algo_subparsers.add_parser(
'unregister', aliases=('unreg',),
description='Unregister a registered customized builtin algorithms. The NNI-provided builtin algorithms can not be unregistered.'
)
parser_algo_unreg.add_argument('name', nargs=1, help='Builtin name of the algorithm')
parser_algo_unreg.set_defaults(func=algo_unreg)
parser_algo_show = parser_algo_subparsers.add_parser('show', help='show the information of algorithm')
parser_algo_show.add_argument('name', nargs=1, help='builtin name of the algorithm')
parser_algo_show = parser_algo_subparsers.add_parser(
'show', description='Show the detailed information of specific registered algorithms.'
)
parser_algo_show.add_argument('name', nargs=1, help='Builtin name of the algorithm')
parser_algo_show.set_defaults(func=algo_show)
parser_algo_list = parser_algo_subparsers.add_parser('list', help='list registered algorithms')
parser_algo_list = parser_algo_subparsers.add_parser('list', description='List the registered builtin algorithms.')
parser_algo_list.set_defaults(func=algo_list)
#parse trainingservice command
parser_ts = subparsers.add_parser('trainingservice', help='control training service')
# parse trainingservice command
parser_ts = subparsers.add_parser('trainingservice', description='*(internal preview)* Manage 3rd-party training services.')
# add subparsers for parser_ts
parser_ts_subparsers = parser_ts.add_subparsers()
parser_ts_reg = parser_ts_subparsers.add_parser('register', help='register training service')
parser_ts_reg.add_argument('--package', dest='package', help='package name', required=True)
parser_ts_reg = parser_ts_subparsers.add_parser('register', description='Register training service.')
parser_ts_reg.add_argument('--package', dest='package', help='Package name', required=True)
parser_ts_reg.set_defaults(func=ts_management.register)
parser_ts_unreg = parser_ts_subparsers.add_parser('unregister', help='unregister training service')
parser_ts_unreg.add_argument('--package', dest='package', help='package name', required=True)
parser_ts_unreg = parser_ts_subparsers.add_parser('unregister', description='Unregister training service.')
parser_ts_unreg.add_argument('--package', dest='package', help='Package name', required=True)
parser_ts_unreg.set_defaults(func=ts_management.unregister)
parser_ts_list = parser_ts_subparsers.add_parser('list', help='list custom training services')
parser_ts_list = parser_ts_subparsers.add_parser('list', description='List custom training services.')
parser_ts_list.set_defaults(func=ts_management.list_services)
# To show message that nnictl package command is replaced by nnictl algo, to be remove in the future release.
def show_messsage_for_nnictl_package(args):
print_error('nnictl package command is replaced by nnictl algo, please run nnictl algo -h to show the usage')
parser_package_subparsers = subparsers.add_parser('package', help='this argument is replaced by algo', prefix_chars='\n')
parser_package_subparsers = subparsers.add_parser('package', description='This argument is replaced by algo.')
parser_package_subparsers.add_argument('args', nargs=argparse.REMAINDER)
parser_package_subparsers.set_defaults(func=show_messsage_for_nnictl_package)
#parse top command
parser_top = subparsers.add_parser('top', help='monitor the experiment')
parser_top.add_argument('--time', '-t', dest='time', type=int, default=3, help='the time interval to update the experiment status, ' \
'the unit is second')
# parse top command
parser_top = subparsers.add_parser('top', description='Monitor the list of all running experiments.')
parser_top.add_argument(
'--time', '-t', dest='time', type=int, default=3,
help='The interval to update the experiment status. The unit of time is second, and the default value is 3 seconds.'
)
parser_top.set_defaults(func=monitor_experiment)
# parse the command of auto generating search space
parser_start = subparsers.add_parser('ss_gen', description='*(deprecated)* Automatically generate search space file from trial code.')
parser_start.add_argument('--trial_command', '-t', required=True, dest='trial_command', help='The command for running trial code')
parser_start.add_argument('--trial_dir', '-d', default='./', dest='trial_dir', help='The directory for running the command')
parser_start.add_argument('--file', '-f', default='nni_auto_gen_search_space.json', dest='file', help='The path of search space file')
parser_start.set_defaults(func=search_space_auto_gen)
# jupyter-extension command
jupyter_parser = subparsers.add_parser('jupyter-extension', help='install or uninstall JupyterLab extension (internal preview)')
jupyter_parser = subparsers.add_parser('jupyter-extension',
description='*(internal preview)* Install or uninstall JupyterLab extension.')
jupyter_subparsers = jupyter_parser.add_subparsers()
jupyter_install_parser = jupyter_subparsers.add_parser('install', help='install JupyterLab extension')
jupyter_install_parser = jupyter_subparsers.add_parser('install', description='Install JupyterLab extension.')
jupyter_install_parser.set_defaults(func=_jupyter_install)
jupyter_uninstall_parser = jupyter_subparsers.add_parser('uninstall', help='uninstall JupyterLab extension')
jupyter_uninstall_parser = jupyter_subparsers.add_parser('uninstall', description='Uninstall JupyterLab extension.')
jupyter_uninstall_parser.set_defaults(func=_jupyter_uninstall)
return parser
def parse_args():
parser = get_parser()
args = parser.parse_args()
args.func(args)
def _jupyter_install(_args):
import nni.tools.jupyter_extension.management as jupyter_management
jupyter_management.install()
print('Successfully installed JupyterLab extension')
def _jupyter_uninstall(_args):
import nni.tools.jupyter_extension.management as jupyter_management
jupyter_management.uninstall()
print('Successfully uninstalled JupyterLab extension')
if __name__ == '__main__':
parse_args()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment