-
First of all, I would like to express my gratitude for your efforts in developing the excellent MACE architecture. Recently, I have been considering whether it is possible to package MACE into a .pt file using Torch's JIT technology and then deploy it using C++. This could potentially improve the inference speed of MACE and seamlessly integrate it with my C++ code, which is exactly what I am aiming for. However, after going through the tutorial, it seems that MACE can only function as a calculator that is invoked by the atoms object in ASE for computation. My project does not require ASE, and the presence of ASE creates issues when packaging the model. Ideally, I would like to achieve something like Below is the code I have tried, but it resulted in an error. Could you please advise if MACE can be used independently of ASE, saved as a .pt model, and deployed with the Libtorch library to handle inputs and output energy and force? Thank you for your attention to this matter. `` device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") species = ['C', 'C'] class Wrapper(torch.nn.Module):
wrapped_model = Wrapper() energy, forces = wrapped_model(species, coordinates) print(f"Energy: {energy}") traced_model = torch.jit.script(wrapped_model) traced_model.save("/home/wayne/data/mace/mace_medium.pt")` |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
ASE calculator is not a must as long as you provide a dictionary that is correct for calling If you want to use it in C++, maybe you can look at how it is used in lammps. |
Beta Was this translation helpful? Give feedback.
-
Isn't the neighbor list calculated in python, which would therefore make it impossible to run in pure C++ without some significant supporting code? |
Beta Was this translation helpful? Give feedback.
-
Yes. I would imagine you will have to write an interface for it though not something easy. (please correct me if I am wrong.) |
Beta Was this translation helpful? Give feedback.
-
Hey @CheukHinHoJerry, Yes it is totally possible to run MACE in C++ using torchscript. This exactly how we made the lammps interface, see here: https://github.com/ACEsuit/lammps/blob/mace/src/ML-MACE/pair_mace.cpp#L308. |
Beta Was this translation helpful? Give feedback.
-
I guess you're right. I find a code in Furthermore, I am not quite sure about nblist you guys mentioned, should I provide the model with nblist? |
Beta Was this translation helpful? Give feedback.
-
This is the neighborlist that mace uses which is implemented in C++ https://github.com/libAtoms/matscipy The mace model needs three things form https://github.com/ACEsuit/mace/blob/main/mace/data/neighborhood.py. Calling this equivalently in C++, and then follow how mace serialize the input should work the same as what python gives. Although I would imagine this requires some work. |
Beta Was this translation helpful? Give feedback.
-
As @CheukHinHoJerry and @ilyes319 have said, it is possible to do what you want with a medium amount of effort, particularly if you are an experienced C++ programmer. The exact procedure required will depend on the details of your code (e.g., whether you need a neighbor list, like that available from
|
Beta Was this translation helpful? Give feedback.
-
Just to add - I recently found https://github.com/Luthaf/vesin to be quite easy to use in C++ that they provide a single-file and you can include and link to your own package. Matscipy binds to python interface a lot so would be difficult to call in C++. I don’t have much experience with that yet but my feeling is that using vesin would be easier. |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I found another question. It seems that I can obtain the force by setting
Therefore, what is the difference betweent |
Beta Was this translation helpful? Give feedback.
As @CheukHinHoJerry and @ilyes319 have said, it is possible to do what you want with a medium amount of effort, particularly if you are an experienced C++ programmer. The exact procedure required will depend on the details of your code (e.g., whether you need a neighbor list, like that available from
matscipy
). A few things to consider: