Skip to content
Open
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
8 changes: 8 additions & 0 deletions dpgen2/entrypoint/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def lmp_args():
"Each task group is described in :ref:`the task group definition<task_group_sec>` "
)
doc_filters = "A list of configuration filters"
doc_lammps_input_file = "The template input file for LAMMPS simulation. Will pass it to dpdata to parse LAMMPS dump file in spin job."

return [
Argument(
Expand Down Expand Up @@ -259,6 +260,13 @@ def lmp_args():
default=[],
doc=doc_filters,
),
Argument(
"lammps_input_file",
str,
optional=True,
default=None,
doc=doc_lammps_input_file,
),
]


Expand Down
11 changes: 9 additions & 2 deletions dpgen2/entrypoint/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
CustomizedLmpTemplateTaskGroup,
ExplorationStage,
ExplorationTask,
LmpSpinTaskGroup,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unused import detected.

The LmpSpinTaskGroup import is not used within this file according to static analysis.

Consider removing this import if it's not needed or add a comment explaining why it's included for future reference.

-    LmpSpinTaskGroup,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LmpSpinTaskGroup,
🧰 Tools
🪛 Ruff (0.11.9)

84-84: dpgen2.exploration.task.LmpSpinTaskGroup imported but unused

Remove unused import

(F401)

🤖 Prompt for AI Agents
In dpgen2/entrypoint/submit.py at line 84, the import LmpSpinTaskGroup is not
used anywhere in the file. Remove this import statement to clean up the code
unless there is a specific reason to keep it, in which case add a comment
explaining its purpose for future maintainers.

LmpTemplateTaskGroup,
NPTTaskGroup,
caly_normalize,
Expand Down Expand Up @@ -318,7 +319,9 @@ def make_naive_exploration_scheduler_without_conf(config, explore_style):
conv_style = convergence.pop("type")
report = conv_styles[conv_style](**convergence)
# trajectory render, the format of the output trajs are assumed to be lammps/dump
render = TrajRenderLammps(nopbc=output_nopbc)
render = TrajRenderLammps(
nopbc=output_nopbc, lammps_input_file=config["explore"]["lammps_input_file"]
)
# selector
selector = ConfSelectorFrames(
render,
Expand Down Expand Up @@ -378,7 +381,11 @@ def make_lmp_naive_exploration_scheduler(config):
# report
conv_style = convergence.pop("type")
report = conv_styles[conv_style](**convergence)
render = TrajRenderLammps(nopbc=output_nopbc, use_ele_temp=use_ele_temp)
render = TrajRenderLammps(
nopbc=output_nopbc,
use_ele_temp=use_ele_temp,
lammps_input_file=config["explore"]["lammps_input_file"],
)
# selector
selector = ConfSelectorFrames(
render,
Expand Down
10 changes: 9 additions & 1 deletion dpgen2/exploration/deviation/deviation_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DeviManager(ABC):
MAX_DEVI_F = "max_devi_f"
MIN_DEVI_F = "min_devi_f"
AVG_DEVI_F = "avg_devi_f"
MAX_DEVI_MF = "max_devi_mf"
MIN_DEVI_MF = "min_devi_mf"
AVG_DEVI_MF = "avg_devi_mf"

def __init__(self) -> None:
super().__init__()
Expand All @@ -32,6 +35,9 @@ def _check_name(self, name: str):
DeviManager.MAX_DEVI_F,
DeviManager.MIN_DEVI_F,
DeviManager.AVG_DEVI_F,
DeviManager.MAX_DEVI_MF,
DeviManager.MIN_DEVI_MF,
DeviManager.AVG_DEVI_MF,
), f"Error: unknown deviation name {name}"

def add(self, name: str, deviation: np.ndarray) -> None:
Expand Down Expand Up @@ -64,7 +70,9 @@ def get(self, name: str) -> List[Optional[np.ndarray]]:
The name of the deviation. The name is restricted to
(DeviManager.MAX_DEVI_V, DeviManager.MIN_DEVI_V,
DeviManager.AVG_DEVI_V, DeviManager.MAX_DEVI_F,
DeviManager.MIN_DEVI_F, DeviManager.AVG_DEVI_F)
DeviManager.MIN_DEVI_F, DeviManager.AVG_DEVI_F,
DeviManager.MAX_DEVI_MF, DeviManager.MIN_DEVI_MF,
DeviManager.AVG_DEVI_MF)
"""
self._check_name(name)
self._check_data()
Expand Down
3 changes: 3 additions & 0 deletions dpgen2/exploration/deviation/deviation_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def _check_data(self) -> None:
DeviManager.MAX_DEVI_F,
DeviManager.MIN_DEVI_F,
DeviManager.AVG_DEVI_F,
DeviManager.MAX_DEVI_MF,
DeviManager.MIN_DEVI_MF,
DeviManager.AVG_DEVI_MF,
)
# check the length of model deviations
frames = {}
Expand Down
20 changes: 19 additions & 1 deletion dpgen2/exploration/render/traj_render_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ def __init__(
self,
nopbc: bool = False,
use_ele_temp: int = 0,
lammps_input_file: str = None, # type: ignore
):
self.nopbc = nopbc
self.use_ele_temp = use_ele_temp
if lammps_input_file is not None:
self.lammps_input = Path(lammps_input_file).read_text()
else:
self.lammps_input = None

def get_model_devi(
self,
Expand Down Expand Up @@ -74,6 +79,11 @@ def _load_one_model_devi(self, fname, model_devi):
model_devi.add(DeviManager.MAX_DEVI_F, dd[:, 4]) # type: ignore
model_devi.add(DeviManager.MIN_DEVI_F, dd[:, 5]) # type: ignore
model_devi.add(DeviManager.AVG_DEVI_F, dd[:, 6]) # type: ignore
# assume the 7-9 columns are for MF
if dd.shape[1] >= 10: # type: ignore

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be better to judge from the lammps input if the spin model deviation is expected to be output or not.
you may implement a method like self.has_spin(self.lammps_input).
If the input implies spin model deviation output, then the shape[1] of dd must be 9 otherwise must be 6.

model_devi.add(DeviManager.MAX_DEVI_MF, dd[:, 7]) # type: ignore
model_devi.add(DeviManager.MIN_DEVI_MF, dd[:, 8]) # type: ignore
model_devi.add(DeviManager.AVG_DEVI_MF, dd[:, 9]) # type: ignore

def get_ele_temp(self, optional_outputs):
ele_temp = []
Expand Down Expand Up @@ -117,13 +127,21 @@ def get_confs(

traj_fmt = "lammps/dump"
ms = dpdata.MultiSystems(type_map=type_map)
if self.lammps_input is not None:
lammps_input_file = "lammps_input.in"
Path(lammps_input_file).write_text(self.lammps_input)
Comment on lines +130 to +132

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of dumping the lammps input script?

else:
lammps_input_file = None
for ii in range(ntraj):
if len(id_selected[ii]) > 0:
if isinstance(trajs[ii], HDF5Dataset):
traj = StringIO(trajs[ii].get_data()) # type: ignore
else:
traj = trajs[ii]
ss = dpdata.System(traj, fmt=traj_fmt, type_map=type_map)
# for spin job, need to read input file to get the key of the spin data
ss = dpdata.System(
traj, fmt=traj_fmt, type_map=type_map, input_file=lammps_input_file
)
ss.nopbc = self.nopbc
if ele_temp:
self.set_ele_temp(ss, ele_temp[ii])
Expand Down
Loading
Loading