Skip to content

Commit

Permalink
Merge branch 'main' into numpy-update
Browse files Browse the repository at this point in the history
  • Loading branch information
juraskov authored Nov 29, 2024
2 parents f5f25e3 + db7c4a7 commit 65941ce
Show file tree
Hide file tree
Showing 37 changed files with 558 additions and 189 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
gha-dependencies:
patterns:
- '*'
5 changes: 4 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
pull_request:

env:
FORCE_COLOR: 1

jobs:
pre-commit:
env:
Expand All @@ -15,4 +18,4 @@ jobs:
uses: actions/checkout@v4

- name: Run pre-commit
uses: pre-commit/action@v3.0.0
uses: pre-commit/action@v3.0.1
72 changes: 58 additions & 14 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ on:
branches: [main]
pull_request:

env:
FORCE_COLOR: 1

jobs:
test:
name: GAP (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.9"]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1

- uses: mamba-org/setup-micromamba@v2
with:
# the create command looks like this:
# `micromamba create -n test-env python=3.9 -f environment.yml`
Expand All @@ -38,7 +41,7 @@ jobs:
run: ./install_gap.sh

- name: Test basic install
run: pytest --cov -k "not test_openmm"
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand All @@ -47,25 +50,66 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
slug: duartegroup/mlp-train

test-ace:
name: ACE (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-22.04"]
python-version: ["3.9"]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@v2
with:
version: '1.6'

- uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment_ace.yml
environment-name: gha-test-env
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}
- name: ACE install
run: ./install_ace.sh

- name: Test ACE
run: pytest --cov=mlptrain -k "not test_openmm"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
flags: python-${{ matrix.python-version }}-ace
token: ${{ secrets.CODECOV_TOKEN }}
slug: duartegroup/mlp-train

test-mace:
name: MACE (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
os: ["ubuntu-22.04"]
python-version: ["3.9"]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@v1

- uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment_mace.yml
environment-name: gha-test-env
Expand All @@ -77,7 +121,7 @@ jobs:
run: ./install_mace.sh

- name: Test MACE install
run: pytest --cov
run: pytest --cov=mlptrain

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: check-shebang-scripts-are-executable
- id: check-added-large-files
args: ['--maxkb=500', '--enforce-all']
exclude: mlptrain/sampling/tests/data.zip
exclude: tests/data/data.zip
- id: check-yaml
- id: check-toml

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![DOI](https://img.shields.io/badge/doi-10.6084/m9.figshare.25816864.v1-blue.svg?style=flat&labelColor=whitesmoke&logo=data%3Aimage%2Fp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ZsM7l4s5gAQuUAzRUoT51hnH3EWofXf2vkD5HJJ33vwE%2FaEWp36GHr6GpMaH4AAPuqM5eabH%2FhfG9zcCz4nN6cPinuAw6IHwtvyB%2FdO1toZciBaPh25U0ducR2PI3Zl7mokyLWKkSnEDOg1x5fCsJE9EKhH7HwFNhWMGMS7%2BqxyYsbHHRUDUH4I%2FAheQY7wujJNnFUH4KdCju83riuQeHU9WEqNzjsJFuF%2FdTDAZ%2FK7%2F1WaAU%2BAWymT59pVMT4g2AxcwNa0XEBDdBDpAPvgDIH73R25teeuAF5ime2Ul0OUIiG4GpSAEJeYW9wDTf43wfwHgHLKJoPznkwAAAABJRU5ErkJggg%3D%3D)](https://doi.org/10.6084/m9.figshare.25816864.v1)
[![pytest CI](https://github.com/duartegroup/mlp-train/actions/workflows/pytest.yml/badge.svg?event=push)](https://github.com/duartegroup/mlp-train/actions/workflows/pytest.yml)
[![codecov](https://codecov.io/gh/duartegroup/mlp-train/branch/main/graph/badge.svg)](https://codecov.io/gh/duartegroup/mlp-train)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![License](https://img.shields.io/badge/License-MIT%202.0-blue.svg)](https://opensource.org/licenses/mit)
[![GitHub issues](https://img.shields.io/github/issues/duartegroup/mlp-train.svg)](https://github.com/duartegroup/mlp-train/issues)

# mlp-train
General machine learning potentials (MLP) training for molecular systems in gas phase and solution
Expand All @@ -16,7 +16,7 @@ Available models:

## Install

Each model is installed into individual conda environment:
Each model is installed into an individual conda environment:

```
# Install GAP
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- cython
- dscribe=2.0
- matplotlib-base
- numpy
- numpy<2
- pytest=8
- pytest-cov=5
- py-plumed
Expand Down
2 changes: 1 addition & 1 deletion environment_ace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- cython
- dscribe=2.0
- matplotlib-base
- numpy
- numpy<2
- pytest=8
- pytest-cov=5
- py-plumed
Expand Down
9 changes: 5 additions & 4 deletions environment_mace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ dependencies:
- scipy
- xtb
- scikit-learn
- openmm
- openmm-torch
- openmm=8.1.2
- openmm-torch=1.4
- nnpops
- openmm-ml=1.2
- git
- pip:
- openmmml@git+https://github.com/openmm/openmm-ml.git@main
- ase@git+https://gitlab.com/ase/ase.git@f2615a6e9a # For PLUMED
- mace-torch
- mace-torch==0.3.6
6 changes: 3 additions & 3 deletions install_ace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ if ! which julia; then
fi

source create_conda_environment.sh
# NOTE: `conda activate` does not work in scripts, we use `conda run` below.
# https://stackoverflow.com/a/72395091

echo "* Adding required registries and packages to Julia *"
echo "using Pkg
Expand All @@ -30,8 +28,10 @@ Pkg.add(\"IJulia\")
Pkg.add(\"ASE\")" > add_julia_pkgs.jl
julia add_julia_pkgs.jl

# NOTE: `conda activate` does not work in scripts, need to use `conda run`, see:
# https://stackoverflow.com/a/72395091
echo "* Setting up Python-Julia integration *"
conda run -n ${CONDA_ENV_NAME} python -c "import julia; julia.install()"
$CONDA_EXE run -n ${CONDA_ENV_NAME} python -c "import julia; julia.install()"

echo "* Pointing PyCall to the version of Python in the new env *"

Expand Down
2 changes: 1 addition & 1 deletion mlptrain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
PlumedCustomCV,
)

__version__ = '1.0.0a0'
__version__ = '1.0.0b0'

__all__ = [
'Configuration',
Expand Down
25 changes: 16 additions & 9 deletions mlptrain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@


class _ConfigClass:
"""mlptrain configuration"""
"""
MLP training configurations
This class contains default parameters for electronic structure computations and training of available MLPs.
Default settings for electronic structures is None to avoid accidentally running the wrong level of theory.
The desired level can be specified by, e.g.
```
from mlptrain.config import Config
Config.orca_keywords = ['PBE', 'def2-SVP', 'EnGrad']
Config.gaussian_keywords = ['PBEPBE', 'Def2SVP', 'Force(NoStep)', 'integral=ultrafinegrid']
```
"""

n_cores = 4
_orca_keywords = ['PBE', 'def2-SVP', 'EnGrad']
_gaussian_keywords = [
'PBEPBE',
'Def2SVP',
'Force(NoStep)',
'integral=ultrafinegrid',
]
_orca_keywords = None
_gaussian_keywords = None

# Default parameters for a GAP potential
gap_default_params = {
Expand Down Expand Up @@ -87,7 +94,7 @@ def gaussian_keywords(self):

@gaussian_keywords.setter
def gaussian_keywords(self, value):
"""ORCA keywords must be gradient"""
"""Gaussian keywords must be gradient"""
self._gaussian_keywords = value


Expand Down
4 changes: 2 additions & 2 deletions mlptrain/configurations/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _method_and_keywords(
def _orca_keywords() -> 'autode.wrappers.keywords.Keywords':
"""Keywords e.g. functional and basis set to use for an ORCA calculation"""

if Config.orca_keywords is None:
if len(Config.orca_keywords) == 0:
raise ValueError(
'For ORCA training GTConfig.orca_keywords must be'
' set. e.g.\nmlt.Config.orca_keywords '
Expand All @@ -101,7 +101,7 @@ def _gaussian_keywords() -> 'autode.wrappers.keywords.Keywords':
"""Keywords e.g. functional and basis set to use for an Gaussian
calculation, either Gaussian09 or Gaussian16"""

if Config.gaussian_keywords is None:
if len(Config.gaussian_keywords) == 0:
raise ValueError(
'To train with Gaussian QM calculations '
'mlt.Config.gaussian_keywords must be set.'
Expand Down
18 changes: 15 additions & 3 deletions mlptrain/potentials/ace/ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,34 @@ def _train(self) -> None:
p = Popen(
[shutil.which('julia'), f'{self.name}.jl'],
shell=False,
encoding='utf-8',
stdout=PIPE,
stderr=PIPE,
)
out, err = p.communicate(timeout=None)

filename_ace_out = 'ACE_output.out'

with open(filename_ace_out, 'a') as f:
f.write(f'ACE training output:\n{out}')
if err:
f.write(f'ACE training error:\n{err}')

delta_time = time() - start_time
logger.info(f'ACE training ran in {delta_time / 60:.1f} m')

if any(
(
delta_time < 0.01,
b'SYSTEM ABORT' in err,
'SYSTEM ABORT' in err,
p.returncode != 0,
not os.path.exists(f'{self.name}.json'),
)
):
raise RuntimeError(f'ACE train errored with:\n{err.decode()}\n')
raise RuntimeError(
f'ACE train errored with a return code:\n{p.returncode}\n'
f'and error:\n{err}\n'
)

for filename in (f'{self.name}_data.xyz', f'{self.name}.jl'):
os.remove(filename)
Expand Down Expand Up @@ -246,7 +258,7 @@ def _print_input(self, filename: str, **kwargs) -> None:
' asmerrs=true, weights=weights)\n'
'save_dict(save_name,'
' Dict("IP" => write_dict(IP), "info" => lsqinfo))\n'
'rmse_table(lsqinfo["errors"])\n'
'#rmse_table(lsqinfo["errors"])\n'
'println("The L2 norm of the fit is ", round(norm(lsqinfo["c"]), digits=2))\n',
file=inp_file,
)
Expand Down
18 changes: 10 additions & 8 deletions mlptrain/potentials/mace/mace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import mlptrain
import argparse
import os
import gc
import ast
import time
import shutil
Expand Down Expand Up @@ -120,6 +121,10 @@ def _train(self, n_cores: Optional[int] = None) -> None:
self._reset_train_objs()

os.remove(f'{self.name}_data.xyz')

gc.collect()
torch.cuda.empty_cache()

return None

@property
Expand Down Expand Up @@ -205,17 +210,14 @@ def _print_error_table(self) -> None:

logging.info('Generating error table')

all_collections = [
('train', self.train_configs),
('valid', self.valid_configs),
]
all_collections = {
'training': self.train_loader,
'validation': self.valid_loader,
}

table = create_error_table(
table_type=Config.mace_params['error_table'],
all_collections=all_collections,
z_table=self.z_table,
r_max=Config.mace_params['r_max'],
valid_batch_size=self.valid_batch_size,
all_data_loaders=all_collections,
model=self.model,
loss_fn=self.loss_fn,
output_args=self.output_args,
Expand Down
Loading

0 comments on commit 65941ce

Please sign in to comment.