Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/pygments-2.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpvandermause committed Sep 16, 2024
2 parents 01754f5 + 089273c commit 86051b5
Show file tree
Hide file tree
Showing 44 changed files with 4,644 additions and 349 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
39 changes: 16 additions & 23 deletions .github/workflows/flare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- name: Build
run: |
sudo apt install liblapacke liblapacke-dev
sudo apt install liblapacke liblapacke-dev libopenmpi-dev
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
Expand Down Expand Up @@ -112,11 +112,23 @@ jobs:
cd tests
pytest test_lammps.py
- name: Run tutorial
run: |
pip install -U jupyter nbconvert
cp tutorials/sparse_gp_tutorial.ipynb tutorial.ipynb
jupyter nbconvert --to script tutorial.ipynb
sed -i '/^get_ipython()/s/^/# /' tutorial.py
sed -i '/^plt/s/^/# /' tutorial.py
wget http://quantum-machine.org/gdml/data/npz/md17_aspirin.npz
wget https://www.ctcms.nist.gov/potentials/Download/1999--Mishin-Y-Farkas-D-Mehl-M-J-Papaconstantopoulos-D-A--Al/2/Al99.eam.alloy
python tutorial.py
rm Al* aluminum.txt aspirin.txt md17_aspirin.npz tutorial.ipynb tutorial.py
- name: Install Sphinx and Breathe
run: |
sudo apt-get update
sudo apt-get install python3-sphinx python3-sphinx-rtd-theme python3-breathe python3-nbsphinx
- name: Run Doxygen
uses: mattnotmitt/[email protected]
with:
Expand All @@ -127,11 +139,12 @@ jobs:

- name: Run Sphinx
run: |
export PYTHONPATH=$PYTHONPATH:$PWD/lammps/python
cd docs
pwd
ls
make html
- name: Publish the docs
uses: peaceiris/actions-gh-pages@v3
with:
Expand All @@ -140,23 +153,3 @@ jobs:
# Change the directory if changes in Doxyfile
publish_dir: ./docs/build/html
if: github.event_name == 'pull_request' && matrix.lapack == 'on' && matrix.omp == 'on'

