Skip to content

Commit 6e37b34

Browse files
committed
Merge branch 'main' into fix
2 parents 78a8bb2 + 20538c9 commit 6e37b34

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ For more details on Allegro itself, background, and the LAMMPS pair style please
99
and
1010
> *Scaling the leading accuracy of deep equivariant models to biomolecular simulations of realistic size* <br/>
1111
> Albert Musaelian, Anders Johansson, Simon Batzner, Boris Kozinsky <br/>
12-
> https://arxiv.org/abs/2304.10061 <br/>
12+
> https://doi.org/10.1145/3581784.3627041 <br/>
1313
1414
`pair_allegro` authors: **Anders Johansson**, Albert Musaelian.
1515

1616
## Pre-requisites
1717

18-
* PyTorch or LibTorch >= 1.11.0; please note that at present we **only recommend 1.11** on CUDA systems.
18+
* PyTorch or LibTorch >= 1.11.0; please note that at present we have only thoroughly tested 1.11 on NVIDIA GPUs (see [#311 for NequIP](https://github.com/mir-group/nequip/discussions/311#discussioncomment-5129513)) and 1.13 on AMD GPUs, but newer 2.x versions *may* also work. With newer versions, setting the environment variable `PYTORCH_JIT_USE_NNC_NOT_NVFUSER=1` sometimes helps.
1919

2020
## Usage in LAMMPS
2121

@@ -32,7 +32,7 @@ To run with Kokkos, please see the [LAMMPS Kokkos documentation](https://docs.la
3232
```bash
3333
mpirun -np 8 lmp -sf kk -k on g 4 -pk kokkos newton on neigh full -in in.script
3434
```
35-
to run on 2 nodes with 4 GPUs each.
35+
to run on 2 nodes with 4 GPUs *each*.
3636

3737
### Compute
3838
We provide an experimental "compute" that allows you to extract custom quantities from Allegro models, such as [polarization](https://arxiv.org/abs/2403.17207). You can extract either global or per-atom properties with syntax along the lines of
@@ -42,22 +42,25 @@ compute polarizability all allegro polarizability 9
4242
compute borncharges all allegro/atom born_charge 9 1
4343
```
4444

45-
The name after `allegro[/atom]` is attempted extracted from the dictionary that the Allegro model returns. The following number is the number of elements after flattening the output. In the examples above, polarization is a 3-element global vector, while polarizability and Born charges are global and per-atom 3x3 matrices, respectively. For per-atom quantities, the second number is a flag indicating whether the properties should be reverse-communicated "Newton-style" like forces, which will depend on your property and the specifics of your implementation.
45+
The name after `allegro[/atom]` is attempted extracted from the dictionary that the Allegro model returns. The following number is the number of elements after flattening the output. In the examples above, polarization is a 3-element global vector, while polarizability and Born charges are global and per-atom 3x3 matrices, respectively.
46+
47+
For per-atom quantities, the second number is a 1/0 flag indicating whether the properties should be reverse-communicated "Newton-style" like forces, which will depend on your property and the specifics of your implementation.
48+
4649

4750
*Note: For extracting multiple quantities, simply use multiple commands. The properties will be extracted from the same dictionary, without any recomputation.*
4851

49-
*Note: The quantities will be attempted extracted at every timestep. In the future, we may add support for passing a flag to the model indicating that the "custom" output should be computed.*
52+
*Note: The group flag should generally be `all`.*
5053

51-
*Note: The group flag shoul generally be `all`.*
54+
*Note: Global quantities are assumed extensive and summed across MPI ranks. Keep ghost atoms in mind when trying to think of whether this works for your property; for example, it does not work for Allegro's global energy if there are non-zero energy shifts, as these are also applied to ghost atoms.*
5255

5356
## Building LAMMPS with this pair style
5457

5558
### Download LAMMPS
5659
```bash
57-
git clone --depth 1 https://github.com/lammps/lammps
60+
git clone --depth=1 https://github.com/lammps/lammps
5861
```
5962
or your preferred method.
60-
(`--depth 1` prevents the entire history of the LAMMPS repository from being downloaded.)
63+
(`--depth=1` prevents the entire history of the LAMMPS repository from being downloaded.)
6164

6265
### Download this repository
6366
```bash
@@ -108,8 +111,8 @@ Note that the CUDA that comes with PyTorch when installed with `conda` (the `cud
108111
#### With OpenMP (optional, better performance)
109112
`pair_allegro` supports the use of OpenMP to accelerate certain parts of the pair style, by setting `OMP_NUM_THREADS` and using the [LAMMPS OpenMP package](https://docs.lammps.org/Speed_omp.html).
110113

111-
#### With Kokkos (GPU, optional, best performance)
112-
`pair_allegro` supports the use of Kokkos to accelerate certain parts of the pair style on the GPU to avoid host-GPU transfers.
114+
#### With Kokkos (GPU, optional, best performance, most reliable)
115+
`pair_allegro` supports the use of Kokkos to accelerate the pair style on the GPU and avoid host-GPU transfers.
113116
`pair_allegro` supports two setups for Kokkos: pair_style and model both on CPU, or both on GPU. Please ensure you build LAMMPS with the appropriate Kokkos backends enabled for your usecase. For example, to use CUDA GPUs, add:
114117
```
115118
-DPKG_KOKKOS=ON -DKokkos_ENABLE_CUDA=ON
@@ -146,4 +149,4 @@ This gives `lammps/build/lmp`, which can be run as usual with `/path/to/lmp -in
146149
Exception: Argument passed to at() was not in the map
147150
```
148151
149-
A: We now require models to have been trained with stress support, which is achieved by replacing `ForceOutput` with `StressForceOutput` in the training configuration. Note that you do not need to train on stress (though it may improve your potential, assuming your stress data is correct and converged). If you desperately wish to keep using a model without stress output, you can remove lines that look like [these](https://github.com/mir-group/pair_allegro/blob/99036043e74376ac52993b5323f193dee3f4f401/pair_allegro_kokkos.cpp#L332-L343) in your version of `pair_allegro[_kokkos].cpp`.
152+
A: We now require models to have been trained with stress support, which is achieved by replacing `ForceOutput` with `StressForceOutput` in the training configuration. Note that you do not need to train on stress (though it may improve your potential, assuming your stress data is correct and converged). If you desperately wish to keep using a model without stress output, there are two options: 1) Remove lines that look like [these](https://github.com/mir-group/pair_allegro/blob/99036043e74376ac52993b5323f193dee3f4f401/pair_allegro_kokkos.cpp#L332-L343) in your version of `pair_allegro[_kokkos].cpp` 2) Redeploy the model with an updated config file, as described [here](https://github.com/mir-group/nequip/issues/69#issuecomment-1129273665).

compute_allegro.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,27 @@ void ComputeAllegro<peratom>::compute_vector()
101101
{
102102
invoked_vector = update->ntimestep;
103103

104-
const torch::Tensor &quantity_tensor =
105-
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().ravel();
104+
// empty domain, pair style won't store tensor
105+
// note: assumes nlocal == inum
106+
if (atom->nlocal == 0) {
107+
for (int i = 0; i < size_vector; i++) {
108+
vector[i] = 0.0;
109+
}
110+
} else {
111+
const torch::Tensor &quantity_tensor =
112+
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().ravel();
106113

107-
auto quantity = quantity_tensor.data_ptr<double>();
114+
auto quantity = quantity_tensor.data_ptr<double>();
108115

109-
if (quantity_tensor.size(0) != size_vector) {
110-
error->one(FLERR, "size {} of quantity tensor {} does not match expected {} on rank {}",
111-
quantity_tensor.size(0), this->quantity, size_vector, comm->me);
112-
}
116+
if (quantity_tensor.size(0) != size_vector) {
117+
error->one(FLERR, "size {} of quantity tensor {} does not match expected {} on rank {}",
118+
quantity_tensor.size(0), this->quantity, size_vector, comm->me);
119+
}
113120

114-
for (int i = 0; i < size_vector; i++) { vector[i] = quantity[i]; }
121+
for (int i = 0; i < size_vector; i++) { vector[i] = quantity[i]; }
122+
}
115123

124+
// even if empty domain
116125
MPI_Allreduce(MPI_IN_PLACE, vector, size_vector, MPI_DOUBLE, MPI_SUM, world);
117126
}
118127

@@ -128,18 +137,23 @@ void ComputeAllegro<peratom>::compute_peratom()
128137
if (nperatom==1) vector_atom = &array_atom[0][0];
129138
}
130139

131-
const torch::Tensor &quantity_tensor =
132-
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().contiguous().reshape({-1,nperatom});
140+
// guard against empty domain (pair style won't store tensor)
141+
if (atom->nlocal > 0) {
142+
const torch::Tensor &quantity_tensor =
143+
((PairAllegro<lowhigh> *) force->pair)->custom_output.at(quantity).cpu().contiguous().reshape({-1,nperatom});
133144

134-
auto quantity = quantity_tensor.accessor<double,2>();
135-
quantityptr = quantity_tensor.data_ptr<double>();
145+
auto quantity = quantity_tensor.accessor<double,2>();
146+
quantityptr = quantity_tensor.data_ptr<double>();
136147

137-
int nlocal = atom->nlocal;
138-
for (int i = 0; i < nlocal; i++) {
139-
for (int j = 0; j < nperatom; j++) {
140-
array_atom[i][j] = quantity[i][j];
148+
int nlocal = atom->nlocal;
149+
for (int i = 0; i < nlocal; i++) {
150+
for (int j = 0; j < nperatom; j++) {
151+
array_atom[i][j] = quantity[i][j];
152+
}
141153
}
142154
}
155+
156+
// even if empty domain
143157
if (newton) comm->reverse_comm(this);
144158
}
145159

pair_allegro.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ template <Precision precision> void PairAllegro<precision>::compute(int eflag, i
335335
// Neighbor list per atom
336336
int **firstneigh = list->firstneigh;
337337

338+
// Skip calculation if empty domain
339+
if (inum==0) return;
340+
338341
// Total number of bonds (sum of number of neighbors)
339342
int nedges = 0;
340343

patch_lammps.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ fi
6868

6969
echo "Updating CMakeLists.txt..."
7070

71+
sed -i "s/set(CMAKE_CXX_STANDARD 11)/set(CMAKE_CXX_STANDARD 17)/" $lammps_dir/cmake/CMakeLists.txt
72+
7173
# Add libtorch
7274
cat >> $lammps_dir/cmake/CMakeLists.txt << "EOF2"
7375

0 commit comments

Comments
 (0)