Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Test pickling with .yace potential and dimer minimization
Address review: cover the Al-Ni .yace test potential and compare
energies/forces along a whole BFGS dimer minimization trajectory
between the original and the unpickled calculator.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BHj67uGNHN5bMH7LPoCR1J
  • Loading branch information
claude committed Jul 15, 2026
commit 650f717f9a0446a5ff0c8e994ce7b0b8bc615249
39 changes: 30 additions & 9 deletions tests/test_PyACECalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,33 @@ def check(at, msg):
check(at, "ZBL forces are inconsistent")


def check_pickle_roundtrip(calc):
a = create_dimer(2.0)
a.set_calculator(calc)
e1 = a.get_potential_energy()
f1 = a.get_forces()
def minimize_dimer(calc, elements):
from ase.optimize import BFGS

at = Atoms(elements, positions=[[0, 0, 0], [0, 0, 2.0]], pbc=False)
at.set_calculator(calc)

energies = [at.get_potential_energy()]
forces = [at.get_forces()]

opt = BFGS(at, logfile=None)
opt.attach(lambda: (energies.append(at.get_potential_energy()),
forces.append(at.get_forces())))
opt.run(fmax=1e-3, steps=50)

return np.array(energies), np.array(forces)


def check_pickle_roundtrip(calc, elements=("Al", "Al")):
calc2 = pickle.loads(pickle.dumps(calc))

b = create_dimer(2.0)
b.set_calculator(calc2)
e2 = b.get_potential_energy()
f2 = b.get_forces()
# minimize the dimer with the original and the unpickled calculator and
# compare energies/forces along the whole trajectory
e1, f1 = minimize_dimer(calc, elements)
e2, f2 = minimize_dimer(calc2, elements)

assert len(e1) > 1
assert e1.shape == e2.shape
assert np.allclose(e1, e2)
assert np.allclose(f1, f2)
return calc2
Expand All @@ -286,6 +300,13 @@ def test_pickle_ctilde_calculator():
assert isinstance(calc2.evaluator, ACECTildeEvaluator)


def test_pickle_yace_calculator():
calc = PyACECalculator(basis_set="tests/Al-Ni_opt_all.yace")
calc2 = check_pickle_roundtrip(calc, elements=("Al", "Ni"))
assert isinstance(calc2.basis, ACECTildeBasisSet)
assert isinstance(calc2.evaluator, ACECTildeEvaluator)


def test_pickle_ctilde_recursive_calculator():
from pyace.evaluator import ACERecursiveEvaluator

Expand Down