Skip to content

[Code scan] Pass type_map to dpdata when preparing FP tasks #31

Description

@njzjz

This issue is a result of a Codex global code scan of deepmodeling/fpop at commit b05b337590c31a5237b2dcbd9c0833b841c08cd4.

Relevant code:

fpop/fpop/prep_fp.py

Lines 121 to 141 in b05b337

inputs = op_in['inputs']
confs = op_in['confs']
type_map = op_in['type_map']
prepare_image_config = op_in["prep_image_config"]
optional_artifact = op_in["optional_artifact"]
optional_input = op_in["optional_input"]
try:
conf_format = optional_input["conf_format"]
except:
conf_format = "deepmd/npy"
task_names = []
task_paths = []
#System
counter = 0
# loop over list of System
for system in confs:
ss = dpdata.System(system, fmt=conf_format, labeled=False)
for ff in range(ss.get_nframes()):
nn, pp = self._exec_one_frame(counter, inputs, ss[ff], prepare_image_config, optional_input, optional_artifact)

fpop/fpop/vasp.py

Lines 90 to 98 in b05b337

for nn in atom_names:
potcar_contents.append(self._potcars[nn])
return "".join(potcar_contents)
def make_kpoints(
self,
box : np.ndarray,
) -> str:
return make_kspacing_kpoints(box, self.kspacing, self.kgamma)

Problem:
PrepFp.execute() reads type_map from op_in, but the value is never passed to dpdata.System(...). For deepmd/npy inputs that contain type.raw but do not contain type_map.raw, dpdata loads atom names as synthetic names such as Type_0 and Type_1.

That breaks downstream preparation. For example, VASP POTCAR generation indexes the pseudopotential map by atom_names, so VaspInputs.make_potcar() can raise KeyError: 'Type_0' even though the workflow input provided type_map=["H", "O"].

Minimal reproduction:

s1 = dpdata.System(root, fmt="deepmd/npy", labeled=False)
print(s1["atom_names"])
# ['Type_0', 'Type_1']

s2 = dpdata.System(root, fmt="deepmd/npy", labeled=False, type_map=["H", "O"])
print(s2["atom_names"])
# ['H', 'O']

Expected behavior:
PrepFp.execute() should preserve the workflow-provided type_map when loading configurations, or otherwise map dpdata's synthetic names before calling backend-specific prep_task() implementations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions