Skip to content

Commit 33baad0

Browse files
authored
doc: dpgen run machine parameters (#710)
* doc: dpgen run machine parameters * unpin sphinx Fix sphinx-doc/sphinx#10291 (comment)
1 parent 25269cf commit 33baad0

File tree

7 files changed

+78
-6
lines changed

7 files changed

+78
-6
lines changed

doc/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
1313
import os
14+
import sys
1415
import subprocess
1516
# import sys
1617
import recommonmark
@@ -79,3 +80,10 @@
7980
autodoc_default_flags = ['members']
8081
autosummary_generate = True
8182
master_doc = 'index'
83+
84+
85+
def generate_arginfo(app):
86+
subprocess.check_output((sys.executable, "gen_arginfo.py"), universal_newlines=True)
87+
88+
def setup(app):
89+
app.connect('builder-inited', generate_arginfo)

doc/gen_arginfo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from dpgen.generator.arginfo import run_mdata_arginfo
2+
3+
run_mdata_doc = run_mdata_arginfo().gen_doc()
4+
with open('run-mdata-auto.rst', 'w') as f:
5+
f.write(run_mdata_doc)

doc/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
DPGEN's documentation
33
==========================
44

5+
.. _parameters::
6+
7+
.. toctree::
8+
:maxdepth: 2
9+
:caption: Parameters
10+
11+
run-mdata.rst
12+
513
.. _tutorial:
614

715
.. toctree::

doc/requirements.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
sphinx==3.2.1
2-
recommonmark==0.7.1
3-
sphinx_rtd_theme==0.5.2
4-
sphinx_markdown_tables==0.0.15
5-
myst-parser==0.13.7
1+
sphinx>=4.0.2
2+
recommonmark
3+
sphinx_rtd_theme
4+
sphinx_markdown_tables
5+
myst-parser
66
deepmodeling_sphinx
7+
.

doc/run-mdata.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dpgen run machine parameters
2+
============================
3+
4+
.. include:: run-mdata-auto.rst

dpgen/dispatcher/Dispatcher.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from distutils.version import LooseVersion
22
import os,sys,time,random,json,glob
3+
from typing import List
34
from dpdispatcher import Task, Submission, Resources, Machine
45
from dpgen.dispatcher.LocalContext import LocalSession
56
from dpgen.dispatcher.LocalContext import LocalContext
@@ -383,5 +384,25 @@ def make_submission(mdata_machine, mdata_resources, commands, work_path, run_tas
383384
return submission
384385

385386

387+
def mdata_arginfo() -> List[Argument]:
388+
"""This method generates arginfo for a single mdata.
386389
387-
390+
A submission requires the following keys: command, machine,
391+
and resources.
392+
393+
Returns
394+
-------
395+
list[Argument]
396+
arginfo
397+
"""
398+
doc_command = "Command of a program."
399+
doc_mdata = "Machine and resources parameters"
400+
command_arginfo = Argument("command", str, optional=False, doc=doc_command)
401+
machine_arginfo = Machine.arginfo()
402+
machine_arginfo.name = "machine"
403+
resources_arginfo = Resources.arginfo()
404+
resources_arginfo.name = "resources"
405+
406+
return [
407+
command_arginfo, machine_arginfo, resources_arginfo,
408+
]

dpgen/generator/arginfo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from dargs import Argument
2+
3+
from dpgen.dispatcher.Dispatcher import mdata_arginfo
4+
5+
def run_mdata_arginfo() -> Argument:
6+
"""Generate arginfo for dpgen run mdata.
7+
8+
Returns
9+
-------
10+
Argument
11+
arginfo
12+
"""
13+
14+
doc_api_version = "Please set to 1.0"
15+
doc_run_mdata = "machine.json file"
16+
arg_api_version = Argument("api_version", str, optional=False, doc=doc_api_version)
17+
18+
sub_fields = [arg_api_version]
19+
doc_mdata = "Parameters of command, machine, and resources for %s"
20+
for task in ("train", "model_devi", "fp"):
21+
sub_fields.append(Argument(
22+
task, dict, optional=False, sub_fields=mdata_arginfo(),
23+
doc=doc_mdata % task,
24+
))
25+
return Argument("run_mdata", dict, sub_fields=sub_fields, doc=doc_run_mdata)

0 commit comments

Comments
 (0)