# - name: Run tutorial
# run: |
# cd tests
# # Download colab notebook
# export fileid="18_pTcWM19AUiksaRyCgg9BCpVyw744xv"
# wget -O tutorial.ipynb 'https://docs.google.com/uc?export=download&id='${fileid}
# # Convert notebook into python script
# pip install -U jupyter nbconvert
# jupyter nbconvert --to script tutorial.ipynb
# # Remove bash commands in the notebook
# sed '/!/d' tutorial.txt > tutorial.py
# cat test_tutorial.py tutorial.py > tuttest.py
# # Download datasets needed for the tutorial
# wget http://quantum-machine.org/gdml/data/npz/aspirin_dft.npz
# wget https://www.ctcms.nist.gov/potentials/Download/1999--Mishin-Y-Farkas-D-Mehl-M-J-Papaconstantopoulos-D-A--Al/2/Al99.eam.alloy
# # Run script
# pytest -s tuttest.py
# # Remove output files
# rm Al* aspirin_dft.npz tutorial.ipynb tuttest.py tutorial.py tutorial.txt
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ _C_flare*
**/xml
**/dist
**egg-info
tutorials/Al*
tutorials/*txt*
tutorials/*npz*
tutorials/*checkpoint*
43 changes: 11 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_OSX_ARCHITECTURES "x86_64")

set(FLARE_PYTHON_VERSION "" CACHE STRING "Python version to use for compiling modules")

if(NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -84,34 +86,13 @@ include_directories(${SOURCE_DIR})

# pybind11
###############################################################################
ExternalProject_Add(
pybind11_project
SOURCE_DIR "${CMAKE_BINARY_DIR}/External/pybind11"
URL "https://github.com/pybind/pybind11/archive/v2.3.0.tar.gz"
URL_HASH MD5=e2120c5b0e3c20a93f2dfcdc55026ba8
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
set(PYBIND11_FINDPYTHON ON)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.13.0
)
if (NOT FLARE_PYTHON_VERSION)
set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6 3.5)
endif()
find_package(PythonLibsNew ${FLARE_PYTHON_VERSION} REQUIRED)

add_library(pybind11 INTERFACE)
ExternalProject_Get_Property(pybind11_project SOURCE_DIR)
target_include_directories(pybind11 SYSTEM INTERFACE ${SOURCE_DIR}/include)
target_include_directories(pybind11 SYSTEM INTERFACE ${PYTHON_INCLUDE_DIRS})

if(APPLE)
TARGET_LINK_LIBRARIES(pybind11 INTERFACE "-undefined dynamic_lookup")
message(STATUS "Building in conda environment on MAC")
else()
target_link_libraries(pybind11 INTERFACE ${PYTHON_LIBRARIES})
endif()

# Greatly reduces the code bloat
target_compile_options(pybind11 INTERFACE "-fvisibility=hidden")
FetchContent_MakeAvailable(pybind11)
###############################################################################

# Specify source files.
Expand All @@ -123,6 +104,7 @@ set(FLARE_SOURCES
src/flare_pp/bffs/sparse_gp.cpp
src/flare_pp/bffs/gp.cpp
src/flare_pp/descriptors/descriptor.cpp
src/flare_pp/descriptors/b1.cpp
src/flare_pp/descriptors/b2.cpp
src/flare_pp/descriptors/b2_norm.cpp
src/flare_pp/descriptors/b2_simple.cpp
Expand Down Expand Up @@ -204,11 +186,8 @@ else()
endif()

# Create pybind module.
add_library(flare_module SHARED ${PYBIND_SOURCES})
target_link_libraries(flare_module PUBLIC flare pybind11)
set_target_properties(flare_module PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
add_dependencies(flare_module pybind11_project)
pybind11_add_module(flare_module ${PYBIND_SOURCES})
target_link_libraries(flare_module PUBLIC flare)
set_target_properties(flare_module PROPERTIES OUTPUT_NAME "_C_flare")

# Add test directory.
Expand Down
35 changes: 10 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,40 @@
[![Build Status](https://github.com/mir-group/flare/actions/workflows/flare.yml/badge.svg)](https://github.com/mir-group/flare/actions) [![pypi](https://img.shields.io/pypi/v/mir-flare)](https://pypi.org/project/mir-flare/) [![activity](https://img.shields.io/github/commit-activity/m/mir-group/flare)](https://github.com/mir-group/flare/commits/master) [![codecov](https://codecov.io/gh/mir-group/flare/branch/master/graph/badge.svg)](https://codecov.io/gh/mir-group/flare)

***NOTE: This is the latest release [1.3.3](https://github.com/mir-group/flare/releases/tag/1.3.3) which includes significant changes compared to the previous version [0.2.4](https://github.com/mir-group/flare/releases/tag/0.2.4). Please check the updated tutorials and documentations from the links below.***

# FLARE: Fast Learning of Atomistic Rare Events

<p align="center">
<img width="527" height="242" src="https://github.com/mir-group/flare/blob/master/docs/images/Flare_logo.png?raw=true">
</p>

FLARE is an open-source Python package for creating fast and accurate interatomic potentials.
FLARE is an open-source Python package for creating fast and accurate interatomic potentials.

## Major Features

<p align="center">
<img src="https://github.com/mir-group/flare/blob/development/docs/images/Flare_features.jpg?raw=true">
</p>

Note:

We implement Sparse GP, all the kernels and descriptors in C++ with Python interface.

We implement Full GP, Mapped GP, RBCM, Squared Exponential kernel and 2+3-body descriptors in Python.

Please do NOT mix them.

## Documentations and Tutorials

Documentation of the code can be accessed here: https://mir-group.github.io/flare

[Applications using FLARE and gallery](https://mir-group.github.io/flare/related.html)

### Google Colab Tutorials
### Tutorials

[FLARE (ACE descriptors + sparse GP)](https://colab.research.google.com/drive/1rZ-p3kN5CJbPJgD8HuQHSc7ecmwZYse6).
The tutorial shows how to run flare with ACE and SGP on energy and force data, demoing "offline" training on the MD17 dataset and "online" on-the-fly training of a simple aluminum force field. All the trainings use yaml files for configuration.
[FLARE (ACE descriptors + sparse GP)](https://github.com/mir-group/flare/blob/master/tutorials/sparse_gp_tutorial.ipynb)
This tutorial shows how to run flare with a sparse Gaussian process model trained on energy and force data, demoing "offline" training on the MD17 dataset and "online" on-the-fly training of a simple aluminum force field.

[FLARE (LAMMPS active learning)](https://bit.ly/flarelmpotf)
This tutorial demonstrates new functionality for running active learning all within LAMMPS, with LAMMPS running the dynamics to allow arbitrarily complex molecular dynamics workflows while maintaining a simple interface. This also demonstrates how to use the C++ API directly from Python through `pybind11`. Finally, there's a simple demonstration of phonon calculations with FLARE using `phonopy`.

[FLARE (ACE descriptors + sparse GP) with LAMMPS](https://colab.research.google.com/drive/1qgGlfu1BlXQgSrnolS4c4AYeZ-2TaX5Y).
The tutorial shows how to compile LAMMPS with FLARE pair style and uncertainty compute code, and use LAMMPS for Bayesian active learning and uncertainty-aware molecular dynamics.

[FLARE (ACE descriptors + sparse GP) Python API](https://colab.research.google.com/drive/18_pTcWM19AUiksaRyCgg9BCpVyw744xv).
The tutorial shows how to do the offline and online trainings with python scripts.
A video walkthrough of the tutorial, including detailed discussion of expected outputs, is available [here](https://youtu.be/-FH_VqRQrso).

[FLARE (2+3-body + GP)](https://colab.research.google.com/drive/1Q2NCCQWYQdTW9-e35v1W-mBlWTiQ4zfT).
The tutorial shows how to use flare 2+3 body descriptors and squared exponential kernel to train a Gaussian Process force field on-the-fly.

[Compute thermal conductivity from FLARE and Boltzmann transport equations](https://phoebe.readthedocs.io/en/develop/tutorials/mlPhononTransport.html).
The tutorial shows how to use FLARE (LAMMPS) potential to compute lattice thermal conductivity from Boltzmann transport equation method, with [Phono3py](https://phonopy.github.io/phono3py/) for force constants calculations and [Phoebe](https://mir-group.github.io/phoebe/) for thermal conductivities.

[Using your own customized descriptors with FLARE](https://colab.research.google.com/drive/1VzbIPmx1z-uygKstOYTj2Nqr53AMC5NL?usp=sharing).
[Using your own customized descriptors with FLARE](https://colab.research.google.com/drive/1VzbIPmx1z-uygKstOYTj2Nqr53AMC5NL?usp=sharing).
The tutorial shows how to attach your own descriptors with FLARE sparse GP model and do training and testing.

All the tutorials take a few minutes to run on a normal desktop computer or laptop (excluding installation time).
Expand Down Expand Up @@ -82,7 +68,7 @@ flare++ is tested on a Linux operating system (Ubuntu 20.04.3), but should also

### Hardware requirements
There are no non-standard hardware requirements to download the software and train simple models&mdash;the introductory tutorial can be run on a single cpu. To train large models (10k+ sparse environments), we recommend using a compute node with at least 100GB of RAM.

## Tests
We recommend running unit tests to confirm that FLARE is running properly on your machine. We have implemented our tests using the pytest suite. You can call `pytest` from the command line in the tests directory.

Expand All @@ -94,11 +80,10 @@ pytest
```

## References

If you use FLARE++ including B2 descriptors, NormalizedDotProduct kernel and Sparse GP, please cite the following paper:

> [1] Vandermause, J., Xie, Y., Lim, J.S., Owen, C.J. and Kozinsky, B., 2021. *Active learning of reactive Bayesian force fields: Application to heterogeneous hydrogen-platinum catalysis dynamics.* Nature Communications 13.1 (2022): 5183. https://www.nature.com/articles/s41467-022-32294-0
If you use FLARE active learning workflow, full Gaussian process or 2-body/3-body kernel in your research, please cite the following paper:

> [2] Vandermause, J., Torrisi, S. B., Batzner, S., Xie, Y., Sun, L., Kolpak, A. M. & Kozinsky, B. *On-the-fly active learning of interpretable Bayesian force fields for atomistic rare events.* npj Comput Mater 6, 20 (2020). https://doi.org/10.1038/s41524-020-0283-z
Expand Down
3 changes: 1 addition & 2 deletions ctests/test_descriptor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "b3.h"
#include "descriptor.h"
#include "test_structure.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -43,7 +42,7 @@ class DescTest : public StructureTest {
}
};

using DescTypes = ::testing::Types<B2, B3>;
using DescTypes = ::testing::Types<B1, B2, B3>;
TYPED_TEST_SUITE(DescTest, DescTypes);

//TEST_P(DescRotTest, RotationTest) {
Expand Down
1 change: 1 addition & 0 deletions ctests/test_structure.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "b1.h"
#include "b2.h"
#include "b2_norm.h"
#include "b2_simple.h"
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
breathe_projects = {"flare_pp": "xml"}
breathe_default_project = "flare_pp"
breathe_default_members = ("members", "undoc-members")
napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_use_param = False

# Add any paths that contain templates here, relative to this directory.
Expand Down
1 change: 1 addition & 0 deletions docs/source/flare/learners/learners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Bayesian Active Learning
:maxdepth: 2

otf
lmpotf
gp_from_aimd
utils
5 changes: 5 additions & 0 deletions docs/source/flare/learners/lmpotf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
On-the-Fly Training in LAMMPS
=============================

.. automodule:: flare.learners.lmpotf
:members:
19 changes: 11 additions & 8 deletions docs/source/tutorials/colabs.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
FLARE: Active Learning Bayesian Force Fields
============================================

We have a few Google Colab tutorials that you can check out and play with.
We have a few tutorial notebooks that you can check out and play with.

`FLARE (ACE descriptors + sparse GP <https://colab.research.google.com/drive/1rZ-p3kN5CJbPJgD8HuQHSc7ecmwZYse6>`_.
The tutorial shows how to run flare with ACE and SGP on energy and force data, demoing "offline" training on the MD17 dataset and "online" on-the-fly training of a simple aluminum force field. All the trainings use yaml files for configuration.
`FLARE (ACE descriptors + sparse GP) <https://github.com/mir-group/flare/blob/master/tutorials/sparse_gp_tutorial.ipynb>`_.
This tutorial shows how to run flare with a sparse Gaussian process model trained on energy and force data, demoing "offline" training on the MD17 dataset and "online" on-the-fly training of a simple aluminum force field.

`FLARE (ACE descriptors + sparse GP) with LAMMPS <https://colab.research.google.com/drive/1qgGlfu1BlXQgSrnolS4c4AYeZ-2TaX5Y>`_.
The tutorial shows how to compile LAMMPS with FLARE pair style and uncertainty compute code, and use LAMMPS for Bayesian active learning and uncertainty-aware molecular dynamics.

`FLARE (ACE descriptors + sparse GP) Python API <https://colab.research.google.com/drive/18_pTcWM19AUiksaRyCgg9BCpVyw744xv>`_.
The tutorial shows how to do the offline and online trainings with python scripts.
A video walkthrough of the tutorial, including detailed discussion of expected outputs, is available `here <https://youtu.be/-FH_VqRQrso>`_.
`FLARE (LAMMPS active learning) <https://bit.ly/flarelmpotf>`_.
This tutorial demonstrates new functionality for running active learning all within LAMMPS, with LAMMPS running the dynamics to allow arbitrarily complex molecular dynamics workflows while maintaining a simple interface. This also demonstrates how to use the C++ API directly from Python through `pybind11`. Finally, there's a simple demonstration of phonon calculations with FLARE using `phonopy`.

`FLARE (2+3-body + GP) <https://colab.research.google.com/drive/1Q2NCCQWYQdTW9-e35v1W-mBlWTiQ4zfT>`_.
The tutorial shows how to use flare 2+3 body descriptors and squared exponential kernel to train a Gaussian Process force field on-the-fly.
.. `FLARE (ACE descriptors + sparse GP) Python API <https://colab.research.google.com/drive/18_pTcWM19AUiksaRyCgg9BCpVyw744xv>`_.
.. The tutorial shows how to do the offline and online trainings with python scripts.
.. A video walkthrough of the tutorial, including detailed discussion of expected outputs, is available `here <https://youtu.be/-FH_VqRQrso>`_.
.. `FLARE (2+3-body + GP) <https://colab.research.google.com/drive/1Q2NCCQWYQdTW9-e35v1W-mBlWTiQ4zfT>`_.
.. The tutorial shows how to use flare 2+3 body descriptors and squared exponential kernel to train a Gaussian Process force field on-the-fly.
`Compute thermal conductivity from FLARE and Boltzmann transport equations <https://phoebe.readthedocs.io/en/develop/tutorials/mlPhononTransport.html>`_.
The tutorial shows how to use FLARE (LAMMPS) potential to compute lattice thermal conductivity from Boltzmann transport equation method,
Expand Down
4 changes: 2 additions & 2 deletions examples/test_SGP_Fake_fresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ flare_calc:
- 14
- 6
single_atom_energies:
- 0
- 0
- -7.4
- -8.9
cutoff: 4.0
variance_type: local
max_iterations: 1
Expand Down
4 changes: 2 additions & 2 deletions examples/test_SGP_LMP_fresh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ flare_calc:
- 14
- 6
single_atom_energies:
- 0
- 0
- -7.4
- -8.9
cutoff: 4.0
variance_type: local
max_iterations: 1
Expand Down
2 changes: 1 addition & 1 deletion flare/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.3"
__version__ = "1.4.2"
9 changes: 8 additions & 1 deletion flare/bffs/sgp/sparse_gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,18 @@ def from_dict(in_dict):
rel_efs_noise = train_struc.info.get("rel_efs_noise", [1, 1, 1])
rel_e_noise, rel_f_noise, rel_s_noise = rel_efs_noise

# check for stress training since ASE atoms assert stress arrays of length 6
if not in_dict["stress_training"]:
struc_stress = np.array(None)
else:
struc_stress = train_struc.stress

gp.update_db(
train_struc,
train_struc.forces,
custom_range=custom_range,
energy=energy,
stress=train_struc.stress,
stress=struc_stress,
mode="specific",
sgp=None,
update_qr=False,
Expand Down Expand Up @@ -516,6 +522,7 @@ def duplicate(self, new_hyps=None, new_kernels=None, new_powers=None):

n_kern = len(kernels)
new_gp = SparseGP(kernels, hyps[n_kern], hyps[n_kern + 1], hyps[n_kern + 2])
new_gp.Kuu_jitter = self.sparse_gp.Kuu_jitter

# add training data
sparse_indices = self.sparse_gp.sparse_indices
Expand Down
2 changes: 1 addition & 1 deletion flare/io/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def write_md_header(self, dt, curr_step, dft_step):
else:
string += f"\n*-Frame: {curr_step} "

string += f"\nSimulation Time: {(dt * curr_step):10.3f} ps \n"
string += f"\nSimulation Time: {(dt * curr_step):10.4f} ps \n"
return string

def write_md_config(
Expand Down
Loading

0 comments on commit 86051b5

Please sign in to comment.