Conversation
zulissimeta
self-requested a review
September 30, 2026 20:47
zulissimeta
approved these changes
Sep 30, 2026
zulissimeta
left a comment
Contributor
There was a problem hiding this comment.
Great catch! Thanks for the PR.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FormationEnergyCalculator.calculate() calls the wrapped calculator directly but never calls Calculator.calculate(self, ...), so the wrapper's self.atoms is never set. ASE's check_state then reports changes on every access, and every get_potential_energy / get_forces / get_stress call reruns the full model even when nothing changed.
In practice this hurts relaxations and MD a lot, since optimizers read energy and forces separately. With a call-counting EMT wrapped in FormationEnergyCalculator, a 10-step BFGS run did 44 base calculations on main vs 11 with this change.
The fix calls Calculator.calculate(self, ...) first so ASE can cache, and copies the check_state override from FAIRChemCalculator so changing atoms.info (charge/spin) still triggers a recompute.
Added test_formation_energy_calculator_caches_results. It uses a small counting calculator (no checkpoint needed) and checks that repeated reads hit the base calculator once, and that moving atoms or changing atoms.info recomputes. It fails on main and passes here. ruff (pinned 0.5.1) is clean.