libAtoms / QUIP

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

RuntimeError in running the tutorial notebook #657

Open yzhang-23 opened 4 months ago

yzhang-23 commented 4 months ago

hi, QUIP developers. I was trying to run the quippy demo notebook on the page https://libatoms.github.io/QUIP/Tutorials/CCP5-June-2021.html#Using-QUIP-with-Python-and-the-Atomic-Simulation-Environment :

from ase.build import bulk
from ase.constraints import ExpCellFilter
from ase.optimize.precon import PreconLBFGS
from quippy.potential import Potential

# construct a potential, usage is the same as `quip` command line
pot = Potential('xml_label=GAP_2017_6_17_60_4_3_56_165',
                param_filename='gp_iter6_sparse9k.xml',
                calc_args='local_gap_variance')

si = bulk('Si', cubic=True) # 8 atom cubic silicon cell
si.calc = pot # associated Atoms with GAP calculator

# relax the unit cell to get equilibrium lattice constant
ecf = ExpCellFilter(si)
opt = PreconLBFGS(ecf, precon=None) # too small for preconditioning
opt.run(fmax=1e-3) # optimize cell and positions (although positions won't change here)
a0 = np.diag(si.cell).mean()
e0 = si.get_potential_energy() / len(si) # ground state energy per atom®

I was using the docker image of QUIP on windows 11. However, I got the following error messages:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-ab591fd60579> in <module>
      7 pot = Potential('xml_label=GAP_2017_6_17_60_4_3_56_165',
      8                 param_filename='gp_iter6_sparse9k.xml',
----> 9                 calc_args='local_gap_variance')
     10 
     11 si = bulk('Si', cubic=True) # 8 atom cubic silicon cell

/usr/local/lib/python3.7/site-packages/quippy/potential.py in __init__(self, args_str, pot1, pot2, param_str, param_filename, atoms, calculation_always_required, calc_args, add_arrays, add_info, **kwargs)
     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

/usr/local/lib/python3.7/site-packages/quippy/potential_module.py in filename_initialise(cls, args_str, param_filename, bulk_scale, error)
    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: 

I really have no clue about what the RuntimeError is. Any hint? Thank you very much for your help!

albapa commented 4 months ago

Is your potential file accessible to the notebook? If you do

!ls

in another notebook cell, do you see gp_iter6_sparse9k.xml in the output?

yzhang-23 commented 4 months ago

Is your potential file accessible to the notebook? If you do

!ls

in another notebook cell, do you see gp_iter6_sparse9k.xml in the output?

The command ! ls showed nothing. Where can I get the file gp_iter6_sparse9k.xml, and where should I put the file? Please forgive me if I am asking some naive questions since I'm a newbie to QUIP. Thanks!

albapa commented 4 months ago

One option is to get it from the silicon testing framework repo: https://github.com/libAtoms/silicon-testing-framework/ in particular: https://github.com/libAtoms/silicon-testing-framework/blob/master/models/GAP/gp_iter6_sparse9k.xml

I don't know how it works on Windows, but if all else fails you can specify the full access path to your file in the param_filename='gp_iter6_sparse9k.xml' line in your code. Or copy the file to the same location where your notebook is.

yzhang-23 commented 4 months ago

One option is to get it from the silicon testing framework repo: https://github.com/libAtoms/silicon-testing-framework/ in particular: https://github.com/libAtoms/silicon-testing-framework/blob/master/models/GAP/gp_iter6_sparse9k.xml

I don't know how it works on Windows, but if all else fails you can specify the full access path to your file in the param_filename='gp_iter6_sparse9k.xml' line in your code. Or copy the file to the same location where your notebook is.

hi, albaqa, thanks for your suggestions. I have downloaded the file gp_iter6_sparse9k.xml and copied it into the container (to the same location where the notebook file is), but still got the same runtime error as above. Is there something wrong in the line calc_args='local_gap_variance' ? Thanks!

albapa commented 4 months ago

In Python you can break lines if they are enclosed within a brackets. So

pot = Potential('xml_label=GAP_2017_6_17_60_4_3_56_165',
                param_filename='gp_iter6_sparse9k.xml',
                calc_args='local_gap_variance')

is one single command and the your notebook is complaining about the whole command. It just happens to be that calc_args='local_gap_variance') is the last line.

I have downloaded the file gp_iter6_sparse9k.xml and copied it into the container (to the same location where the notebook file is),

Did you confirm that you see the file when you do !ls? What you said here

The command ! ls showed nothing.

actually suggests that your current directory is not the same as where your notebook file is - otherwise the command would have showed at least your notebook file. As I said, I don't know how jupyter notebooks work on Windows (and after today, I have even less desire to do anything with Microsoft) or the file structure you are using.

yzhang-23 commented 4 months ago

In Python you can break lines if they are enclosed within a brackets. So

pot = Potential('xml_label=GAP_2017_6_17_60_4_3_56_165',
                param_filename='gp_iter6_sparse9k.xml',
                calc_args='local_gap_variance')

is one single command and the your notebook is complaining about the whole command. It just happens to be that calc_args='local_gap_variance') is the last line.

I have downloaded the file gp_iter6_sparse9k.xml and copied it into the container (to the same location where the notebook file is),

Did you confirm that you see the file when you do !ls? What you said here

The command ! ls showed nothing.

actually suggests that your current directory is not the same as where your notebook file is - otherwise the command would have showed at least your notebook file. As I said, I don't know how jupyter notebooks work on Windows (and after today, I have even less desire to do anything with Microsoft) or the file structure you are using.

I understand how Python is working here, but just suspected that the option line calc_args='local_gap_variance' might cause the issue. Thank you for clarifying this point!

Of course now the "! ls" command shows both the notebook and gp_iter6_sparse9k.xml. I'm sure they are in the same directory. Personally I'm not a super fan of Windows, but there is some restrictions in my work place, so I have to use a Windows machine to run QUIP. I'm running the jupyter notebook in a container using the office docker image of QUIP. Any ideas on what can cause the runtime error above? Your help will be greatly appreciated!

albapa commented 4 months ago

Sorry, I should have said that you also need the sparse point files, which you can find in the same place in the repo.

yzhang-23 commented 4 months ago

Sorry, I should have said that you also need the sparse point files, which you can find in the same place in the repo.

hi, albapa, I have put the file gp_iter6_sparse9k.xml.sparseX.GAP_2017_6_17_60_4_3_56_1651 (this is the sparse point file, right?) under the same directory of the notebook file and run the notebook. But I still got the error messages as the following:

`Exception ignored in: <function Potential.del at 0x7fcca9739200> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/quippy/potential_module.py", line 261, in del quippy._quippy.f90wrap_potential_finalise(this=self._handle, error=error) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' Exception ignored in: <function Potential.del at 0x7fcca9739200> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/quippy/potential_module.py", line 261, in del quippy._quippy.f90wrap_potential_finalise(this=self._handle, error=error) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' Exception ignored in: <function Potential.del at 0x7fcca9739200> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/quippy/potential_module.py", line 261, in del quippy._quippy.f90wrap_potential_finalise(this=self._handle, error=error) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' Exception ignored in: <function Potential.del at 0x7fcca9739200> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/quippy/potential_module.py", line 261, in del quippy._quippy.f90wrap_potential_finalise(this=self._handle, error=error) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' Exception ignored in: <function Potential.del at 0x7fcca9739200> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/quippy/potential_module.py", line 261, in del quippy._quippy.f90wrap_potential_finalise(this=self._handle, error=error) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

RuntimeError Traceback (most recent call last)

in 7 pot = Potential('xml_label=GAP_2017_6_17_60_4_3_56_165', 8 param_filename='/root/gp_iter6_sparse9k.xml', ----> 9 calc_args='local_gap_variance') 10 11 si = bulk('Si', cubic=True) # 8 atom cubic silicon cell /usr/local/lib/python3.7/site-packages/quippy/potential.py in __init__(self, args_str, pot1, pot2, param_str, param_filename, atoms, calculation_always_required, calc_args, add_arrays, add_info, **kwargs) 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 /usr/local/lib/python3.7/site-packages/quippy/potential_module.py in filename_initialise(cls, args_str, param_filename, bulk_scale, error) 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: ` What's the possible reason to cause this? Thanks!