Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALIGNN test on WBM data #37

Merged
merged 20 commits into from
Jun 4, 2023
Merged

ALIGNN test on WBM data #37

merged 20 commits into from
Jun 4, 2023

Conversation

pbenner
Copy link
Collaborator

@pbenner pbenner commented Jun 2, 2023

Added ALIGNN test on WBM data, achieving a MAE of 0.0916. The code needs some double checking to make sure that matbench-discovery is correctly used. coGN would be the next step.

@janosh
Copy link
Owner

janosh commented Jun 3, 2023

This is great, thank you @pbenner! 🎉

Sorry for the slow reply here. Was about to hit send this morning when the day suddenly turned super packed. Needless to say, I'm excited about this 1st external model submission to Matbench Discovery!

I'd thought about running ALIGNN myself but expected it to be similar to MEGNet and so in the end decided against it. But looks like I was wrong. Performance is quite a bit better than expected!

I'll refactor the code here a bit and then start updating all the site metrics. You didn't by any chance log the training and test runs for ALIGNN with wandb?

@janosh janosh added enhancement New feature or request new model Model submission labels Jun 3, 2023
@pbenner
Copy link
Collaborator Author

pbenner commented Jun 3, 2023

Sorry no, had some minor trouble with wandb and excluded it, but should be easy to add to the existing code.

@janosh
Copy link
Owner

janosh commented Jun 3, 2023

@pbenner Just out of curiosity, did you try the pre-trained mp_e_form_alignnn?

from alignn.pretrained import get_figshare_model

model = get_figshare_model("mp_e_form_alignnn")

If not, I'll run it. Would be good to know how it compares to the ALIGNN specifically trained for this benchmark.

Also, looks like we can avoid writing all structures to disk as POSCAR and then reading them in again as Jarvis Atoms. We can convert them directly using JarvisAtomsAdaptor (see fffd6d7).

from pymatgen.io.jarvis import JarvisAtomsAdaptor

@janosh
Copy link
Owner

janosh commented Jun 3, 2023

@pbenner Could you briefly explain the need for alignn-2023.01.10.patch (formerly train_alignn_patch.txt)?

remove now unneeded make_test_data.py
@janosh janosh merged commit 883ee30 into janosh:main Jun 4, 2023
@pbenner
Copy link
Collaborator Author

pbenner commented Jun 5, 2023

I didn't know about the JarvisAtomsAdaptor, that's a good hint!

I tried the pretrained model and got a MAE of 0.1095, so slightly worse. However, I'm not sure if I have to apply some corrections to the energies, so training the model myself seemed safer. In general, predictive performance is quite sensitive to the number of training samples, so it seems best to me to always use the exact same training data instead of pretrained models (at least if the goal is to compare model architectures).

