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

Implement the Alchemical Model from torch_alchemical repo #66

Merged
merged 40 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
53ac431
Initial commit for Alchemical Model
abmazitov Feb 8, 2024
3b82869
Fix of the regression test
abmazitov Feb 8, 2024
be6afa3
Merge branch 'main' into alchemical-model
abmazitov Feb 8, 2024
e4004c1
Update to master branch
abmazitov Feb 8, 2024
2911f9b
Added WIP example for Alchemical Model
abmazitov Feb 8, 2024
67939d4
Added docs for Alchemical Model
abmazitov Feb 8, 2024
2bdb5cb
Linting fix
abmazitov Feb 8, 2024
f4a1d6d
Added workflow for Alchemical Model tests
abmazitov Feb 8, 2024
b492cfe
Fixed workflow name
abmazitov Feb 8, 2024
ec73b36
Added the NL calculation in the training and fixed example
abmazitov Feb 9, 2024
4734372
Merge branch 'main' into alchemical-model
abmazitov Feb 13, 2024
62c97de
Updated train.py to use the mt-learn Dataset and Dataloader
abmazitov Feb 13, 2024
68e205c
Fixed the Dataset usage in normalize.py
abmazitov Feb 13, 2024
e14526e
Removed the metatensor hotfix
abmazitov Feb 13, 2024
a6e8ed5
Small fixes of docs and tests
abmazitov Feb 13, 2024
1d759bf
Added the rascaline NL calculator
abmazitov Feb 13, 2024
caa66f4
Replaced the HEA dataset in the example and fixed the normalize.py
abmazitov Feb 14, 2024
96dcd25
Added NLs workaround
abmazitov Feb 16, 2024
739b11e
Fixed the dataset in the Alchemical Model example
abmazitov Feb 16, 2024
8ca75d9
Fixed linting
abmazitov Feb 16, 2024
920db42
Merge branch 'main' into alchemical-model
abmazitov Feb 16, 2024
1834089
Added model wrapping with MetatensorAtomisticModel in tests
abmazitov Feb 16, 2024
54866d6
Linting fix
abmazitov Feb 16, 2024
8413adc
Fixed training and evaluation example
abmazitov Feb 16, 2024
4f407f7
Handle neighbor lists in systems creation for stresses
frostedoyster Feb 17, 2024
99a2cca
Avoid filtering out all UserWarnings
frostedoyster Feb 17, 2024
4e9e995
Temporary save of changes before merging main
abmazitov Feb 19, 2024
8ae033b
Merge branch 'alchemical-model' of https://github.com/lab-cosmo/metat…
abmazitov Feb 19, 2024
0b18f08
Attempting to merge main into alchemical-model branch
abmazitov Feb 19, 2024
27c7065
Revorked NLs calculation
abmazitov Feb 19, 2024
4312b8a
Updated the example for Alchemical Model
abmazitov Feb 19, 2024
5843cf8
Updating the brach according to comments
abmazitov Feb 19, 2024
ea481c1
Added missing docs
abmazitov Feb 19, 2024
3dc28ca
Added citations
abmazitov Feb 19, 2024
af079cd
Fixed the hea test dataset sample
abmazitov Feb 19, 2024
8c0ba1e
Linting fix
abmazitov Feb 19, 2024
2ebf2bc
Fixed the alchemical_model.yaml file name
abmazitov Feb 19, 2024
cc304f5
Remove unused parameter from yaml file
frostedoyster Feb 20, 2024
a35e064
Allow training on different device and dtype
frostedoyster Feb 20, 2024
1d03698
Change order of composition and normalization
frostedoyster Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/alchemical-model-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Alchemical Model tests

on:
push:
branches: [main]
pull_request:
# Check all PR

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
python-version: "3.11"

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox

- name: run Alchemical Model tests
run: tox -e alchemical-model-tests
env:
# Use the CPU only version of torch when building/running the code
PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu

- name: Upload codecoverage
uses: codecov/codecov-action@v3
with:
files: ./tests/coverage.xml
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ atomistic model.
* - SOAP BPNN
- A Behler-Parrinello neural network with SOAP features

* - Alchemical Model
- A Behler-Parrinello neural network with SOAP features
and Alchemical Compression of the composition space

.. marker-documentation

