-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store additional properties in ASE calculator #658
Conversation
Why did you go with this approach instead of automatically storing energy/energies when computing the forces and stress? The fact that one has to explicitly set these is not ideal, and I feel like a solution to #655 that works without explicit user action would be nicer. |
1797ad8
to
42a8abd
Compare
This was not intended as a fix for #655 (although it is if one knows the internals). It's just to propagate potentially more outputs to the user |
Ok, the initially intended API for doing outputs outside of ASE specification was the |
It looks to me like it recomputes everything... |
No, because this function is not integrated with the rest of ASE interface ( calculator = MetatensorCalculator(...)
outputs = {...}
calculator.run_model(atoms, outputs) Since the user is explicitly calling this function themself, it will only recompute if the users call it again manually. In general there are two separate issues IMO: #655 is about storing multiple that ASE knows about (storing energy when computing forces, etc.); while We need a fix for #655, but I don't think that |
The fact that it is not integrated with the rest of ASE is why the recomputations are necessary. If I need a quantity at some step of MD, I have to recompute, while in principle the same quantity would have been available together with the energy computation at near-zero overhead |
python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py
Outdated
Show resolved
Hide resolved
python/metatensor-torch/metatensor/torch/atomistic/ase_calculator.py
Outdated
Show resolved
Hide resolved
Hello, Yuxuan and I have ported a preliminary chemical shielding model to an ase-MetatensorCalculator. calc = MetatensorCalculator("model.pt")
frame.set_calculator(calc)
cs_iso = frame.get_properties(["mtt::cs_iso"]) However, currently it requires doing this, which I find not so intuitive: output = calc.run_model(frame, outputs)
cs_iso = output['mtt::cs_iso'].block(0).values.detach().numpy() I personally feel like the results should be stored in the results dict as numpy arrays, that way models can be used from users outside the metatensor universe. |
This PR would remove the need to explicitly call
This is not possible for fully generic metatensor outputs, since they could have multiple keys/blocks, and then this function would not know what to do with them. I agree that doing things like this would be nice, but it does not fit in the ASE calculator framework. We could however define a new API that could do what you are asking for standardized outputs, with something like this calc = MetatensorCalculator("model.pt")
cs_iso = calc.get_metatensor_property(atoms, "scalar_chemical_shielding")
assert isinstance(cs_iso, np.ndarray) This requires first defining what the standard outputs are and what I'll open a separate issue to discuss this further, this PR is mainly aimed at things that should be computed together with the energy/forces. |
These changes allow for a user to calculate and store non-standard properties in the ASE calculator. For relatively experienced users, this is also a fix for #655 (one can set"energy", "forces", "stress"
asproperties_to_store
, these will be calculated at each step, and then the inheritedget_property
function will not re-trigger a calculation but just read from thecalc.results
dict).This PR now only contains code to compute energy/forces/stress when one of the three has been requested.
Contributor (creator of pull-request) checklist
Reviewer checklist
📚 Download documentation preview for this pull-request