-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add MACE interface #224
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
Changes from all commits
13fc591
547d35f
d37987d
b78376a
02bd2dc
dd59254
789cdb7
8ca192a
5f5828a
1f8ee25
c8dfc47
683d2ae
d829cfc
9c7bc19
b01d25d
7e5266e
07f1fd5
d11c195
ac63c4d
f23559e
1efe09b
ca739e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 . | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, I think we should do something like this: |
||
|
|
||
| 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) | ||
| " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Is this file needed for tests? If so, we should download it as part of the MACE installation script perhaps.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @danielhollas,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). | ||
There was a problem hiding this comment.
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.shscript, 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
macepackage is not published on conda, I think we should encourage users to use theuvpackage installer, in particular because it has an advanced handling of pytorch.https://docs.astral.sh/uv/guides/integration/pytorch/
i.e. something like this
To install CPU-only version
I am happy to help write this down before we merge this PR.