Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion .github/workflows/gfortran.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ jobs:
if [ $GCC_V -ge 10 ];then export FFLAGS="-fallow-argument-mismatch";export FCFLAGS="-fallow-argument-mismatch";fi && \
./dev_scripts/install_mpich.sh ${HOME}/mpich ${MPICH_V}

- name: Install MACE
run: pip install mace mpi4py ase numpy

- name: build ABIN
run: |
if [ $GCC_V -ge 10 ];then export FFLAGS="-fallow-argument-mismatch $FFLAGS";fi && \
Expand All @@ -339,7 +342,8 @@ jobs:
FFLAGS: ${{ env.ABIN_FFLAGS }} -g
LDLIBS: ${{ env.ABIN_LDLIBS }}
- name: test ABIN
run: make test
run: LD_LIBRARY_PATH=${HOME}/mpich/${MPICH_V}/install/lib make test

- name: Codecov upload
uses: codecov/codecov-action@v6
with:
Expand Down Expand Up @@ -373,6 +377,9 @@ jobs:
if: steps.openmpi-cache.outputs.cache-hit != 'true'
run: ./dev_scripts/install_openmpi.sh ${HOME}/openmpi ${OPENMPI_V} ${OPENMPI_PATCH}

- name: Install MACE
run: pip install mace mpi4py ase numpy

