Skip to content

Commit 99e2611

Browse files
authored
add and run pre-commit to format codes (#302)
- add pre-commit config - run pre-commit
1 parent 4e9a88f commit 99e2611

File tree

96 files changed

+5506
-3357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5506
-3357
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ dbconfig.json
4545
*/_date.py
4646
*.egg
4747
*.egg-info
48-
venv/*
48+
venv/*

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.4.0
6+
hooks:
7+
- id: trailing-whitespace
8+
exclude: "^tests/"
9+
- id: end-of-file-fixer
10+
exclude: "^tests/"
11+
- id: check-yaml
12+
exclude: "^conda/"
13+
- id: check-json
14+
- id: check-added-large-files
15+
- id: check-merge-conflict
16+
- id: check-symlinks
17+
- id: check-toml
18+
# Python
19+
- repo: https://github.com/psf/black
20+
rev: 22.12.0
21+
hooks:
22+
- id: black-jupyter
23+
# Python inside docs
24+
- repo: https://github.com/asottile/blacken-docs
25+
rev: 1.13.0
26+
hooks:
27+
- id: blacken-docs

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DPDispatcher welcomes every people (or organization) to use under the LGPL-3.0 L
44

55
And Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.
66

7-
If you want to contribute to dpdispatcher, just open a issue, submiit a pull request , leave a comment on github discussion, or contact deepmodeling team.
7+
If you want to contribute to dpdispatcher, just open a issue, submiit a pull request , leave a comment on github discussion, or contact deepmodeling team.
88

99
Any forms of improvement are welcome.
1010

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DPDispatcher
22

3-
DPDispatcher is a python package used to generate HPC(High Performance Computing) scheduler systems (Slurm/PBS/LSF/dpcloudserver) jobs input scripts and submit these scripts to HPC systems and poke until they finish.
3+
DPDispatcher is a python package used to generate HPC(High Performance Computing) scheduler systems (Slurm/PBS/LSF/dpcloudserver) jobs input scripts and submit these scripts to HPC systems and poke until they finish.
44
55
DPDispatcher will monitor (poke) until these jobs finish and download the results files (if these jobs is running on remote systems connected by SSH).
66

ci/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2727
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2828
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2929
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30-
THE POSSIBILITY OF SUCH DAMAGE.
30+
THE POSSIBILITY OF SUCH DAMAGE.

ci/ssh/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ services:
2727
- server
2828

2929
volumes:
30-
ssh_config:
30+
ssh_config:

doc/conf.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import sys
1515
import subprocess
1616
from datetime import date
17+
1718
# sys.path.insert(0, os.path.abspath('.'))
1819

1920

2021
# -- Project information -----------------------------------------------------
2122

22-
project = 'DPDispatcher'
23-
copyright = '2020-%d, Deep Modeling' % date.today().year
24-
author = 'Deep Modeling'
23+
project = "DPDispatcher"
24+
copyright = "2020-%d, Deep Modeling" % date.today().year
25+
author = "Deep Modeling"
2526

2627

2728
# -- General configuration ---------------------------------------------------
@@ -30,52 +31,66 @@
3031
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3132
# ones.
3233
extensions = [
33-
'deepmodeling_sphinx',
34-
'dargs.sphinx',
35-
'myst_parser',
34+
"deepmodeling_sphinx",
35+
"dargs.sphinx",
36+
"myst_parser",
3637
"sphinx_rtd_theme",
37-
'sphinx.ext.viewcode',
38-
'sphinx.ext.intersphinx',
39-
'numpydoc',
40-
'sphinx.ext.autosummary'
38+
"sphinx.ext.viewcode",
39+
"sphinx.ext.intersphinx",
40+
"numpydoc",
41+
"sphinx.ext.autosummary",
4142
]
4243

4344
# Add any paths that contain templates here, relative to this directory.
44-
templates_path = ['_templates']
45+
templates_path = ["_templates"]
4546

4647
# List of patterns, relative to source directory, that match files and
4748
# directories to ignore when looking for source files.
4849
# This pattern also affects html_static_path and html_extra_path.
49-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
50+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
5051

5152

5253
# -- Options for HTML output -------------------------------------------------
5354

5455
# The theme to use for HTML and HTML Help pages. See the documentation for
5556
# a list of builtin themes.
5657
#
57-
html_theme = 'sphinx_rtd_theme'
58+
html_theme = "sphinx_rtd_theme"
5859

5960
# Add any paths that contain custom static files (such as style sheets) here,
6061
# relative to this directory. They are copied after the builtin static files,
6162
# so a file named "default.css" will overwrite the builtin "default.css".
62-
html_static_path = ['_static']
63+
html_static_path = ["_static"]
6364
html_css_files = []
6465

65-
autodoc_default_flags = ['members']
66+
autodoc_default_flags = ["members"]
6667
autosummary_generate = True
67-
master_doc = 'index'
68+
master_doc = "index"
69+
6870

6971
def run_apidoc(_):
7072
from sphinx.ext.apidoc import main
71-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
73+
74+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
7275
cur_dir = os.path.abspath(os.path.dirname(__file__))
7376
module = os.path.join(cur_dir, "..", "dpdispatcher")
74-
main(['-M', '--tocfile', 'api', '-H', 'DPDispatcher API', '-o', os.path.join(cur_dir, "api"), module, '--force'])
77+
main(
78+
[
79+
"-M",
80+
"--tocfile",
81+
"api",
82+
"-H",
83+
"DPDispatcher API",
84+
"-o",
85+
os.path.join(cur_dir, "api"),
86+
module,
87+
"--force",
88+
]
89+
)
7590

7691

7792
def setup(app):
78-
app.connect('builder-inited', run_apidoc)
93+
app.connect("builder-inited", run_apidoc)
7994

8095

8196
intersphinx_mapping = {

doc/dpdispatcher_on_yarn.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Support DPDispatcher on Yarn
22
## Background
3-
Currently, DPGen(or other DP softwares) supports for HPC systems like Slurm, PBS, LSF and cloud machines. In order to run DPGen jobs on ByteDance internal platform, we need to extend it to support yarn resources. Hadoop Ecosystem is a very commonly used platform to process the big data, and in the process of developing the new interface, we found it can be implemented by only using hadoop opensource components. So for the convenience of the masses, we decided to contribute the codes to opensource community.
3+
Currently, DPGen(or other DP softwares) supports for HPC systems like Slurm, PBS, LSF and cloud machines. In order to run DPGen jobs on ByteDance internal platform, we need to extend it to support yarn resources. Hadoop Ecosystem is a very commonly used platform to process the big data, and in the process of developing the new interface, we found it can be implemented by only using hadoop opensource components. So for the convenience of the masses, we decided to contribute the codes to opensource community.
44

55
## Design
66
We use DistributedShell and HDFS to implement it. The control flow shows as follows:
@@ -28,7 +28,7 @@ class HDFSContext(BaseContext) :
2828
none
2929
"""
3030
pass
31-
31+
3232
def download(self, submission):
3333
""" download backward files from HDFS root dir
3434
@@ -42,7 +42,7 @@ class HDFSContext(BaseContext) :
4242
none
4343
"""
4444
pass
45-
45+
4646
def check_file_exists(self, fname):
4747
""" check whether the given file exists, often used in checking whether the belonging job has finished
4848
@@ -74,7 +74,7 @@ class DistributedShell(Machine):
7474
usually a yarn application id
7575
"""
7676
pass
77-
77+
7878
def check_status(self, job):
7979
""" check the yarn job status
8080
@@ -86,9 +86,9 @@ class DistributedShell(Machine):
8686
Returns
8787
-------
8888
status: JobStatus
89-
"""
89+
"""
9090
pass
91-
91+
9292
def gen_script_command(self, job):
9393
""" Generate the shell script to be executed in DistibutedShell container
9494
@@ -101,7 +101,7 @@ class DistributedShell(Machine):
101101
-------
102102
script: string
103103
script command string
104-
"""
104+
"""
105105
pass
106106
```
107107

@@ -124,15 +124,15 @@ hadoop fs -test -e /root/uuid/sys-0001-0015/tag_0_finished
124124
cur_dir=`pwd`
125125
cd t sys-0001-0015
126126
test $? -ne 0 && exit 1
127-
127+
128128
## do your job here
129129
mpirun -n 32 vasp_std 1>> log 2>> err
130-
130+
131131
if test $? -ne 0; then
132132
exit 1
133133
else
134134
hadoop fs -touchz /root/uuid/sys-0001-0015/tag_0_finished
135-
fi
135+
fi
136136
cd $cur_dir
137137
test $? -ne 0 && exit 1
138138
fi }&
@@ -178,4 +178,4 @@ An example of machine.json is as follows, whose batch_type is `DistributedShell`
178178
}
179179
}
180180
]
181-
```
181+
```

doc/getting-started.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ DPDispatcher provides the following classes:
66
- {class}`Submission <dpdispatcher.submission.Submission>` class, which represents a collection of jobs defined by the HPC system.
77
And there may be common files to be uploaded by them.
88
DPDispatcher will create and submit these jobs when a `submission` instance execute {meth}`run_submission <dpdispatcher.submission.Submission.run_submission>` method.
9-
This method will poke until the jobs finish and return.
10-
- {class}`Job <dpdispatcher.submission.Job>` class, a class used by {class}`Submission <dpdispatcher.submission.Submission>` class, which represents a job on the HPC system.
9+
This method will poke until the jobs finish and return.
10+
- {class}`Job <dpdispatcher.submission.Job>` class, a class used by {class}`Submission <dpdispatcher.submission.Submission>` class, which represents a job on the HPC system.
1111
{class}`Submission <dpdispatcher.submission.Submission>` will generate `job`s' submitting scripts used by HPC systems automatically with the {class}`Task <dpdispatcher.submission.Task>` and {class}`Resources <dpdispatcher.submission.Resources>`
1212
- {class}`Resources <dpdispatcher.submission.Resources>` class, which represents the computing resources for each job within a `submission`.
1313

@@ -16,24 +16,49 @@ You can use DPDispatcher in a Python script to submit five tasks:
1616
```python
1717
from dpdispatcher import Machine, Resources, Task, Submission
1818

19-
machine = Machine.load_from_json('machine.json')
20-
resources = Resources.load_from_json('resources.json')
19+
machine = Machine.load_from_json("machine.json")
20+
resources = Resources.load_from_json("resources.json")
2121

22-
task0 = Task.load_from_json('task.json')
22+
task0 = Task.load_from_json("task.json")
2323

24-
task1 = Task(command='cat example.txt', task_work_path='dir1/', forward_files=['example.txt'], backward_files=['out.txt'], outlog='out.txt')
25-
task2 = Task(command='cat example.txt', task_work_path='dir2/', forward_files=['example.txt'], backward_files=['out.txt'], outlog='out.txt')
26-
task3 = Task(command='cat example.txt', task_work_path='dir3/', forward_files=['example.txt'], backward_files=['out.txt'], outlog='out.txt')
27-
task4 = Task(command='cat example.txt', task_work_path='dir4/', forward_files=['example.txt'], backward_files=['out.txt'], outlog='out.txt')
24+
task1 = Task(
25+
command="cat example.txt",
26+
task_work_path="dir1/",
27+
forward_files=["example.txt"],
28+
backward_files=["out.txt"],
29+
outlog="out.txt",
30+
)
31+
task2 = Task(
32+
command="cat example.txt",
33+
task_work_path="dir2/",
34+
forward_files=["example.txt"],
35+
backward_files=["out.txt"],
36+
outlog="out.txt",
37+
)
38+
task3 = Task(
39+
command="cat example.txt",
40+
task_work_path="dir3/",
41+
forward_files=["example.txt"],
42+
backward_files=["out.txt"],
43+
outlog="out.txt",
44+
)
45+
task4 = Task(
46+
command="cat example.txt",
47+
task_work_path="dir4/",
48+
forward_files=["example.txt"],
49+
backward_files=["out.txt"],
50+
outlog="out.txt",
51+
)
2852

2953
task_list = [task0, task1, task2, task3, task4]
3054

31-
submission = Submission(work_base='lammps_md_300K_5GPa/',
32-
machine=machine,
55+
submission = Submission(
56+
work_base="lammps_md_300K_5GPa/",
57+
machine=machine,
3358
resources=resources,
3459
task_list=task_list,
35-
forward_common_files=['graph.pb'],
36-
backward_common_files=[]
60+
forward_common_files=["graph.pb"],
61+
backward_common_files=[],
3762
)
3863

3964
submission.run_submission()
@@ -92,12 +117,12 @@ resources = Resources(
92117
queue_name="GPU_2080Ti",
93118
group_size=4,
94119
custom_flags=[
95-
"#SBATCH --nice=100",
120+
"#SBATCH --nice=100",
96121
"#SBATCH --time=24:00:00"
97122
],
98123
strategy={
99124
# used when you want to add CUDA_VISIBLE_DIVECES automatically
100-
"if_cuda_multi_devices": True
125+
"if_cuda_multi_devices": True
101126
},
102127
para_deg=1,
103128
# will unload these modules before running tasks

doc/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
DPDispatcher's documentation
77
======================================
88

9-
DPDispatcher is a Python package used to generate HPC (High Performance Computing) scheduler systems (Slurm/PBS/LSF/dpcloudserver) jobs input scripts and submit these scripts to HPC systems and poke until they finish.
9+
DPDispatcher is a Python package used to generate HPC (High Performance Computing) scheduler systems (Slurm/PBS/LSF/dpcloudserver) jobs input scripts and submit these scripts to HPC systems and poke until they finish.
1010

11-
DPDispatcher will monitor (poke) until these jobs finish and download the results files (if these jobs is running on remote systems connected by SSH).
11+
DPDispatcher will monitor (poke) until these jobs finish and download the results files (if these jobs is running on remote systems connected by SSH).
1212

1313
.. toctree::
1414
:maxdepth: 2
1515
:caption: Contents:
1616

17-
17+
1818
install
1919
getting-started
2020
context
@@ -33,7 +33,7 @@ DPDispatcher will monitor (poke) until these jobs finish and download the result
3333
.. toctree::
3434
:caption: Project details
3535
:glob:
36-
36+
3737
credits
3838

3939
Indices and tables

dpdispatcher/JobStatus.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from enum import IntEnum
2-
class JobStatus(IntEnum) :
2+
3+
4+
class JobStatus(IntEnum):
35
unsubmitted = 1
46
waiting = 2
57
running = 3
68
terminated = 4
79
finished = 5
810
completing = 6
911
unknown = 100
12+
13+
1014
# def __str__(self):
1115
# return repr(self)
12-

0 commit comments

Comments
 (0)