megnet icon indicating copy to clipboard operation
megnet copied to clipboard

Can MEGNet be made end-to-end differentiable wrt atomic positions of atoms?

Open CompRhys opened this issue 2 years ago • 8 comments

How hard would it be to change the construction of the local environment graph to be end-to-end differentiable? This would involve the neighbour list function inside pymatgen being refactored to include a sub-function that returns the index and image index allowing the distances to be computed from TF tensors of the atom positions?

Thinking about BOWSR there would be some benefit to regularising the force predictions of the MEGNet surrogate model to be ~0 given that it is trained on the relaxed structures in MP. As far as I understand the model is not currently given any signal about these structures being local minima.

CompRhys avatar Nov 07 '21 17:11 CompRhys

link to #170

CompRhys avatar Nov 07 '21 17:11 CompRhys

@CompRhys For the pymatgen part, i have done the function you described. Try get_neighbor_list method of Structure.

End-to-end is definitely doable by starting from atom positions.

chc273 avatar Nov 07 '21 18:11 chc273

For the idea on BOWS, what you described is correct. I think this is definitely worth trying by including the force regularization. Please keep me posted, thanks!

chc273 avatar Nov 07 '21 18:11 chc273

Am mostly a pytorch user but if the function is already implemented I will have a look at whether it's easy to make the change here after I submit my thesis in a few weeks. Conceivably the change should be hot swappable provided there are no issues arising out of differences in precision between numpy arrays and TF tensors.

CompRhys avatar Nov 07 '21 21:11 CompRhys

@chc273 did you implement this in order to run the phonon calcs with m3gnet?

CompRhys avatar Mar 07 '22 00:03 CompRhys

@CompRhys Do you mean energy derivative to calculate the forces? Yes. m3gnet will be a new codebase though

chc273 avatar Mar 07 '22 04:03 chc273

Yep, will await new codebase and see if it can be back ported. Is new code also TF based?

CompRhys avatar Mar 11 '22 06:03 CompRhys

@CompRhys thanks. Yes, the code is in TF.

chc273 avatar Mar 11 '22 17:03 chc273