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
This diff is collapsed.
......@@ -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')
......
This diff is collapsed.
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