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

Check warning on line 3 in dpgen/gui.py

View check run for this annotation

Codecov / codecov/patch

dpgen/gui.py#L2-L3

Added lines #L2 - L3 were not covered by tests


def start_dpgui(args: argparse.Namespace):

Check warning on line 6 in dpgen/gui.py

View check run for this annotation

Codecov / codecov/patch

dpgen/gui.py#L6

Added line #L6 was not covered by tests
"""Host DP-GUI server.

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

Raises
------
ModuleNotFoundError
The dpgui package is not installed
"""
try:
from dpgui import (

Check warning on line 20 in dpgen/gui.py

View check run for this annotation

Codecov / codecov/patch

dpgen/gui.py#L19-L20

Added lines #L19 - L20 were not covered by tests
start_dpgui,
)
except ModuleNotFoundError as e:
raise ModuleNotFoundError(

Check warning on line 24 in dpgen/gui.py

View check run for this annotation

Codecov / codecov/patch

dpgen/gui.py#L23-L24

Added lines #L23 - L24 were not covered by tests
"To use DP-GUI, please install the dpgui package:\npip install dpgui"
) from e
start_dpgui(port=args.port, bind_all=args.bind_all)

Check warning on line 27 in dpgen/gui.py

View check run for this annotation

Codecov / codecov/patch

dpgen/gui.py#L27

Added line #L27 was not covered by tests
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

Check warning on line 16 in dpgen/main.py

View check run for this annotation

Codecov / codecov/patch

dpgen/main.py#L16

Added line #L16 was not covered by tests
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 @@
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(

Check warning on line 212 in dpgen/main.py

View check run for this annotation

Codecov / codecov/patch

dpgen/main.py#L212

Added line #L212 was not covered by tests
"gui",
help="Serve DP-GUI.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser_gui.add_argument(

Check warning on line 217 in dpgen/main.py

View check run for this annotation

Codecov / codecov/patch

dpgen/main.py#L217

Added line #L217 was not covered by tests
"-p",
"--port",
type=int,
default=6042,
help="The port to serve DP-GUI on.",
)
parser_gui.add_argument(

Check warning on line 224 in dpgen/main.py

View check run for this annotation

Codecov / codecov/patch

dpgen/main.py#L224

Added line #L224 was not covered by tests
"--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)

Check warning on line 232 in dpgen/main.py

View check run for this annotation

Codecov / codecov/patch

dpgen/main.py#L232

Added line #L232 was not covered by tests
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)
Loading