- name: build ABIN
run: ./configure --mpi "${HOME}/openmpi/${OPENMPI_V}/install" && make
env:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ The optional libraries are:
- [FFTW](http://www.fftw.org/): Fast Fourier Transform library used for normal mode transformation in Path Integral MD.
- [PLUMED](https://www.plumed.org/): A collection of very useful tools for free energy calculations (MetaDynamics, Umbrella Sampling etc).
- [TCPB-CPP](https://github.com/mtzgroup/tcpb-cpp): [EXPERIMENTAL] TCPB interface to TeraChem
- [MACE](https://github.com/ACEsuit/mace): Machine Learning Atomic Cluster Expansion potential.
- Integrated via an MPI interface. Requires a Python environment with `mace-torch`, `torch`, `ase`, and `mpi4py`.
- Use `dev_scripts/install_mace.sh` for easy installation.


## Structure of the repository
Expand Down
28 changes: 28 additions & 0 deletions dev_scripts/install_mace.sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking about this more, I don't think we should provide the install_mace.sh script, there's simply too many variables about how to handle the python environment (and how to handle Torch installation in particular).

I'd rather have a comprehensive installation section in the README. Given the (unfortunate) fact that the mace package is not published on conda, I think we should encourage users to use the uv package installer, in particular because it has an advanced handling of pytorch.

https://docs.astral.sh/uv/guides/integration/pytorch/

i.e. something like this

uv venv
uv pip install mace-torch mpi4py --torch-backend=auto

To install CPU-only version

uv pip install mace-torch mpi4py --torch-backend=cpu

I am happy to help write this down before we merge this PR.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail

REPO_URL="https://github.com/ACEsuit/mace.git"
REPO_DIR="$HOME/mace"
if [[ "$#" -eq 1 && ! -z $1 ]];then
REPO_DIR=$1
fi

if [[ -e $REPO_DIR ]];then
echo "ERROR: $REPO_DIR already exists."
exit 1
fi

git clone "${REPO_URL}" "${REPO_DIR}" && cd "$REPO_DIR"

pip install --upgrade pip

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will install the package into the global python environment (unless the user is already inside a venv or conda. I think we should create a fresh venv for the user.

pip install .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we installing MACE from the repo? We should I think install the package from PyPI.

pip install mpi4py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be clear, I think we should do something like this:

python -m venv .mace_venv
.mace_venv/bin/python3 -m pip install mace-torch mpi4py


echo "
Successfully installed MACE and mpi4py.

To use with ABIN, set MACE_PYTHON in utils/run.mace_mpi_abin.sh
to point to the Python interpreter that has these packages, e.g.:

export MACE_PYTHON=$(which python3)
"
12 changes: 5 additions & 7 deletions dev_scripts/install_mpich.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ set -euo pipefail
MPICH_DIR="${1-$HOME/mpich}"
# We take current stable version as default
# (as of 06 Nov 2020).
MPICH_VERSION="${2-"4.0.2"}"
MPICH_VERSION="${2-"4.3.2"}"

TAR_FILE="mpich-${MPICH_VERSION}.tar.gz"
DOWNLOAD_URL="https://www.mpich.org/static/downloads/${MPICH_VERSION}/${TAR_FILE}"
INSTALL_DIR="$MPICH_DIR/$MPICH_VERSION/install"

# Github Actions machines have two CPUs, per:
# https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners#supported-runners-and-hardware-resources
NCPUS=2

if [[ -d "$INSTALL_DIR" ]];then
echo "Found existing MPICH installation in $INSTALL_DIR"
Expand Down Expand Up @@ -56,12 +53,13 @@ cd "$MPICH_DIR/$MPICH_VERSION/src" && tar -xzf "../pkg/${TAR_FILE}" && cd "mpich
# export FCFLAGS=-fallow-argument-mismatch
./configure FC=gfortran CC=gcc \
--enable-fortran=all \
--with-pm=hydra --with-device=ch3:nemesis \
--with-pm=hydra \
--with-device=ch3:nemesis \
--with-namepublisher=pmi \
--enable-static --disable-shared \
--enable-static \
--prefix="${INSTALL_DIR}" 2>&1 |\
tee configure.log
make -j $NCPUS 2>&1 | tee make.log
make -j 2>&1 | tee make.log
make install 2>&1 | tee make_install.log

echo "
Expand Down
Binary file added interfaces/MACE/MACE-OFF23_medium.model

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a quick comment, I don't think we should be including the MACE-OFF model in the repo, it's a huge binary blob, and it will likely become obsolete soon as new models come out.
We can definitely provide instructions and link about where it can be downloaded though!

Is this file needed for tests? If so, we should download it as part of the MACE installation script perhaps.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree that it's not entirely necessary. The main idea was to provide users with a quick way to test the interface without any further configuration.

The file is not necessary for the tests; however, the default configuration (&mace namelist) uses the file as fallback.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi, @danielhollas,
Are you still of the opinion that we should remove the model from the repo?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, yes I think we should remove it. Please add instructions somewhere (perhaps a README file) where we can tell the users how to download it.

Sorry for the slow review, this is a big PR and I want to have a careful look and we also plan to test it soon.

Binary file not shown.
73 changes: 73 additions & 0 deletions interfaces/MACE/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# MACE MPI Interface for ABIN

This directory contains the Python-based server for the MACE (Machine Learning Atomic Cluster Expansion) potential.

## Requirements

- Python >= 3.8
- PyTorch >= 1.12
- mace-torch
- ase
- mpi4py
- numpy

You can install all dependencies using:
```console
pip install mace-torch ase mpi4py numpy
```
Or use the provided script in the root directory:
```console
./dev_scripts/install_mace.sh
```

## Usage

The MACE server is typically launched alongside ABIN using MPI. ABIN communicates with the server to obtain energies and forces.

### Manual Launch (OpenMPI)

When using OpenMPI, you need an `ompi-server` running for the connection handshake:

```console
# 1. Start ompi-server

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this really the case? We don't seem to need something like this in the TeraChem interface?

ompi-server --no-daemonize -r ompi_uri.txt &

# 2. Start MACE server
mpirun --ompi-server file:ompi_uri.txt -n 1 python3 mace_server.py &

# 3. Start ABIN (in another terminal or same script)
mpirun --ompi-server file:ompi_uri.txt -n 1 abin -i input.in -x geom.xyz
```

### Automatic Launch

It is recommended to use the provided launch script in `utils/`:
```console
./utils/run.mace_mpi_abin.sh
```

## Configuration

MACE settings are controlled via the `&mace` namelist in the ABIN input file (`input.in`). Below is the full list of available parameters:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I am not totally opposed to this, but note that generally we don't put interface-specific parameters in the abin input file since ABIN doesn't really need to know about these.

I feel that in this case it would be better (and more general!) to hava a YAML configuration file in the interface folder which we can than load directly into MACE (I believe MACE supports this natively).


| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `mace_model` | String | `'MACE-OFF23_medium.model'` | Path to a local `.model` file (TorchScript or PyTorch checkpoint) or a foundation model name (e.g., `MACE-OFF23_medium.model`, `medium`). Foundation models are automatically downloaded. |
| `mace_device` | String | `'cpu'` | Execution device: `'cpu'` or `'cuda'`. |
| `mace_default_dtype` | String | `'float64'` | Default tensor precision: `'float32'` or `'float64'`. |
| `mace_batch_size` | Integer | `64` | Batch size for evaluations. |
| `mace_compute_stress` | Logical | `.false.` | Whether to compute the stress tensor. |
| `mace_return_contributions` | Logical | `.false.` | Whether to return energy contributions per body order. |
| `mace_info_prefix` | String | `'MACE_'` | Prefix for MACE-related metadata in the ASE output. |
| `mace_head` | String | `''` | Model head identifier (for multi-head models). |
| `mace_max_mpi_wait_time` | Real | `60.0` | Maximum time (seconds) to wait for the MACE port file to appear. |
| `mace_mpi_milisleep` | Integer | `50` | Sleep interval (milliseconds) when polling for the MACE port or results. |

See `sample_inputs/input.in.mace` for a template.

## MACE License
The provided MACE model (MACE-OFF23_medium.model) is downloaded from the [MACE-OFF GitHub repository](https://github.com/ACEsuit/mace-off) and is licensed under the [Academic Software License Agreement (ASLA)](https://github.com/ACEsuit/mace-off/blob/main/LICENSE.md).

Note that this is not our model and we are not responsible for its performance or any issues related to its use. The purpose of its inclusion here is to provide a working example of how to use MACE with ABIN.

For full terms and conditions, please refer to the [MACE-OFF GitHub repository](https://github.com/ACEsuit/mace-off).
Loading
Loading