This issue comes from a Codex global repository scan.
Problem
Several AtomicData code paths mix PyTorch assumptions into NumPy objects or mishandle optional batched data:
register_fields(env_fields=...) and register_fields(onsitenv_fields=...) always fail because allfields includes those fields but the RHS uniqueness count omits them:
|
allfields = node_fields.union(edge_fields, graph_fields, env_fields, onsitenv_fields) |
|
assert len(allfields) == len(node_fields) + len(edge_fields) + len(graph_fields) |
Batched validation uses ndarray.view(-1, 3, 3), which is not reshape for NumPy arrays:
|
cell = self.cell.view(-1, 3, 3) |
to_ase() enters the cell is None branch and then dereferences cell.shape:
|
if batch is not None: |
|
n_batches = batch.max() + 1 |
|
if cell is None: |
|
if cell.shape[0] == 1: |
|
cell = np.repeat(cell, n_batches, axis=0) |
Unbatched to_ase(extra_fields=...) sets masks to slice(None) and later calls .sum() on those slices:
|
self[key][mask].reshape(mask.sum(), -1) |
|
) |
|
elif key in _EDGE_FIELDS: |
|
mol.info[key] = ( |
|
self[key][edge_mask].reshape(edge_mask.sum(), -1) |
Suggested fix
Include env/onsitenv fields in the uniqueness count and duplicate checks, replace NumPy view(-1, 3, 3) with reshape(-1, 3, 3), handle cell is None without dereferencing it, and branch unbatched extra-field masking away from .sum() on slice objects.
This issue comes from a Codex global repository scan.
Problem
Several
AtomicDatacode paths mix PyTorch assumptions into NumPy objects or mishandle optional batched data:register_fields(env_fields=...)andregister_fields(onsitenv_fields=...)always fail becauseallfieldsincludes those fields but the RHS uniqueness count omits them:dftio/dftio/data/AtomicData.py
Lines 141 to 142 in c9d128f
Batched validation uses
ndarray.view(-1, 3, 3), which is not reshape for NumPy arrays:dftio/dftio/data/AtomicData.py
Line 377 in c9d128f
to_ase()enters thecell is Nonebranch and then dereferencescell.shape:dftio/dftio/data/AtomicData.py
Lines 680 to 684 in c9d128f
Unbatched
to_ase(extra_fields=...)sets masks toslice(None)and later calls.sum()on those slices:dftio/dftio/data/AtomicData.py
Lines 729 to 733 in c9d128f
Suggested fix
Include env/onsitenv fields in the uniqueness count and duplicate checks, replace NumPy
view(-1, 3, 3)withreshape(-1, 3, 3), handlecell is Nonewithout dereferencing it, and branch unbatched extra-field masking away from.sum()onsliceobjects.