Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dpgui entry point and dpgen gui CLI #1349

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install coverage 'pymatgen-analysis-defects<2023.08.22' -e .
run: pip install -e .[test]
- name: Test
run: coverage run --source=./dpgen -m unittest -v && coverage report
- uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-bulk-jdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_bulk parameters
======================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-bulk>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-bulk>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-bulk-mdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_bulk machine parameters
==================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-bulk-machine>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-bulk-machine>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-reaction-jdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_reaction parameters
======================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-reaction>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-reaction>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-reaction-mdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_reaction machine parameters
======================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-reaction-machine>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-reaction-machine>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-surf-jdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_surf parameters
======================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-surf>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-surf>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/init/init-surf-mdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen init_surf machine parameters
==================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-surf-machine>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-init-surf-machine>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.data.arginfo
Expand Down
2 changes: 2 additions & 0 deletions doc/overview/cli.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _cli:

Command line interface
======================

Expand Down
2 changes: 1 addition & 1 deletion doc/run/mdata.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dpgen run machine parameters
============================
.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-machine>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-machine>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.generator.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/run/param.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dpgen run param parameters
=============================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-run>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-run>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.generator.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/simplify/simplify-jdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen simplify parameters
=========================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-simplify>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-simplify>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.simplify.arginfo
Expand Down
2 changes: 1 addition & 1 deletion doc/simplify/simplify-mdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dpgen simplify machine parameters
=================================

.. note::
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-simplify-machine>`_. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.
One can load, modify, and export the input file by using our effective web-based tool `DP-GUI <https://deepmodeling.com/dpgui/input/dpgen-simplify-machine>`_ online or hosted using the :ref:`command line interface <cli>` :code:`dpgen gui`. All parameters below can be set in DP-GUI. By clicking "SAVE JSON", one can download the input file.

.. dargs::
:module: dpgen.simplify.arginfo
Expand Down
27 changes: 27 additions & 0 deletions dpgen/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
"""DP-GUI entrypoint."""
import argparse


def start_dpgui(args: argparse.Namespace):
"""Host DP-GUI server.

Parameters
----------
args : argparse.Namespace
Arguments from argparse.

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=args.port, bind_all=args.bind_all)
24 changes: 24 additions & 0 deletions dpgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dpgen.data.surf import gen_init_surf
from dpgen.database.run import db_run
from dpgen.generator.run import gen_run
from dpgen.gui import start_dpgui
from dpgen.simplify.simplify import gen_simplify
from dpgen.tools.auto_gen_param import auto_gen_param
from dpgen.tools.run_report import run_report
Expand Down Expand Up @@ -206,6 +207,29 @@ def main_parser() -> argparse.ArgumentParser:
parser_db.add_argument("PARAM", type=str, help="parameter file, json format")

parser_db.set_defaults(func=db_run)

# gui
parser_gui = subparsers.add_parser(
"gui",
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)."
),
)
parser_gui.set_defaults(func=start_dpgui)
return parser


Expand Down
12 changes: 6 additions & 6 deletions dpgen/simplify/arginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,42 +60,42 @@ def general_simplify_arginfo() -> Argument:
"model_devi_e_trust_lo",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_model_devi_e_trust_lo,
),
Argument(
"model_devi_e_trust_hi",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_model_devi_e_trust_hi,
),
Argument(
"true_error_f_trust_lo",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_true_error_f_trust_lo,
),
Argument(
"true_error_f_trust_hi",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_true_error_f_trust_hi,
),
Argument(
"true_error_e_trust_lo",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_true_error_e_trust_lo,
),
Argument(
"true_error_e_trust_hi",
float,
optional=True,
default=float("inf"),
default=1e10,
doc=doc_true_error_e_trust_hi,
),
]
Expand Down
24 changes: 23 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,31 @@ Homepage = "https://github.com/deepmodeling/dpgen"
documentation = "https://docs.deepmodeling.com/projects/dpgen"
repository = "https://github.com/deepmodeling/dpgen"

[project.entry-points.console_scripts]
[project.scripts]
dpgen = "dpgen.main:main"

[project.entry-points."dpgui"]
"DP-GEN Run" = "dpgen.generator.arginfo:run_jdata_arginfo"
"DP-GEN Run Machine" = "dpgen.generator.arginfo:run_jdata_arginfo"
"DP-GEN Simplify" = "dpgen.simplify.arginfo:simplify_jdata_arginfo"
"DP-GEN Simplify Machine" = "dpgen.simplify.arginfo:simplify_mdata_arginfo"
"DP-GEN init_bulk" = "dpgen.data.arginfo:init_bulk_jdata_arginfo"
"DP-GEN init_bulk Machine" = "dpgen.data.arginfo:init_bulk_mdata_arginfo"
"DP-GEN init_surf" = "dpgen.data.arginfo:init_surf_jdata_arginfo"
"DP-GEN init_surf Machine" = "dpgen.data.arginfo:init_surf_mdata_arginfo"
"DP-GEN init_reaction" = "dpgen.data.arginfo:init_reaction_jdata_arginfo"
"DP-GEN init_reaction Machine" = "dpgen.data.arginfo:init_reaction_mdata_arginfo"

[project.optional-dependencies]
test = [
"dpgui",
"coverage",
"pymatgen-analysis-defects<2023.08.22",
]
gui = [
"dpgui",
]

[tool.setuptools.packages.find]
include = ["dpgen*"]

Expand Down
11 changes: 11 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -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)