Skip to content

[Code scan] Align CALYPSO optional schema with required input generation #357

Description

@njzjz

Found by Codex global repository scan of deepmodeling/dpgen2 at commit 2679611a3704f5c2646c8cb353e34177518db758.

The CALYPSO task-group schema marks atomic_number and distance_of_ions as optional:

def caly_task_grp_args():
return [
Argument("numb_of_species", int, optional=False, doc="number of species."),
Argument(
"name_of_atoms",
list,
optional=False,
doc="name of atoms.",
),
Argument(
"atomic_number",
list,
optional=True,
doc="atomic number of each element.",
),
Argument(
"numb_of_atoms",
list,
optional=False,
doc="number of each atom.",
),
Argument(
"distance_of_ions",
[list, dict],
optional=True,
doc="the distance matrix between different elements.",

CalyTaskGroup.set_params only infers atomic_number for the nested random-choice form; otherwise it can leave self.atomic_number = None and self.distance_of_ions = None:

self.atomic_number = [atomic_symbols.index(i) for i in self.name_of_atoms]
else:
self.name_of_atoms = name_of_atoms
self.atomic_number = atomic_number
if isinstance(distance_of_ions, dict):
updated_table = copy.deepcopy(covalent_radii)
for key, value in distance_of_ions.items():
updated_table[atomic_number_map[key]] = value
temp_distance_mtx = np.zeros((numb_of_species, numb_of_species))
for i in range(numb_of_species):
for j in range(numb_of_species):
temp_distance_mtx[i][j] = round(
updated_table[atomic_number_map[self.name_of_atoms[i]]] * 0.7
+ updated_table[atomic_number_map[self.name_of_atoms[j]]] * 0.7,
2,
)
self.distance_of_ions = temp_distance_mtx
else:
self.distance_of_ions = distance_of_ions

make_calypso_input later treats both values as required, calling len(atomic_number) and asserting that distance_of_ions has a square matrix shape:

distance_of_ions = np.array(distance_of_ions)
assert (
numb_of_species
== len(name_of_atoms)
== len(atomic_number)
== len(numb_of_atoms)
), f"{numb_of_species:}, {name_of_atoms:} {atomic_number:} {numb_of_atoms:}"
assert distance_of_ions.shape == (
numb_of_species,
numb_of_species,
), f"{distance_of_ions.shape} {numb_of_species:}"

A normalized config that omits these optional fields can crash late during task generation instead of receiving defaults or a clear validation error.

Suggested fix: either make these fields required in the schema, infer them for all supported name_of_atoms forms, or fail validation with an actionable message before make_calypso_input is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions