mir-group / flare

An open-source Python package for creating fast and accurate interatomic potentials.
https://mir-group.github.io/flare
MIT License
276 stars 64 forks source link

Bug: Python API cannot save trained model (Segmentation fault, list index out of range) #386

Open m-a-saleh opened 7 months ago

m-a-saleh commented 7 months ago

Describe the bug After training an SGP model using Python, I am not able to save the model. Using sgp_calc.write_model('my_model.json') generates empty "my_model.json" file, and gives the following error:

Traceback (most recent call last):
  File "train_validate.py", line 289, in <module>
    sgp_calc.write_model('my_model.json') #save the the trained model
  File "/home/saleh/miniconda3/envs/flare/lib/python3.8/site-packages/flare/bffs/sgp/calculator.py", line 158, in write_model
    json.dump(self.as_dict(), f, cls=NumpyEncoder)
  File "/home/saleh/miniconda3/envs/flare/lib/python3.8/site-packages/flare/bffs/sgp/calculator.py", line 139, in as_dict
    out_dict["gp_model"] = self.gp_model.as_dict()
  File "/home/saleh/miniconda3/envs/flare/lib/python3.8/site-packages/flare/bffs/sgp/sparse_gp.py", line 205, in as_dict
    train_struc.info["rel_efs_noise"] = np.array(self.rel_efs_noise[s])
IndexError: list index out of range

The bug is: in "sparce_sgp.py", the lists self.atom_indices and self.rel_efs_noise are initialized to empty but never get populated and stay empty.

On the other hand, using sgp_calc.build_map("lmp.flare", "my_name") generates empty "lmp.flare" file and gives the following error:

Segmentation fault (core dumped)

To Reproduce In the example given here, just add sgp_calc.write_model('my_model.json') and sgp_calc.build_map("lmp.flare", "my_name") to the end of the script.

Expected behavior Write "my_model.json" and "lmp.flare" model files.

Desktop (please complete the following information):

YuuuXie commented 6 months ago

@m-a-saleh can you try manually adding rel_efs_noise to sparse gp to get around this error?

m-a-saleh commented 6 months ago

@m-a-saleh can you try manually adding rel_efs_noise to sparse gp to get around this error?

@YuuuXie I managed to get a working .json model file by the follwing steps: 1-edit flare/bffs/sgp/sparse_gp.py by commenting the line train_struc.info["rel_efs_noise"] = np.array(self.rel_efs_noise[s]) in the as_dict() function. This generated a .json file but without rel_efs_noise and atom_indices 2-edit the .json file by addeding rel_efs_noise and atom_indices

The previous steps worked only for the combination(force_training=True, Energy_training=false, stress_training=false). It did not work for energy_trainig=true.

I am still not able to generate lmp.flare file, which still raise seg fault error.

YuuuXie commented 3 months ago

sorry for the late reply. Can you maybe try an earlier version of flare? like 1.3.0?