diff --git a/backend/dynamic_metadata.py b/backend/dynamic_metadata.py index fa40d332cf..0502684f47 100644 --- a/backend/dynamic_metadata.py +++ b/backend/dynamic_metadata.py @@ -38,6 +38,7 @@ def dynamic_metadata( "pytest", "pytest-cov", "pytest-sugar", + "dpgui", ], "docs": [ "sphinx>=3.1.1", @@ -62,6 +63,9 @@ def dynamic_metadata( "i-PI", *find_libpython_requires, ], + "gui": [ + "dpgui", + ], **get_tf_requirement(tf_version), "cu11": [ "nvidia-cuda-runtime-cu11", diff --git a/deepmd/entrypoints/__init__.py b/deepmd/entrypoints/__init__.py index c46a90fec3..9c3a8b31e1 100644 --- a/deepmd/entrypoints/__init__.py +++ b/deepmd/entrypoints/__init__.py @@ -16,6 +16,9 @@ from .freeze import ( freeze, ) +from .gui import ( + start_dpgui, +) from .neighbor_stat import ( neighbor_stat, ) @@ -41,4 +44,5 @@ "make_model_devi", "convert", "neighbor_stat", + "start_dpgui", ] diff --git a/deepmd/entrypoints/gui.py b/deepmd/entrypoints/gui.py new file mode 100644 index 0000000000..8b6b9e0a09 --- /dev/null +++ b/deepmd/entrypoints/gui.py @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +"""DP-GUI entrypoint.""" + + +def start_dpgui(*, port: int, bind_all: bool, **kwargs): + """Host DP-GUI server. + + Parameters + ---------- + port : int + The port to serve DP-GUI on. + bind_all : bool + Serve on all public interfaces. This will expose your DP-GUI instance + to the network on both IPv4 and IPv6 (where available). + **kwargs + additional arguments + + Raises + ------ + ModuleNotFoundError + The dpgui package is not installed + """ + try: + from dpgui import ( + start_dpgui, + ) + except ModuleNotFoundError as e: + raise ModuleNotFoundError( + "To use DP-GUI, please install the dpgui package:\npip install dpgui" + ) from e + start_dpgui(port=port, bind_all=bind_all) diff --git a/deepmd/entrypoints/main.py b/deepmd/entrypoints/main.py index 2b6f4859d1..782136b542 100644 --- a/deepmd/entrypoints/main.py +++ b/deepmd/entrypoints/main.py @@ -21,6 +21,7 @@ freeze, make_model_devi, neighbor_stat, + start_dpgui, test, train_dp, transfer, @@ -89,6 +90,8 @@ def main(args: Optional[Union[List[str], argparse.Namespace]] = None): neighbor_stat(**dict_args) elif args.command == "train-nvnmd": # nvnmd train_nvnmd(**dict_args) + elif args.command == "gui": + start_dpgui(**dict_args) elif args.command is None: pass else: diff --git a/deepmd_cli/main.py b/deepmd_cli/main.py index 8aa6785681..5a0670d8dc 100644 --- a/deepmd_cli/main.py +++ b/deepmd_cli/main.py @@ -571,6 +571,29 @@ def main_parser() -> argparse.ArgumentParser: action="store_true", help="Skip calculating neighbor statistics. Sel checking, automatic sel, and model compression will be disabled.", ) + + # gui + parser_gui = subparsers.add_parser( + "gui", + parents=[parser_log], + help="Serve DP-GUI.", + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) + parser_gui.add_argument( + "-p", + "--port", + type=int, + default=6042, + help="The port to serve DP-GUI on.", + ) + parser_gui.add_argument( + "--bind_all", + action="store_true", + help=( + "Serve on all public interfaces. This will expose your DP-GUI instance " + "to the network on both IPv4 and IPv6 (where available)." + ), + ) return parser diff --git a/doc/cli.rst b/doc/cli.rst index 4c52a9ede8..668a2df2e3 100644 --- a/doc/cli.rst +++ b/doc/cli.rst @@ -1,3 +1,5 @@ +.. _cli: + Command line interface ====================== diff --git a/doc/train/train-input.rst b/doc/train/train-input.rst index 893dd0980e..2a32aeb930 100644 --- a/doc/train/train-input.rst +++ b/doc/train/train-input.rst @@ -1,7 +1,7 @@ Training Parameters ====================================== .. note:: - One can load, modify, and export the input file by using our effective web-based tool `DP-GUI `_. All training parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file for furthur training. + One can load, modify, and export the input file by using our effective web-based tool `DP-GUI `_ online or hosted using the :ref:`command line interface ` :code:`dp gui`. All training parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file for furthur training. .. dargs:: :module: deepmd.utils.argcheck diff --git a/pyproject.toml b/pyproject.toml index 01f0f4810b..8c5267567b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,9 @@ keywords = ["deepmd"] [project.entry-points."lammps.plugins"] deepmd = "deepmd.lmp:get_op_dir" +[project.entry-points."dpgui"] +"DeePMD-kit" = "deepmd.utils.argcheck:gen_args" + [project.urls] Homepage = "https://github.com/deepmodeling/deepmd-kit" documentation = "https://docs.deepmodeling.com/projects/deepmd" diff --git a/source/tests/test_gui.py b/source/tests/test_gui.py new file mode 100644 index 0000000000..25fd7e6651 --- /dev/null +++ b/source/tests/test_gui.py @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +import unittest + +from dpgui import ( + generate_dpgui_templates, +) + + +class TestDPGUI(unittest.TestCase): + def test_dpgui_entrypoints(self): + self.assertTrue(len(generate_dpgui_templates()) > 0)