Skip to content

[Code scan] Inference-efficiency expansion crashes when a structure exceeds the atom cap #436

Description

@njzjz

This issue was found by a Codex global repository scan of tracked non-test files at commit 8c93925cb10b401b2b83c738bd9263fd74474468.

Relevant code

efficiency = []
for i, atoms in enumerate(test_atoms):
# find maximum allowed natoms
max_natoms = binary_search_max_natoms(model, atoms, natoms_upper_limit)
# on-the-fly expand atoms
scaling_factor = np.int32(np.floor(max_natoms / len(atoms)))
a, b, c = find_even_factors(scaling_factor) # a,b,c is in ascending order
cell_length = atoms.get_cell_lengths_and_angles()[:3]
scaling_index = np.argsort(
cell_length
).tolist() # sort cell length by ascending order
# expand atoms, repeat shorter cell axis with larger scaling factor
a, b, c = (
[c, b, a][scaling_index[0]],
[c, b, a][scaling_index[1]],
[c, b, a][scaling_index[2]],
)
atoms = atoms.repeat((a, b, c))
model.calc.reset() # reset calculator to prevent cached results
atoms.calc = model.calc

divisors = set()
for i in range(1, int(math.isqrt(num)) + 1):
if num % i == 0:
divisors.add(i)
divisors.add(num // i)
return sorted(divisors)
def find_even_factors(num: int) -> tuple[int, int, int]:
"""
Find three factors of a number that are as evenly distributed as possible.
The function returns a tuple of three factors (a, b, c) such that a * b * c = num.
The factors are sorted in ascending order (a <= b <= c).
"""
divisors = get_divisors(num)
best = None
min_spread = float("inf")
for a in divisors:
num_div_a = num // a
divisors_b = get_divisors(num_div_a)
# Since a <= b <= c, no need to consider b < a
for b in divisors_b:
if b < a:

Impact

When len(atoms) > natoms_upper_limit, scaling_factor = floor(max_natoms / len(atoms)) becomes 0. find_even_factors(0) returns None, so unpacking a, b, c raises before inference can run.

That turns an oversized input structure into a task-level failure instead of benchmarking the original structure or reporting a controlled skip.

Suggested fix

Clamp the expansion factor to at least 1, or explicitly skip expansion and benchmark the original structure when the cap is below the input atom count. Add a regression test with len(atoms) > natoms_upper_limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions