mir-group / flare

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

Can not exclude stresses from training #397

Closed FromColleWithLove closed 1 week ago

FromColleWithLove commented 7 months ago

I would like to train my model on forces and energies, excluding stresses. In my input.yaml i have:

input.yaml [.....] flare_calc:
gp: SGP_Wrapper kernels:

This input worked well for trainings that include stresses, however, once I changed stress_training: False And commented the stress noise, I can not run the training. Instead I would get: output

Traceback (most recent call last): File "[...]/miniconda3/envs/envflare/bin/flare-otf", line 8, in sys.exit(main()) File "[....]/flare/flare/scripts/otf_train.py", line 378, in main fresh_start_otf(config) File "[....]/flare/flare/scripts/otf_train.py", line 324, in fresh_start_otf flare_calc, kernels = get_flare_calc(config["flare_calc"]) File "[....]/flare/flare/scripts/otf_train.py", line 99, in get_flare_calc return get_sgp_calc(flare_config) File "[....]/flare/flare/scripts/otf_train.py", line 295, in get_sgp_calc sgp = SGP_Wrapper( File "[.....]/flare/flare/bffs/sgp/sparsegp.py", line 40, in __init_\ self.sparse_gp = SparseGP(kernels, sigma_e, sigma_f, sigmas) TypeError: __init_\(): incompatible constructor arguments. The following argument types are supported:

  1. flare.bffs.sgp._C_flare.SparseGP()
  2. flare.bffs.sgp._C_flare.SparseGP(arg0: List[flare.bffs.sgp._C_flare.Kernel], arg1: float, arg2: float, arg3: float)

Invoked with: [<flare.bffs.sgp._C_flare.NormalizedDotProduct object at 0x7f8465bdae30>], 0.3, 0.1, None

Information FLARE version: 1.3.3

anjohan commented 7 months ago

Hi,

Based on the error message, it looks like this version of the code requires you to set the energy noise even if you're not training on stress.

FromColleWithLove commented 7 months ago

@anjohan

Based on the error message, it looks like this version of the code requires you to set the energy noise even if you're not training on stress.

Did you mean stress noise? Doing so would just train on stresses anyway. If I disable stress calculation in quantum espresso, and run the otf learning, I would get the classic:

raise PropertyNotImplementedError('{} not present in this ' ase.calculators.calculator.PropertyNotImplementedError: stress not present in this calculation

Re-enabling stress calculation, I would get a training on stress as well. I would get stresses predictions and mae on the output file anyway.

Maybe it would output those without using them, but I can not understand if that is the case. This "stress not present" gives me lots of doubts, why would you need it? For validation maybe?

anjohan commented 7 months ago

Sorry, yes, I meant the stress noise.

From what I can tell, it looks like it might work to set stress_training=False but still provide an arbitrary value for the stress noise. https://github.com/mir-group/flare/blob/700f2c86376a5f439483b55b7b0b2129fd0ca48e/flare/bffs/sgp/sparse_gp.py#L365-L366

Note: I have no familiarity with the YAML file and SGP_Wrapper. We're working on new functionality for active learning directly in LAMMPS documented at https://bit.ly/flarelmpotf in case you want to be a test user.

FromColleWithLove commented 7 months ago

@anjohan

I tried an offline training on a database I had which included stress tensors, and actually by setting stress_training: False and giving a placeholder stress noise value, i got different results and the stress noise wasn't changing, furthermore the likelihood gradient for the stress hyperparameter was always 0. I note that in the end the likelihood was slightly larger, yet also were errors, especially in the case of clusters (even though I expected stresses in large empty cells to be worse defined).

Also the potential made worse predictions, so I think I will keep stresses in there.

We're working on new functionality for active learning directly in LAMMPS documented at https://bit.ly/flarelmpotf in case you want to be a test user.

Really interesting. I will contact you about it, I don't think I can contribute with code but will be happy to help.