Skip to content

Commit 0a380c1

Browse files
jngradpm-blanco
andcommitted
Rapid prototyping of Monte Carlo methods
Provide an alternative implementation of SingleReaction, ReactionAlgorithm and ConstantpHEnsemble in pure Python for rapid prototyping of new Monte Carlo methods. Co-authored-by: Pablo Miguel Blanco Andrés <[email protected]>
1 parent a0359cb commit 0a380c1

File tree

7 files changed

+635
-1
lines changed

7 files changed

+635
-1
lines changed

doc/sphinx/reaction_methods.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,41 @@ If the exclusion radius of one particle type is not defined, the value
379379
of the parameter provided in ``exclusion_range`` is used by default.
380380
If the value in ``exclusion_radius_per_type`` is equal to 0,
381381
then the exclusion range of that particle type with any other particle is 0.
382-
For more detail, see :class:`espressomd.cell_system.ExclusionRadius`.
382+
For more detail, see :class:`~espressomd.reaction_methods.ExclusionRadius`.
383+
384+
.. _Writing new Monte Carlo methods:
385+
386+
Writing new Monte Carlo methods
387+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
388+
389+
Most of the logic for reaction methods is implemented at the Python level.
390+
The C++ core is only used for performance-relevant operations on particles.
391+
Hence, one can prototype new reaction methods with relative ease.
392+
For example, the acceptance probability for a Monte Carlo trial move
393+
is exposed in :meth:`ReactionAlgorithm.calculate_acceptance_probability()
394+
<espressomd.reaction_methods.ReactionAlgorithm.calculate_acceptance_probability>`.
395+
Reaction method classes override this function with their custom expression
396+
for the acceptance probability.
397+
398+
Alternatively, the sample script :file:`samples/monte_carlo.py` provides
399+
a re-implementation of the core functionality of reaction methods in Python,
400+
with a focus on the :ref:`constant pH <Constant pH>` and
401+
:ref:`reaction ensemble <Reaction Ensemble>` methods.
402+
More specifically, the :class:`~espressomd.reaction_methods.SingleReaction`,
403+
:class:`~espressomd.reaction_methods.ReactionAlgorithm`,
404+
:class:`~espressomd.reaction_methods.ReactionEnsemble`, and
405+
:class:`~espressomd.reaction_methods.ConstantpHEnsemble`
406+
classes are rewritten in Python.
407+
408+
The goal of this sample is to assist in the rapid prototyping of new Monte Carlo
409+
methods. In particular, the sampling and move generation schemes are expressed
410+
in Python, and can be leveraged by users without C++ programming experience.
411+
The sample is designed to run with the :ref:`kernprof` profiler attached:
412+
413+
.. code-block:: bash
414+
415+
pypresso --kernprof monte_carlo.py --mode=core
416+
pypresso --kernprof monte_carlo.py --mode=python
417+
418+
These Python implementations are roughly four times slower
419+
than their corresponding core implementations.

0 commit comments

Comments
 (0)