Documentation
Expand Down
46 changes: 46 additions & 0 deletions docs/src/architectures/alchemical-model.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. _architecture-alchemical-model:

Alchemical Model
frostedoyster marked this conversation as resolved.
Show resolved Hide resolved
================

This is an implementation of Alchemical Model: a Behler-Parrinello neural network
frostedoyster marked this conversation as resolved.
Show resolved Hide resolved
with SOAP features and Alchemical Compression of the composition space. This model
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with SOAP features and Alchemical Compression of the composition space. This model
with SOAP features and alchemical compression of the composition space. This model

is extremely useful for simulating systems with large amount of chemical elements.

For further details, please refer to the original papers:

- Willatt, Michael J., Félix Musil, and Michele Ceriotti. "Feature optimization for
atomistic machine learning yields a data-driven construction of the periodic table of
the elements." Physical Chemistry Chemical Physics 20.47 (2018): 29661-29668.

- Lopanitsyna, Nataliya, et al. "Modeling high-entropy transition metal alloys with
alchemical compression." Physical Review Materials 7.4 (2023): 045802.

- Mazitov, Arslan, et al. "Surface segregation in high-entropy alloys from alchemical
machine learning." arXiv preprint arXiv:2310.07604 (2023).
frostedoyster marked this conversation as resolved.
Show resolved Hide resolved


Installation
------------

To install the package, you can run the following command in the root
directory of the repository:

.. code-block:: bash

pip install .[alchemical-model]

This will install the package with the Alchemical Model dependencies.


Hyperparameters
---------------

The hyperparameters (and relative default values) for the Alchemical Model model are:

.. literalinclude:: ../../../src/metatensor/models/cli/conf/architecture/alchemical_model.yaml
:language: yaml

Any of these hyperparameters can be overridden with the training parameter file.


2 changes: 2 additions & 0 deletions examples/alchemical_model/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Basic usage of the Alchemical Model CLI
frostedoyster marked this conversation as resolved.
Show resolved Hide resolved
========================================
4,172 changes: 4,172 additions & 0 deletions examples/alchemical_model/hea_samples_bulk.xyz

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions examples/alchemical_model/options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# architecture used to train the model
architecture:
name: alchemical_model

# Mandatory section defining the parameters for structure and target data of the
# training set
training_set:
structures: "hea_samples_bulk.xyz" # file where the positions are stored
targets:
energy:
key: "energy" # name of the target value
forces: false
stress: false

test_set: 0.1 # 10 % of the training_set are randomly split and taken for test set
validation_set: 0.1 # 10 % of the training_set are randomly split and for validation
35 changes: 35 additions & 0 deletions examples/alchemical_model/usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!\bin\bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want this for each model in the docs, right @PicoCentauri? However, maybe we can leave the example here and run it from the test CI of the alchemical model

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I would not duplicate this file. If we want this to be a test, let's make it a test and not an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, then I'll delete this file


metatensor-models train options.yaml

# The functions saves the final model `model.pt` to the current output folder for later
# evaluation. All command line flags of the train sub-command can be listed via

metatensor-models train --help

# We now evaluate the model on the training dataset, where the first arguments specifies
# the model and the second the structure file

metatensor-models eval model.pt qm9_reduced_100.xyz

# The evaluation command predicts the property the model was trained against; here "U0".
# The predictions together with the structures have been written in a file named
# ``output.xyz`` in the current directory. The written file starts with the following
# lines

head -n 20 output.xyz

# All command line flags of the eval sub-command can be listed via

metatensor-models eval --help

# However, before we export the model, we need to run the following command to
# hotfix errors in metatensor.

python ../../scripts/hotfix_metatensor.py

# Finally, the `metatestor-models export`, i.e.,

metatensor-models export model.pt

# creates an `exported-model.pt` file that contains the exported model.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ build-backend = "setuptools.build_meta"

[project.optional-dependencies]
soap-bpnn = []
alchemical-model = [
"torch_alchemical @ git+https://github.com/abmazitov/torch_alchemical.git",
Luthaf marked this conversation as resolved.
Show resolved Hide resolved
Luthaf marked this conversation as resolved.
Show resolved Hide resolved
]

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
2 changes: 2 additions & 0 deletions src/metatensor/models/alchemical_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .model import Model, DEFAULT_HYPERS # noqa: F401
from .train import train # noqa: F401
Loading
Loading