The ALIGNN patch has multiple purposes. First, it fixes some issues when there is no test set (see ALIGNN Issue #104). In this case, we actually forked a test set, but it might be better to use the entire data, as mentioned above, especially if the test set by chance contains some important outliers. Second, the Checkpoint() handler in ALIGNN does not define a score name (see ALIGNN train.py), so it will just save the last two models during training. With this patch, also the best model in terms of accuracy on the validation set is saved, which is the one I use for predictions. This is important, because I used a relatively large n_early_stopping in case the validation accuracy shows a double descent (see Figure 10). Maybe one has to consider here also how individual models are trained, since longer training might be beneficial.

@janosh
Copy link
Owner

janosh commented Jun 6, 2023

I also ran the pre-trained ALIGNN before merging this PR just to check how it compares. The MAE doesn't tell the whole story. As a classifier, it significantly underperforms the ALIGNN trained from scratch for MBD.

Raw pre-trained ALIGNN (mp_e_form_alignn)

photo_2023-06-05 17 49 37

After subtracting the legacy corrections ALIGNN was trained on and adding the new MP 2020 corrections:

Slightly better classification performance but still bad.

photo_2023-06-05 17 49 33


Btw, you can find both the old and new MP corrections in matbench_discovery.data.df_wbm so updating model preds is just two lines: subtract e_correction_per_atom_mp_legacy and add e_correction_per_atom_mp2020.

Speaking of checkpoints, could you send me the checkpoint that was used to make the predictions in this PR? Would be good to provide that for reproducibility.

@pbenner
Copy link
Collaborator Author

pbenner commented Jun 6, 2023

Sure, the model is relatively small, so I just added it to the repo: Alignn best model

@CompRhys
Copy link
Collaborator

CompRhys commented Jun 9, 2023

@pbenner do you know whether it's possible to run your alignn model in a uip-gnn setup where it first relaxes itself according to it's own predictions? In some of the metrics we see what we've been calling a characteristic fire-hook curve which we believe is a function of the task mismatch seen in the IS2RE task that is mostly resolved with uip-relaxed-IS2RE.

@janosh
Copy link
Owner

janosh commented Jun 9, 2023

@CompRhys The original ALIGNN doesn't predict forces. They released a force field version of ALIGNN a year later in 2022 which looks similar to M3GNet. You could use the original ALIGNN to do repeated energy preds to get finite-difference forces but every time I've seen that it worked poorly. The ALIGNN FF would be interesting to add though.

janosh added a commit that referenced this pull request Jun 20, 2023
2023/06/02 Add ALIGNN test on WBM data

* refactor ALIGNN train and test scripts

* add Gibson et al. ref link to perturb_structure() doc str

rename perturb->n_perturb in train_cgcnn.py

* ALIGNN readme add git patch apply instructions

* add alignn/metadata.yml

* param case output dirs

* convert test_alignn_result.json to 2023-06-02-alignn-wbm-IS2RE.csv

* add jarvis-tools, alignn to pyproject running-models optional deps

* test_alignn.py inline load_data_directory() function

* add ALIGNN results to metrics tables and /models page

* fix module name clash with tests/test_data.py causing mypy error

* add test_pretrained_alignn.py

* test_pretrained_alignn.py add wandb logging and slurm_submit()

* gzip 2023-06-02-alignn-wbm-IS2RE.csv

* scripts/readme.md point to module doc strings for details on each script

* drop alignn/requirements.txt (main deps versions are in metadata.yml)

* merge test_pretrained_alignn.py into test_alignn.py

remove now unneeded make_test_data.py

* fix test_pred_files()

* add preds from pretrained mp_e_form_alignn

* change all model pred files from .csv to .csv.gz

---------

Co-authored-by: Philipp Benner <philipp.benner@bam.de>
Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
janosh added a commit that referenced this pull request Jun 20, 2023
2023/06/02 Add ALIGNN test on WBM data

* refactor ALIGNN train and test scripts

* add Gibson et al. ref link to perturb_structure() doc str

rename perturb->n_perturb in train_cgcnn.py

* ALIGNN readme add git patch apply instructions

* add alignn/metadata.yml

* param case output dirs

* convert test_alignn_result.json to 2023-06-02-alignn-wbm-IS2RE.csv

* add jarvis-tools, alignn to pyproject running-models optional deps

* test_alignn.py inline load_data_directory() function

* add ALIGNN results to metrics tables and /models page

* fix module name clash with tests/test_data.py causing mypy error

* add test_pretrained_alignn.py

* test_pretrained_alignn.py add wandb logging and slurm_submit()

* gzip 2023-06-02-alignn-wbm-IS2RE.csv

* scripts/readme.md point to module doc strings for details on each script

* drop alignn/requirements.txt (main deps versions are in metadata.yml)

* merge test_pretrained_alignn.py into test_alignn.py

remove now unneeded make_test_data.py

* fix test_pred_files()

* add preds from pretrained mp_e_form_alignn

* change all model pred files from .csv to .csv.gz

---------

Co-authored-by: Philipp Benner <philipp.benner@bam.de>
Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
@pbenner
Copy link
Collaborator Author

pbenner commented Jun 22, 2023

Just a small update. I am currently testing the ALIGNN-FF model for computing relaxed structures:
https://github.com/pbenner/matbench-discovery/blob/main/models/alignn/alignn_relax.py
It's quite slow, so I have to see how to get results within some reasonable time frame.

@janosh
Copy link
Owner

janosh commented Jun 22, 2023

Nice! 🎉

For CHGnet and M3GNet, I used np.array_split() to split the unrelaxed structures into 100 subsets and then launched slurm jobs to relax each subset in parallel. Takes ~2 hours to get a complete set of predictions on A100s.

df_in: pd.DataFrame = np.array_split(
pd.read_json(data_path).set_index("material_id"), slurm_array_task_count
)[slurm_array_task_id - 1]

@pbenner
Copy link
Collaborator Author

pbenner commented Jun 23, 2023

Thanks! It takes around 10 days on 4 A100 GPUs. Results should be done next week.

@janosh
Copy link
Owner

janosh commented Jun 23, 2023

Sweet, looking forward to it!

@pbenner
Copy link
Collaborator Author

pbenner commented Jul 11, 2023

The relaxed predictions are finally done! You can find the results here:
https://github.com/pbenner/matbench-discovery/tree/alignn/models/alignn

I'm not filing a pull request, because my repository contains the full set of relaxed structures, which you might want to upload to figshare. I had a lot of fun computing the relaxed structures. Some of them converged very poorly, which is why this computation took so long. Also it seems that the prediction error went up. Unfortunately, there is also a bug in ALIGNN or ASE:

Traceback (most recent call last):
  File "alignn_relax.py", line 96, in <module>
  File "alignn_relax.py", line 88, in alignn_relax
  File "../alignn/ff/ff.py", line 310, in optimize_atoms
  File "../alignn/lib/python3.9/site-packages/ase/optimize/optimize.py", line 269, in run
  File "../alignn/lib/python3.9/site-packages/ase/optimize/optimize.py", line 156, in run
  File "../alignn/lib/python3.9/site-packages/ase/optimize/optimize.py", line 129, in irun
  File "../alignn/lib/python3.9/site-packages/ase/optimize/optimize.py", line 108, in call_observers
  File "../alignn/lib/python3.9/site-packages/ase/io/trajectory.py", line 132, in write
  File "../alignn/lib/python3.9/site-packages/ase/io/trajectory.py", line 156, in _write_atoms
  File "../alignn/lib/python3.9/site-packages/ase/io/trajectory.py", line 381, in write_atoms
  File "../alignn/lib/python3.9/site-packages/ase/io/ulm.py", line 400, in write
  File "../alignn/lib/python3.9/site-packages/ase/io/ulm.py", line 325, in fill
OSError: [Errno 24] Too many open files

which forced me to turn off any logging/trajectories. To debug we would have to recompute some trajectories, but the ones that converge poorly take several days to finish.

@janosh
Copy link
Owner

janosh commented Jul 11, 2023

The relaxed predictions are finally done! You can find the results here:

Excellent. That's great news!

I'm not filing a pull request, because my repository contains the full set of relaxed structures, which you might want to upload to figshare.

Sounds good. I'll start prepping a PR with your code and results then?

the ones that converge poorly take several days to finish.

What?! That sounds problematic. You're saying some of the 100 test set batches (~2500 structures) took several days? If so, suggests lack of robustness to data variety in the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new model Model submission
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants