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

configure ruff #260

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ repos:
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.3
rev: v0.6.3
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
files: \.py$
Expand Down
9 changes: 5 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@

# -- Path setup --------------------------------------------------------------

import datetime

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
from datetime import (
date,
)

# -- Project information -----------------------------------------------------

project = "DPGEN2"
copyright = "2022-%d, DeepModeling" % date.today().year
copyright = (
"2022-%d, DeepModeling" % datetime.datetime.now(tz=datetime.timezone.utc).year
)
author = "DeepModeling"


Expand Down
46 changes: 23 additions & 23 deletions docs/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ This section defines how the configuration space is explored.
"command": "lmp -var restart 0"
},
"convergence": {
"type" : "fixed-levels",
"conv_accuracy" : 0.9,
"level_f_lo": 0.05,
"level_f_hi": 0.50,
"_comment" : "all"
"type" : "fixed-levels",
"conv_accuracy" : 0.9,
"level_f_lo": 0.05,
"level_f_hi": 0.50,
"_comment" : "all"
},
"max_numb_iter" : 5,
"fatal_at_max" : false,
Expand All @@ -94,29 +94,29 @@ This section defines how the configuration space is explored.
}
],
"stages": [
[
[
{
"_comment" : "stage 0, task group 0",
"type" : "lmp-md",
"ensemble": "nvt", "nsteps": 50, "temps": [50, 100], "trj_freq": 10,
"conf_idx": [0], "n_sample" : 3
"_comment" : "stage 0, task group 0",
"type" : "lmp-md",
"ensemble": "nvt", "nsteps": 50, "temps": [50, 100], "trj_freq": 10,
"conf_idx": [0], "n_sample" : 3
},
{
"_comment" : "stage 0, task group 1",
"type" : "lmp-template",
"lmp" : "template.lammps", "plm" : "template.plumed",
"trj_freq" : 10, "revisions" : {"V_NSTEPS" : [40], "V_TEMP" : [150, 200]},
"conf_idx": [0], "n_sample" : 3
"_comment" : "stage 0, task group 1",
"type" : "lmp-template",
"lmp" : "template.lammps", "plm" : "template.plumed",
"trj_freq" : 10, "revisions" : {"V_NSTEPS" : [40], "V_TEMP" : [150, 200]},
"conf_idx": [0], "n_sample" : 3
}
],
[
],
[
{
"_comment" : "stage 1, task group 0",
"type" : "lmp-md",
"ensemble": "npt", "nsteps": 50, "press": [1e0], "temps": [50, 100, 200], "trj_freq": 10,
"conf_idx": [1], "n_sample" : 3
"_comment" : "stage 1, task group 0",
"type" : "lmp-md",
"ensemble": "npt", "nsteps": 50, "press": [1e0], "temps": [50, 100, 200], "trj_freq": 10,
"conf_idx": [1], "n_sample" : 3
}
]
]
]
}
```
Expand Down Expand Up @@ -197,7 +197,7 @@ Any of the config in the {dargs:argument}`"step_configs"<step_configs>` can be o
```json
"default_step_config" : {
"template_config" : {
"image" : "dpgen2:x.x.x"
"image" : "dpgen2:x.x.x"
}
},
```
Expand Down
3 changes: 3 additions & 0 deletions dpgen2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
from .__about__ import (
__version__,
)


__all__ = ["__version__"]
8 changes: 8 additions & 0 deletions dpgen2/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
"alloy": AlloyConfGenerator,
"file": FileConfGenerator,
}


__all__ = [
"AlloyConfGenerator",
"ConfGenerator",
"FileConfGenerator",
"conf_styles",
]
4 changes: 1 addition & 3 deletions dpgen2/conf/alloy_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
)
from typing import (
List,
Optional,
Tuple,
Union,
)
Expand All @@ -14,7 +13,6 @@
import numpy as np
from dargs import (
Argument,
Variant,
)

from .conf_generator import (
Expand Down Expand Up @@ -184,7 +182,7 @@ def __init__(
sys.data["atom_numbs"] = [0] * self.ntypes
sys.data["atom_numbs"][0] = self.natoms
sys.data["atom_types"] = np.array([0] * self.natoms, dtype=int)
self.type_population = [ii for ii in range(self.ntypes)]
self.type_population = list(range(self.ntypes))
# record sys
self.sys = sys

Expand Down
2 changes: 1 addition & 1 deletion dpgen2/conf/conf_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_file_content(
type_map,
fmt="lammps/lmp",
) -> List[str]:
r"""Get the file content of configurations
r"""Get the file content of configurations.

Parameters
----------
Expand Down
3 changes: 0 additions & 3 deletions dpgen2/conf/file_conf.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import glob
import os
from pathlib import (
Path,
)
from typing import (
List,
Optional,
Tuple,
Union,
)

import dpdata
from dargs import (
Argument,
Variant,
)

from .conf_generator import (
Expand Down
76 changes: 36 additions & 40 deletions dpgen2/conf/unit_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def gen_box(self):
def poscar_unit(self, latt):
box = self.gen_box()
ret = ""
ret += "BCC : a = %f \n" % latt
ret += "%.16f\n" % (latt)
ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2])
ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2])
ret += "%.16f %.16f %.16f\n" % (box[2][0], box[2][1], box[2][2])
ret += f"BCC : a = {latt:f} \n"
ret += f"{latt:.16f}\n"
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "%d\n" % self.numb_atoms()
ret += "Direct\n"
ret += "%.16f %.16f %.16f\n" % (0.0, 0.0, 0.0)
ret += "%.16f %.16f %.16f\n" % (0.5, 0.5, 0.5)
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
ret += f"{0.5:.16f} {0.5:.16f} {0.5:.16f}\n"
return ret


Expand All @@ -63,18 +63,18 @@ def gen_box(self):
def poscar_unit(self, latt):
box = self.gen_box()
ret = ""
ret += "FCC : a = %f \n" % latt
ret += "%.16f\n" % (latt)
ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2])
ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2])
ret += "%.16f %.16f %.16f\n" % (box[2][0], box[2][1], box[2][2])
ret += f"FCC : a = {latt:f} \n"
ret += f"{latt:.16f}\n"
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "%d\n" % self.numb_atoms()
ret += "Direct\n"
ret += "%.16f %.16f %.16f\n" % (0.0, 0.0, 0.0)
ret += "%.16f %.16f %.16f\n" % (0.5, 0.5, 0.0)
ret += "%.16f %.16f %.16f\n" % (0.5, 0.0, 0.5)
ret += "%.16f %.16f %.16f\n" % (0.0, 0.5, 0.5)
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
ret += f"{0.5:.16f} {0.5:.16f} {0.0:.16f}\n"
ret += f"{0.5:.16f} {0.0:.16f} {0.5:.16f}\n"
ret += f"{0.0:.16f} {0.5:.16f} {0.5:.16f}\n"
return ret


Expand All @@ -91,16 +91,16 @@ def gen_box(self):
def poscar_unit(self, latt):
box = self.gen_box()
ret = ""
ret += "HCP : a = %f / sqrt(2)\n" % latt
ret += f"HCP : a = {latt:f} / sqrt(2)\n"
ret += "%.16f\n" % (latt / np.sqrt(2))
ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2])
ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2])
ret += "%.16f %.16f %.16f\n" % (box[2][0], box[2][1], box[2][2])
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "%d\n" % self.numb_atoms()
ret += "Direct\n"
ret += "%.16f %.16f %.16f\n" % (0, 0, 0)
ret += "%.16f %.16f %.16f\n" % (1.0 / 3, 1.0 / 3, 1.0 / 2)
ret += f"{0:.16f} {0:.16f} {0:.16f}\n"
ret += f"{1.0 / 3:.16f} {1.0 / 3:.16f} {1.0 / 2:.16f}\n"
return ret


Expand All @@ -114,15 +114,15 @@ def gen_box(self):
def poscar_unit(self, latt):
box = self.gen_box()
ret = ""
ret += "SC : a = %f \n" % latt
ret += "%.16f\n" % (latt)
ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2])
ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2])
ret += "%.16f %.16f %.16f\n" % (box[2][0], box[2][1], box[2][2])
ret += f"SC : a = {latt:f} \n"
ret += f"{latt:.16f}\n"
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "%d\n" % self.numb_atoms()
ret += "Direct\n"
ret += "%.16f %.16f %.16f\n" % (0.0, 0.0, 0.0)
ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n"
return ret


Expand All @@ -142,21 +142,17 @@ def poscar_unit(self, latt):
box = self.gen_box()
ret = ""
ret += "DIAMOND\n"
ret += "%.16f\n" % (latt)
ret += "%.16f %.16f %.16f\n" % (box[0][0], box[0][1], box[0][2])
ret += "%.16f %.16f %.16f\n" % (box[1][0], box[1][1], box[1][2])
ret += "%.16f %.16f %.16f\n" % (box[2][0], box[2][1], box[2][2])
ret += f"{latt:.16f}\n"
ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n"
ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n"
ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n"
ret += "Type\n"
ret += "%d\n" % self.numb_atoms()
ret += "Direct\n"
ret += "%.16f %.16f %.16f\n" % (
0.12500000000000,
0.12500000000000,
0.12500000000000,
ret += (
f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n"
)
ret += "%.16f %.16f %.16f\n" % (
0.87500000000000,
0.87500000000000,
0.87500000000000,
ret += (
f"{0.87500000000000:.16f} {0.87500000000000:.16f} {0.87500000000000:.16f}\n"
)
return ret
6 changes: 1 addition & 5 deletions dpgen2/entrypoint/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
Variant,
)

import dpgen2
from dpgen2.conf import (
conf_styles,
)
from dpgen2.constants import (
default_image,
)
from dpgen2.exploration.report import (
conv_styles,
)
Expand Down Expand Up @@ -186,7 +182,7 @@ def variant_filter():
kk,
dict,
conf_filter_styles[kk].args(),
doc="Configuration filter of type %s" % kk,
doc=f"Configuration filter of type {kk}",
)
)
return Variant(
Expand Down
10 changes: 1 addition & 9 deletions dpgen2/entrypoint/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
Path,
)
from typing import (
Dict,
List,
Optional,
Union,
)

import dflow

from dpgen2.utils import (
bohrium_config_from_dict,
dump_object_to_file,
load_object_from_file,
matched_step_key,
print_keys_in_nice_format,
sort_slice_ops,
workflow_config_from_dict,
)
from dpgen2.utils.step_config import normalize as normalize_step_dict


def global_config_workflow(
Expand Down Expand Up @@ -64,5 +56,5 @@ def expand_idx(in_list) -> List[int]:
ret += [int(range_str[0])]
else:
raise RuntimeError("not expected range string", step_str[0])
ret = sorted(list(set(ret)))
ret = sorted(set(ret))
return ret
4 changes: 0 additions & 4 deletions dpgen2/entrypoint/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Dict,
List,
Optional,
Union,
)

from dflow import (
Expand All @@ -14,9 +13,6 @@
from dpgen2.entrypoint.common import (
global_config_workflow,
)
from dpgen2.utils.dflow_query import (
matched_step_key,
)
from dpgen2.utils.download_dpgen2_artifacts import (
download_dpgen2_artifacts,
download_dpgen2_artifacts_by_def,
Expand Down
Loading
Loading