Skip to content

Commit

Permalink
Fix thread safety issue in OpenMM minimiser. [closes #259]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Dec 3, 2024
1 parent d48d138 commit 1e253b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
---------------------------------------------------------------------------------------------

* Please add an item to this CHANGELOG for any new features or bug fixes when creating a PR.
* Fixed :func:`sire.restraints.get_standard_state_correction` to be consistent with the definition of
the "force constanst" as ``F = 2 ** k ** x`` (rather than ``F = k ** x``). Updated docstrings and
restraints documentation to make it clear how the force constants are defined.
* Fixed instantiaton of ``QByteArray`` in ``Sire::Mol::Frame::toByteArray`` and count bytes with ``QByteArray::size``.
* Increase timeout before terminating ``QThread`` objects during ``PageCache`` cleanup.
* Expose missing ``timeout`` kwarg in :meth:`dynamics.minimise()` method.
Expand All @@ -27,6 +24,10 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.
* Reload TorchQMForce module if OpenMM platform changes.
* Fix calculation of non-equilibrium work when starting from QM state.
* Fix stereochemistry in RDKit molecule conversion.
* Fixed :func:`sire.restraints.get_standard_state_correction` to be consistent with the definition of
the "force constanst" as ``F = 2 ** k ** x`` (rather than ``F = k ** x``). Updated docstrings and
restraints documentation to make it clear how the force constants are defined.
* Fix thread safety issue in Sire OpenMM minimiser.

`2024.3.0 <https://github.com/openbiosim/sire/compare/2024.2.0...2024.3.0>`__ - October 2024
--------------------------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions wrapper/Convert/SireOpenMM/openmmminimise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <limits.h> // CHAR_BIT
#include <sstream>
#include <stdint.h> // uint64_t
#include <Python.h>

inline auto is_ieee754_nan(double const x)
-> bool
Expand Down Expand Up @@ -91,7 +92,6 @@ inline auto is_ieee754_nan(double const x)
#include <algorithm>

#include "SireError/errors.h"
#include "SireBase/releasegil.h"

#include "SireBase/progressbar.h"
#include "SireUnits/units.h"
Expand Down Expand Up @@ -619,6 +619,8 @@ namespace SireOpenMM
double starting_k, double ratchet_scale,
double max_constraint_error, double timeout)
{
PyThreadState *_save = PyEval_SaveThread();

if (max_iterations < 0)
{
max_iterations = std::numeric_limits<int>::max();
Expand All @@ -629,8 +631,6 @@ namespace SireOpenMM
timeout = std::numeric_limits<double>::max();
}

auto gil = SireBase::release_gil();

const OpenMM::System &system = context.getSystem();

int num_particles = system.getNumParticles();
Expand Down Expand Up @@ -1105,6 +1105,8 @@ namespace SireOpenMM
CODELOC);
}

PyEval_RestoreThread(_save);

return data.getLog().join("\n");
}

Expand Down

0 comments on commit 1e253b1

Please sign in to comment.