Skip to content

Commit

Permalink
Miscellaneous fixes (#335)
Browse files Browse the repository at this point in the history
1. In the past our SpectralABF examples needed to be manually shifted, but this works fine now, so I'm updating the examples to reflect that.

2. In some cases the synchronization between OpenMM, jax and cupy CUDA contexts/streams might throw an error, so fixing this as well.
  • Loading branch information
pabloferz committed Aug 22, 2024
1 parent aa4c027 commit f8bede3
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 13 deletions.
3 changes: 1 addition & 2 deletions examples/hoomd-blue/spectral_abf/Butane-SpectralABF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@
"A = result[\"free_energy\"]\n",
"# Alternatively:\n",
"# fes_fn = result[\"fes_fn\"]\n",
"# A = fes_fn(mesh)\n",
"A = A.max() - A"
"# A = fes_fn(mesh)"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion examples/hoomd-blue/spectral_abf/Butane-SpectralABF.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ A = result["free_energy"]
# Alternatively:
# fes_fn = result["fes_fn"]
# A = fes_fn(mesh)
A = A.max() - A
```

```python colab={"base_uri": "https://localhost:8080/", "height": 302} id="7_d_XfVLLkbI" outputId="e35db259-31f8-4a3b-b1fa-7e91a8a5c88a"
Expand Down
3 changes: 1 addition & 2 deletions examples/hoomd-blue/spectral_abf/butane.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def get_args(argv):
("time-steps", "t", int, 5e5, "Number of simulation steps"),
]
parser = argparse.ArgumentParser(description="Example script to run SpectralABF")
for (name, short, T, val, doc) in available_args:
for name, short, T, val, doc in available_args:
parser.add_argument("--" + name, "-" + short, type=T, default=T(val), help=doc)

return parser.parse_args(argv)
Expand All @@ -283,7 +283,6 @@ def main(argv=[]):
mesh = result["mesh"]
fes_fn = result["fes_fn"]
A = fes_fn(mesh)
A = A.max() - A

# plot the free energy
fig, ax = plt.subplots()
Expand Down
1 change: 0 additions & 1 deletion examples/hoomd3/spectral_abf/butane.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def main(argv=[]):
mesh = result["mesh"]
fes_fn = result["fes_fn"]
A = fes_fn(mesh)
A = A.max() - A

# plot the free energy
fig, ax = plt.subplots()
Expand Down
1 change: 0 additions & 1 deletion examples/openmm/spectral_abf/ADP_SpectralABF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@
"# mesh = result[\"mesh\"]\n",
"# fes_fn = result[\"fes_fn\"]\n",
"# A = fes_fn(mesh)\n",
"A = A.max() - A\n",
"A = A.reshape(grid.shape)"
]
},
Expand Down
1 change: 0 additions & 1 deletion examples/openmm/spectral_abf/ADP_SpectralABF.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ A = result["free_energy"]
# mesh = result["mesh"]
# fes_fn = result["fes_fn"]
# A = fes_fn(mesh)
A = A.max() - A
A = A.reshape(grid.shape)
```

Expand Down
3 changes: 1 addition & 2 deletions examples/openmm/spectral_abf/alanine-dipeptide.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_args(argv):
("time-steps", "t", int, 5e5, "Number of simulation steps"),
]
parser = argparse.ArgumentParser(description="Example script to run Spectral ABF")
for (name, short, T, val, doc) in available_args:
for name, short, T, val, doc in available_args:
parser.add_argument("--" + name, "-" + short, type=T, default=T(val), help=doc)
return parser.parse_args(argv)

Expand Down Expand Up @@ -108,7 +108,6 @@ def main(argv=[]):

# Set min free energy to zero
A = fes_fn(xi)
A = A.max() - A
A = A.reshape(plot_grid.shape)

# plot and save free energy to a PNG file
Expand Down
5 changes: 2 additions & 3 deletions pysages/backends/openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,12 @@ def bias(snapshot, state, sync_backend):
"""Adds the computed bias to the forces."""
if state.bias is None:
return
biases = adapt(state.bias)
# Forces may be computed asynchronously on the GPU, so we need to
# synchronize them before applying the bias.
sync_backend()
biases = adapt(state.bias)
forces = view(snapshot.forces)
biases = view(biases.block_until_ready())
forces += biases
forces += view(biases.block_until_ready())
sync_forces()

def dimensionality():
Expand Down

0 comments on commit f8bede3

Please sign in to comment.