Skip to content

Commit

Permalink
Add GAP implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
frostedoyster committed May 30, 2024
1 parent e7b293f commit 0555c97
Show file tree
Hide file tree
Showing 14 changed files with 1,960 additions and 2 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/gap-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: GAP 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 SparseGAP tests
run: tox -e gap-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
109 changes: 109 additions & 0 deletions docs/src/architectures/gap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.. _architecture-sparse-gap:

GAP
===

This is an implementation of the sparse `Gaussian Approximation Potential
<GAP_>`_ (GAP) using `Smooth Overlap of Atomic Positions <SOAP_>`_ (SOAP)
implemented in `rascaline <RASCALINE_>`_.


.. _SOAP: https://doi.org/10.1103/PhysRevB.87.184115
.. _GAP: https://doi.org/10.1002/qua.24927
.. _RASCALINE: https://github.com/Luthaf/rascaline

The GAP model in metatensor-models can only train on CPU, but evaluation
is also supported on GPU.


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

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

.. code-block:: bash
pip install .[gap]
This will install the package with the GAP dependencies.


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

:param name: ``experimental.gap``

model
#####
soap
^^^^
:param cutoff: Spherical cutoff (Å) to use for atomic environments
:param max_radial: Number of radial basis function to use
:param max_angular: Number of angular basis function to use also denoted by the maximum
degree of spherical harmonics
:param atomic_gaussian_width: Width of the atom-centered gaussian creating the atomic
density
:param center_atom_weight: Weight of the central atom contribution to the features. If
1.0 the center atom contribution is weighted the same as any other contribution. If
0.0 the central atom does not contribute to the features at all.
:param cutoff_function: cutoff function used to smooth the behavior around the cutoff
radius. The supported cutoff function are

- ``Step``: Step function, 1 if ``r < cutoff`` and 0 if ``r >= cutoff``. This cutoff
function takes no additional parameters and can set as in ``.yaml`` file:

.. code-block:: yaml
cutoff_function:
Step:
- ``ShiftedCosine``: Shifted cosine switching function ``f(r) = 1/2 * (1 + cos(π (r
- cutoff + width) / width ))``. This cutoff function takes the ``width``` as
additional parameter and can set as in ``options.yaml`` file as:

.. code-block:: yaml
cutoff_function:
ShiftedCosine:
width: 1.0
:param radial_scaling: Radial scaling can be used to reduce the importance of neighbor
atoms further away from the center, usually improving the performance of the model.
The supported radial scaling functions are

- ``None``: No radial scaling.

.. code-block:: yaml
radial_scaling:
None:
- ``Willatt2018`` Use a long-range algebraic decay and smooth behavior at :math:`r
\rightarrow 0`: as introduced by :footcite:t:`willatt_feature_2018` as ``f(r) =
rate / (rate + (r / scale) ^ exponent)`` This radial scaling function can be set
in the ``options.yaml`` file as.

.. code-block:: yaml
radial_scaling:
Willatt2018:
rate: 1.0
scale: 2.0
exponent: 7.0
.. note::

Currently, we only support a Gaussian type orbitals (GTO) as radial basis functions
and radial integrals.

krr
^^^^
:param degree: degree of the polynomial kernel
:param num_sparse_points: number of pseudo points to select (by farthest point sampling)

training:
^^^^^^^^^
:param regularizer: value of the energy regularizer
:param regularizer_forces: value of the forces regularizer

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ alchemical-model = [
pet = [
"pet @ git+https://github.com/spozdn/pet.git@9f6119d",
]
gap = [
"rascaline-torch @ git+https://github.com/luthaf/rascaline@5348132#subdirectory=python/rascaline-torch",
"skmatter",
"metatensor-learn",
"scipy",
]

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
3 changes: 2 additions & 1 deletion src/metatensor/models/cli/eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import itertools
import logging
from pathlib import Path
from typing import Dict, List, Optional, Union
Expand Down Expand Up @@ -157,7 +158,7 @@ def _eval_targets(
get_system_with_neighbor_lists(system, model.requested_neighbor_lists())

# Infer the device from the model
device = next(model.parameters()).device
device = next(itertools.chain(model.parameters(), model.buffers())).device

# Create a dataloader
dataloader = torch.utils.data.DataLoader(
Expand Down
14 changes: 14 additions & 0 deletions src/metatensor/models/experimental/gap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .model import GAP
from .trainer import Trainer

__model__ = GAP
__trainer__ = Trainer

__authors__ = [
("Alexander Goscinski <[email protected]>", "@agosckinski"),
("Davide Tisi <[email protected]>", "@DavideTisi"),
]

__maintainers__ = [
("Davide Tisi <[email protected]>", "@DavideTisi"),
]
28 changes: 28 additions & 0 deletions src/metatensor/models/experimental/gap/default-hypers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# default hyperparameters for the SparseGAP model
name: gap

model:
soap:
cutoff: 5.0
max_radial: 8
max_angular: 6
atomic_gaussian_width: 0.3
radial_basis:
Gto: {}
center_atom_weight: 1.0
cutoff_function:
ShiftedCosine:
width: 1.0
radial_scaling:
Willatt2018:
rate: 1.0
scale: 2.0
exponent: 7.0

krr:
degree: 2 # degree of the polynomial kernel
num_sparse_points: 500 # number of pseudo points to select, farthest point sampling is used

training:
regularizer: 0.001
regularizer_forces: null
Loading

0 comments on commit 0555c97

Please sign in to comment.