libAtoms / QUIP

libAtoms/QUIP molecular dynamics framework: https://libatoms.github.io
347 stars 122 forks source link

quippy.Potential reading problem #544

Open yuxzhou opened 1 year ago

yuxzhou commented 1 year ago

Dear developers and users,

I have fitted a potential using the mpi version of gap_fit on Archer2, and tried to validate it comparing to my previously fitted potential (with the same reference dataset). However, I can't use the quippy.Potential to read the new mpi potential in my python code.

This is what I did in my python script:

pot2='/dir_to_potential/gap.xml'
calc2=Potential(param_filename=pot2)

I received the error shown below:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[10], line 1
----> 1 calc2=Potential(param_filename=pot2)

File ~/anaconda3/envs/zyx-py3.8/lib/python3.8/site-packages/quippy/potential.py:81, in Potential.__init__(self, args_str, pot1, pot2, param_str, param_filename, atoms, calculation_always_required, calc_args, add_arrays, add_info, **kwargs)
     78 # init the quip potential
     79 if param_filename is not None and isinstance(param_filename, str):
     80     # from a param filename
---> 81     self._quip_potential = quippy.potential_module.Potential.filename_initialise(args_str=args_str,
     82                                                                                  param_filename=param_filename)
     83 elif pot1 is not None and pot2 is not None:
     84     # from sum of two potentials
     85     # noinspection PyProtectedMember
     86     self._quip_potential = quippy.potential_module.Potential(
     87         args_str=args_str,
     88         pot1=(pot1._quip_potential if isinstance(pot1, quippy.potential.Potential) else pot1),
     89         pot2=(pot2._quip_potential if isinstance(pot2, quippy.potential.Potential) else pot2))

File ~/anaconda3/envs/zyx-py3.8/lib/python3.8/site-packages/quippy/potential_module.py:134, in Potential.filename_initialise(cls, args_str, param_filename, bulk_scale, error)
    132 bare_class = cls.__new__(cls)
    133 f90wrap.runtime.FortranDerivedType.__init__(bare_class)
--> 134 result = quippy._quippy.f90wrap_potential_filename_initialise(args_str=args_str, param_filename=param_filename, \
    135     bulk_scale=None if bulk_scale is None else bulk_scale._handle, error=error)
    136 bare_class._handle = result[0] if isinstance(result, tuple) else result
    137 return bare_class

RuntimeError: 

Do you have any suggestions on this?

Thank you!

jameskermode commented 1 year ago

Most likely the path to the .xml file is wrong - should it really start with a '/', which denotes an absolute path from the root of the filesystem?

yuxzhou commented 1 year ago

Many thanks for this!

I have checked the absolute dir and also update the quippy to the latest version, and it works! After this, I compare the predicted energies and forces of the same structure using both the mpi potential and openmp potential, both of which were fitted using the same reference database and the same hypers.

However, I found that the mpi potential behaves differently with my previous openmp potential.

I followed the exactly same process as you suggested: (1) do only sparsification first using one node; (2) generate input files using the python script gap_prepare_sparsex_input.py; (3) create a new folder, copy all input files and xyz file to the folder and run a mpi gap_fit with separately specified gaps (i.e., gap={ {gap1}:{gap2}:...:{gap9} }, six two-body terms and three soap terms). The reference database for both mpi and openmp potential is the same.

But I think I have two different potentials, not only with different fitting coefficiencies but also different predicted energies and forces from my tests.

I'm not sure if it is appropriate to post this issue here but do you have any suggestions or comments?

Thank you again for you help!

bernstei commented 1 year ago

I think that the gap_rss sparsification is by default stochastic, and if that's true, unless you pass a seed and the random numbers are used in exactly the same way in the OpenMP and MPI parallelized versions of the sparsification (likely, but not guaranteed unless someone thought about this aspect), you'd expect small changes in the resulting model and its predictions. In fact, you can in some sense use those variations as a committee to estimate uncertainty.

jameskermode commented 1 year ago

How different are the energy and force values for the two potentials?

yuxzhou commented 1 year ago

A quick test: I calculated the energy and forces for two different structures - one is an amorphous structure (on which the potentials are specifically trained) and the other one is a highly disordered liquid structure at elevated temperatures.

It seems quite reasonable since the regularization parameters for energy and forces are 0.01 and 0.2 separately. So if two potentials are generated using different random seeds, I assume that the numeric differences between two different potentials should also lie in this uncertainty (regularization) range (namely, 0.01 for energy and 0.2 for forces)?

However, I also see some differences in running practical MD simulations for these two potentials. In some melt-quench MD simulations which starts at high temperatures (e.g., 3000K), the mpi potential will predict a very large forces which caused super large pressures (e.g., 100k - 200k bars) and led to lost atoms in LAMMPS. This doesn't happen in the openmp potential with the same starting configurations.

BTW, thanks so much for @bernstei 's comments on the idea of using the variations from independently fitted potentials as a committee to estimate uncertainty, which can be used in some active learning algorithms I think.

Baristali commented 1 year ago

However, I also see some differences in running practical MD simulations for these two potentials. In some melt-quench MD simulations which starts at high temperatures (e.g., 3000K), the mpi potential will predict a very large forces which caused super large pressures (e.g., 100k - 200k bars) and led to lost atoms in LAMMPS. This doesn't happen in the openmp potential with the same starting configurations.

I think it's not a problem of the potential. I made a mpi potential and also was employed to melt-quench simulation for producing an amorphous model. It works fine at molten temperature and quench process even if some unphysical configurations appeared in the amorphous model.

yuxzhou commented 1 year ago

One quick question: can the current quippy package reads in the mpi potential which is fitted using the latest version of gap_fit (QUIP) code?

I installed the latest version of quippy using pip install quippy-ase and the version is 0.9.12. However, when I try to read the new mpi potential and call Potential, an error comes out saying that Database was created with a later version of the code.Version of code used to generate the database is 1675289491.Version of current code is 1673447045. Please update your code.

It seems that the quippy has to be updated before reading any new mpi potentials?

bernstei commented 1 year ago

It's always true that the code used to evaluate a GAP potential has to be at least as new as the one used to create it, to ensure compatibility.

yuxzhou commented 1 year ago

Thanks. Can I use pip to install the latest version of quippy, or shall I manually intall it via make?

jungsdao commented 1 year ago

I'm having same problem with GAP version when reading GAP with quippy.potential. I received error message as following. RuntimeError: Database was created with a later version of the code.Version of code used to generate the database is 1643998566.Version of current code is 1631710424. Please update your code.

I realized that I can search for gap_version in my potential file (**.xml) and when I replace that particular line of GAP version to current version number (1643998566 --> 1631710424), it works fine as expected. I think it could be easy way around for this problem rather than reinstalling QUIP and so on. But I wonder would this be problematic for evaluation of some properties or source of unexpected behavior. If anyone have idea on this way of solution (whether it's okay or not), I would be happy to listen! Thank you in advance

Best Hyunwook

gabor1 commented 1 year ago

We only update the pypi version infrequently. so if you really want to work with the latest code, install it manually

gabor1 commented 1 year ago

can I close this?

jungsdao commented 1 year ago

I think you can.. sorry for late reply but thank you for your comment!On 18. May 2023, at 10:40, gabor1 @.***> wrote: can I close this?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>