Philipp Höllmer
email: hoellmer@physik.uni-bonn.de

Liang Qin
email: liang.qin@phys.ens.fr

Michael F Faulkner

A C Maggs

Werner Krauth
email: werner.krauth@ens.fr

JeLLyFysh-Version1.0 -a Python application for all-atom event-chain Monte Carlo ✩,✩✩

Keywords:

Markov chain N-body simulation Event-chain algorithm Long-range potentials Python application a b s t r a c t We present JeLLyFysh-Version1.0, an open-source Python application for event-chain Monte Carlo (ECMC), an event-driven irreversible Markov-chain Monte Carlo algorithm for classical N-body simulations in statistical mechanics, biophysics and electrochemistry. The application's architecture mirrors the mathematical formulation of ECMC. Local potentials, long-range Coulomb interactions and multibody bending potentials are covered, as well as bounding potentials and cell systems including the cell-veto algorithm. Configuration files illustrate a number of specific implementations for interacting atoms, dipoles, and water molecules.

Acknowledgement

I feel fortunate to pursue the highest academic degree, lighting up my way to explore the world of infinite knowledge throughout life. I want to express my acknowledgment to the diverse and inclusive school, École normale supérieure, that offered me a scholarship covering my master's and doctoral studies. I cherish this opportunity helping me step into the world.

I can never imagine today's accomplishment without the direction of my advisor, Werner Krauth, who patiently guided me in every project, from scientific details to academic conduct. You brought me a friendly working environment and the most intriguing problems that I could not help thinking about all the time.

I also express my appreciation to my collaborator, Anthony Maggs, for your rich knowledge and willingness to share. Nothing can be more encouraging than that direct questions received your immediate replies.

The doctoral school makes me feel at home. I thank the former director, Jean-François Allemand, for caring for us students not only on administrative procedures but on our growth. I thank Frédéric Chevy as the new director and former head of master education. My years in Paris would be harder without your supports. Also, I want to thank every supporting member of the department.

I appreciate Alberto Rosso for his course on computational physics that opened to me the door of Monte Carlo, Synge Todo and Hidemaro Suwa for expanding my research horizon, and Koji Hukushima for the day of exciting discussion over the extended ensemble Monte Carlo. Also, I would like to thank Marc Mézard, who I have no direct contact with, for the most impressive course as if the spin glass is the most valuable treasure in the world, and for directing the whole ENS.

I want to thank Pierre Pansu as my tuteur and Nicolas Regnault as my parrain for carefully listening to my progress twice at the end of academic years and giving me advice as professors outside my project.

The completion of my thesis is also the fruit of my colleagues. I want to thank the former members in the group, Etienne Bernard, Sebastian Kapfer, Manon Michel, Tommaso Comparin, and Yoshihiko Nishikawa, for orienting me at the difficult beginning and for your pioneering works prior to my thesis. I want to thank Ze Lei and Juliane Klamser for telling me everything I need to lead a doctoral life. A particular appreciation is given to two years of collaboration with Philipp Höllmer, for your expertise and rigorous working manner. I also thank Michael Faulkner for coworking in the first paper, and thank Botao Li for your continued and invaluable discussions.

I also appreciate all the young friends who work around me. Besides the infinite help, your daily greetings are the warmest things in a day.

Finally, I express my gratitude to the thesis jury for the careful examination and recognition of my works. They are Silke Biermann, Ben Leimkuhler, Ralf Everaers, and Kurt Kremer. I thank Werner Krauth, Philipp Höllmer and Botao Li for reviewing this manuscript and for the helpful feedback during the preparation of my defense.

General Introduction

People have developed classical molecular models to understand the behavior of systems ranging from hard disks to proteins. Equilibrium statistical physics connects atomic interactions and macroscopic physical quantities such as pressure, specific heat, and, more profoundly, order parameters that decide criticality. Although chemical reactions and biochemical conformational changes are often out-of-equilibrium, their statistics like reaction paths and rates can also be understood by simulating atomic models. The Boltzmann distribution is fundamental in statistical physics but requires high-dimensional integral beyond any analytical solution. Molecular mechanics and Monte Carlo stand out as the two most successful numerical methods, laying the base of modern molecular simulations.

Much effort was devoted in pursuit of increasingly large-scale simulations in various fields of study. Phase transitions of special physical interests occur in the thermodynamic limit, and studies of finite-size effect also desire simulations of larger space and time for the sake of accuracy. In biochemical settings, numerous interesting reactions occur on a millisecond time scale, far beyond the nanosecond time scale reached by personal computers and state-of-the-art molecular dynamics.

Among all problems, long-range interactions are notoriously onerous from a computational perspective, in spite of their pervasive role in nature. Electrostatic interactions are indispensable in reproducing realistic properties in a system with a polarized solvent. Practical large-scale algorithms must avoid pairwise iteration while calculating the Coulomb force. And so far, the most commonly used method heavily relies on the spatial discretization, which brings systematic bias.

Event-chain Monte Carlo (ECMC) is a novel irreversible Monte Carlo method applicable in any continuous system, and it has demonstrated excellent efficiency from simple hard disks to spin systems. Taking advantage of its factorized nature, its first long-range variant was proposed with O(N 4/3 )-per-sweep time complexity for threedimensional Coulomb particles.

During the past three years, we focused on long-range algorithms under the framework ECMC, and applied them to realistic water systems. We established its theoretical foundation and also initiated an open-source application for all researchers. This thesis is a summary of my work under the supervision of Werner Krauth and in collaboration with Anthony Maggs, Philipp Höllmer, and Michael Faulkner.

The thesis will expand as follows. In chapter 1, we will review molecular simulation methods as a general background. Methods other than ECMC-molecular dynamics, reversible Monte Carlo, and existing trials over irreversibility-will be briefly introduced.

In chapter 2 we introduce ECMC in detail. Apart from other ECMC formulations, we describe its theoretical foundation with general many-body factors, through a novel graphic lifting scheme, and establish a connection between factorization and redundant flow. We then provide the event-driven implementation and its specific thinning process, which brings ECMC with faster speed and applicability to all energy forms. In chapter 3, we talk about existing work and our progress of long-range ECMC adaptation. We find that the tin-foil electrostatics is the most suitable because its pairwise form facilitates factorization. Apart from the traditional Ewald summation, various approaches exist for ECMC's Coulomb calculation, and they all converge to the tin-foil electrostatics. Furthermore, factorization plays a significant role in reducing the event rate for dipoles, thus lowers the overall complexity. Three lifting schemes corresponding to dipole factors are proposed and result in different dynamics. Combining all these discoveries plus the cell-veto method leads to a three-dimensional Coulomb ECMC method of O(N log N )-per-sweep complexity. This work [1] has been published on the Journal of Chemical Physics.

We also attach emphasis on application development and release JELLYFYSH-V1.0 as a universal python application for all-atom simulations. Summarizing our work [2] published on Computer Physics Communication, chapter 4 describes its underlying architecture, in which we reformulate ECMC in favor of event processing, with all potential operations as an event stream. The mediator design pattern featuring a central hub and peripherical functioning modules is believed to accommodate future extensions best. Then in chapter 5, we continue our way towards the real simulation by providing event handlers for diverse environments with concrete instances for users to follow.

We put JELLYFYSH into practice in chapter 6 with large systems of water molecules. Besides the programming adaptation to the real Coulomb system, we also make great effort to optimize the long-range modules, in particular the cell-veto method. Detailed profiling of Coulomb events provides insights over the rate, distribution, and types of Coulomb events. Furthermore, we test JELLYFYSH with a water system up to 216 molecules. The polarization signal not only reflects the speed of relaxation but shows unusual excitation for few-molecule states. For the first time, we incorporate molecular translation into single-active-particle ECMC and measure its effect in the relaxation of overall polarization.

Given the double time scales in the equilibration of water polarization, we proceed with an additional study over sequential choices of direction in Monte Carlo in chapter 7. Moving directions that change progressively exhibit exotic dynamics of the dipole angle, and we find that proper sequential schemes outperform the conventional way that always resamples along orthogonal axes. It also reveals that the set of resampling directions has a great impact on the performance, whose comprehensive mechanism is left as our future study. We submitted the results [3] to journals and now it is a preprint.

In the appendices, we attach the three aforementioned papers published or submitted during my doctoral study.

Chapter 1 Simulation method review 1.1 The need for large-scale simulation

The impression when talking about simulation is that we are going to integrate an equation of motion such as Newton's law m i ∂ 2 r i /∂t 2 = -∇ i U , or equations for continuum like Maxwell equations or Navier-Stokes equations. We can know everything if the evolution of a system's elements is evident.

Problems arise concerning non-continuous space such as spin systems in which each variable takes discrete values. Such physical configurations serve as abstract models of reality but can reflect the intrinsic properties of complex systems. No deterministic equation of motion is present for discrete systems. On the other hand, due to the Lyapunov instability, the behavior of the simulated system is very sensitive to the initial condition. In other words, even if a sufficiently sophisticated program can predict the exact state r i (t) for some time t, the computer-representation inaccuracy of the initial state r i (0) results in an exponential difference between r i (t) and the real position, let alone the cumulative error brought by numerical integrators, and deviation from rough model and environment noises. In fact, progress has deviated from the exact solution of r i (t) since the invention of simulation algorithms like molecular dynamics and Monte Carlo.

Usually, we care more about statistics under thermodynamic conditions than orbits, and equilibrium statistical mechanics is capable of capturing the nature of static states. It can calculate the freezing point of water, predict the stable phase of an alloy, and obtain the average time for two molecules to react as well as the reaction path. The ultimate physical equation we need to solve throughout our work is Boltzmann's law describing the probability of a state in equilibrium

π(c) = 1 Z e -βU (c) , (1.1.1)
where β, U and Z are the inverse temperature, energy and normalizing factor respectively. Physical quantities can be acquired by sampling the configuration space, and flexible approaches exist to this end. Molecular dynamics simulates a canonical ensemble with the help of a thermostat by integrating Newton's equation of motion (or more Chapter 1. Simulation method review generally, Hamilton's equations), which can reach the target Boltzmann distribution in small step limit. Monte Carlo methods perform moves that are not connected by the equation of motion and reach the desired distribution by respecting the global balance condition. It is a convenience of Monte Carlo methods that only the relative probability between two states is required. Now Monte Carlo becomes a universal technology to reveal properties of a variety of systems, from simple particles, biochemical molecules, to engineering and finance.

Examples

Here we give two examples of how simulations help us understand nature.

Hard disks

Even though modern physics has developed to be so sophisticated and high-energy that daily experiments can never justify, it is surprising to see that the hard-disk melting problem has been puzzling physicists for half a century.

Phases in condensed matter are often characterized by correlation length, typically classified into long-range, quasi-long-range, and short-range orders. Hard disk serves as the two-dimensional prototype to explain the classical phase transition on a plane. Theorists have early established through an elastic model that long-range order cannot appear in systems of less than three dimensions. Thus, two-dimensional systems become the focus of physical interests, in which solid states feature quasi-long order and liquid states feature short-range order. Kosterlitz and Thouless [4] proposed in 1973 their famous theory that topological defects-that are unbinding pairs of vortex and anti-vortex in XY model-are suddenly favorable when the temperature passes a threshold. First-order scenarios can also exist, such as in the narrow-well XY model that resembles q > 4 Potts model. For hard-disks, things become more complicated in the presence of positional and orientational orders. The well-known Kosterlitz-Thouless-Halperin-Nelson-Young theory [5,6,7] proposed in the late 1970s predicts that the unbinding of dislocation and disclination will consecutively break positional and orientational orders, making hard disks transition from the solid to the hexatic state and finally to the liquid through second-order transition, in competition with other first-order theories.

A large number of realistic and numerical experiments were conducted just for the hard-disk phase transition. Since the first simulation [8], people simulated via molecular dynamics and Monte Carlo with increasing system size and precision. Not until later works [9,10,11] cleaned up the puzzle using large-scale ECMC simulation, people had been debating over the nature of hard-disk phase transition for thirty years.

In 2011, the ECMC algorithm was applied [9] to equilibrate up to a million disks around criticality, which was confirmed by later work [11] which also compared several most advanced methods at that year and drew the long-anticipated equation of state of hard disks. They concluded that: with decreasing density, hard disks undergo a second-order transition to a hexatic phase, then to a liquid phase with the first-order transition, which contradicts both the KTHNY theory and other first-order 1.1. The need for large-scale simulation [11].) scenarios. Shown in Fig. 1.1 is the orientational order of three configurations around critical density produced with massively parallel Monte Carlo. With the information of equilibrated states, they were able to differentiate phases and measure the transition orders.

SARS-CoV-2

Large-scale biochemical simulations are instrumental in revealing the dynamics and conformation of proteins, in which D. E. Shaw is a pioneer who founded his research center called D. E. Shaw Research, and devised a special-purpose supercomputer to perform all-atom simulations.

Less than one month after the outbreak in the U.S. of Covid-19, the disease caused by SARS-CoV-2, D.E. Shaw Research released their simulation results [12] relevant to the virus' proteins. Shown in Fig. 1.2 are two critical biochemical configurations of the trimetric spike protein of the virus, human ACE2 (receptor of the virus protein), and tested drug molecules. The millisecond large-scale atomic simulations are rich in dynamical information of the virus. They suggest that specific molecules from the human body are susceptible to the virus' characteristic protein, making them easy targets of the deadly virus. And medical solutions at the molecular level come out at the same time as simulations show that part of drug molecules prohibits the required binding of the virus and human protein.

They reported that among 5152 molecules in the drug library, 78 can be bound to ACE2, and 50 can be bound to the spike protein as candidates for the next pharmaceutic process. The valuable information provided by D. E. Shaw Research is believed to be helpful in drug development.

State of the art

Despite the progress in hard disks and the success in simulating SARS-CoV-2 proteins, months-long intensive computation played a crucial role, and larger-scale sim- (From Ref [12].) ulations are still heavily in demand. In order to prepare 64 independent 1024 2 -disk states, Bernard and Krauth spent nine months running ECMC on a single CPU core [9,10]. The only algorithm that can outperform ECMC and validate their finding was massively parallel Monte Carlo in 2013, while such high performance was only achieved with the help of 1536 cores of an NVIDIA GeForce GTX 680. Still, such intensive simulation appeared slow in relaxing the system's orientational order, and a larger system of hundreds of millions of disks is still desirable for benchmark and confirmation.

The data by D. E. Shaw Research was produced by a special supercomputer called Anton [13] that was designed exclusively for protein molecular dynamics simulation and outperformed all the general supercomputers at that time. Anton, supported with 512 nodes, each containing highly optimized functioning components, can advance a system of 20,000 atoms by ten microseconds in a day, compared with less than 1ns by GROMACS on a personal computer. Furthermore, it can potentially handle larger systems in a scalable manner (almost constant complexity per sweep) thanks to its maximally parallel architecture.

There is a variety of scientific software for molecular simulations, and it is all designed for special contexts. From quantum-effect particles to macro-scale proteins, from serial ones to GPU-parallelization, using Monte Carlo or molecular dynamics, each software works in its specific field to balance versatility and performance. Many widespread tools are open-source, so they attract a worldwide community to maintain and contribute to them. For example, LAMMPS [14] stands for Large-scale Atomic/Molecular Massively Parallel Simulator, and is now maintained and distributed by researchers in Sandia National Labs and Temple University. In this work, we aim to develop ECMC for large-scale all-atom simulations and regard LAMMPS as the fu-1.2. Molecular dynamics ture model.

As for methodology, molecular dynamics tells important time-dependent information such as the accessibility of a given molecular surface, the transition time between two protein states, the appearance and disappearance of a particular chemical channel or cavity. And due to the simultaneous motion of all elements, fast algorithms exist to compute the long-range force on each particle, and parallel algorithms by domain decomposition apply as efficiently as short-range systems. That is why molecular dynamics becomes popular in most biochemical simulation software. On the other hand, just in terms of operation, Monte Carlo abandons the system's natural motion, and it is allowed to take imaginary moves such as cluster flipping in spin models, chain regeneration for polymers, and atomic tunneling to realize substantial changes (see section 1.3.3.4 for more examples). Actually, Monte Carlo restricted only by Eq. 1.1.1 bears much more flexibility in diverse contexts. In the problem of ensemble consideration, parallelization, energy minimization, and many others, Monte Carlo has successfully exploited the freedom of a given system.

In the rest of this chapter, we will introduce molecular dynamics in section 1.2, talking about how the state-of-the-art molecular dynamics works and its major practical concerns. Then in sections 1.3 and 1.4 we will introduce Monte Carlo methods from the most naive reversible one to our irreversible ECMC. In section 1.5, we will give some other necessary knowledge, including the molecular models and measurables in preparation for our work.

Molecular dynamics

According to the ergodic theorem, the time average of a natural orbit equals the ensemble average over the configuration space, so integrating the equation of motion and taking the average along the path converge to statistics in equilibrium. An ideal integrator perfectly reproduces the solution of Newton's equation of motion, or more systematically, of Hamilton's equations

∂q i ∂t = ∂H ∂p i , ∂p i ∂t = - ∂H ∂q i , (1.2.1)
where q i 's are generalized coordinates, and p i 's are generalized momentums.

A molecular dynamics algorithm consists of a numerical integrator and a thermostat used to correct the deviation caused by the integrator. Nevertheless, statistical bias is inevitable during the numerical integration. A second source of error comes from the long-range force calculation since modern Coulomb computation heavily relies on the spatial discretization. What is more annoying is that a source of error implies a set of parameters that a user must handle, and in the case of molecular dynamics, they are integrators, mesh sizes, interpolation methods.... By comparison, Monte Carlo methods do not perform temporal discretization, and ECMC can even avoid long-range force error through its distinct way of the Coulomb force calculation.

Integrator

For time integral, people have developed many algorithms (see [15,16] for reference) that can approximate Newton's equation of motion. Numerical integrators in general all bear some errors without exception, while the error remains at a relatively low level if the integrator respects the structural properties of Hamilton's equations-the time reversibility, volume preservation, conservation of energy and momentum, and more importantly, simplecticity. In practice, energy drift is observed in many kinds of integrators. Zhong and Marsden [17] in 1988 proved that if the energy and the momentum map include all the integrals of motion, then one cannot create integrators that are symplectic, energy preserving, and momentum preserving. As symplecticity implies phase space volume preservation, one cannot, in general, have preservations of phase space volume, energy, and momentum all in one method. In molecular dynamics practice, people use two classes of mechanical integrators: symplecticmomentum and energy-momentum integrators.

Long-range algorithms

Biochemistry requires models with the Coulomb interaction in which truncations in its tail lead to serious artifacts [18]. The solvent consisting of water and possible ions can impose a polarizing effect over charged organic molecules. Challenges arise when long-range interaction is considered, and even modern algorithms heavily depend on mesh methods on which charge spreading and interpolation are commonly based. Imprecision does not vanish, but we control it at a tolerable level. When using LAMMPS with tunable precision levels, one can observe the slowdown with higher precision.

We need fast computation of the Coulomb interaction upon each atom without iterating all atomic pairs. Among all trials, the so-called particle-mesh Ewald [19,20], particle-particle-particle-mesh [21] and an Anton adaptation called k-space Gaussian split Ewald [22] stand out as today's widespread methods.

All predominant long-range methods are developed upon Ewald's summation that splits the potential into a short-range core and a long-range smooth tail. The short-range part is calculated via visiting each particle's neighbors, and the longrange part is dealt with by sophisticated mesh-based methods. Usually, charges are spread into nearby grid points, then it performs convolution by fast Fourier transformation to gain potential values on grids, and does interpolation to acquire forces on individual charges. The second step for the long-range term takes O(N log N ) time and often predominates the total time consumption in molecular simulations (see Table 1 of [13]).

Event-driven molecular dynamics

It is worth mentioning event-driven molecular dynamics here for two reasons: it does improve molecular dynamics performance by getting rid of small timesteps, and our ECMC resembles event-driven molecular dynamics in terms of event processing.

Traditional Monte Carlo

Event-driven molecular dynamics deals with short-range interactions exclusively. In order to get rid of small timesteps, it sacrifices much accuracy of the potential by replacing it with a step-wise potential [23]. Velocities change only when two particles touch the potential step. Such improvement makes molecular dynamics event-driven that the program needs only to predict the next "step-touching" event between which all velocities remain constant, and calculates outgoing velocities. It is an accurate algorithm to simulate inaccurate models.

Event-driven molecular dynamics is particularly suitable for hard disks, and one has to update the time stamps only for colliding disks even though all disks are moving. All upcoming collisions are stored in a central heap to select the soonest event, which is very similar to event processing in ECMC. Consequently, the central heap becomes the algorithmic bottleneck and usually takes O(log N ) to have an event, although there are efforts [24,25] to ease the burden of the heap.

The unpredictable correlation between any parts of the simulated system renders event-driven molecular dynamics difficult to parallelize. An event happening in one corner may trigger immediate events in the distance and destroy all speculations by another thread. People have devised many algorithms [26,27,28] for parallel harddisk simulators and successful algorithms rely on good avoidance of conflicts and fast reversion of already-done moves, and more effort will have to be made for further interaction range.

Traditional Monte Carlo

The term Monte Carlo is used in most cases in company with Markov chain, which indicates a stochastic process that the next state relies only on the current state. The program walks along a chain of target-space states s 1 → s 2 → s 3 • • • , and the probability distribution of s i+1 is solely determined by s i . This is the behavior of all simulations 1 , so we will use the name Monte Carlo but omit Markov chain2 except in section 1.3.1 when talking about its mathematics.

A Monte Carlo algorithm samples a prior probability distribution π(s) of a state space that one only has to know relative probabilities between any two states, i.e., π(s 1 )/π(s 2 ). It includes a strategy to jump to the next state, given the current state. The probability in an n-state space can be described with a vector π = (π 1 , π 2 , ..., π n ), and let T be the transition matrix whose element T ij indicates the probability to go from s i to s j . It satisfies

j T ij = 1, T ij ≥ 0, ∀1 ≤ i, j ≤ n.
(1.3.1) Matrix satisfying Eq. 1.3.1 is also known as stochastic matrix. The distribution of the next state can be conveniently written as πT and it becomes πT n after n moves.

Chapter 1. Simulation method review

Properties of transition matrix 1.3.1.1 Balance condition

The goal of Monte Carlo algorithms is to acquire statistics for the target distribution π, so we hope that π is the stationary distribution of the transition matrix T . Expanding πT = π we get j π(s j )T ji = π(s i ),

which is called global balance condition. This is a necessary condition for target distribution, and it means the conservation of probability flow

j f ji = k f ik = π(s i ), (1.3.3)
with f ji = π(s j )T ji the probability flow from j to i.

There are degrees of freedom to construct a transition matrix T respecting the global balance condition. However, universal constructs applicable to all spaces and energy forms fall under a smaller category. It obeys detailed balance condition that enforces canceling flow between any two states π(s i )T ij = π(s j )T ji , ∀i, j.

(

It is easy to verify that detailed balance implies global balance by summing over j of Eq. 1.3.4. In section 1.3.3 we will present several detailed-balance Monte Carlo methods, but decades of development tell us that a Monte Carlo method as general as the Metropolis-Hasting algorithm and without detailed balance does not exist. Also, we have two properties for the transition matrix which will be used later Proposition.

• If T (1) and T (2) both obey the global balance condition, their product T (1) T (2) satisfies global balance too.

• If T (1) and T (2) commute and obey detailed balance, T (1) T (2) satisfies the detailed balance condition.

Convergence to stationary distribution

A stochastic matrix with the balance condition is not sufficient for the Markov chain to sample the entire space as desired. Intuitively, one must be able to go to any state with an arbitrary starting point, so the space must be connected by the transition matrix.

Another less common situation is that if the chain exhibits periodicity, the chain itself does not converge, but its long-term average does. The two properties are defined as • Irreducibility. For any i and j, there exists a positive integer r so that T r ij > 0.

• Aperiodicity. Let GCD be the greatest common divisor of a set of integers, then T = GCD{s : T s ii > 0} can prove independent of i, and T is aperiodic if T = 1. As for the criteria of convergence, total variation distance [29] is the most common one defined as ππ TVD = 1 2 i |π i -π i |.

Traditional Monte Carlo

(1.3.5)

In the following, we call π = (π 1 , π 2 , ..., π n ) with 0 ≤ π i ≤ 1 and i π i = 1 a valid initial state. Fig. 1.3 (a) shows an example with period T = 2 thus the chain jumps between the sets {1, 4} and {2, 3}. In the case T > 1, π (0) T p does not converge as k → ∞, while the average 1 p p k=0 π (0) T k converges as p → ∞. Theorem 1. Given an n × n irreducible stochastic matrix T , and a valid initial state π (0) , then the average after p iterations

π p = 1 p p-1 k=0 π (0) T k , (1.3.6)
converges to a vector π ∞ as p → ∞. This π ∞ satisfies π ∞ T = π ∞ , and is unique regardless of the initial state.

Its proof can follow that of Theorem. 2, which is given by Levin et al. [29]. In existence of aperiodicity the convergence holds without taking the average. Theorem 2. Given an n × n irreducible aperiodic stochastic matrix T , and a valid initial state π (0) , then π (0) T k → π ∞ as k → ∞. This π ∞ is the unique stationary distribution. Furthermore, there exists α ∈ (0, 1) and C > 0 that

π (0) T k -π ∞ TVD < Cα k . ( 1

.3.7)

A proof can be found in [29], theorem 4.9. This theorem rules out chains jumping between non-intersecting sets, as shown in Fig. 1.3 (a) .

In fact, irreducibility and aperiodicity are satisfied in most physics simulations. The global balance condition is equivalent to that the target distribution is one eigenvector with eigenvalue 1. Theorem. 2 tells us that the Markov chain will surely reach the desired distribution. Therefore, the global balance condition is usually the key requirement to construct Monte Carlo methods.

Ergodic theorem

The ergodic theorem has a similar role as the strong law of large numbers. It states that the stationary distribution is reached, not only statistically when we start from numerous initial states, but also in a single chain when the time tends to infinity. Fig. 1.3 (b) provides an example in which π 1 = π 2 = 1/2 is reached with infinite trials starting from state 3, but no single chain can visit both state 1 and state 2. Irreducibility is violated in this example.

With irreducibility, the target distribution can be ensured when taking statistics of a single chain. Theorem 3. A Markov chain (X 1 , X 2 , ...) is drawn with an arbitrary starting state and transition rule T that is an irreducible stochastic matrix. The mean vectors µ (p) Then the probability

P lim p→∞ µ (p) = π ∞ = 1, (1.3.9)
with π ∞ the unique stationary distribution.

If one starts with state 3 of Fig. 1.3 (b) , with P = 1/2 it gets the chain (3, 1, 1, 1, ...) and otherwise gets the chain (3, 2, 2, 2, ...), which is excluded by this theorem due to the violation of irreducibility. See appendix C of [29] for a proof.

We also have the conjecture without proof that aperiodicity can lead to a stronger conclusion Conjecture 1. A Markov chain (X 1 , X 2 , ...) is drawn with a starting state X 1 and the transition rule T that is an irreducible aperiodic stochastic matrix. We pick an infinite sequence of positive integers a 1 < a 2 < a 3 < • • • The mean vectors ν (p) Then the probability

P lim p→∞ ν (p) = π ∞ = 1, (1.3.11)
with π ∞ the unique stationary distribution.

If this proposition holds, mixing is guaranteed for any pre-selected elements of a single Markov chain.

Eigenvalue analyses

Eigenvalues and eigenvectors are informative in understanding the structure of an operation encoded as a matrix. For a transition matrix representing detailed-balance Markov chain, it has n real eigenvalues.

Traditional Monte Carlo

Theorem 4. Let T be an n × n stochastic matrix that is irreducible and aperiodic, and its stationary vector π = (π 1 , ..., π n ) satisfies π i T ij = π j T ji ∀i, j. Then it is diagonalizable and has eigenvalues

1 = λ 1 > λ 2 ≥ λ 3 ≥ • • • ≥ λ n > -1.
Intuitively, starting with any single state, we project the initial state onto the eigenvectors of T , the component corresponding to the stationary distribution will stay invariant, while other components will be multiplied with λ i after each move. Hence the distance to the stationary distribution decays exponentially, at the rate of λ = max {|λ i | : λ i = 1, i = 1, ..., n} , (1.3.12) if the component corresponding to λ does not vanish. More specifically, we have the following theorem Theorem 5. Let T be an irreducible aperiodic transition matrix for a Markov chain with detailed balance condition, and d(p) be the worst case total variation distance at time p d(p) = max π (0) T pπ ∞ TVD : π (0) is a valid initial state , (1.3.13) where π ∞ is the stationary distribution of T . Then

lim p→∞ d(p) 1/p = λ . (1.3.14)
It means that the second largest eigenvalue really indicates the speed of convergence. We recommand the chapter 12 of [29] as systematic proofs of the two theorems above.

Tricks by modifying target distribution

One of the excitement while thinking about the Monte Carlo method is that we can never expect what will happen if we combine two distinct ideas. Here, we are going to cover several important Monte Carlo methods throughout its history. What is intriguing is that they are not mutually exclusive but extend the power of Monte Carlo in different dimensions. For example, skew detailed balance described in section 1.4.2.2 has an obvious application in the one-dimensional walk in a non-uniform space, so can apply to temperature jumps in extended Monte Carlo. Stochastic potential switching is able to derive the factorization for the Metropolis-Hastings algorithm and ECMC, and can also lead to the cluster algorithm for soft-potential particles.

Many Monte Carlo methods improve by proposing unrealistic moves specific to each physical system, and others construct probability flows beyond the detailed balance condition. Nevertheless, some ideas appear even by reconsidering the target distribution. Here we introduce three methods that reach the desired probability via a different energy function.

Importance sampling

Sometimes the target distribution π fails to cover the phenomenon of interests, e.g., singularities with little weight but significant contribution to physics, rare events that Chapter 1. Simulation method review occur infrequently but are crucial to the studied system. If we have some prior knowledge under what circumstance the crucial event happens more, then we can bias the sampler by giving it a new distribution π . π concentrates more on the interesting points, and the Monte Carlo algorithm with importance sampling takes π as the target distribution and performs any Monte Carlo method. However, the drawn samples are weight with π(s i )/π (s i ) to make the estimator unbiased .3.15) where on the rightmost side, {s k } are N s states generated by a standard Monte Carlo algorithm with biased π .

O = n i=1 O i π i = n i=1 O i π i π i π i ≈ 1 N s Ns k=1 O(s k ) π(s k ) π (s k ) , ( 1
A straightforward example of importance sampling is to integrate 1 0 x -p dx (see [30], section 1.4.2), where naive Monte Carlo by drawing randomly x i ∈ (0, 1] is slow to capture the property around x = 0. Applications of importance sampling include rare event simulations [31]. However, it has two drawbacks: First, π is not always obvious 3 ; Second, π/π is hard to calculate, especially when the partition function is unknown.

Stochastic potential switching

Stochastic potential switching was first formulated by Mak [32]. Before, the initial idea appeared in Swendsen and Wang's cluster algorithm [33] for the Ising model that probabilistically turns off part of interactions. Here we present it by splitting the desired probability distribution.

One can split the target distribution into two positive parts π = π + π . For each term we design a tailored Monte Carlo algorithm, i.e., using one Monte Carlo algorithm to explore π and the other to explore π . This is feasible because Monte Carlo only needs to know π(s i )/π(s j ) instead of absolute values. Before each Monte Carlo step or several steps, the program must determine which term of π it is going to explore by the corresponding ratio, namely π (s i )/π(s i ) and π (s i )/π(s i ).

Fig. 1.4 illustrates the stochastic potential switching process. Changing π to π or π amounts to using new potentials instead, and they satisfy exp(-βU ) = exp(-βU ) + exp(-βU ) and hence the name. Splitting π into many does not always speed the mixing of states. However, if we have a fast Monte Carlo algorithm for π then the overall sampling is fast4 . Mak found another example [32] besides the cluster Ising model. In the Lennard-Jones liquid, he turned off by certain probability the attractive tail of the Lennard-Jones interaction (each interaction pair is switched separately, so strictly speaking, π is divided into 2 P terms where P is the number of pairs interacting with Lennard-Jones tail). With the majority of interactions off, faster algorithms become effective such as cluster flipping, which promotes the overall efficiency of the original simulation. Incidentally, stochastic potential switching can also derive factorization, for both Metropolis-Hastings algorithm and ECMC. Taking the Metropolis-Hastings algorithm for a two-state system as example, let π(s 1 ) = 1 and π(s 2 ) = e -β(U 1 +U 2 ) , then a Metropolis-Hastings acceptance ratio is min{1, e -β(U 1 +U 2 ) }. We assume U 1 ≤ U 2 and split their probabilities as π (s 1 ) = min 1, e -βU 1 , π (s 1 ) =1 -min 1, e -βU 1 , π (s 2 ) = min 1, e -βU 1 min 1, e -βU 2 , π (s 2 ) =e -β(U 1 +U 2 ) -min 1, e -βU 1 min 1, e -βU 2 .

Traditional Monte Carlo

(1. 3.16) Transition rates become switching rates multiplied by acceptance rates for both channels. One can check that the transition rate s 1 → s 2 is min 1, e -βU 2 min 1, e -βU 1 through π , and is 0 through π under the condition U 1 ≤ U 2 (otherwise we switch U 1 and U 2 ). The result is the same as the factorized Metropolis-Hastings method (see section 1.3.3.1).

Replica exchange Monte Carlo

Replica exchange Monte Carlo is also known as extended ensemble Monte Carlo. The equilibrium state is physically a function of temperature π = π(•, β), and it is intuitive that, for one dimension, the high temperature boosts the transition across the energy barrier between local minimums. One way to exploit high-temperature's fast transition while leaving the estimation unbiased is by extending the ensemble to replicas of multiple temperatures.

The state space {s i } is then given an additional temperature variable {s i , β k } with

β k ∈ {β 1 > β 2 > • • • > β B > 0}
and β 1 is the desired system temperature. π(s i , β k ) ∼ Chapter 1. Simulation method review e -β k U (s i ) /Z k agrees with the state probability at β k , and the program just samples in this extended space. If we hope that program to stay in all temperature replica with the same probability then we have to set Z k = s i e -β k U (s i ) /B, the free energy at β k divided by B.

Simulated tempering proposed by Marinari and Parisi [34] keeps one replica at each moment as normal Monte Carlo. It travels at fixed β k , but jumps to β k-1 or β k+1 occasionally and leaves the physical state invariant. To reach homogeneous probability in β, the spirit of Monte Carlo is employed again, and the simplest Metropolis-Hastings method (see section 1.3.3.1) suggests r = min{1, e -(β k±1 -β k )U (s) Z(β k )/Z(β k±1 )} where U (s) is the energy for the current state independent of β. Numerous problems revolve around simulated tempering. How to acquire Z(β)? Is the homogeneous distribution always good? Are there better schemes than local jumps of the Metropolis-Hastings style?

Hukushima and Nemoto [35] proposed parallel tempering where B states each with β 1 , • • • , β B are kept and simulated simultaneously. At certain moments neighboring states exchange their configurations, i.e., {s 1 , β k }, {s 2 , β k+1 } → {s 2 , β k }, {s 1 , β k+1 } and the Metropolis-Hastings style acceptance ratio is min{1, e -(β k -β k+1 )(U (s 2 )-U (s 1 ) }. Parallel tempering serves as a powerful tool for the acceleration of all Monte Carlo simulations and attracts a great number of studies over its implementation and adaptation. The additional temperature axis brings another degree of freedom concerning the temperature switching scheme. Finally, it is important to note that the number of temperatures scales as the total energy variation in order to keep a reasonable acceptance in switching, while the total energy is usually proportional to the system size.

Several reversible algorithms

If detailed balance holds, the chance for a chain (s 1 , s 2 , • • • , s n ) equals its reverse because

P (chain = (s 1 , • • • , s n )) = π(s 1 )T s 1 s 2 • • • T s n-1 s n =T s 2 s 1 • • • T (s n s n-1 )π(s n ) = P (chain = (s n , • • • , s 1 )).
(1.3.17)

In the second step the detailed balance condition is applied. The converse statement is also true by expanding P (chain = (s i , s j )) = P (chain = (s j , s i )). Under the detailed balance condition people have developed lots of Monte Carlo variants for it allows a wide range of probability redistribution schemes.

Metropolis-Hastings algorithm

Metropolis et al. [36] first applied Monte Carlo in physical simulations, and their idea was generalized by Hastings [37]. They decomposed the choice of the next state T ij into proposing followed by accepting, with probabilities f p and f a respectively. If the proposal rate is symmetric, i.e., f p (s i → s j ) = f p (s j → s i ), then detailed balance requires e -βU (s i ) f a (s i → s j ) = e -βU (s j ) f a (s j → s i ).

(1.3.18)

Traditional Monte Carlo

Metropolis et al. found a simple solution

f a (s i → s j ) = min 1, e -β(U (s j )-U (s i )) (1.3.19)
satisfying the detailed balance. In fact, for a two-state space, the famous Metropolis-Hastings algorithm maximizes the flow between the states. The acceptor obviously relies on the total energy change of the system. Interestingly, if we split the total energy into terms U = r U r and let each term lead an individual acceptor, detailed balance is respected in which the final acceptance implies that all terms accept, which we called factorized acceptance ratio

f Fact a (s i → s j ) = r min 1, e -β(Ur(s j )-Ur(s i )) .
(1.3.20)

We call each U r a factor, and the way to split U is called factorization. In appearance, a factorization does not speed up mixing because it reduces the transition rate while increasing the rejection rate (i.e., the probability of staying in the same state). In some special cases, factorization has inspired fast algorithms without calculating total energy (see section 3.3). If the system involves long-range interactions, any move of a particle leads to changes of O(N ) terms, and the factorized form allows efficient sampling instead of O(N ) enumeration, which is the key idea for ECMC to simulate long-range systems. The Metropolis-Hastings algorithm is so simple in concept and easy to implement that it becomes the baseline of all later advances. However, such a simple idea suffers a significant drawback: a naive implementation enforces local proposals, and the detailed balance condition imposes diffusive dynamics over the probability flow, which renders the method slow to reach the stationary distribution.

Gibbs sampler

The Gibbs sampler [38] is also known as heat-bath Monte Carlo. In a multivariate system if one component of the state s i = (x 1 , x 2 , ..., x p ) takes among n values v 1 , ..., v n , Gibbs sampler relaxes one variable each time to its conditional target probability. Putting explicitly, let

s i = (x 1 , x 2 , ..., x k = v i , ..., x p ) and s j = (x 1 , x 2 , ..., x k = v j , ..., x p ) then T s i s j = π((x 1 , x 2 , ..., x k = v j , ..., x p )) vn v=v 1 π((x 1 , x 2 , ..., x k = v, ..., x p )) (1.3.21)
which does not rely on the current value of x k . The Gibbs sampler that chooses random i and updates {x i } satisfies detailed balance, whereas the one updating x i in a sequential manner violates detailed balance but preserves only global balance (see section 1.4.1.1). Taking a two-state example, the Gibbs sampler always means that the next state is s 1 with probability π(s 1 ) and s 2 with π(s 2 ). This is in fact slower than the Metropolis-Hastings algorithm because the latter will never allow two consecutive s 2 if π(s 1 ) ≥ π(s 2 ).

Chapter 1. Simulation method review

Overrelaxation

For simplicity, assume that we are sampling according to a univariate normal distribution π(x) ∼ e -ax 2 , and by Gibbs sampling the transition from x to x is identical to probability of π(x ). Adler [39] modified the proposal distribution to have the form

T x,x = 1 Z exp - a ω(2 -ω) (1 -ω)x -x 2 , (1.3.22)
with an adjusting parameter ω and the normalizing parameter Z. When ω = 0, x = x; when ω = 1, the same Gaussian distribution is taken where x centers around 0; when ω = 2, x = -x. This method, called overrelaxation, directly applies to the energy of the quadratic form. Whitmer [40] showed that taking ω close to 2 leads to much faster sampling in multi-quadratic actions of the lattice model. Moreover, as the number of variables increases, ω close to 2 is more favorable, meaning that the algorithm always tends to negate the previous x i .

Efforts have been made to generalize to arbitrary energy functions since the overrelaxation of quadratic form was proposed. Parameterization into a conditional Gaussian distribution [41] is possible, yet more systematic solutions [42] rely on sampling and filtering. Neal [43] proposed a smart algorithm by sampling a number of the variable to be updated, conditioned on other variables, and taking the same index as in the old value but in reverse order.

Cluster Monte Carlo

Cluster Monte Carlo very well reflects the advantage of the Monte Carlo method. It performs substantial changes in the system, connecting two faraway points in the phase space that molecular dynamics cannot achieve. Some systems are really hard to sample using local methods. For example, the two-dimensional Ising spin at the critical point has infinite spatial correlation, giving rise to huge clusters (i.e., connected same spins) 5 . Here we present briefly cluster Monte Carlo for spins, hard disks, and polymers (see [44] and section 2.4 of [45] for reference). [33] first proposed a fast-relaxation algorithm for the critical-point 2D Ising model by constructing clusters based on configurations and randomly assigning the same spin within clusters. This idea was reformulated by Wolff [46] later to become the most popular cluster spin algorithm.

Spin Swendsen and Wang

Each cluster move of the Wolff algorithm starts with one random spin, adds a same neighboring spin into the cluster with probability e -2βJ where coupling constant appears in U =i,j Js i s j , and flips the spin of the entire cluster as one move. They argued that this sophisticated rejection-free scheme satisfies detailed balance, and numerical tests showed that it brought the dynamical critical exponent down to z = 0.13 from z ≈ 2 of local Monte Carlo.

Irreversible Monte Carlo

The success in the Ising model inspired the generalization in continuous spin models [46], anti-ferromagnetic models and spin glasses [47,48]. A key issue to the efficiency of cluster algorithms is the cluster size. We hope that both the cluster size and its complement are of the magnitude of system size, which occurs at the percolation threshold.

Hard disk Large-scale moves of hard disks are more easily realized in relatively low density. The best-known algorithms are the geometric cluster algorithm [START_REF] Dress | Cluster algorithm for hard spheres and related systems[END_REF] and the Jaster algorithm [START_REF] Jaster | An improved Metropolis algorithm for hard core systems[END_REF], both of which favor low density to achieve fast mixing.

The geometric cluster algorithm chooses a pivot to perform reflections on the original configuration. The overlap of new and old configurations induces bonds between disk pairs, and clusters are formed with the inter-disk bonds. Reflecting one entire cluster does not have conflicts with any other cluster, so clusters can be either reflected or remain unchanged, which is rejection-free. On the other hand, the Jaster algorithm starts with translating a random disk by distance in a random direction, and does the same for the one causing collision until no collision occurs, and it accepts the translated configuration. If one translation results in more than one conflict, then it is rejected. The same concern of moved cluster size exists in both algorithms. Incidentally, the Jaster algorithm resembles ECMC in the sense that they both induce a chain of hard disks displaced in the same direction.

Polymer A polymer can be described as chains of interacting particles p 1 , p 2 , ..., p N .

The ties between two adjacent particles within a chain are much stronger, sometimes even rigid, than the rest of particle pairs, so polymer transformation is usually considered as an unconventional move to fast explore the polymer's conformational space.

Proposed by Siepmann and Frenkel [51] is a typical Monte Carlo algorithm by resampling part of the polymer's chain. It would be easier if we set all particles on lattice sites. First, it relaxes a random segment p k , p k+1 , ..., p N of the chain from one end, then settles p k and records non-occupied sites W k and all possible sites W k for it. And do the same for p k+1 until p N . The acceptance rate is the product N i W i /W i which is lowered with increasing density.

Irreversible Monte Carlo

Irreversible Monte Carlo evolves through a Markov chain with a definite time direction, generating a Markov chain with a different probability from its reversed chain. As reversibility is synonymous with the detailed balance condition, the reversible probability flows f ij and f ji cancel between i and j under detailed balance, so the program explores the configuration space in a random-walk manner. Only with detailed balance, universal algorithms exist, such as the Metropolis-Hastings algorithm and the Gibbs sampler applicable to all energy functions.

We call a series of operations that change O(N ) elements a sweep, such as N single-flip trials for a spin system. To understand the dynamical benefit brought by irreversible Monte Carlo, we express the time consumption to draw an effective sample Chapter 1. Simulation method review as t = C * t swp * t cor .

(1.4.1)

Time for a sweep t swp is O(N ) for short-range system, and is complicated for longrange system depending on methods to compute O(N ) interactions. It is also noteworthy that a larger system usually implies a greater rejection rate if pairwise factorization is employed. The correlation time t cor indicates how many sweeps it costs to have an independent sample. It is not evident but is usually acquired by realistic measurements, taking the form of t cor = O(L z ) where L is the system side length, since it relates to physical modes propagating across the system. z is called dynamical exponent and has special physical interests.

Since the invention of reversible Monte Carlo, people have been trying to improve it by introducing directions to guide the program in the state space. Random walks in a system of size N usually take O(N 2 ) steps, and from the perspective of a continuous system, the Metropolis-Hastings algorithm introduces diffusive dynamics, so any density disturbance takes O(L 2 ) to propagate, that is why it often results in z ≈ 2 in many common systems.

Turitsyn et al. [52] draw an analogy to mixing sugar in a cup of coffee, in which detailed-balance Monte Carlo with diffusive behavior equilibrates like the sugar naturally dissolving into the coffee. Stirring the liquid will conceivably accelerate the mixing, and in this case, there is a preferred direction for any point in the configuration space. Illustrated in Fig. 1.5 are different degrees of irreversibility. Sometimes it is not difficult to construct small loops in a micro-system, i.e., directional tour in a few local states, which proves helpful but cannot essentially change Monte Carlo's behavior. Only with a global direction can an algorithm get rid of O(L 2 ) scaling and achieve fast exploration.

However, there is no easy construct of irreversible Monte Carlo, for it must satisfy the global balance condition. Methods presented in the following achieve irreversibility either with limited improvement, or under additional information. Our goal is to have an algorithm that eliminates the random-walk behavior so that observable autocorrelations will not scale up as O(L 2 ). The challenge is that even people painstakingly devise an irreversible Monte Carlo, it proves locally irreversible (case of Fig. 1.5 (b) ), and the exponent z does not improve. By contrast, ECMC works in any continuous space 6 , and achieves a reduction in the dynamical exponent in many systems though its move is local.

We classify irreversible Monte Carlo methods into two classes: one with lifting variables and the other with no lifting variable. Information kept in lifting variables somehow resembles a general direction, so it presents more hope to achieve global directionality, whereas non-lifting Monte Carlo has no more information than traditional ones, so it is expected to only accelerate by a constant.

Irreversible Monte Carlo

Non-lifting irreversible Monte Carlo

While developing ECMC, we always wonder what role the lifting variable that indicates active particle plays for the efficiency of ECMC. Such a lifting variable makes the active particle motion persistent, and by imposing very short chains, the performance of ECMC returns to the case of traditional Monte Carlo. However, advancing active particles in the same direction is not equivalent to traveling in phase space without turning back. On the other hand, keeping explicit directions in lifting variable does not always help, as suggested by the example of skew detailed balance (see section 1.4.2.2).

By presenting three examples of non-lifting Monte Carlo followed by two with lifting, we review people's effort in achieving irreversibility. Actually, two of three non-lifting irreversible Monte Carlo keep additional implicit information: The next variable to relax in a sequential scheme, and the momentum in hybrid Monte Carlo. Checking how different degrees of irreversibility improve mixing provides us instructive (though feeble) clues over the role of lifting in ECMC's excellent performance.

Sequential updates

The most straightforward irreversible scheme comes from updating variables in a sequential manner. While performing Metropolis-Hastings or Gibbs style updates on spin systems, instead of randomly choosing the next spin to flip for the Ising model, we can try to change spin 1, spin 2,..., until spin N and then go back to spin 1. This method is obvious without detailed balance since one cannot change back spin k immediately after making trial on it.

Denote T (k) as the transition matrix for relaxing the variable k using any reversible scheme. The whole procedure is then imposing T (i) consecutively for i from 1 to N . Since each T (k) satisfies detailed balance, the product T (1) T (2) • • • T (N ) preserves global balance.

Early in the inital paper [36] of Monte Carlo methods, Metropolis et al. has already applied sequential updates of particles. Ren and Orkoulas [53] investigated the performance of a sequentially updating scheme in comparison with a random one. Intuitively, updating one spin will result in the tendency of changing its neighbors. They argued that the transition matrix T S = N i=1 T (i) has smaller diagonal terms T S ii than those for random updates. According to Peskun's theorem [54], a transition matrix with small diagonal terms implies less rejection rate and faster equilibration. The advantage of sequential updates is not only a prefactor faster in simulation, but underpins a rigorous parallelization paradigm. Ren and Orkoulas [55] showed that sequential updates can be split into several non-interacting branches based on domain decomposition, which can be performed concurrently. Multiple processors will be able to execute each branch in a parallel manner without losing accuracy.

In fact, the concept of sequential updates has broader usage than just in Metropolis-Hastings or Gibbs updates. It favors a manual selection of the next variable to be relaxed. Lei and Krauth [56] proved that, if we treat each chain in ECMC as an operation, for N hard disks on a ring, a sequential choice of the initial particle of each chain can reduce the mixing time scaling from O(N 2 log N ) to O(N 2 ). Furthermore,

Geometric Allocation

When the number of states is limited, Suwa and Todo [START_REF] Suwa | Markov chain Monte Carlo method without detailed balance[END_REF][START_REF] Todo | Geometric allocation approaches in Markov chain Monte Carlo[END_REF] graphically interpreted the global balance condition as reallocating probabilities. They found an efficient scheme with zero flow into the same configuration. Demonstrated in Fig. 1.6 are probability allocations for three common algorithms. Each state s i has contribution π(s i ) (i.e., outgoing flow) and capacity π(s i ) (i.e., incoming flow), illustrated as color bars and frames respectively in Fig. 1.6. The Metropolis-Hastings algorithm is the random proposal followed by a ratio filter, and Gibbs sampler relies on proportionate redistribution, both of which cannot avoid self-flow f ii . Instead, the Suwa-Todo algorithm starts from the maximum-probability state denoted as s 1 , inserts contributions π(s 1 ), π(s 2 )... into a first-in-first-out (FIFO) queue. Then, it begins fulfilling capacities from s 2 with elements outputting from the FIFO queue. In this way, if π(s 1 ) ≤ 1/2, the rate of rejection is always zero.

For systems whose configurations are countable, it is usually possible to perform geometric allocation with respect to individual components. For a state consisting of p variables, s = (x 1 , x 2 , ..., x p ) with x k taking value among v 1 , ..., v n , a list of n elements π((x..., x k-1 , •, x k+1 , ...)) will be created with n elements to update variable x k .

Direct applications include the Potts model [START_REF] Suwa | Markov chain Monte Carlo method without detailed balance[END_REF][START_REF] Todo | Geometric allocation approaches in Markov chain Monte Carlo[END_REF] in which the Suwa-Todo algorithm exhibits considerable acceleration depending on the system specification. An interesting application is the temperature change in extended-ensemble Monte Chapter 1. Simulation method review Carlo (see section 1.3.2). People have tested the Suwa-Todo allocation in temperature updates for both simulated tempering [START_REF] Mori | Simulated tempering based on global balance or detailed balance conditions: S uwa-t odo, heat bath, and m etropolis algorithms[END_REF] and parallel tempering [START_REF] Itoh | Replica-permutation method with the Suwa-Todo algorithm beyond the replica-exchange method[END_REF], and it is reported that the irreversible Suwa-Todo scheme facilitates temperature exchange and hence the overall performance. Despite the zero probability returning to any state, the Suwa-Todo method remains locally irreversible and the speedup is up to a constant, because it is usually unfeasible to put the entire phase space to the FIFO queue.

Hybrid Monte Carlo

Hybrid Monte Carlo, also known as Hamiltonian Monte Carlo, was introduced by Duane et al. [START_REF] Duane | Hybrid monte carlo[END_REF]. It applies only to continuous configuration space because it uses a molecular dynamics integrator to generate proposal moves. The Metropolis-Hastings filter is used to accept the move (see [START_REF] Brooks | Handbook of markov chain monte carlo[END_REF], chapter 5).

Hybrid Monte Carlo process can be described as:

1. Extend the state space s = (q 1 , ..., q n ) to a phase space with velocity so that s = (q, v), q = (q 1 , ..., q n ), and v = (p 1 , ..., p n ). Define the Hamiltonian H(q, p) = U (q) + n i=1 p 2 i /2.

(a)

For the current (q, p), perform Hamiltonian mechanics of Eq. 1.2.1 for time t, which reduces to qi = p i and ṗi = -∂U/∂q i . Then let p = -p(t), q = q(t). (b) Accept (q , p ) with the Metropolis-Hastings filter, and the energy is replaced with H.

3. Flip p ← -p .

Disturb p by p

= p √ 1 -α + αN,
where N is a normal distribution with same dimension of p centering around zero and has variance corresponding to the temperature, α is a tuning parameter.

5. Take (q , p ) as a new state and go to step 2 until halted.

Let T (1) , T (2) , T (3) be operators representing steps 2, 3, and 4 respectively. We can argue that hybrid Monte Carlo ensures the desired distribution π. First, p and q are decoupled in H so p π(q, p) ∝ e -βU (q) . Second, which is crucial, Hamiltonian mechanics is reversible and volume-preserving, thus T (1) respects detailed balance, and detailed balance for T (2) and T (3) is obvious, so their product T (1) T (2) T (3) respects global balance. Third, ergodicity is ensured by α > 0.

Flipping twice p is for arguing the balance condition, which needs not explicitly performing. Step 2 must be done with a numerical integrator, and it follows that the integrator must be time-reversible and volume-preserving, such as the leap-frog method. Nevertheless, the entire scenario is clear: New state is deterministically generated by the Hamiltonian integrator for certain time steps. If α = 1, it accepts the new state through the filter, then erases the previous momentum and resamples anew. If α = 0, it keeps the momentum for an accepted move and reverses the momentum for a rejected move. Keeping the momentum contributes to directional exploration, while momentum reversal makes it double back. Thus α serves as a crucial parameter over 1.4. Irreversible Monte Carlo reversibility 7 , and good balance [START_REF] Culpepper | Building a better probabilistic model of images by factorization[END_REF] must be kept for optimal efficiency. Also, hybrid Monte Carlo introduces a set of tuning parameters such as the small step , t, and possibly masses m i assigned to each momentum, which all affect the performance.

Lifting irreversible Monte Carlo

Reversible Monte Carlo methods employ symmetric proposal probabilities f p (i → j) = f p (j → i) so that tuning the acceptance rate allows us to realize detailed balance. Many systems achieve fast exploration with explicit use of direction. For example, particle momentum counteracts diffusive dynamics to make components in a fluid mix faster. Angular momentum drives a molecule under constant rotation. Persistence in flipping up spins or flipping down will also lead to rapid decorrelation between spin configurations.

Lifting variables allow people to add information in Monte Carlo moves so that the program has the memory of previous moves. A state s i is extended with a lifting variable s i = (x i , a i ), and the proposal depends heavily upon the lifting variable a i . Here we present several lifting irreversible Monte Carlo ideas, including onedimensional random walk, skew detailed balance, and our ECMC.

One-dimensional random walk

A chain of N sites with uniform desired probability is one of the few models with lifting variables that rigorous mathematics can apply. Diaconis et al. [START_REF] Diaconis | Analysis of a nonreversible Markov chain sampler[END_REF] established the first rigorous scaling of convergence for lifting irreversible Monte Carlo, proving that its mixing time converges within O(N ) steps compared to O(N 2 ) with an undirected random walk.

Previously, an unbiased random walk may jump from site i to i -1 or i + 1 each with probability 1/2. The end of the chain needs special treatment if periodic boundary conditions are not applied. Diaconis et al. added the direction to the state represented by (i, d) with d = ±1, and the transition rule is

T (i,d)→(i+d,d) = 1 - 1 N , T (i,d)→(i+d,-d) = 1 N . (1.4.2)
A special transition rule is needed for the site 0 and N -1 since they did not employ periodicity. It means that Monte Carlo will probably move in the same direction as the preceding move with probability 1 -1/N , but may also change the lifting variable with probability 1/N . They proved that starting with any state, the total variation distance with respect to the stationary state after l updates drops to ∼ C l/N where 0 < C < 1. This implies that the convergence rate in terms of sweeps, does not rely on the system size, which outperforms unbiased random walk which takes N 2 steps (namely N sweeps) to reach a distance of N . The generalization to two-dimensional cases is mentioned in Chen et al. [START_REF] Chen | Lifting Markov chains to speed up mixing[END_REF] Chapter 1. Simulation method review

For non-uniform distribution, Diaconis et al. [START_REF] Diaconis | Analysis of a nonreversible Markov chain sampler[END_REF] also gave an algorithm with transition

T (i,d)→(i+d,d) = p MH (1 -θ), T (i,d)→(i+d,-d) = p MH θ, T (i,d)→(i,d) = (1 -p MH )θ, T (i,d)→(i,-d) = (1 -p MH )(1 -θ), (1.4.3)
where p MH = min{1, e -β(U (s i+d )-U (s i )) } is the Metropolis-Hastings filter, and θ is a small adjusting parameter. Special conditions are needed for sites on the boundary. Improvement depends on specific problems and individual distributions.

In fact, this one-dimensional non-uniform sampler is not unique. The Suwa-Todo algorithm in section 1.4.1.2 gives another construct with zero flow back to the same site, but needs to know π(s i ) for all i before allocation. The ladder construct of nondetailed-balance Hybrid Monte Carlo by Sohl-Dickstein et al. [START_REF] Sohl-Dickstein | Hamiltonian Monte Carlo without detailed balance[END_REF] provides one more possibility, which reduces rates of d → -d by looking ahead (If current site is s i , it calculates relative values of π(s i ), ..., π(s i+K )). Skew detailed balance introduced in section 1.4.2.2 has a direct application in the one-dimensional chain, and achieves minimal turnaround rate of d → -d using π(s i±1 ) and π(s i ) only.

Skew detailed balance

Skew detailed balance was first proposed by Turitsyn et al. [52,[START_REF] Vucelja | Lifting-a nonreversible Markov chain Monte Carlo algorithm[END_REF], a framework allowing people to manipulate proposed directions. It is constructed upon existing reversible flow.

To apply skew detailed balance, as other lifting Monte Carlo methods, we first extend any state with an additional lifting variable s = (x, a). For simplicity, we let a ∈ {-1, +1}. We have to make clear what the proposed states are for any value of x and a. For example, in the two-dimensional Ising model, a = 1 means that the next move is to flip up one spin, and a = -1 means to flip down one spin. Thus the proposed set of configurations for s i are grouped into two small sets {p - i } and {p + i }. Then one has to choose an underlying reversible flow that is presumably Metropolis-Hastings style while other schemes have been tested [START_REF] Faizi | Efficient Irreversible Monte Carlo Samplers[END_REF]. We duplicate states {s i } into two copies {s + i } and {s - i }. For {s

+ i } the flow {p - i } → s + i → {p + i } are kept, and for {s - i } the flow {p + i } → s - i → {p - i } are kept
. Also, we have to set up flows between s + i and s - i to make incoming and outgoing flows meet, together with self-loops to reach global balance. Specifically we have Note that skew detailed balance requires flows of both incoming and outgoing states to determine replica switching flow, which is not always feasible and limits the applicability of skew detailed balance algorithms. Turitsyn et al. [52] originally applied the skew detailed balance to the mean-field Ising model, i.e., Ising model in which any spin interacts with all others with the same intensity 8 . They found that critical slowdown appearing in the Metropolis-Hastings algorithm does not exist with irreversible skew detailed balance, which was also reported by Fernandes and Weigel [START_REF] Fernandes | Non-reversible Monte Carlo simulations of spin models[END_REF]. Sakai and Hukushima [START_REF] Sakai | Eigenvalue analysis of an irreversible random walk with skew detailed balance conditions[END_REF] studied the transition matrix under skew detailed balance condition on a N -state circle with a uniform distribution and concluded that proper choice of parameters does improve the relaxation rate.

T (j,d),(i,d) =T ji , ∀j = i, j ∈ {p -d i }, T (i,d),(j,d) =T ij , ∀j = i, j ∈ {p d i }, π(s i )T (i,d),(i,-d) =    j∈{p -d i } π(s j )T (j,d),(i,d) - j∈{p d i } π(s i )T (i,d),(j,d)    + + C, T (i,d),(i,d) =1 - j∈{p d i } T (i,d),(j,d) -T (i,d),(i,-d) , ( 1
Further investigations were done in both one-dimensional and two-dimensional Ising models. The Ising model is one of the few models that allow us to calculate flow sums like s∈p - i s → s + i in O(1) time, with the bookkeeping of the number of spins for each kind of neighbor compositions. Sakai and Hukushima [START_REF] Sakai | Dynamics of one-dimensional Ising model without detailed balance condition[END_REF] discussed in detail the effect in the dynamics of different constructs of skew detailed balance. They found that one of the parameter choices was able to reduce the dynamical critical exponent. For the two-dimensional Ising model, however, no evidence shows a significant reduction in dynamical exponent [START_REF] Fernandes | Non-reversible Monte Carlo simulations of spin models[END_REF][START_REF] Hukushima | An irreversible Markov-chain Monte Carlo method with skew detailed balance conditions[END_REF]. Nevertheless, skew detailed balance provides an ideal sampling algorithm in one-dimensional states, with the only requirement of neighboring state probabilities. Sakai and Hukushima [START_REF] Sakai | Irreversible simulated tempering[END_REF] also applied it to simulated tempering and gained acceleration in the relaxation of the two-dimensional Ising model.

Chapter 1. Simulation method review

Models and measurements

We are not going to study various molecular models in this thesis but will take the all-atom SPC/Fw water model [START_REF] Wu | Flexible simple point-charge water model with improved liquid-state properties[END_REF] as an ideal testbed.

Molecular models

Classical molecular models are classified into three levels-all-atom, united-atom, and coarse-grain models, depending on the represented atomic groups for one simulated unit. The all-atom model is also known as explicit-atom model, meaning that each atom is represented by one object, typically a point charge, regardless of the atom type and size. The united-atom model, in contrast, groups several atoms into one unit, usually called a radical group like -CH 2 -, -CH 3 and -O-. Each united atom group is treated as one object. Moreover, a coarse-grain model combines a couple of united atoms into a bigger object. The interactions in all three models consist of bounded interactions between two adjacent units and non-bounded interactions, possibly between any pair. Parameters for the interaction are obtained from simulations or ab initio methods. From all-atom model, united-atom model, to coarse-grain model, they become more efficient in computation but are less accurate [START_REF] Chen | A comparison of united atom, explicit atom, and coarse-grained simulation models for poly (ethylene oxide)[END_REF].

We focus on the all-atom water model in this thesis for the sake of simplicity even though ECMC can, in principle, handle all kinds of models and interactions.

Measurements

There are various approaches to measure the convergence of a certain Monte Carlo method such as correlation time, mixing time, χ 2 rate of convergence, etc (see [29] for reference). They do not agree in value and even in scaling with respect to the system size. Here we are not going to discuss their difference but present the correlation time, which is the simplest and most visible in our numerical experiments.

An observable is a function of states: X : C → R possibly representing any physical quantity 9 , where C is the configuration space. Through a Markov chain we get a series of observables {X i } for i = 1, ..., M (see section 2.3.3 for sampling in ECMC). Then we obtain its estimate by

X = i π(s i )X(s i ) ≈ 1 M i X i , (1.5.1)
The deviation of data scales as 1/ √ M and we wonder how the quality of the estimate increases with larger sample size. Explicitly, a good measure for the convergence speed is

var(X) = lim M →∞ M var M i=1 X i M . (1.5.2)
This limit converges to a constant and it is determined by the number of independent samples in a chain. Thus it is straightforward to introduce the sample autocorrelation

cor X (t) = (X(s) -X)(X(s + t) -X) X2 -X2 (1.5.3)

Models and measurements

where X is the same as X . By expanding var(X) we have

var(X) = lim M →∞ 1 M X i 2 -M 2 X2 = +∞ t=-∞ cor X (t) X2 -X2 , (1.5.4)
with the assumption that cor X (t) decays exponentially for large t. Actually cor X (t) ∼ e -t/τcor , and τ cor is the autocorrelation time of X. The curve cor X (t) is our measure of convergence in later chapters.

cor X (t) = (X(s) -X) * (X(s + t) -X) |X| 2 -| X| 2 (1.5.5)

Chapter 2

Event-chain Monte Carlo

Introduction

ECMC was proposed [START_REF] Bernard | Event-chain Monte Carlo algorithms for hard-sphere systems[END_REF] by Bernard and Krauth in 2009. It was initially designed to equilibrate hard-disk systems. In that work, hard disks undergo sequential moves called chains, during which one hard disk moves in a fixed direction until it hits another disk. Then the target disk, which previous moving disk collides with, takes over the velocity until it hits a third disk, or the sum of displacements of all disks reaches the constant chain length . This simple process preserves global balance, and different options exist in deciding the target disk's direction of motion and how to sample the initial direction for each chain. Bernard and Krauth found that the scheme moving all disks in the same direction within one chain, which violates detailed balance, achieves the fastest mixing. Later, they applied ECMC in an unprecedented large-scale hard-disk simulation [9] and revealed the phase transition of the hard-disk system with the most convincing evidence ever. The continuous transition followed by a first-order phase transition in solid-hexatic-liquid melting scenario contradicts both the long-established one-step melting and the two-step KTHNY process [4,5,6,7]. In the following work, different state-of-the-art simulation methods were implemented. ECMC, event-driven molecular dynamics and massively parallel local Monte Carlo were compared in the sense of their performance. For 512 2 hard disks, ECMC is roughly 70 times faster than local Monte Carlo and is seven times faster than event-driven molecular dynamics, and is only defeated by parallel local Monte Carlo when more than one thousand GPU cores run simultaneously.

The generalization of ECMC to arbitrary continuous potentials did not appear until the work by Peters and With [START_REF] Peters | Rejection-free Monte Carlo sampling for general potentials[END_REF] which prove that the global balance condition is respected if, for a factor, the energy change before the next event is drawn from an exponential distribution with mean 1/β. Afterward, the extension for many-body interactions was proposed [START_REF] Harland | Event-chain Monte Carlo algorithms for three-and many-particle interactions[END_REF] by Harland et al., with the same event rate β[∂U/∂x A ] + as a two-body factor, but one must specify an additional scheme to determine the next active particle. We will give a graphic explanation for it in section 2.2.2. In addition, Michel et al. found a succinct expression [START_REF] Michel | Generalized event-chain Monte Carlo: Constructing rejection-free global-balance algorithms from infinitesimal steps[END_REF] to obtain NVT system pressure via ECMC statistics.

Chapter 2. Event-chain Monte Carlo

In the meanwhile, ECMC is tested in other systems including hard spheres [START_REF] Isobe | Hard-sphere melting and crystallization with eventchain Monte Carlo[END_REF], soft-potential particles [START_REF] Kapfer | Soft-disk melting: From liquid-hexatic coexistence to continuous transitions[END_REF], XY model [START_REF] Michel | Event-chain Monte Carlo for classical continuous spin models[END_REF][START_REF] Lei | Irreversible Markov chains in spin models: Topological excitations[END_REF], Heisenberg model [START_REF] Nishikawa | Event-chain algorithm for the Heisenberg model: Evidence for z 1 dynamic scaling[END_REF], onedimensional short-range system [START_REF] Kapfer | Irreversible local markov chains with rapid convergence towards equilibrium[END_REF]56,[START_REF] Lei | Event-chain Monte Carlo with factor fields[END_REF], dense polymers [START_REF] Kampmann | Monte Carlo simulation of dense polymer melts using event chain algorithms[END_REF], and even quantum chromodynamics [START_REF] Hasenbusch | Testing the event-chain algorithm in asymptotically free models[END_REF]. It is noteworthy that in XY and Heisenberg spin models, ECMC can fast explore systems driven by spin waves, while it suffers a critical slowdown that the dynamical exponent is higher around the system's critical point. And the reason [START_REF] Lei | Irreversible Markov chains in spin models: Topological excitations[END_REF] is found related to the topological defect of the model. So far, all the complexities come from numerical experiments except that the mixing time of one-dimensional hard disks [START_REF] Kapfer | Irreversible local markov chains with rapid convergence towards equilibrium[END_REF]56] can be obtained rigorously.

The discovery of ECMC has spawned numerous studies of the irreversible Markov chains. The original work [START_REF] Bernard | Event-chain Monte Carlo algorithms for hard-sphere systems[END_REF] tested reversible and irreversible straightchain ECMC, and a reflected-chain alternative. Infinite choices that respect the global balance exist in theory for direction change at the collision moment and at the end of chains, yet only a few studies [START_REF] Michel | Forward Event-Chain Monte Carlo: a general rejection-free and irreversible Markov chain simulation method[END_REF][START_REF] Weigel | Equilibration of orientational order in hard disks via arcuate event-chain Monte Carlo[END_REF] have contributed to this freedom. On the other hand, the idea of factor field [START_REF] Lei | Event-chain Monte Carlo with factor fields[END_REF] has lowered the dynamical exponent to the theoretical lower bound 1/2 in one-dimensional short-range systems, a novel concept countering all existing experience gained in conventional Monte Carlo.

It is not difficult to generalize ECMC to arbitrary energy landscapes, giving rise to mathematical variants such as the bouncy particle sampler [START_REF] Bouchard-Côté | The bouncy particle sampler: A nonreversible rejection-free Markov chain Monte Carlo method[END_REF] and the zigzag process [START_REF] Bierkens | The zig-zag process and superefficient sampling for Bayesian analysis of big data[END_REF]. In the following, we will introduce ECMC using the classical physics model. The proof of global balance will not be rigorous but is brief and sufficiently convincing. In section 2.2 we explain the basic process of ECMC via infinitesimal displacement, then in section 2.3 we talk about approaches that can significantly speed up the computation.

Basics

We start with lifted configurations and derive the event rate in the presence of a single factor based on the global balance condition. Unlike other ECMC tutorials, we assume since the beginning that factors are many-body, of which pairwise interactions are special cases. Lifting schemes will also be given in section 2.2.2. Then we extend to the case of multiple factors and provide a more general view of the probability flow.

Lifted configurations

ECMC is built upon lifted configurations. The basics of equilibrium statistical mechanics tell us that the distribution of a physical configuration satisfies π(c) = e -βU (c) /Z where c is the general position of a physical system relying on Ñ coordinates c = c(x 1 , x 2 , ..., x Ñ ) which we call physical variables. An extended configuration attaches a lifting variable a to the physical variable, and we denote the extended configuration as a tuple (c, a). This lifting variable often represents the moving index at the currrent moment, and in many cases a is an integer ranging from 1 to Ñ , meaning that the coordinate x a is changing. For a physical configuration, the probability π(c) is equally shared by each lifted configuration, so π(c, a) = e -βU (c) /ZN a , where N a

Basics

is the number of values that a can take (we sometimes omit this normalizing factor in the following arguments). The lifted configuration is also viewed as replicas of original configuration in the literature.

For example, for N particles moving along a one-dimensional chain we can set up the lifted configuration as c = ((x 1 , ..., x N ), a) where x i 's are coordinates and a ∈ {1, .., N } meaning that x a is advancing. For two dimensions, physical variables become (x 1 , ..., x N , y 1 , ..., y N ) and a ∈ {1 x , ..., N x , 1 y , ..., N y }. Generally speaking, a is allowed to take more values than the set of physical variables. For instance, if we allow one-dimensional N particles to move forward and backward, then a can take values from the set {1, .., N } × {+, -} of 2N elements, the sign indicating the direction of motion. Likewise, a can also indicate the mode where multiple variables change together, which we will encounter in section 5.1.4 and section 6.3.2 for molecular translation.

Factor event rate

In ECMC events are triggered by factors. Factors originate from interactions. They can be one interaction, one or more terms of an interaction, or even a set of interactions. Different arrangements of factors considerably contribute to ECMC's variety and flexibility. Later in chapter 4, we even regard auxiliary operations as pseudofactor such as sampling and direction switching. Here we denote a factor as a tuple of its index set and the type (I M , T M ) where I M is a subset of {1, .., Ñ }. We start with a single many-body factor.

Between two consecutive events, active particles move at a constant velocity. An event in ECMC changes the lifted variable, i.e., the velocity, while keeping the physical variable invariant. The universal event rate per unit length in ECMC is given by

q = β ∂U ∂x a + (2.2.1)
where [x] + = max(x, 0) and U = U ({x i }) is the potential for the factor. In the language of infinitesimal steps, the active particle has to hand over its activity with the probability q∆s in the forthcoming small step ∆s. It means that events occur only when the active particle move increases the potential, and a scheme must be specified to choose the next active particle, which we call target particle. Then the previous active particle stops, whereas the target particle starts moving until a new event happens, and the activity passes to a third particle(it can be the same as the first active particle). Fig. 2.1 gives an illustration of ECMC process. For a factor involving two particles, the other particle is the target. However, for many-body interactions, the scheme is not straightforward and is in general not unique. 2.1: Process of ECMC evolution with three particles on a plane. We demonstrate here the system evolution under ECMC with three particles in a periodic box. The nine subfigures are the event moments, including eight physical events and one direction switching. displacement. Ignoring the normalizing factor 1/N Z, its value is

Basics

F mass = e -βU (c ) 1 -β ∂U ∂x a + + o( ) = e -βU (c) - ∂e -βU (c) ∂x a 1 -β ∂U ∂x a + + o( ) = e -βU (c) 1 + β ∂U ∂x a 1 -β ∂U ∂x a + + o( ) = e -βU (c) 1 + β ∂U ∂x a - + o( ), (2.2.2)
where [x] -= min(x, 0). On the other hand, the lifting probability flow coming from (c, b) with b = a is

F lift = b =a e -βU (c) β ∂U ∂x b + λ ba + o( ). (2.2.3)
Here we refer to λ ij as the probability to choose j as the proceeding active particle when i is active at the event time. It has λ ij ∈ [0, 1] and j λ ij = 1.

By applying global-balance condition F mass + F lift = π(c) = e -βU (c) , we get

∂U ∂x a - + b =a ∂U ∂x b + λ ba = 0, ∀a. (2.2.4)
If ∂U/∂x a > 0, then λ ba = 0 for all b, meaning that events happen while the energy is increasing. If ∂U/∂x a ≤ 0, no event happens as particle a moves, but moves of other particles within the factor may activate a with the event rate multiplied by λ ba that obeys

b =a ∂U ∂x b + λ ba = - ∂U ∂x a , ∀ ∂U ∂x a < 0.
(2.2.5) To better understand this process, at the instant when the event happens, we divide all particles within this factor into two sets I + and I -, so that

∂ x i U < 0, ∀i ∈ I -,
(2.2.6)

∂ x i U ≥ 0, ∀i ∈ I + . (2.2.7)
Then we create bars for each of them whose lengths equal |∂ x i U |. Put the bars with positive derivatives above, and place those with negative derivatives below. Total length of positive bars should equal total length of negative bars due to the translational invariance, namely i ∂U/∂x i = 0. We refer to a specific choice of λ ba as a lifting scheme, which can be interpreted as the allocation of positive bars into negative bars, as shown in Fig. 2.3. For a factor (I, T ) with |I| = 2, the target particle is unique, and λ ij = 1 for ∂ x i U > 0 and ∂ x j U < 0 otherwise λ ij = 0. For |I| = 3 the choice is unique, too, while a random number is needed if two particles have negative derivatives. For |I| > 3 there can be infinite choices, a simple ratio lifting scheme is

λ ij = |∂ x j U | j ∈I -|∂ x j U | , (2.2.8)
which is independent of i. Now we obtain a general lifting scheme, and in section 3.5 we will order the atoms according to their molecular indices and devise lifting schemes that prioritize the flow going inside or outside the active molecule.

Basics

Factorization

Multiple Factors

If the potential can be written as a sum of many terms U = M ∈M U M , each U M can be regarded as a factor and it can trigger events independently. Each factor M that involves active particle a has an effect at every small step of the ECMC process, with the same expression of the event rate β[∂U M /∂x a ] + , and with individual lifting schemes λ M ij . Throughout the derivation in section 2.2.2, is small enough that two events are improbable to coincide in the same interval , so that the probability of encountering more than one events is at most O( 2 ).

Therefore the probability flows in existence of many factors, take similar forms as Eqs. 2.2.2 and 2.2.3

F mass = e -βU (c ) 1 - M β ∂U M ∂x a + + o( ) = e -βU (c) 1 + M β ∂U M ∂x a - + o( ),
(2.2.9)

F lift = M b =a e -βU (c) β ∂U M ∂x b + λ M ba + o( ), (2.2.10
)

with λ M ij that ∂U M ∂x a - + b =a ∂U M ∂x b + λ M ba = 0, ∀a. (2.2.11)
It is easy to verify F mass + F lift = e -βU (c) + o( ) and global balance holds in presence of more than one factors. Factorization in traditional Monte Carlo does not usually have advantages. Splitting the potential into small factors often leads to a higher rejection rate, thus slows the system's relaxation. However, ECMC favors factorization for the reason that factors involving many particles have to invoke complicated lifting schemes that require all relevant particles' derivatives at the event time. On the contrary, splitting factors usually facilitates the calculation of the event time and the target particle. In the simulation of soft-potential particles [START_REF] Kapfer | Soft-disk melting: From liquid-hexatic coexistence to continuous transitions[END_REF], the two-body factor is always employed. Another example of factorization is the particle system interacting via the Lennard-Jones potential U = A/|r| 12 -B/|r| 6 , where it is favorable to split into A/|r| 12 and -B/|r| 6 so that both terms can be easily inverted.

Redundant flow

We can interpret the difference between factorizations as introducing loops of excess probability flow. Interaction consisting of many terms U = M U M may be treated as one or more small factors. If only one factor exists, particles with positive derivatives are sources of the probability transfer, i.e., have outgoing flows; particles with negative derivatives are receivers of the probability flow. When we split one factor into Chapter 2. Event-chain Monte Carlo We can describe a redundant flow loop by a set of additional sources q R i > 0 for i = 1, ..., N , and a distribution ratio λ R ij . The Eqs. 2.2.2 and 2.2.3 now become

F mass = e -βU (c ) 1 -β ∂U ∂x a + -q R a + o( ) = e -βU (c) 1 + β ∂U ∂x a - -q R a + o( ) (2
.2.12)

F lift = b =a e -βU (c) β ∂U ∂x b + λ ba + q R b λ R ba + o( ), (2.2.13)
under the following constraint

b =a q R b λ R ba = q R a , ∀a. (2.2.14)
Again, F mass + F lift = e -βU (c) + o( ) holds in the presence of the term q R . The similarity between Eqs. 2.2.9 ∼ 2.2.11 and Eqs. 2.2.12 ∼ 2.2.14 suggests their same mathematical essence. Factorization stems from splitting physical interactions, which is more apparent and intuitive, while the construct of redundant flow can be arbitrary and flexible.

It is the flexible choice of probability flows that brings ECMC with infinite variety and enormous posibilities. In the first place, all interactions are one factor U ; thus, the incoming flow and outgoing flow do not coexist upon one coordinate. Then we split U into smaller factors, usually for computational convenience. Sometimes one may even add flows from nothing, i.e., by adding 0 = U -U , which is our current manner for direction change that can be considered as a mutual flow x ↔ y that 2.3. Fast implementation guarantees ergodicity. It appears that redundant flows have no gain in simulation dynamics, making it more likely to stay with the current configuration. However, the construct of the factor field [START_REF] Lei | Event-chain Monte Carlo with factor fields[END_REF] enables us to lower the dynamical exponent in a one-dimensional system, countering people's intuition.

To sum up, the ECMC algorithm for single active particles via a time-driven approach can be described as follows, with the example of N particles moving in one direction:

1. Initialize the lifted configuration (c, a).

Iterate over the factors

U M with x a ∈ U M .
3. For each factor, calculate the corresponding derivative with respect to x a . Draw a random number r

∈ [0, 1], if r happens to be in [0, β [∂ xa U M ] + ],
an event occurs. If more than one events coincides within , then pick a random one. should be tuned to ensure that coincidences are very rare.

4. If an event occurs, calculate the next active particle using the derivatives of all particles of the factor. For two-body factors, the target particle is simply the non-active one. The current active particle stops, and the target particle starts moving.

5. If no event occurs, advances the active particle by .

6. Go back to step 2 and repeat.

Fast implementation

If ECMC stays in the time-driven approach, it will hardly be capable of competing with other well-established methods. It consumes a great deal of time to integrate over small timesteps and introduces imprecision that is hard to analyze. Molecular dynamics has accumulated progress to overcome this inefficiency over the years, by parallel computing forces throughout the entire system, or altering potentials into piecewise-constant ones (see section 1.2.3) to which event-driven approaches can apply.

ECMC is a stochastic process with a natural event-driven formulation with whatever potential the system has. In section 2.3.1 we describe how to convert small step integration into inverting potential functions. Then in section 2.3.2, we introduce the bounding potential that simplifies the event calculation so that only the derivative of the original potential is called.

Event-driven approach

Assume that the system has only one factor. At a moment the active particle is at position x a . Its probability to travel a distance of η without any event rejecting it, M . (From Ref [1].)

The Eq. 2.3.2 tells us that the probability for the active particle to go beyond η is e -βU + (η) . The change of U + to next event can be sampled via

∆U + = - 1 β log r (2.3.3)
in which r is a random number uniformly distributed in (0, 1]. Then we invert ∆U + M (η) to get η.

For the case with more than one factor, we can obtain the displacement η M from each relevant factor M . The displacement to the next event is the minimum of displacements among all factors, and the triggering factor is the one with smallest displacement,

M trigger = argmin M,a∈I M {η M } , (2.3.4) η = min M,a∈I M {η M } . (2.3.5)
The succeeding active particle is calculated using a lifting scheme within the triggering factor.

Bounding potential

The method described in section 2.3.1 requires explicitly calculating the inversion of U + that is not usually possible in most realistic cases. In our SPC/Fw water model that employs the Amber force field in section 5.3.3, the intra-molecular harmonic potential, and oxygen-oxygen Lennard-Jones potential are invertible, while the tension part and the Coulomb interaction with periodic boundary conditions are not. Bounding potentials allow us to sample the next event time of non-invertible potential factors.

For a potential U , the bounding potential U B is a function of x a whose derivative not less than

∂ x U everywhere if ∂ x U > 0, i.e., [∂ x U B ] + ≥ [∂ x U ] + . (2.3.6)
An example is shown in Fig. 2.6. In the time-driven approach, we can use U B in place of U to check if an event occurs within displacement . Since U B overestimates the event rate, a certain portion of events may be false, with ratio given by

r C =    ∂U ∂x + / ∂U B ∂x , if ∂U B ∂x > 0; 0, otherwise. (2.3.7)
It means that we have to perform a confirmation by drawing a random number between 0 and 1 to check if it falls within [0, r C ] so the event has truly happened. The method discussed in section 2.3.1 replaces small timesteps with a direct sampling of event times. Likewise, we can sample the displacement given by an bounding potential in an event-driven manner, then confirm it by Eq. 2.3.7. Since no more restrictions exist on the specific form of bounding potential except Eq. 2.3.6, we have a variety of choices to make it easily invertible.

In practice, we employ various forms of bounding potentials. In section 3.4 we will take c/|r at | as bounding potential for the Coulomb interaction under periodic boundary conditions. The cell algorithm that we will introduce in section 3.3 is essentially a potential with static piecewise-constant derivatives, estimated before Markov chains. Moreover, a potential with dynamic piecewise-constant derivative by speculation is also possible and is our event-driven solution for the tension force of the SPC/Fw H 2 O model.

Sampling

Sampling is an auxiliary but indispensable component of ECMC. It does not affect ECMC's dynamics but is the way for ECMC to output observables of physical interests.

In principle, any observable X can be extracted using the configuration average along the path of ECMC

X ∼ 1 T T 0 X(c(t))dt (2.3.8)
where c(t) is the configuration at time t. This formula contains integral, so it is hard to compute. Empirically we can instead draw samples in constant interval

X ∼ 1 N s Ns n=1 X(c(nt s )) (2.3.9)
where t s is the sampling interval.

One may also consider non-constant sampling intervals such as exponential distribution, but no studies have contributed to it. A pitfall for sampling is that one draws samples exactly at the event time to avoid explicit "sampling events" in the program. This approach leads to wrong estimates of physical observables. For example, in hard-disk simulations, two disks touch each other at event times, while the probability of touching disks tends to zero among all possible states.

Direction switching and restarts

Direction switching is necessary to ensure ergodicity, e.g., to mix hard disks in both directions. Its validity can be understood as a constant flow x ↔ y that will not break the global balance. In higher dimensions, switching schemes have more options, either choosing the next direction randomly or cyclically. We will give a measurement in section 3.6. In principle, the constant probability flow x ↔ y means that the switching interval should be an exponential random number. In practice, however, a constant time interval is usually employed without bias in the results.

Sometimes we can also set up restart events that drop current active particles and randomly select a new one. This operation can be regarded as a constant flow between each pair of particles. Restarts have been shown to affect dynamics [START_REF] Kapfer | Irreversible local markov chains with rapid convergence towards equilibrium[END_REF]56,[START_REF] Lei | Event-chain Monte Carlo with factor fields[END_REF][START_REF] Kapfer | Sampling from a polytope and hard-disk Monte Carlo[END_REF] of ECMC though more studies are on the way.

Chapter 3

Event-chain Monte Carlo for long-range interaction 3.1 Long-range system

The Coulomb potential is a fundamental interaction whose nature is strongly influenced by its long tail [18]. The Lennard-Jones potential and inverse-power-law potentials, if no cutoff is introduced, lead to correlations between the system's faraway components. Modern biochemical simulations commonly use the Amber force field involving inter-molecular long-range terms with empirical parameters, without which the resulting statistics fail to reflect the true nature of simulated bodies [18]. Although long-range interactions are crucial in revealing realistic physical phenomena, they remain a bottleneck of large-scale biochemical simulation algorithms.

In this chapter, we focus on long-range systems simulated by ECMC to see if the novel irreversible Monte Carlo can bring breakthroughs. As introduced in section 1.2.2, the state-of-the-art method that splits the Coulomb potential into a short-range core and a relatively smooth long-range tail leads to Ewald's formula [START_REF] De Leeuw | Simulation of electrostatic systems in periodic boundary conditions. I. Lattice sums and dielectric constants[END_REF], with the latter solved by fast Fourier transformation. New methods under the framework of ECMC without resort to Fourier transformation may be more efficient.

Long-range interactions are related to boundary conditions, at least in a computational sense, and the periodic boundary conditions are usually adopted in order to avoid boundary effects. Mathematically, let S 1 be the topological space of a circle, then a periodic plane becomes a torus denoted as S 1 × S 1 , illustrated in Fig. 3.1 (a) , and three-dimensional periodic space can be described as S 1 × S 1 × S 1 . Taking Coulomb interaction as an example, the long-range interaction, at the first place, is ill-defined in light of periodicity because no solution exists for Poisson's equation ∇ 2 U (r) = c i δ(r -r i ) that determines the potential of a point-charge system if the system is non-neutral (taking the zeroth Fourier mode leads to 0 = const). We may take another view by unfolding the periodic system, which implies that every object has an infinite number of images, as shown in Fig. 3.1 (b) . Summing up contributions from all images for two charges n 1/|r 12 + nL| obviously diverges.

We categorize long-range interactions into the following three classes:

1. Finite-range interactions that have cutoffs beyond which the forces vanish. 2. Long-range interactions of fast decay, that is, the interaction whose tail scales as 1/r p and p > d. The potential computation has no ambiguity since n 1/|r + nL| p converges absolutely.

3. Long-range interactions of slow decay, that is, the interaction whose tail scales as 1/r p and p ≤ d.

Assuming that the system is big enough and that interactions exist between all pairs, we cannot enumerate all the interacting pairs to sample the event with reasonable time. In the first case, a cell system is sufficient for fast access of relevant pairs given the active particle. In the second case, a smart scheme is needed to avoid iteration over all the N -1 pairs. The cell algorithm [START_REF] Kapfer | Cell-veto Monte Carlo algorithm for long-range systems[END_REF], which we will introduce in section 3.3, can meet this requirement for homogeneous systems in which density ρ ≈ const.

In the third case, an ambiguity arises under periodic boundary conditions, and we will focus on one working convention called tin-foil electrostatics and develop its equivalent forms for ECMC. We will address the formulation issue of slow-decay interaction at first in section 3.2, to derive a self-consistent definition of the two-body Coulomb event rate. We find that ECMC provides various approaches that circumvent Ewald summation for the calculation of pairwise Coulomb interaction. All these methods can be easily adapted to other kinds of long-range interactions too.

The second issue that is treated this chapter is to efficiently sample the next event among all O(N ) factors that involve the active particle. The cell algorithm, together with Walker's method, serves as the mainstay to effectively reduce the complexity from O(N ) to O(1) for the three-dimensional Coulomb plasma. This algorithm applies to short-range interaction as well and helps avoid iterating over all possible neighbors.

In addition to the Coulomb derivative given in section 3.2, one also needs a bounding potential since its periodic version is no longer invertible. We will give a simple Coulomb bounding potential in section 3.4, taking into account its 1/|r| singularity at the origin.

Calculation of pairwise Coulomb interaction

Next, we will introduce our finding of the dipole factor that enable us to reduce the event rate from O(N 1 3 ) to O(log N ). Furthermore, two lifting schemes in addition to the ratio lifting scheme for dipole systems will be proposed. The inside-first lifting scheme yields an inter-dipole lifing rate that scales as 1/r 4 . This fully exploits the 1/r 4 dipole-dipole interaction within ECMC's capacity. Realistic systems mostly comprise or can be decomposed of dipoles, so the invention of the dipole factor will hopefully accelerate biochemical simulations in the future.

Good agreement between different methods such as the Metropolis-Hastings algorithm and ECMC, atomic and dipole factorizations, and various lifting schemes will be presented at the end of this chapter, and in chapter 5, we will provide more verifications of the cell setup.

Calculation of pairwise Coulomb interaction

Ewald summation

The Coulomb potential of N charges c 1 , c 2 , ..., c N in a cubic box under periodic boundary conditions is generally the solution of Poisson's equation ∇ 2 φ = c i δ(r i )/ 0 . However, this simple expression has no solution for non-neutral systems, and the fact that solutions are not unique raises physical unclarity. We will follow the formulation proposed by de Leeuw et al. [START_REF] De Leeuw | Simulation of electrostatic systems in periodic boundary conditions. I. Lattice sums and dielectric constants[END_REF] and will list the results below.

Intuitively, in the unfolded view of periodic boundary conditions, the total energy of the system can be expressed as

U C = 1 2 n∈Z 3 1≤i,j≤N c i c j |r i -r j + nL| , (3.2.1)
where L is the box side length, and the summation should exclude self-interaction of the same image. In this expression, different summing orders lead to distinct results, so it does not converge absolutely. de Leeuw et al. showed that summing for spherical shells results in

U C = 1≤i<j≤N 1 L c i c j ψ r ij L + 2 π 3L 3 |P| 2 + U self (α), (3.2.2)
in which

ψ(r) = n erfc(α|r + nL|) |r + nL| + 1 π m∈Z 3 ,m =0 e 2πim•r-π 2 |m| 2 /α 2 |m| 2 , (3.2.3)
with erfc the complementary error function

erfc(x) = 1 -2π -1 2 x 0 e -t 2 dt, (3.2.4)
U self a term of self energy independent of r i , and P the system's polarization

P = 1≤i≤N c i r i . (3.2.5)
In Eq. 3.2.2, is the dielectric constant that originates from summing order. The value = 1 corresponds to summing over spherical shells. To avoid many-body Coulomb interaction we adopt the so-called tin-foil convention where = 0 so that the polarization term vanishes. Then the energy can be decomposed as a sum of pair energies that are sufficient to reach precision δ. In practice, α is chosen so that the real-space part, i.e., the term with the complementary error function, converges faster than the Fourier part, which can reduce the costly computation of the error function.

U C = 1≤i<j≤N c i c j   n∈Z 3 erfc(α|r ij + nL|) |r ij + nL| + 4π L 3 q =(0,0,0) e -q 2 /(4α 2 ) q 2 cos (q • r ij )   + U self (α). ( 3
To get the event rate of a single moving particle in ECMC, we just take the derivative of Eq. 3.2.6, and the result comprises individual pairs, each consisting of a Fourier-space term and a real-space term qClb (r 12 = r 2 -r 1 ) = qreal (r

) = c 1 c 2 4π L 3 q =0
q x e -q2 /(4α 2 ) q 2 sin(q • r 12 ) (3.2.10) in which we assume that the particle 1 is active. Fig. 3.2 shows the values on four z profiles q Clb = β [q Clb ] + .

In the simulation of a number of charges, we find by profiling the program that direct calculation of the Coulomb derivative by Eqs. 3.2.9 and 3.2.10 takes the majority of total time (>80%). In fact, over a hundred terms must be taken into account to achieve the error level of double-precision float (2 -53 ). However, there are tricks to speed up the computation: (g)(h)z 12 = 0.4, and (i)(j)z 12 = 0.5. Subfigures on the left are event rates with the merged-image approach given by Eqs. 3.2.9 and 3.2.10, while those on the right are for separate-image event rates by Eq. 3.2.37. (From Ref [1].) Chapter 3. Event-chain Monte Carlo for long-range interaction 3. Exploiting the positive-negative symmetry of Fourier-space terms with respect to components of q. In fact, only roughly 1/8 of all terms have to be calculated.

4. Pre-calculating sin and cos of q x r 12,x , q y r 12,y , and q z r 12,z , then sin(q • r 12 ) can be calculated in an iterative manner.

After taking into account the tricks above, the Coulomb derivative computation takes roughly 30% of the time (run by JELLYFYSH, see chapter 4). Actually, as a stochastic algorithm, ECMC has the potential to circumvent all detailed calculations while keeping the results unbiased, which is still under development.

Line-charge method

Construct

One may by intuition write down the two-body Coulomb derivative as the sum of image derivatives

qClb = c 1 c 2 n ∂ ∂x 1 1 |r 12 | = c 1 c 2 n x 12 |r 12 | 3 . (3.2.11)
Again, this summation suffers from poor convergence even though it indeed converges to some true charge-charge derivatives with a certain dielectric constant depending on the summing order. For a faraway image R = |nL|, the derivative decays as R -2 . The expression does not converge absolutely since ∞ r -2 d 3 r = ∞.

The line-charge model overcomes this divergence by bundling a charged line of length pL image, laid along the direction of motion of the active particle with the target image in the center. Every line is charged evenly with a density -c 2 /pL. The composite of the target image and the accompanying line charge, labeled as n, will contribute to the derivative qClb,line (r = r 12 + nL = (x, y, z))

=c 1 c 2 x |r| 3 + 1 pL 1 |r + pLê x /2| - 1 |r -pLê x /2| . (3.2.12)
This formula results in identical statistics as Eqs. 3.2.9 and 3.2.10, as shown in Fig. 3.3 (a) . The agreement is intuitive whereas rigorous proof remains non-obvious. We will justify the equivalence by introducing a homogeneous volume-charge model. Eq. 3.2.12 is computationally powerful in two respects. First, it has vanishing charge and dipole moments, and the leading term behaves as a charge-quadrupole interaction and thus scales as R -4 . Moreover, qClb,line (r 12 , n)+ qClb,line (r 12 , -n) decays even faster at the speed of R -5 . When summing through cubic or spherical shells,

R qClb,line (r 12 , n)dn ∼ R r -3 dr ∼ U -R -2 , (3.2.13)
argeeing with our numerical test shown in Fig. 3.3 (a) . Second, Eq. 3.2.12 needs no explicit calculations of the line-charge contribution, that is, of the second and third terms in Eq. 3.2.12 for each image. Only those at the Figure 3.3: Convergence comparison in logarithmic scale between results of various methods for pairwise Coulomb derivatives at r 12 = (1/3, 1/6, 1/7). (a) Line-charge model with p = 1 and p = 2, kite-charge model, volume-charge model, and algebraic compensation. The curve "algebra-2" corresponds to using T 1 of Eq. 3.2.33 as the compensating term, and "algebra-3" corresponds to T 3 of Eq. 3.2.33. (b) Richardson's method starting with p = 1 line-charge model. The original series is with respect to increasing cutoffs. end of "concatenated" lines survive. This effect significantly reduces the computation work of the line-charge model, with only a few additional terms on the boundary.

For the choice of the line charge length p in Eq. 3.2.12, any positive integer is acceptable while 2p(2n + 1) 2 ends of lines are unable to cancel. In Fig. 3.4 (a) and (b) we show unfolded images of the target particle compensated by L and 2L line charges respectively. Usually, p = 1 is the ideal choice if we sum up Eq. 3.2.12. This way, we put all images as one factor, so it is called "merged-image" factorization. However, if we factorize images and treat each image accompanied by its screening charge as an individual factor, singularities appear at the image charge position and ends of the line charges. In this case, p = 1 suffers a non-physical singularity at r 12 = (L/2, 0, 0) besides the physical one at (0, 0, 0). Hence in the separate-image approach, we propose p = 2 so that these two singularities coincide.

Equivalence to tin-foil convention

Here we demonstrate the equivalence between Ewald's method with the tin-foil convention and the line-charge method. We will show that the line-charge method has the identical result as a homogeneous volume-charge method. The equivalence to the polarization-free Ewald's summation is because the net target charge vanishes in the volume-charge method, whereas we will not cover this part of the argument here.

For a static charge with structure factor ρ 2 (q), a test charge c 1 has a potential Summing up (2K + 1) 3 images, we use the following formula

U (r 12 ) = 4πc 1 ∞ -∞ d 3 q (2π) 3 e iq•r 12 ρ 2 (q) |q| 2 . ( 3
D K (q x ) = K l=-K e iqxlL = sin [q x L(K + 1/2)] sin(q x L/2) , (3.2.15)
and we denote DK (q) = D K (q x )D K (q y )D K (q z ). Taking into account (2K + 1) 3 images and in the limit of K → ∞, we reach

D K (q x ) K→∞ ----→ 2π L ∞ m=-∞ δ q x -m 2π L . ( 3.2.16)
For a point charge c with line-screening charge of length pL

ρ line = c(1 -sinc pq x L 2 ), (3.2.17)
and for one with volume-screening charge of side length L

ρ volume = c(1 -sinc q x L 2 sinc q y L 2 sinc q z L 2 ) (3.2.18)
where sinc(x) = sin(x)/x. By taking their difference, we get

∆U = U line -U volume = c 1 c 2 d 3 q 2π 2 D K (q) e iq•r 12 |q| 2 sinc q x L 2 sinc q y L 2 sinc q z L 2 -sinc pq x L 2 . (3.2.19)
Eq. 3.2.16 tells us that D K (q) peaks around q i = 2πm/L, m ∈ Z, while sinc(q i L/2) is zero at those values except for q i = 0. A short analysis suggests that non-zero terms of Eq. 3.2.19 come from q x = 0 (the q x = q y = q z = 0 case needs special analysis). The line-charge and volume-charge models have different potentials. However, taking the derivative with respect to x 1 yields

∂∆U ∂x 1 = c 1 c 2 d 3 q 2π 2 D K (q) q x sin(q • r 12 ) |q| 2 sinc q x L 2 sinc q y L 2 sinc q z L 2 -sinc pq x L 2 .
(3.2.20)

Calculation of pairwise Coulomb interaction

Due to an additional q x , the integer points q x = 0, q y q z = 0 vanish as well. At around q x = q y = q z = 0 we expand the trigonometric functions and get

∂∆U ∂x 1 q→0 ---→ q 2 x (p 2 -1)q 2 x -q 2 y -q 2 z |q| 2 D K (q) ∼ 0. (3.2.21)
Therefore, the contribution around q = 0 is zero for large K too. In summary, the above derivation demonstrates the equivalence between the linecharge method and the volume-charge method in the limit of infinite images.

Higher-order methods

The success of the line-charge method provides an alternative for calculation of the pairwise Coulomb derivative. As discussed in section 3.2.2.1, the remainder of counting (2n + 1) 3 images decays as n -5 . To reach double-float precision (2 -53 ), we have to calculate ∼ 2 30 terms, far beyond the allowed limit of any molecular simulator. Hence, to reach relatively high precision, the line-charge method is outperformed by Ewald's method. Nevertheless, algorithms exist that can converge faster than the compensating line charge besides Ewald's sum, and many of them inherit the idea of screening charge.

The following methods that we develop to compute Coulomb potential derivatives have actually exceeded the current need in the program. In JELLYFYSH introduced in chapter 4 and its applications, the Ewald summation is sufficient. It has the best precision with acceptable time consumption. We propose the following higherorder methods as complements that may be advantageous in other situations.

Volume-charge method

During the proof that the line-charge method Eq. 3.2.12 is equivalent to tin-foil electrostatics of Eq. 3.2.6, we introduce a volume-charge model illustrated in Fig. 3.5 (a) , which actually converges two-order faster than line-charge model due to its vanishing quadrupole and octupole moments.

Similar to Eq. 3.2.12, the volume-charge model for two charges c 1 and c 2 with c 2 surrounded by a homogeneous cubic compensating charge of side length L, has the following derivative

qClb,volume (r 12 , n) = c 1 c 2 x 12 + n x L |r 12 + nL| 3 + 1 L 3 [I 1 (x 12 + L/2, y 12 , z 12 , L) -I 1 (x 12 -L/2, y 12 , z 12 , L)] , (3.2.22)
where the integration is defined as Explicitly integrating I 1 , we have

I 1 (x 0 , y 0 , z 0 , L) = y 0 +L/2 y 0 -L/2 dy z 0 +L/2 z 0 -L/2 dz 1 x 2 0 + y 2 + z 2 = sy,sz∈{+1,-1} s y s z I 2 (x 0 , y 0 + s y L/2, z 0 + s z L/2).
I 2 (x, y, z) =y log x 2 + y 2 + z 2 + z + z log x 2 + y 2 + z 2 + y -x arctan yz x x 2 + y 2 + z 2 + x arctan y x -y. (3.2.24)
The entire expression consists of as many as 8 × 5 terms before simplification, and many of them contain costly logarithm and inverse trigonometric functions. It is thus difficult to evaluate, even in the case that compensating terms cancel for neighboring images. Thus we seek other methods to construct screening charges with zero quadrupole moments.

Kite-charge method

The volume-charge model is not the unique construct with a vanishing quadrupole moment. More than one compensating line charge can be associated with one image, giving more freedom of the screening charge construct. In fact, a tricky arrangement of four line charges can cancel the quadrupole moment.

According to the definition of the quadrupole moment of a single charge

Q ij = q(3r i r j -|r| 2 δ ij ), (3.2.25)
a line of charge density 1/L extending from (-L/2, y, z) to (L/2, y, z) carries a quadrupole moment

Q =    L 2 /6 -y 2 -z 2 0 0 0 -L 2 /12 + 2y 2 -z 2 3yz 0 3yz -L 2 /12 -y 2 + 2z 2    . (3.2.26)
It is easy to let the diagonal terms vanish by making y 2 = z 2 = L 2 /12. To cancel the off-diagonal terms 3yz we should have more than one line. Considering symmetries required to cancel the dipole moment, we conclude that we need a minimum of four lines evenly distributed on the y 2 + z 2 = L/6 circle. One possibility is

Calculation of pairwise Coulomb interaction

(y, z) = (s y L/ √ 12, s z L/ √ 12) for s y , s z ∈ {+1, -1}, meaning that four lines of length L center around the target particle image pointing along +x (hence the name "kite") as shown in Fig. 3.5 (b) . And furthermore, the composite remains invariant under the rotation along x axis, thus the simplest solution that we found is

(y 1 , z 1 ) = (L/ √ 6, 0), (y 2 , z 2 ) = (0, L/ √ 6), (y 3 , z 3 ) = (-L/ √ 6, 0), (y 4 , z 4 ) = (0, -L/ √ 6), (3.2.27)
and the corresponding imagewise derivative becomes qClb,kite (r = r 12 + nL = (x, y, z))

=c 1 c 2   x |r| 3 + (y,z)∈K 1 4L 1 |r + Lê x /2 + yê y /2 + zê z /2| - 1 |r -Lê x /2 + yê y /2 + zê z /2| , (3.2.28)
where K is the set whose elements are listed in Eq. 3.2.27. A kite of length L is given above while the generalization to pL(p ∈ Z + ) is straightforward. Fig. 3.3 (a) justifies its two-order faster decay than for the line-charge method with increasing n, in which (2n + 1) 3 images are evaluated.

Richardson acceleration

Richardson's method [START_REF] Bender | Advanced Mathematical Methods for Scientists and Engineers I: Asymptotic Methods and Perturbation Theory[END_REF] is a general algorithm to accelerate the convergence of a sequence with polynomial remainder. Assume that the sum S n of the first n terms of a series has

S n = S ∞ + C n p + o(n -p ), p > 0. (3.2.29)
The constructed series,

S n = (n + 1) p S n+1 -n p S n (n + 1) p -n p , ( 3.2.30)
can eliminate the n -p term, preserve the S ∞ limit, and thus converge at least as fast as n -p-1 . Iterating this process can create a series that converges at arbitrary order. We let S n be the sum of derivative contributions of (2n + 1) 3 line-charge composites and then perform Richardson's acceleration, as shown in Fig. 3.3 (b) . The relative magnitudes of n and S (m) n agree with the expectation that the m-th order Richardson's method applied to the line-charge model can converge at the speed of n -m-2 .

Algebraic compensation

All the methods mentioned above aim to accelerate the convergence of the summation of a sequence. All kinds of screening charges are derived from physical settings, but it may imply a more general series-acceleration algorithm from a mathematical point of view.

In the screening charge model of line shape or kite shape, the terms resulted from screening charges both take the form of the Coulomb potential 1/|r|, which can be viewed as an indefinite integral of the summed function (here the target function is ∂ x (1/|r|), and the integral is 1/|r| which we called line charge). We find that taking derivatives of summed functions instead of integrals as compensating terms is capable of obtaining a series of faster convergence.

Assume that we hope to calculate ∞ p=1 f (p), and let F (x) = f (x) and f (n) (x) = d n f (x)/dx n the nth order derivative. Their Taylor expansions are given by

f (x + a) = ∞ n=0 1 n! f (n) (x)a n , F (x + a) = ∞ n=0 1 (n + 1)! f (n) (x)a n+1 , f (m) (x + a) = ∞ n=m 1 (n -m)! f (n) (x)a n-m . (3.2.31)
We expect that a combination of F (x ± 1/2) and f (n) (x ± 1/2) is able to approximate f (x) to arbitrary order. First, with inspiration of the line-charge model we get

F (x -1/2) + f (x) -F (x + 1/2) = O(f (2) (x)), (3.2.32)
with the assumption that f (n) decays faster for larger n, which is true for the Coulomb interaction. Next, we let

T 1 (x) =F (x) - 1 24 f (1) (x), T 3 (x) =F (x) - 1 24 f (1) (x) + 7 5760 f (3) (x), T 5 (x) =F (x) - 1 24 f (1) (x) + 7 5760 f (3) (x) - 31 967680 f (5) (x), (3.2.33) then T 1 (x -1/2) + f (x) -T 1 (x + 1/2) = O(f (2) (x)), T 3 (x -1/2) + f (x) -T 3 (x + 1/2) = O(f (4) (x)), T 5 (x -1/2) + f (x) -T 5 (x + 1/2) = O(f (6) (x)).
(3.2.34) Fig. 3.3 (a) verifies the faster convergence of algebraic constructs T n in an application of three-dimensional periodic Coulomb system. Similar to the line-charge method, compensating terms T n cancel for neighboring images. Only T n (r 12 + (n +x + êx )L) and T n (r 12 -(n -x + êx )L) survive. Although terms with higher-order derivatives of 1/|r| decay faster, it introduces more complexity in the computation of their derivatives, which becomes the bottleneck of this algebraic approach. In fact, F (x) and f (n) (x) at x + p/2 for p ∈ Z and p > 1 can also help eliminate slow decaying terms, and ∂ y f and ∂ z f are candidates for three-dimensional function too. A systematic investigation of this method is still missing.

Interpolation

Interpolation is a universal approximate method applicable to all sufficiently smooth functions. It is also feasible for evaluating the Coulomb derivative of Eq. No evidence shows a substantial difference in the qualities of using qf,1 or qf,2 , so qf,1 is chosen in our event-driven implementation. We will not discuss various interpolation methods but take first-order and third-order Lagrange polynomial interpolations for testing purposes. They are also known as linear and cubic interpolations, respectively, and the generalization to three dimensions is straightforward. We compare their resulting errors in Fig. 3.7.

Separate-image method

As discussed in section 2.2.3, ECMC allows for different ways of grouping interacting terms, which presents no physical effects but leads to distinct algorithmic complexities and Markov-chain dynamics. All the methods mentioned above yield converging expressions for qClb of Eq. 3.2.8, but all regard the pair energy as one factor in ECMC. Terms of potential can be grouped into more than one factor. We will describe below the example of splitting Eq. 3.2.12.

In the separate-image approach, we do not sum up Eq. 3.2.12 to obtain qClb but regard each image represented by n as an individual factor that is able to trigger events with the rate q Clb,line (r = r 12 + nL = (x, y, z))

=β c 1 c 2 x |r| 3 + 1 pL 1 |r + pLê x /2)| - 1 |r -pLê x /2)| + =β [q Clb,line (r)] + . (3.2.37)
In the naive time-driven approach, each time the active particle proposes a tiny move , the program iterates over all images of the other particle (perhaps with a cutoff for images), calculates q Clb,line for each image and checks whether an event happens within . Similarly to section 2.2.3, the displacement up to the next event in eventdriven description is chosen from the minimum of all displacements given by each image factor. We verify imagewise factorization in Fig. 3.8 in a simple two-atom system. In general, every formula calculating the pairwise Coulomb derivative has corresponding "term-wise" factorization, and how it facilitates the simulation depends on the difficulty of inverting each term, the efficiency of sampling remaining terms, and on whether loop flows can be avoided.

Calculation of pairwise Coulomb interaction

The analysis in section 2.2.3.2 tells us that factorization is equivalent to introducing extra probability flows which are particularly manifest in the separate-image method. For the line-charge model, we need to demonstrate the following

n q Clb,line (r 12 + nL) - n q Clb,line (r 21 + nL) =β qClb (r 12 ) = β n qClb,line (r 12 + nL). (3.2.38)
In fact, the left-hand side of this equation can be written as where we use that qClb,line (-r) = -q Clb,line (r) which can be proved by Eq. 3.2.37. In summary, we show that the imagewise factorization in the line-charge model does not change the net flow, so it just amounts to an extra loop between the active charge and the target. Consequently, flows between them are greater than those in the mergedimage approach. We show in Fig. 3.2 the comparison of magnitudes of flows of merged-image and separate-image approaches.

n q Clb,line (r 12 + nL) - -n q Clb,line (r 21 -nL) = n q Clb,line (r 12 + nL) - n q Clb,line (-r 12 -nL) =β n [q Clb,line (r 12 + nL)] + -[q Clb,line (-r 12 -nL)] + =β n [q Clb,line (r 12 + nL)] + -[-q Clb,line (r 12 + nL)] + =β n qClb,line (r 12 + nL) (3.

ECMC cell-veto algorithm

Description

The cell-veto algorithm [START_REF] Kapfer | Cell-veto Monte Carlo algorithm for long-range systems[END_REF] is an ideal algorithm, under the framework of ECMC, to sample the minimum displacement among dense interactions, i.e., any active particle interacting with other O(N ) particles. This algorithm builds upon two ideas: pairwise factorization and upper bounds for each of the factors. Consider for example a continuous spin system where the coupling constants are non-zero for all pairs but decay as J(i, j) = |r ij | -p where r ij is the minimum separation vector of site i and j.

Then we can bound from above the pair potential of each interaction by a constant, and it is easy to sample from N independent constant Poisson processes with different intensities.

In particle system the algorithm takes more complex forms. First, we have to divide the simulation box into cells, usually into square ones, denoted as C. For the time being, each cell is allowed to have only one occupant (later we will consider the exception that more than one object coincides in one cell). Then for each pair of cells C and C , we must provide an upper bound for the event rate for any possible particle The cell setup provides a piecewise-constant bounding potential for the two-body interaction, and there are three kinds of events related to it-unconfirmed physical event, confirmed event, and cell-boundary event (labeled by A, B and C respectively). (From Ref [1].)

pair with one within C and the other within

C q cell (C, C ) ≥ max r 1 ∈C,r 2 ∈C q(r 12 = r 2 -r 1 ). (3.3.1)
Instead of all other particles rejecting the active particle's move, now the triggering objects can be regarded as individual cells, each enforcing a constant event rate. We put all q(C, C ) except C = C into Walker's table, to later sample C with probability proportional to q(C, C ) in O(1) time. The detail of Walker's method will be given in section 3.3.3. And we define the total cell-veto event rate as

q tot (C) = C ∈C,C =C q cell (C, C ). (3.3.2)
We show the decomposition of cells in Fig. 3.9 (a) .

During the Markov chain, the program samples the displacement η for the event rate q tot , and thereafter samples from Walker's table which cell C triggers the event. Then it advances the active particle by η and inspects the cell C . If C has no occupant, it is a fake event. If C has an occupant, it calculates the instant separation r 12 after advancing the active particle by η, the instant real event rate q(r 12 ), and the confirmation rate r C = [q(r 12 )/q cell (C, C )] + . It confirms the event with probability r C , and once confirmed, the activity is passed to the occupant of C .

Usually the cell decomposition is sufficiently regular and symmetric, so that q cell (C, C ) = q cell (C -C) relies on the relative separation of C and C . Then only one Walker's table holding the relative cells is required. When we draw an element ∆C from Walker's table, we must retrieve the target cell through C = C + ∆C.

Cell-boundary events must be considered every time the active particle crosses the boundary. The computer then changes the internal registration of the cell system. Fig. 3.9 (b) shows three kinds of events related to cells. There are two kinds of exceptional events, one occurring if there is more than one particle in a cell, the other coming from infinite or too large q cell (∆C) for some ∆C's. First, we have to keep a list of surplus particles whose cells have already been occupied, and the number of the surplus should keep O(1); otherwise, iterating over the surplus list will considerably lower the performance. Second, we have to exclude the exceptional cells from Walker's table and iterate them separately for each move of the active particle. The full procedure can be described as follows 1. Divide the box into cells C, register particles into cells, and keep the surplus list.

2. Estimate q cell (∆C).

3. Put all moderate-valued q cell (∆C) into Walker's table, and keep the list for exceptions.

4. During the Markov chain, for the current active particle, calculate displacements {η M } of other factors (those not related to cells).

5. Calculate displacements {η e } by occupants of exceptional cells, and by surplus particles.

6. Calculate the displacement η b to the cell boundary.

7. Calculate the displacement η c according to q tot . 8. Determine the minimum displacement η = min{η c , η b , {η e }, {η M }} and advance the active particle by η.

9. If η comes from {η M } or {η e }, use the normal procedure to determine the nature of the event (true or fake) and the target particle.

10. If η is from η b , change the information registered in the cell occupancy system.

11. If η is from η c , then draw from Walker's table an element ∆C, and calculate the triggering cell C = C + ∆C. Then inspect the occupant of C :

• If C is empty, the event is not confirmed.

• Let r 12 be the instant separation between active particle and the particle in C , calculate r C = q(r 12 )/q cell (∆C) and draw a random number r ∈ [0, 1].

If r ≤ r C the event is confirmed, C 's occupant becomes active; otherwise, the event is not confirmed.

12. Go back to step 4 and repeat.

The cell-veto algorithm is essentially a constant bounding potential for arbitrary interactions within each cell. It is valid since q cell (C, C ) is greater than any true event rate inside. Some remarks for cell algorithms are

• The cell size must be carefully tuned. Too small cells lead to too big q tot and hence slow the simulation, while big cells will cause more surplus particles.

• We do not need the exact maximum q(r 12 ) in a cell to obtain q cell . A rough estimator suffices, and one can multiply it by a constant. We will provide several estimators in section 4.5.4.

• If an event is not confirmed or the event is boundary-crossing, we do not, in principle, have to recalculate all proposed displacements from step 4. In this case, only the unconfirmed event or the boundary event needs refreshing.

Cell-veto event rate

We devise the cell algorithm so that the surplus list and the exceptional cells stay constant with increasing system size. It is the cell-veto event rate that predominates all triggered events. The cell-veto events consist of empty-cell events, unconfirmed events due to overestimating q cell , unconfirmed events due to variance of q, and real events.

q tot = R e R over R var q tot real . (3.3.3)
R e is the ratio of all cells over occupied cells. It is roughly ∼ 10 for charged atoms and the water system described in section 3.6.2. R over means the q cell value returned by the estimator divided by the right-hand side of Eq. 3.3.1. It depends on the estimator and is usually slightly greater than 1. R var is the estimate of the variance between the true q(r 12 ) and max{q(r 12 )}. For faraway cells holding atoms it is close to one, while for dipole systems there is a factor of 4.0 (see Eq. 3.5.13).

The q tot real represents the confirmed event rate. For the example of Coulomb particles with identical charges, we have

q tot real ∼ L r 0 ρq(r)d 3 r ∼ L r 0 1 r 2 r 2 dr ∼ L ∼ N 1 3 . (3.3.4)
This means that the event rate for plasma simulation scales as N ) time. This simplified analysis has actually captured the true complexity and we will give a more detailed derivation in section 3.5.2.

Walker's method

Given m items with probabilities π 1 , ..., π m with m i=1 π i = 1, we wonder how to efficiently draw items from the list so that their rates of occurrence correspond to {π i }. One simple way is by binary search. First we draw a random number r ∈ (0, 1], and then find the minimum number k so that k i=1 π i ≥ r, which can be done with O(log N ) time using binary search.

Walker's algorithm provides an optimally efficient approach that can sample with O(1) complexity, under the condition that the probabilities must be static and fixed before the simulation. It works through elaborately disassembling π i , and rearranging them into m boxes with volume 1/m. Each of these holds exactly two pieces of different origins (except for the end of the construct). The procedure can be described as follows 1. Put all π i into two lists, one with π i > 1/m ("big" list) and the other with π i ≤ 1/m ("small" list).

2. Take one item π s from the small list and one π b from the big list and register a Walker item

[(π s , s), (1/m -π s , b)].
A Walker item is a tuple of the form (probability, original index).

The non-registered big item now is π

b -(1/m -π s ).
Put it back to the small or big list according to its remaining value. Go back to step 2 until one of the lists becomes empty.

4. Elements in the remaining list must be of probability 1/m. Put them all into Walker's table.

After m iterations of the steps above, Walker's table has m elements, each with a tuple of two probability pieces. The two probabilities sum up to 1/m for each of the table's elements. Note that the number of remaining items in both lists equals the iterations to be done. Once one of the lists is exhausted, the remaining list items must be all with a value 1/m. Fig. 3.10 illustrates the rearrangement of the raw probabilities. Once Walker's table is ready, one can randomly draw an item from its m elements, and return i with probability mπ i and j with probability 1 -mπ i .

[(π i , i), (1/m -π i , j)]

Coulomb bounding potential

The Coulomb potential for periodic boundary conditions given by Eq. 3.2.6 is noninvertible. The cell algorithm has already provided an effective bounding potential based on cells. For excluded cells and surplus particles, however, the Coulomb derivative is not upper-bounded. Hence non-cell-based schemes are required to sample displacements.

We propose that U Rather than being smooth everywhere except at the origin, U

Clb is discontinuous at the surface x = ±L/2, but has the same period L as U Clb of Eq. 3.2.6.

Dipole factors

Many realistic systems are neutral, mostly because they appear as dipoles or can be treated as a combination of dipoles. Models of small molecules consisting of charged atoms are often natural dipoles such as water; otherwise, for big molecules such as charged polymers, we have ways to decompose them into two-atom dipoles, as shown in Fig. 3.11.

As mentioned in section 3.3.2, the event rate of a three-dimensional Coulomb system increases as N 1 3 . This scaling is a natural effect of the 1/r 2 Coulomb interaction. In this framework, the event rate can however be lowered by exploiting the 1/r 4 dipole-dipole interaction. The answer is positive in the framework of ECMC. By translating a dipole without rotating or changing its inner structure, the event rate triggered by a faraway dipole can scale as 1/|r 12 | 4 , which alone cannot, however, guarantee ergodicity. In this section, we will introduce the dipole factor for moving a single active atom. This way can take advantage of the 1/r 3 charge-dipole interaction and finally reach an O(log N ) total event rate.

Two-dipole case

We consider the ECMC event rate for two dipoles in an infinite space. Particles in dipole one are 1 and 2, and those in the other are 3 and 4. Each particle carries the same charge unit, by c 1 = c 3 = -c 2 = -c 4 . We denote their centers as A and B, with condition that r AB r 12 and r AB d 34 , as shown in Fig. 3.12. Coulomb interactions exist between 1-3, 1-4, 2-3, and 2-4.

If we treat the four pairs of Coulomb potentials as four factors referred to as atom factors, M = {({i, j}, Coulomb) i = 1, 2; j = 3, 4}, the event rate for active particle 1 is

q 1,atom = βc 2 ∂ ∂x 1 1 |r 13 | + + - ∂ ∂x 1 1 |r 14 | + .
(3.5.1)

Using r 13 = r 1B + r B3 , we expansion and the same for 1/|r 14 |. By taking into account r B3 • ∇ B ∼ r B3 /L 1, we find that the leading term survives in Eq. 3.5.1 and results in

∂ ∂x 1 1 |r 1B + r B3 | ≈ (1 + r B3 • ∇ B ) ∂ ∂x 1 1 |r 1B | . ( 3
q 1,atom ≈ βc 2 ∂ ∂x 1 1 |r 1B | + + - ∂ ∂x 1 1 |r 1B | + = βc 2 ∂ ∂x 1 1 |r 1B | , (3.5.3) which decays as 1/|r 1B | 2 for large r 1B .
We can also bundle four pairs of Coulomb interaction into one factor, M = {({1, 2, 3, 4}, Coulomb)} which we call dipole factor. It sounds like an artificial fourbody Coulomb interaction with no distinct physical effect from pairwise ones, but in ECMC when we calculate the event rate for active particle 1

q 1,dipole = βc 2 ∂ ∂x 1 1 |r 13 | - ∂ ∂x 1 1 |r 14 | + ≈ βc 2 (r 43 • ∇ B ) ∂ ∂x 1 1 |r 1B | + , (3.5.4)
in which the first term of the right-hand side of Eq. 3.5.2 cancels but the second term survives. Eq. 3.5.4 implies that event rate for the particle-dipole interaction scales as 1/|r 1B | 3 (one derivative lowers it by one order).

To further exploit the dipole-dipole interaction with its 1/r 4 scaling, we have to expand to second order. Take 1/|r 13 | for example,

∂ ∂x 1 1 |r 1A + r AB + r B3 | ≈ [1 + r B3 • ∇ B + r A1 • ∇ A + T 2 ] ∂ ∂x A 1 |r AB | , (3.5.5)
where T 2 is the second order expansion operator

T 2 = 1 2 (r B3 • ∇ B + r 1A • ∇ A ) 2 . (3.5.6)
The event rate caused by the move of particles 1 and 2 as a whole is

q 12,dipole = βc 2 ∂ ∂x 1 1 |r 13 | - ∂ ∂x 1 1 |r 14 | - ∂ ∂x 2 1 |r 23 | + ∂ ∂x 2 1 |r 24 | + .
(3.5.7)

Dipole factors

By inserting Eq. 3.5.5 into the above equation, we find that the leading term and the first order term of Eq. 3.5.5 both vanish, due to the relations r B3 = -r B4 and r A1 = -r A2 . The first surviving term is brought by

T 2 q 12,dipole ≈ βc 2   1 2 i=1,2; j=3,4 (r Ai • ∇ A + r Bj • ∇ B ) ∂ ∂x A 1 |r AB |   + = βc 2 1 2 (r 12 • ∇ A ) 2 + (r 34 • ∇ B ) 2 ∂ ∂x A 1 |r AB | + . (3.5.8)
It decays as 1/|r AB | 4 for large r AB . As suggested before, when we translate the dipole as a whole, the derivative with respect to this move takes the form of Eq. 3.5.7. And we will show in section 3.5.3 that the inside-first lifting scheme that prioritizes the atom 2 as the next active particle, will have probability as 1/|r| 4 to pass its activity to atoms in dipole B.

Homogeneous systems

In this section, we will analyze the total event rate of the Coulomb factor with atom and dipole factorizations. We always assume that the system is homogeneous, and refer to the density of charges or dipoles as ρ.

First, the tin-foil Coulomb potential of Eq. 3.2.6 takes the form

U C (r 12 ) = c 1 c 2 |r 12 | f 1 r 12 L , (3.5.9)
where f 1 is a smooth function defined in [-1/2, 1/2] 3 . This is manifest by noting that for r 12 → γr 12 and for L → γL, we have U C → U C /γ (which can be obtained by α → α/γ in Eq. 3.2.6). Let r s = r/L and we have

U C (r s ) = c 1 c 2 L 1 |r s | f 1 (r s ), (3.5.10
)

qClb (r s ) = c 1 c 2 L 2 x s f 1 (r s ) -|r s | 2 ∂ xs f 1 (r s ) |r s | 3 = c 1 c 2 L 2 x s |r s | 3 f 2 (r s ). (3.5.11) Since ∂ xs f 1 (r s )| xs=0 = 0, f 2 (r s
) is another smooth function that we denote as qf,1 in section 3.2.4.

For the case of atom factorization, assuming that all particles have charge c, the total event rate for an active charge is

Q atom = [-L/2,L/2] 3 -R( ) ρ [q Clb (r)] + d 3 r = [-1/2,1/2] 3 -R( /L) ρL 3 [q Clb (r s )] + d 3 r s = [-1/2,1/2] 3 -R( /L) ρc 1 c 2 L x s |r s | 3 f 2 (r s ) + d 3 r s , (3.5.12)
where R( ) is the sphere of radius centering around the origin. The integrand is proportional to 1/|r s | 2 while d 3 r s contributes |r s | 2 around the origin as well. Thus the integration is finite around r s = 0 and the final result is proportional to L. We conclude that the event rate for atom factorization scales as N 1/3 under periodic boundary conditions.

As for dipole factorization, we use d • ∇q Clb to approximate the charge-dipole event rate for a faraway dipole d. However, we have to average over dipole orientations. To this end, let v be an arbitrary vector and n a vector uniformly distributed on R (1). Then

[n • v] + n = |v| 4π π 0 dθ 2π 0 dφ sin θ [cos θ] + = |v| 4 , (3.5.13)
and so

Q dipole = [-L/2,L/2] 3 -R( ) ρ [d • ∇q Clb (r s )] + d d 3 r s = |d| 4 ρ|c 1 c 2 | [-1/2,1/2] 3 -R( /L) ∇ s x s |r s | 3 f 2 (r s ) d 3 r s , (3.5.14)
where ∇ s is the gradient operator with respect to r s and ∇ s = L∇. The integrand in Eq. 3.5.14 is proportional to 1/|r s | 3 . Thus we have

Q dipole ≈ |d| 4 |c 1 c 2 | C -log L ≈ |d| 4 |c 1 c 2 | log L, as L → ∞. (3.5.15)
Dipole factorization can reduce the event rate scaling to log L. Likewise, we may calculate the total event rate with respect to dipole translation.

Q dipole-dipole = [-L/2,L/2] 3 -R( ) ρ [d 2 • ∇ (d 1 • ∇q(r))] + d 2 d 3 r = |d 1 ||d 2 | 4 ρ [-L/2,L/2] 3 -R( ) |∇ • (n d 1 • ∇q(r))| d 3 r = |d 1 ||d 2 |c 1 c 2 ρ 4L [-1/2,1/2] 3 -R( /L) ∇ s (n d 1 • ∇ s ) x s |r s | 3 f 2 (r s ) d 3 r s .
(3.5.16) As the integrand scales as 1/|r s | 4 , we obtain

Q dipole-dipole ∝ |d 1 ||d 2 |c 1 c 2 ρ 4 -1 - C L , (3.5.17)
which means that the total event rate is bounded from above and the difference to the limit decays as 1/L.

Dipole lifting schemes

We introduce in section 2.2.2 that a lifting scheme is needed to select the next particle to move in the presence of many-body interactions. The ratio lifting scheme [START_REF] Harland | Event-chain Monte Carlo algorithms for three-and many-particle interactions[END_REF] is a universal way to distribute the probability flow in proportion to the magnitude of derivatives for those decreasing energy. For dipoles, the ratio lifting scheme works as

∂ x 1 U M > 0, ∂ x 4 U M > 0, ∂ x 2 U M < 0 and ∂ x 3 U M < 0. (b)
Ratio lifting scheme. (c) Inside-first lifting scheme. The outflow to activate atoms in the other dipoles is indicated by the mismatch of

∂ x 1 U M and |∂ x 4 U M | that is proportional to 1/|r| 4 . (d) Outside-first lifting scheme. (From Ref [1].)
indicated in Fig. 3.13 (b) and ensures the target distribution. Moreover, we propose in the following two other lifting schemes, namely an "inside-first" lifting scheme and an "outside-first" lifting one featuring dipole-dipole interaction.

We first classify and align the derivative bars, i.e., bars of length proportional to absolute value of the corresponding derivatives, into a positive table and a negative table. Those with positive derivatives are sorted in a positive table by their atom indices, and those with negative derivatives are inserted into a negative table by order of atom indices. Since the positive table's length equals the negative table's length, any position in the positive table corresponds to one in the negative one, meaning that we can establish a bijective map between the two tables. Then we draw a random position within the active bar, which must be in the positive table, and search the resulting point in the negative table. In this way, we find the target atom, as shown in Fig. 3.13 (c) . For the outside-first scheme, we reverse the negative table at first (or equivalently reverse the positive table), and do the same mapping to find the target atom, as shown in Fig. 3.13 (d) .

Since we index atoms in an dipole by dipole order1 , atoms of the same dipole will be sorted to the same side of both tables. Hence the inside-first scheme prioritizes other atoms in the same dipole to be the target atom. In contrast, the outside-first scheme favors atoms from the other dipole, and it maximizes the flow going out of the dipole. Furthermore, we find that outgoing flow, i.e., the inter-dipole lifting rate in the inside-first scheme is exactly indicated by the mismatch between positive bars and negative bars of one dipole (see Fig. 3.13 (c) ), whose magnitude is given by Eq. 3.5.8 in proportion to 1/|r AB | 4 . Eq. 3.5.17 tells us that the outgoing probability is bounded from above no matter how large the system is.

The event rates and lifting rates are summarized in the Table . 3.5.3, for atom factorization and dipole factorization with three proposed lifting schemes.

Chapter 3. Event-chain Monte Carlo for long-range interaction

scheme q intra q inter < Q intra > < Q inter > atom factors 0 |r| -2 0 N 1 3 ratio lifting |r| -3 |r| -3 log N log N dipole factors inside-first lifting |r| -3 |r| -4 log N B -C/N 1 3
outside-first lifting |r| -3 |r| -3 log N log N Table 3.1: Pairwise Coulomb event rate scalings with respect to dipole separation, and total Coulomb event rate scalings with respect to system size, for different factorizations and lifting schemes.

Numerical tests

We give two more simulations apart from Fig. 3.8 to verify our methods. One contains two dipoles and the other simulates 32 water molecules.

Dipole system

In the dipole model, we introduce harmonic bonds connecting two atoms within a dipole

U bond (r 12 ) = 1 2 k b (|r 12 | -r b ) 2 (3.6.1)
and a short-range repulsive potential

U rep (r 12 ) = k 2 r 0 |r 12 | 6 (3.6.2)
with k b , k 2 , r 0 and r b all positive. We make it decay fast enough that no periodicity needs considering. With the indices of Fig. 3.13 (a) , harmonic potentials exist between atom 1 and 2, and between 3 and 4. Moreover, we impose repulsive potential between atom 1 and 4, 2 and 3. Thus the harmonic and repulsive factors are {({1, 2}, bond), ({3, 4}, bond), ({1, 4}, rep), ({2, 3}, rep)}.

(3.6.3)

Note that we are using the notation introduced in section 2. In Fig. 3.14, we simulate two dipoles using five methods: merged-image particle factorization, separate-image dipole factorization with inside-first lifting scheme, merged-image dipole factorization with ratio, inside-first, and outside-first schemes. All methods agree visibly in the distribution of |r 13 | and |r 14 |, and we will give more accurate verifications in section 5.3.

L = 1, c 1 = -c 2 = c 3 = -c 4 = 1.0, k b = 400, k 2 = 1.0, r 0 = 0.1 and β = 1.0. (From Ref [1].)

SPC/Fw water model

The popular SPC/Fw [START_REF] Wu | Flexible simple point-charge water model with improved liquid-state properties[END_REF] (simple point-charge flexible) water model treats each atom as a point charge. Interactions include a harmonic force as in Eq. 3.6.1 with r 0 = 1.012 Å and k b = 1059.162 kcal mol -1 Å -2 , and a bending potential related to each H-O-H angle

U bending (r 1 , r 2 , r 3 ) = 1 2 k a (φ 123 -φ 0 ) 2 , (3.6.6)
where φ 123 represents the angle formed by the vectors r 21 and r 23 , with φ 0 = 113.24 • and k a = 75.90 kcal mol -1 rad -2 . A Lennard-Jones potential acts between any pair of oxygens

U LJ (r 12 ) = k LJ σ |r 12 | 12 - σ |r 12 | 6 (3.6.7)
with k LJ = 0.62 kcal mol -1 and σ = 3.165 Å. The Lennard-Jones potential decays sufficiently fast that no periodic boundary conditions needs to be considered for it. Finally, Coulomb potentials exist between any intermolecular atom pair, with -2c H = c O = -0.82e where e is elementary charge.

The factor set without Coulomb factor between two SPC/Fw water molecules labeled as in Fig. 3.15 (a) is ({1, 2}, bond), ({2, 3}, bond), ({4, 5}, bond), ({5, 6}, bond) ({1, 2, 3}, bending), ({4, 5, 6}, bending), ({2, 5}, LJ).

(3.6.8) First, we verified our methods by comparing the distribution of the oxygenoxygen separation |r OO | as shown in Fig. 3.16. In order to investigate the event composition and justify the efficiency of dipole factors, we measure event rates for increasing system sizes for all four interactions, as shown in Fig. 3.17. We conclude that the Coulomb events are predominant, and that Q Clb is proportional to log N H 2 O as N H 2 O → ∞, while the event numbers of the other interactions remain roughly constant in varying system sizes since they are local. By extrapolation we expect that Q Clb ≈ 107Å -1 for 2 20 water molecules.

Furthermore, we select systems of N H 2 O = 64, 128 and 256 and focus on the distance between the active and the target particle at the moment when Coulomb events happen. Different lifting schemes for dipole factorization are compared in Fig. 3.18. All systems exhibit sharp peaks around 1Å with heights proportional to log N H 2 O , complying with Table . 3.5.3. As expected, the inside-first scheme as shown in Fig. 3.18 (c) has a faster decay than others as 1/|r|2 (1/|r| 4 in Eq. 3.5.8 multiplied by the spherical measure |r| 2 ), which numerically implies that the outflow of the inside-first scheme scales as 1/|r| 4 and the total outgoing probability is upper bounded. Also, we test the influence of the chain length over the rotation speed of a single water molecule. Our ECMC implementation features atomic motion along axes in comparison with arbitrary directions, which greatly simplifies the code, while it remains a question whether such a scheme can achieve as fast molecular rotation as other methods.

We define the orientation of a molecule as its polarization

P = r OH1 + r OH2 . ( 3
Q Coulomb Q bond Q LJ Q bending Figure 3
.17: Event rates of different factor types with increasing system size, from 16 water molecules to 256. Measurements are done using dipole factorization and the same parameters as in Fig. 3.16. (From Ref [1].) Taking a global one-angstrom displacement as a unit of time, we can define the autocorrelation of P through the inner product

10 0 10 1 10 -1 10 0 10 1 10 2 10 3 Q Coulomb (|r|) log(N H2O ) 1/|r| ratio 10 0 10 1 |r| [ Å] log(N H2O ) 1/|r| outside-first 10 0 10 1 log(N H2O ) 1/|r| 2 inside-first N H2O =64 N H2O =128 N H2O =256
C P (t) = P(s) • P(s + t) s .
(3.6.12)

In equilibrium, C P (t) decays exponentially as C P (t) ∼ e -t/λ with the autocorrelation time λ. In Fig. 3.19, we test two direction switching schemes each with respect to a range of chain length . One scheme is the random choice of the next direction, and the other is cyclic as xyzxyz.... It shows that minimal correlation is realized at around ≈ 0.1Å, and cyclic the scheme has smaller λ than the random scheme. We generalize the result to = 0.2N H 2 O for N -molecule systems as used in section 6.3.2.

Numerical tests

JeLLyFysh architecture

All current molecular-simulation packages employ molecular dynamics, for the reason that Monte Carlo cannot produce time-dependent information and is slow in treating Coulomb interactions. With our development of long-range ECMC in theory, it becomes a promising candidate for long-range systems. Also, Monte Carlo performs non-realistic moves for a fast exploration of configuration space, which is helpful in various settings. For example, it may take long time for a molecular dynamics simulation to observe a certain chemical reaction, one can prepare multiple independent initial states via Monte Carlo methods and then simulate them with molecular dynamics. However, the slow diffusive bahavior of Monte Carlo methods has impeded this approach.

On the other hand, since ECMC has shown its powerful advantages in simple physics models, it is usually desirable to generalize to a more complicated system up to macro-scale biochemical molecules. In pursuit of methodological improvement and widespread usage, an efficient platform will considerably contribute. Reusable codes will ease the burden of reinventing programs for all researchers and reduce the risk of bugs that have long been undermining the reliability of simulation research.

Moreover, a robust application also serves as a scientific and methodological benchmark. New features of ECMC or comparison between methods will benefit from an ECMC application with excellent stability. Adaption to diverse chemical and biological models cannot be done by individuals but the entire society of relevant fields. Modern scientific software such as LAMMPS [14], GROMACS [START_REF] Berendsen | GROMACS: a messagepassing parallel molecular dynamics implementation[END_REF], and AMBER [START_REF] Salomon-Ferrer | An overview of the Amber biomolecular simulation package[END_REF] has spawned their communities, to which thousands of worldwide developers make contributions. Taking them as our model, we developed JELLYFYSH (JF), an ECMC simulation application for all-atom systems, in hopes that JF can one day become useful in routine applications.

We are aware of many kinds of functionalities and desirable simulation environments in the long term. Apart from the advanced algorithms, many aspects are crucial to an application's success, such as parallelization, GPU support, data visualization, and extendability to non-ECMC methods(quantum, replica exchange, etc.). We leave these possibilities open for the future but lay the foundation of JF.

When JF-V1.0 was released [2] in August 2019, it was able to run particle systems consisting of atoms or dipoles, with short-range potentials and the long-range Chapter 4. JeLLyFysh architecture Coulomb potential, and supported by cell-veto algorithms and other bounding potentials. We implemented its structure and simple applications through about 20,000 lines of python code, which was believed to be the best language for architecture and further extension. Modules are expected to speed up by replacing them with C/C++. JF-V1.0 has included all the state-of-the-art methods in chapter 2 and chapter 3, so it is intrinsically event-driven. All physical collisions and operations like sampling, direction switching, and even the start and the end of the program, are treated as events. The program simulates in a manner of event flow processing, which we believe is the most compatible way to incorporate future developments.

JF is available on GitHub (repository https://github.com/jellyfysh/ JeLLyFysh) with all source code open under the license GNU GPLv3.

Issues of application development

The JF application is more than a program to generate data shown in the previous chapters. Not only is it able to realize more functionalities in a single framework, but it also has to consider the possibility of user-customized modules in various contexts. Specifically, we list the considerations of scientific application in the following, though none of them is independent.

1. Structure. In order to incorporate multiple mandatory or optional functioning modules, a highly efficient structure [START_REF] Gamma | Design patterns: elements of reusable object-oriented software[END_REF] is required in analogy to a processing line. Different functioning parts must be written in separate modules, and we realized it for JF by different python packages. Modules to store the current configuration, distribute events, calculate event times, select the next event, and output something, all have to have their own relatively self-contained packages.

In JF we adopt the "mediator" design pattern (see [START_REF] Gamma | Design patterns: elements of reusable object-oriented software[END_REF], chapter 5) to communicate data between modules.

2. Reusability. Any written code is supposed to function for the long term. To achieve this goal, one must make up a standard of code and has a mechanism to regulate extensions. In JF each package contains an abstract class that explicitly defines all mandatory interfaces for any implementation. Once a module is completed, a corresponding unittest must be provided so that errors are easily detected in future modifications.

3. Extendability. As mentioned above, we have only implemented a couple of realistic simulation examples and leave its vast potential for the future. Objectoriented programming languages are capable of meeting this requirement, and python is a modern object-oriented language. The majority of the modules in JF are coded as python classes. Future developers can extend any package by adding classes inheriting from an abstract class. Furthermore, users are allowed to create and customize the used set of packages by specifying configuration files. On the other hand, a simpler principle implies, in general, more compatibility. We treat all kinds of operations as events so that they can be realized by corresponding event handlers.

4.2.

Features of JELLYFYSH-V1.0 4. Readability. For future developers and contributors from outside, it will be beneficial to facilitate their involvement. Understanding several tens of thousands of lines is not easy. The aforementioned structure helps to simplify tedious specifications. We also enforce strict python coding conventions, including the naming of classes, modules, and variables. Also, docstrings are written for every function of every module of JF-V1.0 as an essential element of documentation.

5. Ecosystem. It is a big topic related to not only every aspect of the application itself but the way we manage it. One must maintain a good ecosystem for an application in order to attract more users and developers. All the aforementioned considerations are essential to a thriving ecosystem. Apart from them, we release JF on GitHub with source code open, and we will follow the working flow of GitHub to incorporate external contributions. We are aware that version control is crucial as well, though version 1.0 has only been released so far. License, code of conduct, and several quick manuals are provided in the main directory of the application.

Features of JELLYFYSH-V1.0

In JF-V1.0, we realized the modules that accomplish the working structure, provide basic settings, calculate basic events, and implement the long-range ECMC algorithms. The mediator pattern and the factory facility are expected to live for all versions. We designed a hierarchical representation of big molecular objects, and all current modules must respect such a protocol. As for the functioning parts, we have activators based on factor map and cells, event handlers that realize physical events and pseudo-events, potentials for the SPC/Fw model, and a heap scheduler. To support the state-of-the-art cell-veto method, the cell facility, the cell occupancy and corresponding event handlers are also provided. Inside the project, there are many other helping modules that we do not list here. We hope to realize the following features in the future.

1. Parallelization. This will be done by allowing multiple active particles.

2. Multiprocessing support, to simultaneously calculate times for several candidate events.

3. Fast unconfirmed event processing. JF-V1.0 treats unconfirmed events as normal events that trash and recreate almost all other events. In fact, unconfirmed events can leave other events intact, which will significantly reduce the calculation burden.

4. Smart trashing and recreating schemes. For now, users must set up the lists for which events are trashed and which events are recreated.

5. Speedup via more efficient language like C/C++.

6. More packages of potentials and event handlers to adapt to various particle systems.

Basic concepts 4.3.1 Event flow

ECMC advances the configuration in a fixed direction and deflects it with lifting events. We devise JF as a processing line running with all kinds of events and treat auxiliary operations such as sampling in the same manner as treating physical collisions, except that no lifting move occurs at the sampling moment. We describe JF's event flow as Fig. 4.1.

Besides physical events, those operational events are called pseudo-events. They do not change the direction of configuration advances, as shown in Fig. 4.2. Moreover, we associate each pseudo-event with a triggering pseudo-factor. All events have event times, indicating when they occur. States restricted to its factor or pseudofactor, before and after the event time, are called the event's in-state and out-state. Also, an event has a tag indicating its nature. The program must select from candidate events the soonest one and calculates its resulting operation. Then, it removes and recreates some events according to a specific scheme. We will describe this procedure in section 4.4.1.

Units

We denote particle objects simulated in JF as point masses. Each point mass has a position, a velocity, an identifier, charges, and a time stamp as properties. Thus we prepare Unit class with those five attributes. Later, when introducing the tree structure, the unit is also used to represent artificial center-of-mass objects (which are not point masses) in the tree's non-leaf node. Units are universal in JF acting as information carriers shipped among modules; thus, most functioning parts have to extract, process, and create units. A similar term in JF especially in the tree state handler (see section 4.3.3) is called particle that has only position and charge. As the number of active point masses is much smaller than the total number of point masses, the tree state handler stores them in separate modules. Hence the position and charge of a unit independent of its lifting variable will be stored as a Particle instance.

Basic concepts

Given the information of a unit with position s, velocity v and time stamp t 0 , its position can be inferred by

s(t) = s, if v = None; s + v(t -t 0 ), if v = None. (4.3.1)
Eq. 4.3.1 is only sensible in an event-driven approach. The effect of an event usually includes time-slicing involved units, i.e., to update the position and time stamps up to the event time. Units that do not belong to the triggering factor are allowed to have time stamps lagging behind the most recent event. For example, sampling events and end-of-chain events have to time-slice all active units to the event time. The cell-boundary event, however, time-slices only the active unit. We have to note that whether to time-slice and which units to be time-sliced become more complicated in the presence of the tree structure in order to respect consistency.

Global state and internal state

The global state stands for the configuration of the point masses and related barycenters. JF-V1.0 treats configurations via a tree structure of connected nodes, with leaf nodes hosting a real point mass and upper nodes holding artificial objects that represent barycenters of their direct child nodes. A barycenter node together with all its child nodes, is treated as a composite object in JF-V1.0. Thus, a composite object has all information appearing in point masses, including position, velocity, identifier, charge, and time stamp. The position and velocity of a non-leaf node unit are calculated simply via the average of units of its direct children, and the program keeps in the state handler (see section 4.4.4) a list of top nodes in order to iterate over them. The identifier adopted in JF-V1.0 comes from its order in the tree. The state handler numbers root nodes, and nodes number their child nodes. The identifier of a unit is the tuple with all the numbers along the path towards it.

An active point mass moves by itself, inducing its parent unit to move, and all its ancestors gain activities. On the other hand, a composite object unit can move at velocity v as well and makes all descendants within the subtree move at v. The latter case is realistic, and can be molecule motion as a whole. Thus we introduce the term of an independent active unit and an induced active unit. The unit for an original moving point mass and composite object unit for molecule moving as a whole are regarded independent, while their ancestors and children acquiring velocity belong to induced active units. Apart from the global state, JF defines an internal state to maintain useful information concerning the global state. For example, cell occupancy makes use of a cell setup, and updates unit-cell correspondence according to the current global state, as shown in Fig. 4.3 (c) . Thus the internal state is partial information of the global state. JF keeps internal states in the activator (see section 4.4.3), and there can be multiple internal states created for one simulation.

An internal state has two mandatory methods. update is called during mediator step 2, and it uses the current active state to update the internal state. For those internal state changes without lifting moves, we must regard them as extra events. Internal states can be accessed with indices, so its __getitem__ method is required.

Essential modules

Essential modules

Simulating particle systems demands the coordination of many functions. JF distributes them in various modules, and in JF-V1.0, it has a mediator, an activator, a state handler, event handlers, a scheduler, and an input-output (IO) handler. We depict their communication in Fig. 4.4 featuring a clear mediator design pattern whose topology takes a star shape. It means that the mediator stands in the center and connects all the rest while data exchanges between peripheral modules are forbidden.

Mediator

The mediator is the hub of all activities of JF. It provides a Mediator class mandating the run and post_run methods that will be called by the executing script. The main loop of event-driven ECMC is hosted in the run method. And also, the mediator is attached with event-handler-specific methods to get arguments for an event's out-state (methods with name get_argument + event_handler_name) and to do any operations at the event moment (methods with name mediate + event_handler_name).

We implemented the SingleProcessMediator and the MultiProcessMediator. The main loop of the SingleProcessMediator consists of nine steps:

1. The mediator requests the state handler for an active global state, whose format can vary according to different state handlers.

2. It sends the active global state to the activator. The activator returns a list of factors (indicated by event handlers in JF-V1.0) and involved unit identifiers.

Chapter 4. JeLLyFysh architecture 4. The mediator calls the method send_event_time of event handlers obtained in step 2 with the in-state arguments acquired in step 3. Then it pushes all returned candidate event times into the scheduler.

5. It asks the scheduler which event handler produced the nearest event.

6. The mediator calls the send_out_state method of the event handler that produced the smallest event time, optionally with arguments obtained by the mediator's event-handler-specific get_argument method that may inquire the activator.

7. The out-state is sent and recorded in the state handler.

8. The mediator asks the activator for event handlers to be stopped and removes them from the scheduler.

9. The mediator requests the entire global state from the state handler and sends it to the IO handler for measurement. This step is only executed for event handlers associated with the output handler.

This loop continues until an EndOfRun exception occurs. The post_run method is invoked afterwards. The MultiProcessMediator makes use of python's multiprocessing package. It distributes the job of each event handler to one long-lived process and designates a two-way pipe (multiprocessing.Pipe object) to each event handler. The mediator and other modules are executed through another process, indicated by the red dashed line in Fig. 4.4. Only the mediator needs to be changed when switching from single processing to multiprocessing, and all event handlers are automatically modified in two ways. First, a run_in_process method is added to loop over the four states shown in Fig. 4.5; second, the send_event_time and send_out_state methods are decorated so that the only argument is the pipe connecting to the event handler, and that the in-state, the resulting out-state, and other arguments are transferred via pipes.

We split an event calculation into an event time and the following out-state. An event-handler process may stay in one of the four states during the Markov chain: idle, event_time_started, suspended and out_state_started. The event-handler process takes actions under the control of a multi-process mediator through shared multiprocessing.Event objects. A start event and a continuing event (this event is not the event in ECMC) are set up for an event-handler process to undergo stages of event computation in order. In addition, our multi-process mediator takes into consideration the available number of CPU cores. If N c cores are designated for simulation, N c -1 are allowed to run at any moment in order to avoid task-switching cost, which we realize through a multiprocessing.Semaphore instance. During stage 4 that requests candidate event times, the mediator prioritizes the calculation of event times of all active event handlers while suspending out-state calculations. When a CPU core is idle, one of the event handlers' out_state_started events is released, and the CPU core can go on with its out-state calculation. This coordinating scheme can, in principle, optimize the usage of CPU resources while it suffers from a computational bottleneck in practice.

Event handler

Since all physical lifting moves, artificial direction switching, and operational state recording are treated as events in JF, event handlers play a versatile role throughout JF's event flow.

The abstract class EventHandler mandates send_event_time and send_out_state methods. An in-state usually accompanies the former. As their names suggest, they return event times and out-states respectively, while out-states may not always be requested unless the event handler is chosen as the nearest event. Once send_event_time is called, the event handler calculates the event time, stores temporarily the state, and waits for the request of out-state. The mediator is responsible for making the proper invoking order, e.g., to avoid calling send_out_state consecutively, as shown in Fig. 4.5.

Some event handlers have no in-state such as the sampling event handler. However, some need more information to produce the out-state. For example, an end-ofchain event handler requires the current state at the event time, so the mediator sends it as an argument of out-state. A cell-veto event handler also requests the occupant information of the target cell by accompanying the event time with a cell index. It is important to note that all state updates are computed in event handlers. In particular, event handlers are responsible for maintaining the consistency of the hierarchical state representation.

Most event handlers do calculations in company with helping modules. Factor event handlers need to connect to potentials where physics is contained, and potential becomes a JF package that will be detailed in section 4.5.4. Customized event handlers and potentials reflect the variety of particle simulation reality.

Activator

Fig. 4.6 depicts the working of JF's activator. It does three jobs: 1. The method get_event_handlers_to_run searches relevant factors for given active units; 2. The method get_trashable_events provides the list of event handlers to be removed after an event; 3. It maintains internal states, and returns its information via the method get_info_internal_state. Here in JF-V1.0, a relevant factor is represented by a list of unit identifiers plus an event handler instance. To this end, the activator requires the proceeding event handler. Even though complete information on active units is sent to the activator, it keeps partial information of the global state in internal states.

In JF-V1.0 we implemented the class TagActivator which categorizes events with tags. Events with the same tag are deemed as the same nature, and they will be created or trashed indiscriminately. For example, while simulating Coulomb atoms via cell-based bounding potential, sampling, end-of-chain, cell-bounded Coulomb, excluded cell, and surplus particles appear as tags in order to process events in a simplified way. JF-V1.0 creates each type of event through Tagger instances, depending on how to find involved units for the event type. For instance, the NoInStateTagger class produces candidate events without seeking any in-state; a FactorTypeMapIn-StateTagger instance is equipped with a factor map specifying interactions between atoms according to their identifiers; cell-related taggers have the responsibility to invoke the update of the cell system, a typical internal state, and acquires the units of in-state by inquiring it.

Besides numerous ways to obtain in-state identifiers, taggers are specified with a multi-dispatching table detailed in the configuration file in JF-V1.0. For each tagger, a trashable list and a creating list of events are provided, then once an event occurs, the activator looks through the trashable list and returns all running event handlers with tags in it (that is why the proceeding event handler is necessary). It creates new candidate events in the same way. Another two lists are activating and deactivating lists which are exclusively used for root-mode motion in JF-V1.0. They allow events to deactivate and re-activate certain taggers, which provides a convenient realization of switching between atom motion and dipole translation. Also, the activator manages the event handler pool, and users must specify the number of event handler instances in JF-V1.0.

Essential modules

State handler

A StateHandler instance not only stores the global state, namely the physical configuration plus lifting variables, but also rules the protocol of communication among the entire JF. The other modules must act in accordance with the output format of the specified state handler, and event handler return out-states that are acceptable by the state handler. In JF-V1.0, we provide TreeStateHandler class whose output values are tree branches, so event handlers, activators, and IO handlers of JF-V1.0 must work with the format of tree branches.

Positions and charges of units are taken as physical variables, and they are stored in an instance of the PhysicalState. The velocity and the time stamp are kept in a LiftingState instance. As the number of active units is limited, the storing strategies for them are usually different. For the TreeStateHandler that implements the tree structure described in section 4.3.3, it uses Node objects to construct trees in its TreePhysicalState, whereas it adopts a simple python dictionary to store non-zero elements of the lifting state. The instance of TreePhysicalState keeps the list of root nodes of composite objects, and each node has links to all direct descendants and parent node. Node information, instances of the Particle class, is kept in the value attribute. An example of the internal storage of the tree state handler is shown in Fig. 4.7. Both the lifting state and the physical state provide basic methods like set and get to update and output information.

The state handler has four abstract methods in total. extract_from_global_state returns the desired state for a given identifier. For the global tree state, we rule that the returned value is the "branch" of the corresponding node with all ancestors and descendants, and with units attached to each node. Fig. 4.7 illustrates the interface of this method. Another method insert_into_global_state is used to commit events' resulting out-state. The tree state handler accepts a sequence of root nodes of branches, then makes corresponding changes inside. During mediator step 1, the method extract_active_global_state is called, in which information of active units (for tree state handler, it becomes branches of independent active units) are returned and passed to the activator. Finally, the extract_global_state method outputs the entire global state for the purpose of measurement that output handlers will perform.

It is important to note that the tree state handler reconstructs branches to send to the outside, using newly instantiated nodes and units. This convention means that outside modules have no access to the state handler's inner storage, and that is why the name cnode appears elsewhere in JF.

Scheduler

JF's scheduler has relatively simple functionality compared to other modules. The abstract class Scheduler has three methods. push_event is used to input an event handler together with its event time. get_succeeding_event returns the event handler instance with the smallest event time within the scheduler, and trash_event removes a certain event handler from it.

A heap structure is capable of treating all aforementioned requests with complexity O(log N E ), where N E is the current number of event handlers inside the scheduler. In JF-V1.0 we implemented the HeapScheduler class via the python package heapq. Actually, we found later that a naive list is faster since the number of candidate events is usually very small, while the ListScheduler class does not appear in JF-V1.0.

Input-output handler

The input-output handler is equipped with an input handler and an arbitrary number of output handlers. Each run of JF can specify one input handler and multiple output handlers. The class InputOutputHandler connects the mediator directly, and has read , write and post_run methods to read from the input handler, write to a specific output handler, and close output handlers.

The input handler is called only once at the beginning of the Markov chain, in order to prepare the initial configurations. Any implementation of an input handler needs to specify its read function. In JF-V1.0, we provide two input handlers. The RandomInputHandler class randomly generates an initial state, and the PdbInput-Handler reads the state from a .pdb (protein data bank) file. This class depends on the MDAnalysis package.

Output handlers are diverse, including measurement, state recording, memory dumping, etc. They only have to implement the write method to generate output data and post_run method to close files. We provided in JF-V1.0 separation output handlers calculating atom separations for a configuration, the pdb output handler to write to .pdb file, one output handler to calculate H 2 O molecule bond angle and bond length, and one to dump the entire program state via the dill package.

All input and output handlers work with tree representation. The input handler returns a list of trees with nodes attached with Particle objects. Output handlers get the global state organized as trees and have to resolve them.

Important tools

Important tools

Several modules of JF-V1.0 are not crucial to its architecture, but are essential techniques of large-scale ECMC simulation or are necessary to provide modules with required information. The setting package and the Initializer class are indispensable to run any application. The Cell, CellOccupancy, Estimator, Potential and LiftingScheme classes are closely related to the ECMC algorithm, so we explain here briefly their implementation.

Globally used modules

The information of the simulated system, e.g., the temperature and the box side length, is kept in an independent package called setting, and actually, it leads another configuration tree (see section 5.2) other than the main architecture represented by the mediator.

The basic setting parameters include β, dimension, number of root nodes and so on (see file setting/__init__.py). They all live in the namespace of setting. A specific setting may have its own variables (e.g., the side length of a cubic setting), but it must give values of those in basic parameters. We implemented in JF-V1.0 the HypercuboidSetting and the HypercubicSetting, each with an additional system_length variable. Basic parameters have their copies under those specific settings, too. Also, by defining hypercuboid setting as a similar setting of the hypercubic one, the program can automatically determine values for the hypercuboid one. For example, once we set beta to be β and system_length to be L in hypercubic setting, β will also exist as setting.beta and setting.hypercuboid_setting.beta, and L will also be in setting. hypercuboid_setting.system_lengths as a tuple of D identical values.

We place functions related to position and separation calculations in implementation of the PeriodicBoundaries class, whose instance is an attribute of both basic setting module and specific setting, too. For example, method separation_vector that maps an arbitrary vector onto its nearest image, may be in setting.hypercubic_ setting.periodic_boundaries and setting.periodic_boundaries.

Besides, some other commonly used functions, such as vector operations, are in base directory.

Cells and cell occupancy

The cell system is important for fast accessing the active particle's interacting pairs, and is also basic to Walk's method to sample the displacement for long-range systems (see section 3.3). JF-V1.0 regards cell occupancy as an internal state and takes cells as an attribute of cell occupancy. As exemplified by Fig. 4.3 (c) , a JF simulation is allowed to have more than one cell and cell occupancy instance.

Cells

A cell instance defines the geometry of the cell division, including not only the position and the shape of each cell but their translational relation. There are six abstract methods within the Cells class. yield_cells is used to iterate all cells. Given one cell, excluded_cells returns the set of cells that have to be treated exceptionally 1 . The position_to_cell method, as the name suggests, returns the cell identifier for a given point. This method has been unambiguously implemented that any computer representation of float-number coordinates within the simulation box range is mapped to one cell 2 . cell_min and cell_max give points with minimum and maximum coordinates respectively within the cell, though it applies to only hypercuboid cells 3 . Finally, the successor method gives an adjacent cell in a certain direction. Fig. 4.8 (a) shows an example of the cell methods.

In addition to Cells, child class PeriodicCell mandates methods translate, relative_cell and zero_cell. zero_cell is the exact origin of the cell system used for other methods, though JF-V1.0 applications never call it. Method translate calculates the cell obtained by translating one cell by another cell's vector, which is especially useful in the cell-veto algorithm. Likewise, relative_cell returns the relative vector of cells a and b, which can also be expressed as a cell. The aforementioned methods make sense only when the system exhibits periodicity, and an example is shown in Fig. 4.8 (b) . A typical implementation of periodic cells is cuboid cells with homogeneous division, realized in CuboidPeriodicCells.

Important tools

Cell occupancy

JF cell occupancy comprises occupants, surplus units, and variables for active units and cells, as shown in Fig. 4.9. Information on the current active units is passed from the state handler via the mediator to the activator. The activator analyzes active unit information plus the proceeding event in order to update the internal states. The change of internal state leads to additional pseudo-events such as cell-boundary crossing.

The abstract class CellOccupancy keeps the cell occupancy information with the yield_surplus and yield_active_cells methods, and the cells and cell_level properties. Property cells returns the underlying Cells instance, and cell_level gives which level of units are taken as occupants. We implemented SingleActive-CellOccupancy in which one or zero active unit is present. It can optionally take into account a charge value specified during instantiation, so that only units of nonzero charge are registered as occupants. It keeps the occupants in a list mapping cell indices onto occupants or None, and surplus units are stored in a dictionary mapping cells onto a list of surplus units.

Initializer

The JF application starts with a factory (see section 5.2) to create all necessary instances according to the customized configuration file. The mediator's run method leads the main running body. Between instantiation and simulation, some modules need to be initialized because we find that several initializing operations must be done after all instances are well prepared. For example, an input handler has to read in the initial physical configuration, and install it within the state handler and the activator. Also, a cell-veto event handler requires charge information of particles in order to set up the cell-veto event rate.

We make JF perform those operations through the initialize method of required classes, and these classes must inherit from the Initializer class (thus multiple inheritances must apply). Instances of Initializer will freeze all their public methods Chapter 4. JeLLyFysh architecture right after instantiation, but thaw them once the initialize method is called 4 . Although the purpose of initialization is straightforward, JF-V1.0 undergoes an obscure procedure to call all required initialize methods5 . Hence it is not users' business to customize initializers, but it is for developers.

Potentials, estimator

We place physical potentials in a separate directory and have two abstract classes Potential and InvertiblePotential. All potentials must implement derivatives, and an invertible potential has to, in addition, provide a displacement for certain energy change. We designed them in a straightforward style. derivative takes one or more separation vectors and a direction of motion, and displacement requires potential change in addition. Users are encouraged to create any potential that is needed for simulation.

The estimator is used to obtain an upper bound and a lower bound within a hypercuboid area of given potential. This estimation can be achieved by taking evenly or randomly a large number of points inside the region. For point-point interaction, we implemented the BoundaryPointEstimator and the InnerPointEstimator which draw points evenly from the surfaces and from the entire hypercuboid respectively. For point-dipole interaction, two-point potentials are only provided, so the estimator must know the typical dipole moment and take all possible orientations into account. The DipoleMonteCarloEstimator samples a large number of dipole positions and orientations randomly, then takes their maximum; The DipoleInnerPointEstimator draws s D points from a D-dimensional hypercuboid with s points per dimension, aligns an imaginary dipole along the direction of the potential gradient and takes the maximum from all positions, which proves more efficient than the Monte Carlo estimator. It is important to note that no method can ensure optimality in estimating an arbitrary function. Thus a prefactor can be specified, and the result will be multiplied by it. Moreover, an estimator allows the user to provide an empirical bound to rule out possible unphysical results. If the estimated result is greater than the empirical bound, the empirical bound is returned instead.

Lifting schemes

Lifting schemes described in section 2.2.2 serve as an independent package and are invoked by many-body event handlers. We provide in JF-V1.0 RatioLifting, Inside-FirstLifting, and OutsideFirstLifting as three implementations of the Lifting abstract class. The base class has already realized methods for resetting and inserting new particles as well as their derivatives (and aligning them into negative and positive tables). Specific lifting schemes have to provide ways to select the next active particle among the negative table in the method get_active_identifier.

Chapter 5

JELLYFYSH simulation

In this chapter, we prepare realistic applications of JF with the help of concrete instances. We show how to write configuration files for methods introduced in chapter 3. By running real simulations, users will understand the functions and the mechanism of various event handlers, and how event handlers treat each event in a two-step manner. Taggers have many types, but fortunately, taggers that have already been developed satisfy the requirement of most particle simulations. The potential package will be supplemented with real potentials and bounding potentials.

Event handlers of JELLYFYSH-V1.0 5.1.1 Event handler for two-body invertible potentials

The TwoLeafUnitEventHandler class is the most typical event handler that inverts a two-body physical potential. Its instance is created with a invertible potential (an instance of the InvertiblePotential class) and the relevant charge name.

The design of this class complies with the tree structure of the internal state. When its send_event_time is called, it at first resolves the in-state in the form of a sequence of branches to obtain lists of leaf nodes and leaf units. Next, it identifies the active node and the active unit, as well as other information like the direction of motion and the speed. The random number corresponding to the energy change is generated within the send_event_time method, too. Finally, it calls the potential's get_displacement method with the separation between the active point mass and the non-active one to acquire the displacement s. A new event time t is returned by adding the corresponding traveling time to the active unit's time stamp. For send_out_state, it just time-slices the active unit to t by advancing its position and time stamp, then exchanges the velocities and time stamps of two leaf units though they are None for the non-active unit. A specific series of methods is provided in the base classes to keep variables consistent along the trees in a registerand-commit manner. The entire procedure is typical for all event handlers.

Event handlers for non-invertible potentials

For non-invertible-potential event handler, the addition to an invertible-potential event handler is a bounding potential and a confirmation step (see section 2.3.2). In JF-V1.0, we provided three kinds of bounding potentials: by a direct invertible potential, by a cell-based potential with piecewise-constant derivatives, and by speculated potential with piecewise-constant derivatives.

Direct bounding potential

An InvertiblePotential instance as bounding potential must be specified for the TwoLeafUnitBoundingPotentialEventHandler, both for two-body interactions. In send_event_time, it samples a displacement under the bounding potential and returns the corresponding event time.

An event confirmation takes place only after the send_out_state method is called. The method advances point masses like in the invertible case, then confirms the event with the ratio given by Eq. 2.3.7. If the event is confirmed, an out-state will be returned with exchanged lifting variables; otherwise, velocities and time stamps remain the same while the active unit is advanced 1 . The procedure is shown in Fig. 5.1. 1 Treating unconfirmed events in the same way as confirmed events leads to inefficiency especially in cell-veto events. Later improvements include letting out-state of unconfirmed events be None, and the mediator repeats requesting event times and out-states until concrete out-state is returned. See section 6.1. 102 5.1. Event handlers of JELLYFYSH-V1.0

Cell-based bounding potential

Even if an analytical bounding potential is hard to provide, JF is able to define one by setting derivatives to local maximums. Specifically, for any pairwise potential U

q cb U (r 1 , r 2 ) = q cell U (C 1 , C 2 ) ≥ max r 1 ∈C 1 ,r 2 ∈C 2 ∂U (r 1 , r 2 ) ∂x 1 + . (5.1.1)
Obviously it is constant for any position pair with

r 1 ∈ C 1 and r 2 ∈ C 2 . q cell U (C 1 , C 2 ) is usually simplified as q cell U (C = C 2 -C 1 )
for periodic cells. Users must provide with an CellBoundingPotential instance which is instantiated with an estimator, in order to calculate q cell U during initialization. A process similar to section 5.1.2.1 with a cell bounding potential is performed with q cb U as its bounding event rate. We implemented in JF-V1.0 the TwoLeafUnit-CellBoundingPotentialEventHandler class for atom factors and TwoComposite-ObjectCellBoundingPotentialEventHandler class for dipole factors. Both their event handlers must be used in company with cell-boundary events (instance of the CellBoundaryEventHandler class) to incorporate internal state changes. The displacement sampled for the event time may drive the active unit out of the current cell.

Dynamic bounding potential

A bounding potential can also be constructed by speculating derivatives for a distance in front of the active unit. A simple speculation for two-body potentials U can be

q spec U (r 12 ) = max {q U (r 12 ), q U (r 12 -v 1 ∆t)} + c s , (5.1.2)
where ∆t is an adjustable speculation time and c s is a positive offset. This formula is able to bound potential with relatively small fluctuation, and is implemented in the TwoLeafUnitEventHandlerWithPiecewiseConstantBoundingPotential class.

Similarly, the FixedSeparationsEventHandlerWithPiecewiseConstantBounding-Potential class is given for many-body potentials. We find in practice that they provide efficient bounding potentials with very few exceptions for the Lennard-Jones potential in Eq. 3.6.7 and the bending potential in Eq. 3.6.6.

Cell-veto event handler

Cell-veto event handlers deal with a set of two-body potential factors with the cellveto algorithm described in section 3.3. In JF-V1.0 we implemented LeafUnitCell-VetoEventHandler for atom factors and CompositeObjectCellVetoEventHandler for dipole factors. They both feature an elaborate communication with the mediator, in the process of event time and out-state computation. The in-state for a cell-veto event handler is not the entire global state, but rather the branch for the active unit alone. A cell-veto event handler samples the event time through exponential random distribution with the rate q tot defined by Eq. 3.3.2, and draws the relative cell ∆C with a probability proportional to q cell U (∆C), which can be done in constant time through Walker's method. Then it has to identify the cell C 1 that hosts the active unit and calculate the triggering cell by

C 2 = C 1 + ∆C.
The triggering cell identifier C 2 is sent back accompanying the event time, then the get_arguments_cell_veto_event_handler method is called in the mediator to inquire the internal state for the occupant inside C 2 . The branch corresponding to C 2 occupant will be sent via arguments of send_out_state. The cell-veto event handler uses the global state for the active unit and the triggering unit to compute the real event rate q real , and confirms a cell-veto event by q real /q cell U . A cell-veto event usually does not appear alone to treat long-range potentials. Surplus units excluded cells often exist. Surplus and occupants of excluded cells are, however, handled by normal two-body event handlers with a bounding potential. Direct two-body events, and factor events for an active unit interacting with surplus units and excluded cell occupants, differ in taggers that create them. Like the event handler with cell-based bounding potential, the cell-veto event handler works with a cell-boundary event handler to update the internal state.

Event handlers for composite object motion

Motions in ECMC are not restricted to single particle moves. section 2.2.1 has formulated ECMC in such a way that any set of general coordinates {a i } can be chosen and the lifting schemes require only i a i • ∇U = 0. In dipole or water molecule simulations, we can select a part of {a i } to be translations of one molecule along x, y or z axes, accompanied with molecular rotation or normal particle motion to guarantee ergodicity.

There is much to be studied concerning the factorization, lifting schemes, bounding potentials, and cell scheme for composite object motion. We leave it for the future, but gave a simple JF implementation for the moment. We prepare in JF-V1.0 event handlers to move a composite object as a whole and event handlers to switch between point-mass motion and molecular motion. The RootUnitActiveTwoLeafUnitEvent-Handler class is for the event handler to deal with two-body inter-dipole factors. Similar to the TwoLeafUnitEventHandler, it gets an in-state with two leaf units and calculates event times as in particle mode, but requests the entire branch for the moving molecule and the object molecule by send_out_state arguments, time-slices them and exchanges their velocities. The RootUnitActiveTwoCompositeObjectSummed-BoundingPotentialEventHandler class is used to treat interactions between all intermolecular pairs with dipole factorization, with bounding potential consisting of separate pairwise bounding potentials (note that no many-body lifting schemes are needed because there are only two general directions involved).

We also provide the RootLeafUnitActiveSwitcher class as an event handler to switch between the leaf mode and the root mode. It exploits the event handler's function of activation and deactivation, which allows to freeze and reactivate specific taggers at event times specified by the user. One must create an event handler as a leaf-to-root switch and the other as a root-to-leaf switch. They deactivate themselves and reactivate each other to achieve alternating motions. The event handler for leaf mode will pick randomly one leaf unit from the active branch as the next active point mass, while the event handler for root mode will impose the velocity onto the whole

Sampling event handler and end-of-chain event handler

The function of the sampling event handler is to draw samples of the global state at certain moments, and the end-of-chain event handler is used to impose artificial direction switches. Their logics both deserve sufficient consideration. Taking FixedIntervalSamplingEventHandler as an example, it sets up an internal counter for sampling times by accumulating a constant interval and is instantiated with a specified output handler. The sampling event handler has no in-state, but at the event time, the active global state will be sent from the state handler to the sampling event handler via the mediator in order to push them all to the event time. After committing the out-state, the mediator dumps the entire global state to the corresponding output handler. All measurements and data recording will take place within the output handler.

The mechanism of the end-of-chain event handler is a bit more complicated. As shown in Fig. 5.2, the global state when send_event_time is called, is meaningless, but rather the state when send_out_state is called, will be processed. The new active unit identifier is returned alongside the event time, and branches for both the current active unit and the next active unit are communicated through send_out_state argument. With this information, the end-of-chain event handler can easily terminate the current motion and start the desired one. In JF-V1.0, end-of-chain event handlers are designed based on the EndOfChainEventHandler abstract class, which requires a specific implementation to only give a new chain length, active identifier, and direction of motion. The SameActivePeriodicDirectionEndOfChainEventHandler, as the simplest example, always takes the same chain length and does not change the active unit but alternates the direction of motion in a cyclic manner.

Other helping event handlers

JF simulation has no mandatory event handlers other than the StartOfRunEvent-Handler and the EndOfRunEventHandler class that indicate the beginning and the finishing of the run as their names suggest. It is inscribed inside the TagActivator class that, for the first time to generate candidate events, only the start-of-run event handler will be returned, which usually introduces an event at time zero. The first set of real candidate events can then be conveniently defined as in the creating list of the start-of-run event. And also, the InitialChainStartOfRunEventHandler class does the job of imposing the velocity and time stamp for the first active unit.

The total simulation time is set in the parameter of an FinalTimeEndOfRunEvent-Handler instance that is created at the beginning (by the start-of-run event handler) and stays inside the scheduler throughout the whole simulation. It does two things, to time-slice all active objects to the event time and to raise an EndOfRun exception.

We also created special facilities to dump the whole program for debugging purposes. This is realized through an DumpingEventHandler instance similar to a sampling event handler, and an DumpingOutputHandler instance. The magical thing is that, with the help of the dill package, all memory can be packaged and restored later by dumping the mediator object, because other objects are all direct or indirect attributes of it.

Factory

Figs. 5.3 and 5.4 best illustrate the forms of the class signature, configuration files and the underlying tree structure ruled by the factory design pattern [START_REF] Gamma | Design patterns: elements of reusable object-oriented software[END_REF]. By such a treelike organization of program objects, JF preserves vast flexibility and extensibility.

To understand the factory pattern, we first have to introduce JF's packages. Physically, a JF package is a directory somewhere in the program, whose name is indicated by the directory's name. It contains several modules (i.e., formatted python scripts), each defining a usable class that we call "option" here. Options within a package follow the design of python class inheritance, and an abstract class usually exists in one script ruling the interface of its child classes. The name of an option is indicated by its script's name and class name, which are supposed to be the same except the difference between the Pascal case and snake case. For example, inside the package scheduler we can see abstract class Scheduler. Also, there is an option called heap_scheduler whose class HeapScheduler inherits from the Scheduler class.

Then we can explain the factory design pattern using the tree of Fig. 5.4.

1. Nodes of the tree except the root Run are packages of JF. An option must be specified for one node. For instance, the HeapScheduler option is for the node Scheduler required by a single-process mediator. 3. The factory.py script creates instances before the Markov chain, using the information given in the configuration file and the importing paths of modules. Usually, an object has access to its direct child objects, but not its indirect children or nodes of upper levels except that particular communication is performed initially.

Factory

The factory mechanism significantly facilitates customization and future extension of the application, which will be described in section 5.2.2. Next, we will describe aspects more related to user interfaces and then explain how the factory builds up such a tree-structured set of objects.

Running

The application starts with executing run.py in root directory using python3 or pypy3. In version 1.0, we provide a couple of running options that are shown with python3 run.py -h command, including the logging level, log file, and JF version. A configuration file must follow if we hope to start a simulation. A successful execution can be python3 run.py -v -l logs/logs.txt\ config_files/2018_JCP_149_064113/\ coulomb_atoms/power_bounded.ini in the directory src.

run.py executes the following jobs consecutively.

1. Set up the logging function.

2. Parse the configuration file through the configparser package.

3. Use the factory to build up a Setting instance to configure common parameters.

4. Use the factory to build up a Mediator instance.

5. Call mediator.run(), until an EndOfRun exception is thrown.

Call mediator.post_run().

A similar resume.py is provided alongside run.py to resume the program with a dumped file. States of all objects under the mediator, as well as the setting and the random number object, are completely stored in the dumped file.

We have tried to minimize the usage of external packages. However, some are inevitable in order to perform special functions. The dumping facility has to import dill. The plotting scripts in src/output/2018_JCP_149_064113 depends on matplotlib and numpy. PdbInputHandler and PdbOutputHandler use mdanalysis to read .pdb files.

Factory

Customization

In this section, we will briefly explain how to customize the simulation by adapting configuration files and how to extend the functionality of JF-V1.0 by writing our modules and packages. For more detail we refer readers to those introductory .md files in the root directory, especially FACTORY.md.

Configuration file

The format of configuration files implements a tree structure inside. For a section representing a JF class, properties correspond to arguments of its __init__ method and users can specify values for the created instance. If an argument is a JF class (usually it is an abstract class), a value must be (or can be, if it is a keyword argument) specified with a child class of the required one in the snake case. Furthermore, in most cases, the given class must be instantiated with positional parameters, then we have to give a new section of the configuration file with the same name as the class. The configuration file allows aliases in addition to value-section correspondence. With the format "property = alias (value)", the section for it will be the "alias" instead of the "value" (conversion to Pascal case is still necessary).

For example, in Fig. 5.3 (a) , to create an instance of SingleProcessMediator, one has to give an InputOutputHandler, an Activator, a Scheduler and a StateHandler. Thus in the SingleProcessMediator section of Fig. 5.3 (b) , we designate four values for them which are child classes of the abstract ones. And also, three of them except HeapScheduler require arguments, so corresponding sections must be created detailing all necessary parameters which may also be JF classes. In this way, the treestructured set of objects is expressed serially in the configuration files. The bounding potential is no longer needed due to the invertibility of harmonic potential.

Development

It is easy to extend a package by adding one realization of the abstract class. For example, to write your own invertible potential, you just have to implement derivative, potential, and displacement methods. All necessary parameters for the potential are defined as arguments of the __init__ method that must be accompanied with type hints. For more complicated modules like event handlers and taggers, the communication protocol with the mediator and the rest should be considered. If one of the arguments of __init__ method is a JF class, a package must be created for it, as mentioned in the factory pattern. We choose PEP8 style for python code except that the line length is set to 120 characters, and PEP257 conventions for docstrings.

Verifications

Examples shown in this section serve purposes not only for JF integration test but also as examples of various taggers, event handlers, and potentials. Their physical systems are not different from those described in chapter 3-which are Coulomb atoms, dipoles, and the SPC/Fw water model--but much more precise measurements can bring confidence in both our algorithms and JF code.

For the verifications described below, they all feature a single-process mediator, heap scheduler, hypercubic setting, and tag activator. JF's integration of different systems and algorithms proves that we have adopted a vastly flexible code structure.

Coulomb atoms

The two-Coulomb-atom system has a very simple factor, that is, merged-image Coulomb factor M = {((1, 2), Coulomb)}, with β = 2.0, box side length L = 1.0, chain length = 0.78965 and charges c 1 = c 2 = 1.0. We simulate this system via three methods with configuration files in the directory src/config_files/2018 _JCP_149_064113/coulomb_atoms.

We performed multiple long runs and measured the probability of |r 12 | < 0.6 as well as its error with all three approaches in the following-the inverse-power bounding potential, cell-based bounding potential, and cell-veto algorithm-as shown in Fig. 5.6.

The initial physical state is generated with two random-positioned atoms inside the input handler, whereas a start-of-run event handler gives the lifting state. Hence one can change the number of atoms in the RandomInputHandler section and initial active atom in section StartOfRunEventHandler. Also, measurements take place within the SeparationOutputHandler instance, which is linked with the sampling event handler.

Inverse-power Coulomb bounding potential

The configuration file in power_bounded.ini is used for simulating atoms each with charge 1.0 through the inverse-power bounding potential described in section 3.4. Corresponding part of the configuration file specifying the Coulomb factor is shown in the left panel of Fig. 5.5. To deal with the Coulomb interaction via inversepower bounding potential, one must set up a FactorTypeMapInStateTagger, which reads in factors from a given file and designate two-body event handlers with bounding potential for it. Since only two atoms are simulated, one event handler will be sufficient. The Coulomb factor event trashes itself and recreates itself too. The Coulomb potential and the inverse-power bounding potential are set inside parameters of the event handler. Other events are sampling, end-of-chain, start-of-run, and end-of-run, all of which have no in-state; thus, the NoInStateTagger is used.

Verifications

Cell-Based bounding potential

A cell-bounding-potential event must be configured to draw the event time and the displacement in place of a normal two-body event with bounding potential. Furthermore, as we introduce a cell-occupancy internal state, we have to create an additional cell-boundary event handler, sufficient excluded-cell event handlers, and cell-surplus event handlers. The configuration file for it is cell_bounded.ini JF-V1.0 activates events of the cell-based bounding potential by instance of CellBoundingPotentialTagger, and specify TwoLeafUnitCellBoundingPotential-EventHandler for it since atoms are represented by separate nodes. Inside the event handler section, we specify its potential as MergedImageCoulombPotential and its bounding potential as CellBoundingPotential where the piecewise-constantderivative potential is estimated and sampled. The estimator is specified as a parameter of cell-bounding potential. Excluded-cell events and cell-surplus events are activated by the ExcludedCellsTagger and the SurplusCellsTagger respectively while their event handlers are of the same TwoLeafUnitBoundingPotentialEventHandler class which uses an inverse-power Coulomb bounding potential, and works in the same way as that of section 5.3.1.1. We must give an internal state label, to all these cell-related taggers as well as the cell-boundary tagger.

Cell-veto method

A replacement of the cell-bounding potential tagger with a cell-veto tagger in configuration of section 5.3.1.2 leads to the cell-veto simulation of two charged atoms as configured in cell_veto.ini.

The cell-veto tagger is then given LeafUnitCellVetoEventHandler to deal with atom factors in which an estimator must be given. Likewise, cell-surplus, excludedcell, and cell-boundary events are also necessary to run via the cell-veto method, and they are configured in the same way as in section 5.3.1.2.

Dipoles

The two-dipole system is defined by Eqs. Here we present five methods featuring atom or dipole factorizations, using inverse-power bounding potential or cell-based bounding potential, or cell-veto algorithm. The first four are with single active atom, while the last one is for testing the dipole mode of motion, as illustrated in Fig. 5 Like in the two-atom case, the initial dipole state is created randomly by an RandomInputHandler instance, while the node creator becomes the DipoleRandom-NodeCreator class which distributes dipole centers evenly within the simulation box and samples dipole orientations on a unit sphere. In the root mode one dipole is translated as a whole, so the root has an independent active unit while its leaves have induced active units.

Verifications

Atomic Coulomb factors

The configuration file atom_factors.ini adopts atomic Coulomb factorization given by Eq. 3.6.4. Coulomb, harmonic and repulsive factor events are all activated by FactorTypeMapInStateTagger instances. Like in section 5.3.1, the Coulomb interaction is treated with an inverse-power bounding potential, while the harmonic potential and the repulsive potential are invertible thus TwoLeafUnitEventHandler objects are created for them. For the active atom at any moment, there are four two-body factors relevant to it (2 Coulomb + 1 harmonic + 1 repulsive).

Dipole Coulomb factors, cell-based bounding potential

The configuration file cell_bounded.ini features a cell-based bounding potential to deal with the Coulomb dipole factor. To realize that, we must provide ways to identify the target dipole's cell, estimate the charge-dipole event rate, and give a bounding potential for exceptional cases.

The SingleActiveCellOccupancy class is coded so that it can take non-leaf units as occupants. Potential users can choose an arbitrary level of nodes as cell occupants by setting the property cell_level (value 1 for dipole, 2 for atom in the dipole case). The event handler to treat dipole factors via cell-based bounding potentials is an TwoCompositeObjectCellBoundingPotentialEventHandler instance, for which an underlying pairwise potential, a cell-based bounding potential and a lifting scheme must be specified. In the configuration section CellBoundingPotential, we have to choose a dipole estimator among those described in section 4.5.4.

As for the direct bounding potential, we choose the sum of individual pairwise bounding potential, i.e., the inverse-power one. The TwoCompositeObjectSummed-BoundingPotentialEventHandler class is designed for this purpose. It needs to know only the two-body real potential and the two-body bounding potential. In this way, the bounding event rate is the sum of those of pairs involving the active atom so that the event time can be calculated as the minimum of each relevant pair. The real event rate takes into account the dipole factor, which can be guaranteed to be equal to or less than the bounding potential sum. Excluded-cell events and cell surplus events have to be treated in this way.

Since the cell occupancy registers dipoles instead of atoms, it is the dipole node position that determines the corresponding cell. Hence, the cell change of an atom

Atomic Coulomb factors inverse-power bounded, Lennard-Jones inverted

The configuration file coulomb_power_bounded_lj_inverted.ini sets up the harmonic, bending, Coulomb and Lennard-Jones factors in a similar way as in section 5.3.1.1 and section 5.3.2.1. The factor map must be carefully set to reflect a total of 16 factors between two water molecules (9 Coulomb + 1 LJ + 2 bending + 4 harmonic) (see factor_set_water_atomic.txt).

The event handler different from previous examples is the FixedSeparations-EventHandlerWithPiecewiseConstantBoundingPotential which uses a speculated bounding potential (see section 5.1.2.3).

Dipole Coulomb factors inverse-power bounded, Lennard-Jones cell-bounded

The configuration file coulomb_power_bounded_lj_cell_bounded.ini takes dipole Coulomb factorization and uses cell-based bounding potential for Lennard-Jones interaction. For each pair of water molecule there exists only one Coulomb factor involving all six atoms. It treats Coulomb interaction using the TwoComposite-ObjectSummedBoundingPotentialEventHandler class in the same way as we do for excluded-cell occupants and surplus units in section 5.3.2.2.

To have a cell-based bounding potential for the Lennard-Jones potential, we have to construct a cell occupancy exclusively for oxygen atoms. We exploit the "charge" property of the SingleActiveCellOccupancy class and set it as the oxygen indicator (an instance of ChargeValues). Oxygen atoms have 1.0 for this value, while hydrogen atoms have 0.0 so that oxygen atoms are registered in the cell occupancy.

Dipole Coulomb factors cell-veto, Lennard-Jones inverted

The configuration file coulomb_cell_veto_lj_inverted.ini uses the cell-veto algorithm for the dipole Coulomb factorization. To this end, we need to have a cell occupancy that reflects the position of the molecular center, which can be achieved by setting cell_level to be 1. Then the handling of the Coulomb event is the same as in section 5.3.2.3.

Dipole Coulomb factors cell-veto, Lennard-Jones cell-veto

The configuration file coulomb_cell_veto_lj_cell_veto.ini deals with the Coulomb and the Lennard-Jones interactions both via the cell-veto algorithm. Hence two sets of cell occupancy have to be created, one with cell level one, and the other with cell level two and the oxygen indicator as charge. For large systems, the cell-veto algorithm becomes indispensable to achieve acceptable time costs.

Chapter 6

Realistic water system

In this chapter, we put JF into real system simulation to have benchmarks for both the event-chain algorithm and JF application. In chapter 3, we propose an eventdriven approach for the simulation of long-range systems though our proof of concept relies on simple time-driven codes. ECMC is supposed to face real challenges when entering complex biochemical systems. The configuration, observable, and physical order are no longer as simple as for the hard-disk testbed.

First, we will introduce important improvements to JF-V1.0 in order to eliminate obvious overhead in JF-V1.0. Then in section 6.2, we investigate the optimal setting for a large water system, notably for the cell-veto method that is rich in information where it costs most of the time. Finally, we test JF with water systems from 8 molecules to 216 against LAMMPS to better understand ECMC's efficiency.

Speeding up JELLYFYSH

The general architecture laid out in chapter 4 is a simplified event stream aimed to handle all kinds of operations. There, we focus on its extensibility but sacrifice the efficiency. For example, JF-V1.0 treats unconfirmed events in the same way as confirmed events, and the heap scheduler is developed for a large number of candidate events. We did not take into account features of simulated systems, including the event composition and time consumptions, which are crucial to the next improvement. Any popular scientific platform demands extreme optimizations, for the whole user group will repeatedly use common modules. In this sense, JF remains a prototype since the python codes are slow among programming languages, and functioning modules are to be rewritten.

Fast track for unconfirmed events

In JF-V1.0, the happening of each event requires recalculation of the other event times, except sampling, the start-of-run, and the end-of-run. This strategy becomes particularly costly since most of the events are unconfirmed events from bounding potentials and the cell-veto algorithm. In the cell-veto algorithm, event rates are highly overes-Figure 6.1: JF architecture adapted for events with bounding potentials. We add an extra loop to update by calling event handlers' resend_event_time without touching events already in the scheduler. timated (see sections 3.3.2 and 6.2.2). In fact, it proves much cheaper to handle empty target cells and unconfirmed cell events than confirmed cell events.

It can save much computation power if unconfirmed events do not interfere with other events but update their event times. This goal is achieved using an extended communication scheme between event handlers and the mediator, and an additional loop inside the mediator. For the mediator, we create another loop inside the main loop between requesting the shortest event time and committing out-state, as shown in Fig. 6.1. It repeats until an event is confirmed by inspecting that the returned out-state is not None. The scheduler sorts event times as usual, and pops an event in every iteration of re-requesting event times. When an out-state is sent back, the inner loop breaks and the out-state is committed in the state handler for the subsequent operations.

In the event handler part, a new abstract class EventHandlerWithUnconfirmed-Events is created featuring the method resend_event_time that has no arguments. If the event is not confirmed, the value None will be sent back as the return value of send_out_state. The mediator then calls the event handler's resend_event_time instead of going back to call send_event_time. The whole event handler procedure is modified as shown in Fig. 6.2.

Other improvements

After the release of JF-V1.0, we developed other JF features to spread and speed up JF. First, for those time-consuming modules, it is advisable to implement in C and compile before execution. There are multiple ways to realize a mixture of C code in a python project, and we chose cffi to replace several calculation-intensive and selfcontained modules 1 . Also, a scheduler using python list is provided. We found that 6.2. Coulomb event profiling Figure 6.2: Stages of event handler with the method of resending the event time, for treating events with bounding potential. resend_event_time is called until send_out_state returns a value that is not None. The three event handler methods are called by three corresponding mediator stages on the left.

HeapScheduler costs a large portion of time probably because the external module heapq is not suited for event operation and because the number of candidate events does not warrant heap structure. The third thing we tested in order to speed up is a node-free version of JF, in which only unit is kept while node and the tree structure were abandoned. The measurements tell us that, for hard disks, the speed of the nodefree version is 1.6 times the speed with nodes, so we will keep the node structure for all simulated systems to preserve consistency.

Another notable feature after JF-V1.0 is that we made JF into a python package. In fact, python provides tools to develop, encapsulate, distribute, and install packages (search python steuptools for reference). After the installation, one can run JF in any directory and the typical command becomes jellyfysh -v -l logs.txt config_file.ini where logs.txt and config_file.ini are the log file and the configuration file.

Coulomb event profiling

We study in this section how JF deals with long-range Coulomb events to find underlying statistics related to Coulomb events via the cell-veto algorithm, in hopes for more profound insights into time cost of the Coulomb event processing. We fix simulated system to be 20 3 water molecules in a box of side length 62.722Å (so with density ∼ 1g/cm 3 ) at 300K. In such a system all algorithms dealing with the Coulomb interaction become prohibitively slow except the cell-veto algorithm. In the cell-veto algorithm, a key quantity Qcell Clb is the reduced total Coulomb derivative. This is the sum kept in Walker's table, representing the sum of cell-based bounds of chargewater derivatives with unit active charge. When speaking of the Coulomb event rate Q cell Clb , their relation is

Q cell Clb = β( 1 3 |c O | + 2 3 |c H |) Qcell Clb = 0.918 Qcell Clb . (6.2.1)

Charge-water estimator

ECMC is an unbiased sampler under the condition that potentials are exact, and bounding potentials have event rates not less than the energy function derivatives everywhere, as indicated in Eq. 2.3.6. In the case of the Coulomb cell-veto algorithm, bounding potentials are constant within any cell and are given by an estimator in JF. N = 20 3 molecules imply around 40 3 cells, necessitating an efficient estimating method.

Early in JF-V1.0, we developed dipole estimators and applied them to twomolecule water simulations. However, there are signs showing that bounds by simplifying water as dipole fail to capture true properties of the charge-water interaction. A dipole model as simplified water molecule leads to significant underestimation. If one insists on the dipole estimator, a prefactor must be applied and results in worrying large event rates (see section 6.2.2 where bounds are given by charge-dipole estimator).

Thus, we implemented another two estimators for charge-water Coulomb interaction. They take water's inner structure into account but regard the water molecule as a three-point rigid structure. The first one is ChargeWaterOptimizationEstimator that uses scipy.optimize.minimize to obtain the maximum and minimum derivatives. It fixes at first the active atom, and calculates the effective position range of the target molecule, then explores the parameter space of the target molecule (a total of six degrees of freedom). This estimation is done by sampling the initial guess and calls scipy to find local extreme values. The second estimator randomly samples the position of the active atom as well as the target molecule's position and orientation. It can not only return extremes but the distribution of the charge-water derivative.

Assuming a homogeneous distribution of the active water molecule and the target molecule, for both their positions and orientations, we show in Fig. 6.3 the distributions of charge-water derivatives in two selected cells. In light of a large sample size of 1.28 × 10 9 , we find that they rarely reach even 0.9 times of their maximums. Therefore, a precise estimation by searching the maximum is not necessary. Moreover, most of the extremes come from molecule positions on the cell boundary. Thus we expect that using a non-homogeneous distribution and favoring molecules on the boundary will lead to higher estimation efficiency.

Optimizing cell-veto events

We tested a wider range of cell-occupancy parameters including the number of cells per side and layers around the zeroth cell treated as exclusion. The result is shown in Table . 6.1.

Table . 6.1 contains much information. First, 32 3 cells have effectively eliminated surplus particles to an acceptable level, and with 34 3 cells, the surplus number can be ignored. Second, the highest speed comes with 40 3 cells and 5 3 exclusions, so we take N cell = 8N as the best choice of cell density from now on.

We also measured and got the confirmed Coulomb event rate for non-excluded cells as Q cv Clb = 43 ± 1Å -1 . The reduced rate given by the estimator, however, is 13549Å -1 for 40 3 cells. It means that our cell-veto implementation has seriously over- • 13549/8 = 1694Å -1 occupied-cell events,

Coulomb event profiling

N cell N excluded Q tot Clb Q tot LJ N spl Clb N spl LJ speed(Å/
• 43Å -1 confirmed events.

The empty-cell event is considered as inevitable, yet the large gap between 43 and 1694 can be divided into the following facts

• Estimator overestimates by 1.37 times.

• For ideal dipole, there is a factor 4 for its orientation.

• Water molecule inner structure accounts for 4.08.

• The large cell size brings a factor 1.62.

Dipole factor vs. atomic factor

When we propose dipole factor in section 3.5 the complexity per sweep to sample a dipole system reduces from O(N 4/3 ) to O(N log N ). However, such a speedup is not expected to manifest in a system of 8000 molecules because N 1/3 / log N = 1.54 for N = 8000, and we are concerned that a complicated dipole algorithm introduces another factor which is more than 1.54.

The dipole factorization has more computational burdens than the atom factorization. The event time sampling involves the interactions between the active atom and the entire target molecule, meaning three times as much computation for water as two atoms. To confirm an event, it demands night pairs of Coulomb interaction and has to perform an elaborate lifting scheme while one pair is sufficient in atomic factors. 123 Chapter 6. Realistic water system Also, as discussed in section 6.2.1, it is more complicated to bound from above the charge-water derivative than the charge-charge derivative.

Thus we tested the atom factorization for 8000 molecules through JF. While the dipole factorization using the cell-veto algorithm is a fundamental feature in JF, the implementation of atom factorization for our benchmark model proves tricky. It is unrealistic to have one single-occupant cell holding either a hydrogen atom or an oxygen atom because the typical H-O separation 1.013Å is too short that a vast number of cells are needed. In the end, it is done by setting up three cell occupancies holding the first hydrogen atom, the second hydrogen, and the oxygen atom, respectively. Any type of active atom interacts with all three sets of cells 2 .

In a system of the same setting, but with unit charges, our estimator tells us that the corresponding Q cell Clb = 12228Å -1 . For three charged sets, the total reduced rate is

12228Å -1 * (2|c H | + |c O |) = 20054Å -1
, and this number is comparable with reduced cell-veto derivative bound 9917Å -1 for dipole factors. We expect that simpler computation in the atomic factor case can compensate for its larger event rate.

However, atomic factorization takes more than three times longer as the dipole case, contrary to what we believed. We found that the confirmed event rate in the dipole factor case is around 84Å -1 , including 64Å -1 Coulomb events, and this number rises to 578Å -1 with 546Å -1 Coulomb events in the atomic factor case. Confirmed events imply lifting moves that require recalculation of all candidate events, which seems inevitable. In our testing model, there are 5 3 /8 ≈ 15 particles treated as excluded neighbors for one set of cell, and typical surplus atoms is 13, so there are 15 * 3(Coulomb nearby) + 15(LJ nearby) + 13(Coulomb surplus) + 2(intramolecule) ≈ 75 pair interactions to be updated, accounting for the slowdown in atomic factorization. This measurement reveals that it is the confirmed cell-veto event that takes the majority of the time.

In the future, instead of trashing all physical events for each lifting move, we can stash the candidate events for each atom in hope that it will be reused later. For example, keeping a list for every atom within the active molecule until a new molecule becomes active will avoid around 40% recalculation if the inside-first scheme is adopted, according to our tests.

Water system benchmark

In this section we are going to start with relatively small systems, from 8 molecules to 216, with the box side length fixed to 18.975Å to keep the density 1g/cm -3 for 216 molecules (so for less molecules this means a dilute system). We measure the total polarization as the criteria of the system's relaxation, which is defined for N molecules as

P = N i c H (r i,OH1 + r i,OH2 ), (6.3.1)
where r i,OH1 and r i,OH2 are separations between oxygen atoms, and the first or the second hydrogen atom respectively. Periodic boundaries are taken into account so that r i,OH1 and r i,OH1 do not cross the entire system. The corresponding autocorrelation function is defined as

C P (t) = P(s) • P(s + t) s , (6.3.2)
where the average is taken over all valid samples, and the normalized autocorrelation is CP (t) = C P (t)/C P (0). (6.3.3)

Chain state

We observe that C P for an 8-molecule simulation behaves strangely. Shown in Fig. 6.5 are C P and CP of 40 independent runs each with 10 6 Å total displacement and starting with one equilibrated state prepared by LAMMPS. Two CP curves deviate from others with much slower decay, and their corresponding absolute values show that those chains bear higher polarizations than the rest.

Then we pick one of the outliers and plot P as a function of time in Fig. 6. 6. We find that one of its components presents a step-like shape: At some point, it increases to an unusually high level, stays for a period, and finally drops back to normal. The other abnormal C P curves also exhibit such an excitation. The runs whose autocorrelations C P are normal, however, do not feature the step-like polarization signal.

It seems that the system transitions to an unusual excited state at some point. This state has a distinguished polarization but has low free energy because its duration comprises less than one-hundredth of the total simulation. Due to the symmetry in the positive and negative direction, and in x, y, and z coordinates, similar excitations are also observed with P i < 0 and i ∈ {x, y, z}. To capture the excited state's nature, we record the trajectories of runs and make them into animation. In Fig. 6.7, we present three snapshots during the simulation. The times are carefully picked to have one in the normal state, one in rising slope, and a third in a highly polarized state. The chain state shown in Fig. 6.7 (c) lays out molecules in order, thus has lower entropy. This chain state cannot exist without periodicity in the simulation box, so the system topology is crucial to its stability. A simulation conducted by LAMMPS suggests that the chain state has similar total energy as the drop state, and there is an energy barrier in between. We plot the polarizations on x -y plane in Fig. 6.8 acquired by 20 hours of LAMMPS. Admittedly, LAMMPS is much faster than JF in reproducing the 8-molecule chain state.

Molecular translation

We start increasing the molecule number in order to approach realistic situations. The box side length remains as L = 19Å while the numbers of water molecules N are taken to be 8, 27, 64, and 212. L = 19Å corresponds to N = 216 at the density 1g/cm 3 . However, N = 212 is used instead because the less packed state is believed to speed up the relaxation. Here we fix the chain length = 0.2N , and the cyclic switching scheme is employed. As discussed in section 6.3.1, the presence of outliers due to the chain state may heavily drive the mean CP upwards. Thus we take the median of CP from many runs as the measured normalized autocorrelation. To gain uncertainty for their median, we apply the bootstrapping method. If there are n runs, then n samples are drawn with replacement from them, and we can get the median from the drawn samples. Repeat this process, and the standard deviation of repetitions is the desired error.

The autocorrelation of P shown in Fig. 6.9 suggests a significant slowdown for large system size, making it prohibitively slow for realistic case. We notice that the initial part of CP decays faster but faces a slower decay afterwards.

The presence of two time scales usually implies an underlying factor impeding the relaxation of the algorithm. Here, ECMC seems to shake molecules during a short period but is hindered immediately by the configuration structure. To better understand the reason, we implement molecule translation, that is, moving a single molecule as a whole, just like the root-mode dipole motion described in section 5.1.4. What is new is that the cell-veto algorithm is included in the root-mode scheme, and the corresponding event handler and water-water Monte Carlo estimator are also implemented.

We alternate atom motion and molecule motion, and switch the moving direction right after each turn of the molecule move. Thus the pattern becomes

X a X m Y a Y m Z a Z m X a X m .
.. where a means atom mode, and m means molecule mode. The atom mode persists a while molecule mode lasts m ( m is the total translation displacement, and the sum of individual atom displacement will be 3 m ). We fix a = 0.2N while testing varied m . Samples are only drawn in atom mode, and only atom mode is taken into sampling interval. Fig. 6.10 shows the change of CP with different lengths of molecule mode sandwiched in atom mode, as well as the errors. With the help of molecule mode, CP decays faster and there is sign that the second time scale is eliminated. The total performance in terms of CP , however, does not improve with consideration of the molecule mode cost.

However, with increasingly molecule numbers, the improvement by introducing the molecule translation diminishes, as shown in Fig. 6.11. Long simulation time also disables us to precisely quantify their accelerations 3 , but no evidence shows that X a X m Y a Y m ... scheme can help reduce the second time scale to the level of LAMMPS. Other schemes like (X a Y a ) n (Y a Z a ) n (Z a X a ) n are also tested whereas the improve-

Water system benchmark

ments are also limited. More tests and theoretical analyses are needed to reveal the reason of the double time scales.

Discussions

Apart from the above results, we also performed other measurements though the data are not ready to be published. First, ECMC can still achieve short correlation times for the density mode of water systems, so it is the collective rotation instead of the translation that poses challenges. The animation of a 216-molecule simulation displays restricted movements of dense molecules. Each molecule vibrates around its initial position, while the orientation and separations relative to the neighbors are almost frozen. It does not help by changing the lifting schemes proposed in section 3.5. On the other hand, traditional Monte Carlo also faces slow relaxation of the molecular polarization if only the atomic displacement is applied. It achieves a significant speedup by the proposal of molecular rotation.

To close the gap between JF with translational motion and LAMMPS, we analyze their procedures and list the differences here. The previous measurement in Fig. 3.19 only confirms the relaxation of molecule polarization through the motion along axes, but it does not reveal the relaxation speed.

First, LAMMPS is highly optimized, while JF-V1.0 remains immature. LAMMPS is mainly written in C++ and is compiled before running, but JF-V1.0 uses python. Moreover, LAMMPS features massive parallelization and even GPU acceleration. When running on a personal computer, multiple cores are used at the same time. It will be a good comparison by writing LAMMPS' algorithm and ECMC in the same language and the same style. Some may argue that the ten-fold overestimation of the cell-veto Coulomb event rate is the main reason, as discussed in section 6.2.2. Further parameter adjustment may bring a slight speedup, while the unconfirmed events caused by the freedom of dipole rotation and particle movement within a cell are inevitable. We believe that a more profound mechanism exists that impedes the collective molecular rotation, given the presence of the second time scale and our test that molecular rotations can also speed up traditional Monte Carlo.

Next, trajectories given by molecular dynamics suggest that the motion in arbitrary directions may imply a faster equilibrium, so we can lift the restriction that all displacement must be along axes, which motivates chapter 7. In chapter 7, we will test the idea where the proposed direction of relaxation changes gradually, and the reduction in the mixing time is confirmed for dipoles with relatively narrow potentials. One can further exploit this freedom since there are numerous combinations of proposed directions.

Furthermore, lifting schemes provide another way to realize motions in general directions. One example is the reflective chain in the initial proposal [START_REF] Bernard | Event-chain Monte Carlo algorithms for hard-sphere systems[END_REF] of ECMC, and it renders ECMC more similar to physical collisions. Intuitively, reflective chains enforce consistent rotation for a single planar dipole, whereas its generalization to higher dimensions is unclear.

Chapter 7

Sequential Monte Carlo

The dynamics of water molecule rotations obtained in section 6.3 bring a novel question for the ECMC. Simple complements through molecular rotation help, but do not significantly eliminate the slow time scale in the relaxation of the polarization. In fact, much freedom of the ECMC has not been exploited, and we have so far been restricting on the motion in positive senses of three orthogonal axes, namely +x, +y, and +z. It is intuitive to think that the molecular dynamics is faster due to its motion in all spatial directions.

On the other hand, sequential proposals in conventional Monte Carlo methods are regarded as the first approach leading to irreversibility, as discussed in section 1.4.1.1. Metropolis et al. mentioned the sequential scheme of updating particles in the original paper [36] of Monte Carlo method (it said "...we move each of the particles in succession according to..."). Orkoulas et al. formulated sequential updates in spin system [53] and then applied them to various other scenarios [55,[START_REF] O'keeffe | Parallel canonical Monte Carlo simulations through sequential updating of particles[END_REF][START_REF] Orkoulas | Spatial updating Monte Carlo algorithms in particle simulations[END_REF]. The speedup was demonstrated by both theoretical analyses and simulations, while they only studied the sequentiality in terms of spin or particle order.

In this chapter, we combine the two ideas above and apply the sequential proposal in the choice of directions, to study the possible gain and underlying dynamics if the proposal direction evolves gradually. In view of the difficulties experienced in chapter 6, we considered a system of a two-dimensional dipole as the testbed for this method and found that the evolution of the dipole angle exhibits distinct patterns, that is, the so-called "zigzag" and "excursion". The order of directions imposes an additional level of irreversibility to the existing schemes of ECMC. Finely tuning the speed of the direction change can achieve several times of speedup, and the generalization to higher dimensions and multiple molecules is possible in the future.

Single-dipole system

Configuration

We extract from more realistic models a simple dipole placed on a plane, as shown in Fig. 7.1 (a) . Two atoms of the dipole are represented by positions x 1 and x 2 . We impose hard-disk potential between any two atoms and another intra-dipole hard potential so that the energy of the studied single-dipole system can be expressed as

U (x 1 , x 2 ) = 0 if r ≤ ρ ≤ R, ∞ otherwise, (7.1.1)
where ρ = |x 1 -x 2 | is the distance between two atoms. The potential is illustrated in the right panel of Fig. 7.1 (a) . We can reparametrize any valid state as where θ represents the angle of dipole orientation and (ρ, θ) becomes the polar representation of x 2 -x 1 . In light of periodic boundary condition, x 1 must be in S 1 × S 1 , the two-dimentional torus. The condition for a valid state is simply expressed as ρ ∈ [r, R] and θ ∈ [0, 2π), and the probability is evenly distributed (Euclidean measure) within a ring Ω, as shown in Fig. 7.1 (b) .

Sequential Monte Carlo method

Among (x 1 , ρ, θ), the parameter x 1 is trivially distributed in S 1 × S 1 , and we are not interested in the equilibration of this part. x 1 corresponds to the collective translation of the molecular systems, and ECMC has proved efficient in decorrelating density modes. On the other hand, the θ coordinate is a simplification of molecular orientations whose mixing presents a realistic challenge. Although such a ring's stationary distribution can be obtained analytically, we hope that this simplified model serves as a prototype to reveal new mechanisms of Monte Carlo with sequential directions.

Single-dipole system

Here we list three algorithms that respect the global balance condition for the distribution of x = x 2 -x 1 .

The most straightforward algorithm is the direct application of the Metropolis-Hastings method with symmetric proposals as described in Algo. 1.

Algorithm 1 Metropolis-Hastings algorithm initialize x ← x 0 for 1 ≤ i ≤ N s do draw ∆x ∈ [-, ] 2 x = x + ∆x if x is in the ring Ω then x ← x end if print x end for
The ECMC algorithm simulates with consecutive chains that follow a determined series of directions. Each time we draw a chain length from a certain distribution and a direction from the pre-determined set. The active particle is advanced until it hits the hard wall induced by the other particle, or the cumulative displacement reaches . Previously, the directions of motion were kept along positive senses of axes, but now we extend to the sequence {e 0 , e 1 , ...} with e k = (cos φ k , sin φ k ), φ k = πnk/180, where n is the change in degree between two consecutive directions. We denote the series as D n and for the moment we focus on n ∈ Z. And also, it is clear that moving x 1 in e is equivalent to moving x in -e, so the ECMC for sampling x becomes Algo. 2. It is noteworthy that in Algo. 2, the function distance_before_collision Algorithm 2 Event-chain Monte Carlo with finite chain length initialize x ← x 0 for 1 ≤ i ≤ N s do draw chain length e ← (cos φ i , sin φ i ) while > 0 do s = min( , distance_before_collision(x, e))

x ← x + e * s ← -s e ← -e end while print x end for must consider both the inner circle and the outer circle of Ω. Here, samples of x are drawn at the end of chains, which is valid when the chain length is unrelated to the collision. Taking n = 90 is similar our conventional ECMC implementation that alternates between +x and +y directions.

Usually, Algo. 2 samples from a distribution with a characteristic length 0 .

To further simplify the model, we set up 0 → ∞ to eliminate the finite-chain-length effect, which amounts to sampling x along the cut l, that is, the ring Ω cut by the line x + αe. Thus, we have the direct sampling Algo. 3. The pesudocode for Algo.

Algorithm 3 Direct sampling initialize x ← x 0 for 1 ≤ i ≤ N s do e ← (cos φ i , sin φ i ) l ← cut_line(Ω, x, e)
x ← random point from l print x end for 3 simulates in the normal reference frame, and the sampling directions will evolve gradually following the series φ 0 , φ 1 , ..., as shown in the middle panel of Fig. 7.1 (a) . In practice, one can also operate in the reference frame always with φ = 0. In this case, one has to rotate x clockwise ∆φ = nπ/180 before each iteration. We will use the two interpretations to describe the evolution later in Fig. 7.3. In the rest of this chapter, Algo. 3 will be used as the common method to study the effect of sequential choices of the direction. We vary the set D n to see the resulting physical and algorithmic consequences.

Each iteration in Algo. 3 is taken as one time unit. Also, rolled-out angles are labeled with tilde so we have φt = πnt/180, the corresponding θt and ρ t . We define the impact parameter λ t , i.e., the component of x normal to e t , as

λ t = sin(θ t -φ t )ρ t /r. (7.1.2)
Obviously, λ t ∈ [-R/r, R/r]. When x is on the left side of the direction e t , λ t is positive; otherwise, it is negative. Moreover, λ t has a crucial threshold ±1 which will be manifest later. For now, one can distinguish that if |λ t | < 1, as illustrated in Fig. 7.1 (b) and (c), x will be resampled from a segment formed between the two circles; if |λ t | > 1, as shown in Fig. 7.1 (d) , x is free along a chord of the outer circle. These two cases do not only differ in the program but have distinct features in dynamics.

Validation

We verify our Algo. 3 here using the distributions of ρ and λ, which can be obtained analytically, as well as the homogeneous distribution over Ω.

The stationary probability density of ρ should be proportional to ρ itself, so we have

π(ρ) = 2ρ r 2 (η 2 -1) , ( 7.1.3)
where η = R/r is the ratio of the outer and inner circles of the ring.

As for the distribution of λ, it should also be proportional to the length of l, namely The normalizing factor is C = 4/π(η 2 -1).

π(|λ|) =    C η 2 -λ 2 , if 1 ≤ |λ| ≤ R/r; C η 2 -λ 2 - √ 1 -λ 2 , if 0 ≤ |λ| ≤ 1. (7.1.4)
We performed a long simulation using the code of Algo. 3. The statistics of ρ, λ and x are plotted in Fig. 7.2. The agreement between the simulated and analytical distributions validates the global balance condition under the sequential method.

Rotational dynamics

We track the evolutions of θ and λ as shown in Fig. 7.3 that exhibit distinct patterns which are never observed in traditional Monte Carlo simulations. In this section we study the typical dynamics presented under moderate choices of η and D n , which consist of "zigzags" and "excursions" in the curves of λ, as shown in Fig. 7.3 (a) and (b). We also observed exotic behaviors when using large n values. For example, n = 85 leads to "amplitude-modulated" waves of λ, while we will not cover it in this thesis.

Zigzag and excursion

In Fig. 7.3 (a) and (b), the rolled-out dipole angle θ can rise and fall with fluctuation during a long simulation. The rising parts of θ correspond to |λ| > 1 and the falling parts correspond to |λ| < 1. When θ increases, λ behaves like a one-dimensional random walk, but when θ decreases, λ undergoes a more deterministic evolution that drives it between ±1. Patterns of decreasing θ contain more than a drifted random walk but a series of steps, each corresponding to a λ period (see the middle panel of Fig. 7.4).

Given λ t , the dipole separation x t lies on the segment parallel to e t . It is possible to infer the distribution of λ t+1 through rotating x t by ∆φ. The drift term for λ t+1 is

Eλ t+1 =        λ t cos ∆φ -A t sin ∆φ if |λ| < 1 and x t ∈ S + , λ t cos ∆φ + A t sin ∆φ if |λ| < 1 and x t ∈ S -, λ t cos ∆φ if |λ| ≥ 1, (7.2.1)

Rotational dynamics

where A t = (B t + C t )/2 with B t = η 2 -λ 2 t and C t = √ 1 -λ 2 . S + and S -are the part of l t where cos(θ -φ) > 0 and the part where cos(θ -φ) < 0, as shown in Fig. 7.1 (b) . And the variance of λ t+1 is

σ 2 (λ t+1 ) = 1 12 (B t -C t ) 2 sin 2 ∆φ if |λ t | < 1, 1 3 B 2 t sin 2 ∆φ if |λ t | ≥ 1. (7.2.2)
According to Eq. 7.2.1, for small ∆φ, the drift term Eλ t+1 -λ t is proportional to (∆φ) 2 when |λ t | > 1, while it is proportional to ∆φ if |λ t | < 1, which agrees with the observation that the former case is driven by random walk, whereas the latter is dominated by motion with less randomness.

In the case of |λ| > 1, given that the drift and the variance are both proportional to (∆φ) 2 , we can write down the equation for λ as

λ t+1 = λ t + D 1 ∆φ 2 + D 2 ∆φω , ( 7.2.3)
where

D 1 = -1/2, D 2 = (η 2 -λ 2 t )/3
, ω is a uniform random number within [-1/2, 1/2], in agreement with Eqs. 7.2.1 and 7.2.2. After a long period ∆t, the change of λ should take the form of discrete Langevin equation

λ t+∆t = λ t + D 1 ∆φ 2 ∆t + D2 ∆φ √ ∆tω. (7.2.4)
Here, D2 is an effective value of D 2 during the period, and ω is a Gaussian random number with zero mean and unit variance. It is not difficult to notice the rescaling invariance of Eq. 7.2.4 by letting ∆φ → k∆φ, t → k -2 t (the same for ∆t) and λ t → λ k -2 t . Thus, in Fig. 7.3 (a) and (b), we set the axes as ( φt -φ0 )∆φ and ( θt -θ0 )∆φ, then the lengths and frequencies of excursions are comparable for different ∆φ values. In addition, the |λ| > 1 condition for excursions suggests that, x remains in a circular segment of Ω, as illustrated in the left panel of Fig. 7.4. As the circular segment rotates following the change of φ, the dipole angle should rotate in the same speed, which results in a slope equal to 1 in the rising side of θ ∼ φ curve. As for the zigzags, the |λ| curve consists of a succession of V-shapes, meaning that λ goes between ±1 in a more deterministic manner. The corresponding values of θ take downward steps with relatively fixed widths and heights. If we track x in this period, we find that it stays outside the circular segments of |λ| > 1 but jumps between S + and S -. The right panel of Fig. 7.4 shows the correspondence of critical moments of λ and x. When x is in the middle of S + or S -, θ remains roughly the same; when it hits the edge of |λ| = 1, θ may jump from S + or S -to the other, giving rise to a sharp drop of the θ value.

Analytical approaches exist to approximate the zigzag curves. Taking Eq. 7.2.1 but neglecting the variance given by Eq. 7.2.2 leads to a reasonable estimate since the diffusion term is minimum, as shown by the black curve of Fig. 7.5. If we further expand Eq. 7.2.1, say, for the first case, we get This can further be approximated by a continuous differential equation

λ t+1 = λ t (1 -∆φ 2 /2) -A t ∆φ. ( 7
- dλ 1 2 η 2 -λ 2 - √ 1 -λ 2 = dφ. (7.2.7)
The solution of λ has an analytic expression

φ -φ 0 = -λ η 2 -λ 2 -η 2 arcsin λ η + λ √ 1 -λ 2 + arcsin λ η 2 -1 . (7.2.8)
Replacing φ with t ∼ φ/∆φ, we reach a continuous relation of λ and t. Fig. 7.5 starts with λ = 1 and shows a good agreement between the Monte Carlo method, the discrete and the continuous analytical solutions.

Large-time limit

In this section, we study the change of the dipole angle θ. In general, the expectation of θ can increase or decrease, depending on whether the initial x belongs to S -or S + region. To simplify the analysis, we assume an equilibrated initial distribution of x. First, if x t and the induced θ t have equilibrated uniform distributions, x t+1 and θ t+1 are uniformly distributed too. One can argue that π( θt+1 -θt ) is symmetric around zero because the contributions from the points with θt = φt + φ and those with θt = φt -φ have opposite effects to the change of θ. The zero mean is confirmed by Fig. 7.6 (a) . Furthermore, the change in the rolled-out angle after more than one iteration has zero mean as well, because

E( θt -θ0 ) = t i=1 E( θi -θi-1 ) = 0.
(7.2.9) Each term of E( θiθi-1 ) vanishes because θi-1 and x i-1 have uniform distrubtions. However, θt -θ0 is no longer symmetric due to the shift of φ, as shown in Fig. 7.

(b) and (c).

As ∆t increases, π( θt+∆t -θt ) becomes asymmetric, with main part around zero and a small bump on the right. The position of the small bump agrees with the change of φ. It represents trajectories that stay in excursions, so the magnitude of the bump diminishes for larger ∆t since the probability for always staying |λ| > 1 decays. For large ∆t limit, the small bump is no longer visible, and the overall shape of π( θt+∆t -θt ) tends to a Gaussian distribution because it consists in contributions from different times that are uncorrelated. For η = 1.1 and ∆φ = π/180, Fig. 7.6 (c) tells us that π( θt+∆t -θt ) approaches a Gaussian distribution with zero mean and 0.165 2 ∆t variance.

Mixing of orientation

To measure the advantage of our method with sequential direction choices, we take the mixing time as the criterion. The mixing time is defined upon total variation distance given by Eq. 1.3.5, and by Levin's convention [29], it is the time at which the total variation distance to the equilibrated state reduces to 1/4. And for our single dipole system, we are interested in algorithms that can fast explore the space of its orientation, so we project the probability of x onto θ component. The target distribution is π(θ) = 1/2π. The mixing time in our case can be written as

t mix = min t : π(θ t ) - 1 2π TVD ≤ 1 4 . (7.3.1)
Many factors affect the mixing time. First, we study the effect of the initial state. Levin and Peres define the mixing time as Eq. 7.3.1 given by the worst-case initial state. In order to identify this worst case, we tried different choices of initial θ and , the initial state leading to the worst mixing time occurs near the sides with |λ| = 1, but the mixing times are very close for all initial points with |λ| < 1. Thus, we take θ 0 = 0 and ρ 0 = (r + R)/2 for following measurements (φ 0 is always 0). Shown in Fig. 7.7 (b) and (c) are total variation distances from π(θ t ) to the target 1/2π, with increasing t. It first confirms that our method can reach the theoretical equilibrium, and different choices of ∆φ have influence over the speed. For the case of η = 1.1 and η = 1.01, ∆φ = 25 • is optimal compared with 1 • , 45 • and 90 • . Furthermore, we investigate the effect of the series D n , i.e., ∆φ = nπ/180. We wonder whether the elements of D n have the major influence, or its order makes the main contribution. Hence, we perform the direct sampling Algo. 3 with D n , either sequentially or randomly, which are denoted as (D n , S) and (D n , R). Also, we tested the variant that randomly chooses directions with no constraint, i.e., directions from the unit circle, which is denoted as D ∞ .

In Fig. 7.8 (a) , we plot the mixing times with respect to various values of D n , and they are chosen sequentially. We find that if n is very small, φ changes slowly, and the mixing time is large. However, t mix has multiple peaks around certain values of n, and those peaks coincide with the inverse number1 of elements in set D n , denoted as |D| -1 . This coincidence implies that periodicity is a factor in choices of D, and a large period (or aperiodicity) is preferred.

Then we compare the sequential selection of D n and the random selection in Fig. 7.8 (b) , with η = 1.005. We find that sequential order always outperforms random order, and mixing times of random order are lower-bounded by that of D ∞ . Compared with t mix of D ∞ that is also the minimum for (D n , R), (D n , S) can reach a lower mixing time that is around 1.5 times faster. In Fig. 7.8 (c) we study the cases with η = 1.01 and η = 1.05. Peaks are less intense with increasing η, while the optimal D n 's in sequential order can all outperform random direction schemes. Finally, we measure the optimal choices of D n that give the lowest mixing times and the overall speedup, as plotted in Fig. 7.9. The optimal ∆φ's present a complicated pattern, and it is hard to extract a formula. Small values of η favor relatively small ∆φ, while when η > 1.4 the optimal ∆φ's are between π/4 and π/2. As for the speedup, sequential directions can indeed accelerate, especially compared with directions constrained in +x and +y for small η. When we compare with arbitrary random directions, the sequential method has still around 1.5 times speedup for all η < 2.0. So far, we have only understood the mechanism for small ∆φ. Further theories need to be established for moderate values of ∆φ and the optimal choice.

Mixing of orientation

General Conclusion

During the past three years we aimed to apply the ECMC algorithm to long-range systems, in hope that ECMC that exhibits exciting speedup in hard-disk and spin systems can also outperform widespread molecular dynamics in biochemical simulations. The bottleneck to simulating a realistic system is the long-range Coulomb interaction, while ECMC with factorized filter provides an innovative approach by sampling from pairwise Coulomb factors.

The currently most efficient molecule dynamics have always invoked the N -body Coulomb computation. First, we rewrote the Coulomb interaction in a two-body form, since the ECMC's advantage relies on the pairwise factorization. We proved that the line-charge method proposed by Kapfer and Krauth [START_REF] Kapfer | Cell-veto Monte Carlo algorithm for long-range systems[END_REF] is an alternative of tin-foil electrostatics. With its inspiration, we proposed several other methods of fast convergence such as kite-charge and volume-charge models.

Second, for dipole systems, we exploited the freedom of factorization in ECMC to find that dipole factors are able to achieve O(N log N ) time complexity for a sweep. Interesting lifting schemes appeared for dipole systems, and we proposed two schemes in addition to the simplest ratio scheme. In particular, the inside-first lifting scheme which maximally favors next active atoms to be located within the same molecule, has a bounded inter-molecule lifting rate regardless of molecule numbers. We demenstrated these concepts in [1].

Then, we developed a Python application called JELLYFYSH for ECMC simulation of the particle systems, with belief that a universal scientific platform will greatly benefit researchers. For the first time, we implemented a complete prototype version of ECMC with the dipole factorization and the cell-veto algorithm. The structured codes allow us to easily customize physical settings and enrich the function of JF. The specification of JF was published in [2].

Furthermore, we studied the efficiency of ECMC through JELLYFYSH benchmark. It shows that Coulomb events cost most of the time, and in particular, it is the confirmed events that predominate time consumption due to the recalculation of candidate events. For this reason, dipole factors outperform atomic factors by three times. The autocorrelation of the total polarization presents double time scales, and the second significant slows down a water system's rotation. Enforcing molecule translation helps to alleviate the slowdown while the mechanism is still to be discovered.

Finally, our proposal of sequential Monte Carlo provides an approach to overcome the slow rotation. Tests over a planar dipole showed a speedup depending on the potential width and they led to asymmetric evolutions of the dipole orientation. We found that the inverse number of unique directions coincides with the speedup, implying that the periodicity plays an important role in the optimal set of directions. Relaxing the dipole in an ordered sequence of directions is always preferred, compared to taking directions randomly from the sequence. We published the results in [3].

There are many open problems to be studied in the future. ECMC with pure atomic motions proved fast in mixing single-molecule orientations, while it is inefficient for the bulk-molecular rotation, thus the reason remains unknown for the efficiency gap between molecular dynamics and ECMC, just as rotating molecule can significantly speed up the decorrelation in traditional Monte Carlo methods. And also, we are not clear about the role of factorizations and lifting schemes in ECMC's dynamics. The correlation time drops dramatically when the optimal factorization is chosen as in the study of factor field, and here the three lifting schemes proposed in section 3.5 may bring distinct dynamics. Advantages of ECMC are more evident for atomic systems, where open questions include parallelization and the factor field beyond one dimension. We apply the irreversible event-chain Monte Carlo (ECMC) algorithm to the simulation of dense all-atom systems with long-range Coulomb interactions. ECMC is event-driven and exactly samples the Boltzmann distribution. It neither uses time-step approximations nor spatial cutoffs on the range of the interaction potentials. Most importantly, it need not evaluate the total Coulomb potential and thus circumvents the major computational bottleneck of traditional approaches. It only requires the derivatives of the two-particle Coulomb potential, for which we discuss mutually consistent choices. ECMC breaks up the total interaction potential into factors. For particle systems made up of neutral dipolar molecules, we demonstrate the superior performance of dipole-dipole factors that do not decompose the Coulomb potential beyond the two-molecule level. We demonstrate that these long-range factors can nevertheless lead to local lifting schemes, where subsequently moved particles are mostly close to each other. For the simple point-charge water model with flexible molecules (SPC/Fw), which combines the long-ranged intermolecular Coulomb potential with hydrogen-oxygen bond-length vibrations, a flexible hydrogen-oxygen-hydrogen bond angle, and Lennard-Jones oxygen-oxygen potentials, we break up the potential into factors containing between two and six particles. For this all-atom liquid-water model, we demonstrate that the computational complexity of ECMC scales very well with the system size. This is achieved in a pure particle-particle framework, without the interpolating mesh required for the efficient implementation of other modern Coulomb algorithms. Finally, we discuss prospects and challenges for ECMC and outline several future applications. Published by AIP Publishing. https://doi.org/10.1063/1.5036638

All-atom computations with irreversible Markov chains

I. INTRODUCTION

A. Irreversible Markov processes

Numerical methods are ubiquitous in the natural sciences, with Markov-chain Monte Carlo (MCMC) 1 and molecular dynamics 2 playing central roles. Markov-chain Monte Carlo applies to any computational science problem that can be formulated as an (perhaps fictitious) equilibrium-statisticalphysics system and whose solution requires sampling its probability distribution. As in physical and chemical systems, equilibrium within the computational context usually means that all probability flows vanish. This requirement is enforced by the detailed-balance condition, an essential ingredient of most Markov-chain Monte Carlo methods and notably of the Metropolis algorithm. 3 Monte Carlo algorithms usually take much time to approach equilibrium 4 and, once in equilibrium, to generate independent samples. This is, in part, due to the fact that detailed balance leads to time-reversible Markov-chain dynamics, which is diffusive and therefore slow.

In recent years, a new class of irreversible "eventchain" Monte Carlo (ECMC) algorithms has been proposed. 5,6 ECMC algorithms violate detailed balance but satisfy a weaker global-balance condition. Configurations at large times sample the equilibrium distribution, but the asymptotic steady state comes with non-vanishing probability flows. In particle systems with periodic boundary conditions, for example, atoms may continue to move preferentially in certain directions. In continuous spin systems, likewise, configurations realize the equilibrium distribution even though spins rotate in a preferred way. 7-9 ECMC moves (displacements of particles, rotations of spins, etc.) are infinitesimal and persistent: An "active" particle moves directly from one event to the next, that is, it continues to move until a proposed move is vetoed by a unique "target" particle, which in turn becomes the active particle. This passing of the active-particle label is called a lifting, 10,11 and this concept overcomes the characteristic rejections of randomly proposed finite moves in the Metropolis algorithm. The ECMC algorithm was instrumental in the solution of the hard-disk melting problem, after decades of debate. 12,13 For soft potentials, 6 it can decorrelate with a smaller dynamical exponent than the local Metropolis algorithm. 7,9 Furthermore, in a onedimensional particle system, ECMC was demonstrated to mix on shorter time scales than Markov chains that satisfy detailed balance. 14,15 In ECMC, the traditional Metropolis acceptance criterion based on the change in potential is replaced by a consensus rule. This is the essence of the factorized Metropolis filter, which applies to translation-invariant systems with pairwise interactions between particles 6 models whose interactions can be split into sets of independent factors. 16 The ECMC algorithm does not compute the total system potential energy. This makes it very appealing for long-range-interacting systems, where this computation is costly. For Coulomb systems, ECMC altogether avoids traditional algorithms for the electrostatic potential, 17 the dominant computational bottleneck for long-range-interacting models. Rather, the cell-veto algorithm 18 efficiently establishes consensus on the acceptance or the rejection of a proposed move, even if all particles interact with each other. This is the starting point for the present work. Generally, computations in statistical physics fall into two categories. They either aim at thermodynamic averages (energy, specific heat, spatial correlation functions, etc.) or at dynamic properties (time correlations, nucleation barriers, coarsening, etc.). In principle, the computation of thermodynamic averages is the realm of Markov-chain Monte Carlo, whereas the analysis of dynamical behavior calls on molecular dynamics, as it solves Newton's equations of motion. Specifically, however, the field of large-scale all-atom computations with long-ranged interactions is today dominated by molecular dynamics for both categories. The dominance of molecular dynamics is rooted in two facts: First, traditional Monte Carlo methods usually update just O(1) particles at a time, and the acceptance/rejection step is then followed by the exact computation of the change in potential. The best currently known algorithm 19 for the change in potential after such a local update in a Coulomb system is of complexity O( √ N) so that one Monte Carlo sweep (a sequential update of all N particles) requires O(N 3/2 ) computations. In molecular dynamics, by contrast, the discretized Newton's equations update all particle positions simultaneously, and the necessary computation of the forces on all particles comes at a cost of O(N log N), much less than for a Monte Carlo sweep. Second, Newtonian dynamics conserves momentum and explores phase space more efficiently than the local Metropolis algorithm. This advantage of molecular dynamics over Monte Carlo is, for example, brought out by the different scaling of the velocity auto-correlation functions in the context of long-time tails. 20,21 The time evolution of molecular dynamics has physical meaning, but from an algorithmic point of view, it is constrained by the requirement that it must implement Newton's law. As a result, there is no additional freedom to accelerate the exploration of phase space. By contrast, Monte Carlo dynamics is non-physical and only constrained by the global-balance condition. A well-chosen Monte Carlo dynamics can considerably speed up the sampling of the equilibrium distribution. Those equilibrium samples may also serve as starting configurations for parallel molecular-dynamics calculations that give access to high-precision dynamical correlation functions. Furthermore, if more complex out-of-equilibrium rare-event physical phenomena (such as protein folding) are of interest, the time scales of long-time features can be accessed by the inspection of the rare events produced by parallel simulation on N proc processors. Similar to the half-life analysis of radioactive substances composed of large numbers of atoms, a rare event that takes place on a time scale τ on a single processor will then take place on a time scale τ/N proc on one of the N proc processors.

In this work, we develop the framework for the application of ECMC to classical long-range-interacting all-atom systems. In particular, we demonstrate efficient ECMC methods that rigorously sample the canonical ensemble, without even evaluating the total potential. The factorizations that we implement with the cell-veto algorithm allow us to move a single particle from one event to the next in a computer run time that is independent of the number of point charges in a system. For a local charge-neutral system (for example, collections of charge-neutral many-atom molecules), the mean-free path (the mean distance between events) decreases only logarithmically with the number of point charges in the system. This implies that the computational effort required to move every particle in a simulation a constant distance scales as only O(N log N), with no approximation and without the demanding interpolation onto the mesh that is introduced in many modern electrostatic simulations.

We validate our algorithm through explicit comparisons with a standard Metropolis algorithm and with moleculardynamics simulations, each performed with Ewald summations. We focus on two conceptual issues. One is the computation of Coulomb pair-event rates, that is, essentially, the derivatives of the two-particle Coulomb potential with respect to the position of the "active" particle. In the simplest version of ECMC, this corresponds to the probability with which an active particle will stop and induce a lifting to another particle. The other issue concerns the factorization schemes of the system potential in which we lump together different interactions that partially compensate each other so that the ECMC mean-free path between events is much increased. We first apply our ECMC algorithm to a pair of like Coulomb point charges and then to systems of chargeneutral dipoles in a three-dimensional simulation box with periodic boundary conditions. We finally demonstrate the perfect agreement of thermodynamic observables between ECMC and conventional Monte Carlo and molecular dynamics for up to 256 water molecules at the standard density and temperature. The freedom offered by ECMC in choosing dynamics, factor decompositions, and lifting schemes leaves ample room for improvements. We expect it to be widely applicable to all-atom simulations of charged systems.

B. All-atom molecular simulations

Of great importance in soft-matter research, biological physics, and related fields, the all-atom approach projects the full quantum-mechanical many-body system onto the reduced classical degrees of freedom of the atomic positions. The projection yields the potential energy as a function of all the particle positions, and the Monte Carlo method can then, in principle, be applied directly. Molecular dynamics also starts from the atomic potential, as the forces in Newton's equations are given by its spatial derivatives. Presentday parametrized empirical force-field models 22,23 further break up the potentials and make them amenable to practical computations. For example, separate terms in the potential typically describe deviations of chemical bonds from their equilibrium values, with individual contributions for stretching, bending, and torsion. Likewise, distinct intermolecular potentials capture longer-ranged features of the interactions; for example, dispersion forces, hard-core repulsions, and longranged charge-charge and dipolar interactions. The all-atom reduction from quantum mechanics to a classical interacting system is approximate and not uniquely defined. Various forcefield models are used in a number of code bases, 24,25 which are also implemented in other prominent codes. 26-28 The parameters in each force-field model are optimized to reproduce thermodynamic and structural features over a reduced range of temperatures and pressures. Different potential functions coexist even for the description of simple molecules such as water. 29 We use in this work an all-atom potential for water that features two-body bond stretching, three-body bending as well as long-ranged Coulomb interactions, and a Lennard-Jones (LJ) potential. 30 Modern codes generally compute the long-ranged Coulomb potential through variants of the Ewald algorithm applied to a discretized analog of the continuous position space. The Fourier contribution to the potential is evaluated by first interpolating each point charge to multiple points on a mesh and then solving the Poisson equation via fast Fourier transform, which, combined, is of complexity O(N log N) per computation of the potential energy. Numerous formulations of this algorithm have been developed starting with the particle-particle-particle-mesh method. 31 More recent generations combine the particle-mesh philosophy with the Ewald formula, to create the particle-mesh-Ewald method 32 together with many variants 33-35 which, together, remain the workhorse of modern simulation codes. The charge interpolation onto the mesh generally presents the main computational workload. These methods use intricate strategies to maintain a high level of accuracy. Mesh interpolation leads to very large self-energy artifacts which have to be subtracted with great care in order not to modify the physical interactions.

Alternative approaches exist for the computation of the Coulomb potential and the electrostatic forces on particles. The hierarchical multipole-moment expansion, 36 for example, expands the interactions of a particle with all the other particles in terms of spherical harmonics, and therefore avoids Fourier transforms and mesh interpolations. However, the expansion converges only with high orders of the multipole moments so that one molecular-dynamics time step, although it is of complexity O(N), comes with a prohibitive prefactor. Local algorithms that propagate electric fields rather than solve the Poisson equation also bypass the fast Fourier transform. 37-39 This is an advantage in architectures where the Fourier transform involves large-scale non-local information transfers. In these algorithms, the complexity of a singleparticle update is O(1) but the use of a background mesh to discretize the electrostatic degrees of freedom again leads to costly interpolations from the continuum charges to the discrete space. 40,41 In contrast to well-established methods, ECMC is directly formulated in continuous space, and its successful implementation only relies on translational invariance on all length scales. In essence, ECMC requires no discretization of the simulation box, and the total Coulomb potential and forces may remain unknown throughout the simulation.

All-atom molecular-dynamics simulations must take into account a variety of time scales and lengths. Indeed, the high-precision time integration of intramolecular spring forces requires a discretization time in the femtosecond range. The physics associated with the much longer time scales that one wishes to study include density fluctuations (which relax on the picosecond time scale), Debye-layer equilibration (nanoseconds), and conformation changes (milliseconds). At the same time, the precise rendering of dielectric and screening properties requires high-quality computations, and the long-ranged nature of the interaction calls for large system sizes in order to overcome finite-size effects. In order to efficiently manage both the stiffness (the presence of many relevant time scales) and long-ranged potentials, interactions are often broken up and sophisticated multiple time-step algorithms are implemented. 42,43 Use of a thermostat 44 is crucial in order to counteract a drift of the system energy and to connect the potential-energy surface with the system temperature. The ECMC algorithm considers the same potentials as its competitors, but it is fundamentally event-driven. 45 This is exceptional in the presence of continuous potentials, whereas the eventdriven formulation for hard-sphere 5 or for stepped potentials 46 finds its correspondence in event-driven molecular-dynamics algorithms. 47,48 In the absence of discrete-time approximations, the exact Boltzmann distribution is sampled at any given temperature. This renders the thermostat unnecessary. In our application, the triggering of events remains well balanced between intramolecular, short-range intermolecular, and long-ranged intermolecular Coulomb events.

The remainder of this work is split into two parts. Part I corresponds to Sec. II, where we review recent advances in ECMC. We present the literature in a consistent mathematical language, which provides a unified framework for the application of ECMC to Coulomb systems. In Part II (Secs. III-V), we apply this framework to all-atom computations of various systems with Coulomb interactions. We demonstrate both the convergence to the Boltzmann distribution and the algorithmic scaling discussed in Sec. I A. The precise comparison of computer run time with established molecular-dynamics and Monte Carlo algorithms is, however, not presented in this work.

II. ECMC ALGORITHM

ECMC 5,6 is an irreversible continuous-time Markov process: Its moves are thus infinitesimal. Analogously, Newton's differential equations are of course also defined in continuous time. The molecular-dynamics algorithms that solve Newton's equations must be time-discretized for all systems except for hard spheres 2 or for stepwise constant potentials. 47,48 By contrast, in ECMC, discretization is generally avoided through the event-driven approach. In the present section, we discuss the essential issues of the algorithm's setup and implementation as well as its complexity.

A. Factors, factorized Metropolis filter

In ECMC, the interactions in an N-particle system are split into a finite or infinite set of factors M = (I M , T M ) ∈ P 1, . . . , N × T, where P is the power set of the indices (comprising all indices, pairs of indices, triplets, etc), and T is a set of interaction types. We refer to I M as the index set of the factor and to T M as its type. The total potential U, which is a function of all particle positions r 1 , . . . , r N , is written as a sum over factor potentials

U M U r 1 , . . . , r N = M ∈M U M r i : i ∈ I M , (1)
where U M only depends on the factor indices I M and is of type T M . In Eq. ( 1), the set M = M : U M 0 ⊂ P 1, . . . , N × T only contains factors that have a nonzero contribution for some values of the positions. In a system with only pair interactions, a non-zero factor may be i, j , pair . The corresponding factor potential would then be U ({i,j }, pair) (r i , r j ), and the total potential in Eq. ( 1) then becomes U = i<j U ({i,j }, pair) (r i , r j ), which is normally written as U = i <j U pair (r i , r j ).

In this work, we use more general factorizations. The Lennard-Jones factor, that we write as i, j , LJ , has a factor potential

U ({i,j }, LJ) r ij = k LJ       σ |r ij | 12 - σ |r ij | 6      , ( 2
)
where r ij = r jr i is the shortest separation vector from particle i to particle j, possibly corrected for periodic boundary conditions. The Lennard-Jones factor "LJ" in Eq. ( 2) may be replaced by two types, namely, the type LJ 6 (describing the 1/|r ij | 6 part of the Lennard-Jones interaction) and the type LJ 12 (describing its 1/|r ij | 12 part). 6 For two indices i and j, this yields two factors, namely, i, j , LJ 6 and i, j , LJ 12 .

Likewise, the bending energy in a water molecule with particles i, j, k will correspond to a factor index I M = i, j, k and to a factor type given by the specific function chosen for this interaction. A similar approach was introduced for modeling neighboring beads in a polymer. 16 In Secs. IV B and V, we consider factors that lump together all of the Coulomb interactions between the four particles comprising two distinct dipoles and even between the six particles of two water molecules, respectively. The factor corresponding to the latter case is given by i, j, k, l, m, n , Coulomb . (For simplicity of notation, we do not differentiate in this work the Coulomb types for two, four, and six particles.) As mentioned, the set of factors can be infinite, 18 even for finite N.

As an example, in a finite periodic system, one can view the three-dimensional Coulomb interaction between particles i and j as a sum of interactions between i and each periodic copy of j indexed by an image index n ∈ Z 3 . For the case of the above two-water-molecule Coulomb interaction, we would then have M = i, j, k, l, m, n , Coulomb n . The type set T would then contain all of the separate-image Coulomb interactions,

Coulomb n : n ∈ Z 3 ⊆ T, (3)
where the set of Coulomb types may be a proper or an improper subset of T. We will treat such factor types in Sec. III. Given the potential factorization enforced by Eq. ( 1), the Boltzmann weight π(c) = exp -βU(c) of configuration c = r 1 , . . . , r N reduces to a product over factor weights π

M (c M ) = exp -βU M (c M ) , π(c) = M π M (c M ) = M exp -βU M (c M ) , (4)
where c M is the factor configuration, that is, the configuration c restricted to the indices of factor M. The traditional Metropolis filter, 1 which defines the acceptance probability for a move from configuration c to configuration c in the Metropolis algorithm, does not factorize in a similar fashion,

p Met c → c = min 1, exp -β∆U , (5)
= min       1, M exp -β∆U M       , ( 6
)
where

∆U M = U M (c M ) -U M (c M
) is the factor-potential difference between factor configurations c M and c M . The recent factorized Metropolis filter 6 inverts the order of the product and the minimization and thus casts the acceptance probability of a move into the same factorized form as the Boltzmann weight,

p Fact c → c = M min 1, exp -β∆U M . ( 7
)
The factorized filter in Eq. ( 7) and the Boltzmann weight are now written as analogous products. Strictly speaking, M is a generalized index denoting a factor exp -β∆U M or min 1, exp -β∆U M . It is for simplicity that we refer to M as a "factor" rather than a "generalized index for the Boltzmann factor and the filter factor."

The factorized Metropolis filter satisfies the detailedbalance condition,

π(c)p Fact (c → c ) = π(c )p Fact (c → c). ( 8
)
This is evident if there is only a single factor [U = U M in Eq. ( 1) so that Eqs. ( 5) and ( 7) are identical] because the Metropolis algorithm itself is well known to satisfy it,

π(c)p Met (c → c ) F Met c→c = π(c )p Met (c → c) F Met c →c . ( 9
)
If there is more than one factor, p Fact also satisfies detailed balance because the Boltzmann weight π of Eq. ( 4) and the factorized Metropolis filter p Fact of Eq. ( 7) factorize (that is, break up) in exactly the same way and Eq. ( 7), on the level of a single factor, is again equivalent to the Metropolis algorithm.

Applying the Metropolis filter p Met of Eq. ( 5) is equivalent to drawing a Boolean random variable,

X Met (c → c ) =      "True" if ran(0, 1) < p Met (c → c ),
"False" else, (10) where "True" means that the move from configuration c to configuration c is accepted. Similarly, the factorized Metropolis filter p Fact could be applied by drawing a single Boolean random variable with p Fact replacing p Met in Eq. ( 10). However, because p Fact ≤ p Met , this would yield a less efficient algorithm.

We rather view the factorized Metropolis filter as a conjunction of Boolean random variables,

X Fact (c → c ) = M ∈M X M c M → c M . ( 11
)
Now, X Fact (c → c ) is "True" if the independently drawn factorwise Booleans X M are all "True",

X M =      "True" if ran M (0, 1) < e -β∆U M , "False" else, ( 12
)
where the uniform random variables ran M (0, 1) are mutually independent for all M.

The conjunction of Eq. ( 11) formulates the consensus principle: In order to be accepted, the move c → c must be independently accepted by all factors M. For example, for a homogeneous N-particle system with pair factors i, j , pair , the move of a single particle k must be individually accepted by the factors k, j , pair ∀j k. In other words, the move of particle k must be accepted by all other particles, each through its individual Metropolis filter.

For a continuously varying potential, the acceptance probability of a single factor M has the following infinitesimal limit:

min 1, exp (-β∆U M ) = exp -β∆U + M ∆U M →dU M ---------→ 1 -βdU + M , (13)
where

x + = max(0, x) ( 14
)
is the unit ramp function of a real number x. In this limit, the factorized Metropolis filter becomes

p Fact (c → c ) = 1 -β M dU M (c M → c M ) + , ( 15
)
and the total rejection probability for the move becomes a sum over factors

1 -p Fact (c → c ) = β M dU M (c M → c M ) + . ( 16
)
In ECMC, the infinitesimal limit generally corresponds to the continuous-time displacement of a particle k at position r k = (x k , y k , z k ) and it is usually along a coordinate axis. Supposing that this displacement is in direction êx , the differential of the factor potential becomes

dU M = qM,k dx k , ( 17
)
where qM,k r i :

i ∈ I M = ∂U M ∂x k , (k ∈ I M ) ( 18
)
is the factor derivative with respect to particle k. We then define the factor event rate with respect to particle k as

q M,k = β qM,k + , ( 19
)
so that each of the terms dU + M becomes

βdU + M = q M,k dx k . ( 20
)
The event rate q M ,k yields the probability of an event being triggered by particle k within factor M. The total event rate

Q k r 1 , . . . , r N = M=(I M ,T M ):k ∈I M q M,k r i : i ∈ I M (21)
with respect to a particle k naturally involves only event rates for factors that contain k in their index set.

B. Lifting and factorization schemes

The lifting concept 10 is central to ECMC. It lends persistence to the individual Monte Carlo moves and thereby allows one to take the zero-displacement limit. It is in this limit that the sampling of factors becomes unique. We now describe the implementation of a lifted irreversible Markov chain for the simulation of pair-interacting particles, 6 starting with a single pair. We then generalize 16 the method to complex multi-particle potentials.

In a standard Markov-chain Monte Carlo algorithm, the rejection of a move of some particle at time s imposes that the state c(s + 1) of the Markov chain at time s + 1 remains unchanged with respect to the state c(s) at time s. A new move is then proposed. For a local Monte Carlo algorithm in a particle system, this new move normally consists in an independently sampled displacement applied to another randomly chosen particle. In order to converge toward the correct stationary distribution π, we recall that the Markov chain must satisfy the global-balance condition,

F c = c F c →c = c π(c )p(c → c) = π(c), (22)
meaning that the total flow F c into a configuration c must equal its Boltzmann weight. 49 The detailed-balance condition of Eq. ( 8) is only a special solution of Eq. ( 22). In addition to the global-balance condition, the Markov chain must also be irreducible and aperiodic. These two conditions are easily satisfied; 4 the former guarantees that any configuration will eventually be visited, while the latter guarantees that the largetime limit has no hidden periodicities. In ECMC, any physical configuration c (that is, any set of particle coordinates) is augmented (or "lifted" 11 ) to include the so-called lifting variable describing which particle is "active",

c ≡ r 1 , . . . , r N → (c, a). ( 23
)
In principle, the Boltzmann weight now depends on a, but, for simplicity, we require π[(c, a)] = π(c)/N and absorb the normalization factor 1/N into the zero of the potential and omit it in the following.

In ECMC, furthermore, the particle a (the active particle) remains active for subsequent moves as long as they are accepted, and the displacement (in the case that we will treat) is always the same. 50 For simplicity of notation, in the following, the displacement η is applied in the êx direction for all moves so that the position r a is updated to r a + η êx for accepted moves. When a displacement r a → r a + η êx is rejected by a target particle t, the state of the lifted Markov chain changes in the augmented space as (c, a) → (c, t), (24) but the physical configuration c remains unchanged. Liftings thus replace rejections, and the resulting ECMC algorithm is rejection-free on the augmented space. The global-balance condition must be written in terms of the augmented configurations, and the probability flow F (c,a) into each lifted configuration (c, a) is then given by the sum of the mass flow F mass (c,a) , that is, the flow corresponding to a particle displacement and the lifting flow F lift (c,a) . This sum must equal the statistical weight of (c, a) that, as discussed, equals π(c),

F (c,a) = F mass (c,a) + F lift (c,a) = π(c). ( 25
)
In order to assure irreducibility of the Markov chain, one may change the direction of motion, most simply by selecting from the set êx , êy , êz in a way that does not need to be random (see the discussion in Sec. V B). In ECMC, the process in between two changes of direction is the eponymous "event chain." The length of an event chain (the cumulative sum of the displacements) and the distribution of are essential parameters for the performance of the algorithm.

To demonstrate that ECMC satisfies the global balance condition and to study the conditions on the lifting probabilities, we first consider a system of two particles 1, 2 . We may suppose, without restriction, that the active particle is 1 so that, at a given time, the lifted configuration is (c, 1). This lifted configuration can only be reached from two other lifted configurations, one that differs in the configuration variable and the other in the lifting variable (see Fig. 1). The lifted configurations and the corresponding flows are (26) where c = r 1 , r 2 , c = r 1η êx , r 2 , and c = r 1 , r 2 + η êx . The mass flow of the lifted algorithm from (c , 1) to (c, 1) equals the total Metropolis flow from the non-lifted configuration c to c. Because of detailed balance, the latter equals the (non-lifted) Metropolis flow from c to c so that

F mass (c,1) = F Met c →c = F Met c→c see Eq. (9) = π(c)p Met (c → c ). ( 27
)
The lifting flow in Eq. ( 26) equals the rejection probability of the Metropolis move c → c . Because of translational invariance (c is a translated version of c ), it agrees with the Metropolis rejection probability of the move back from c to c , F mass (c,1) and F lift (c,1) thus add up to the Boltzmann weight π(c) and global balance is satisfied. The validity of the lifted algorithm (which only satisfies global balance, but breaks detailed balance) hinges on the fact that the underlying Metropolis algorithm satisfies detailed balance and on the translation invariance of the system.

F lift (c,1) = π(c) 1 -p Met (c → c ) , = π(c) 1 -p Met (c → c ) . (28)
In the infinitesimal limit, for N particles and a particlepair factorized potential, the total probability flow into a lifted configuration (c, a) has up to N components, namely, N -1 lifting flows from (c, k) to (c, a) for k a and one mass move from (c , a) to (c, a), where c is again the non-lifted configuration with x a replaced by x adx. This corresponds to one lifting flow F lift (k → a) equivalent to that in Eq. ( 26) per target particle k a and a mass flow that is the infinitesimal analog of that in Eq. ( 26). Furthermore, a particle-pair potential may be further factorized according to multiple factor types T M ; there then exist N -1 lifting flows for each factor M consisting of two particles (|I M | = 2, with I M the index set of M). Of course, factors that do not contain a in their index set do not contribute to this flow.

Factors M with more than two particles (|I M | > 2) can also be handled within the lifting framework 16 because, by translational invariance, the sum over the factor derivatives with respect to particle k satisfies

k ∈I M ∂ x k U M r i : i ∈ I M = 0. ( 29
)
It is useful to separate the particle indices k ∈ I M of a factor M into two sets I + M (with positive factor derivatives) and I - M (negative factor derivatives) such that

k + ∈ I + M ⇔ ∂ x k + U M > 0, ( 30
) k -∈ I - M ⇔ ∂ x k -U M < 0, ( 31
)
where the factor derivatives satisfy (32) [see Fig. 2(a)].

k + ∈I + M ∂ x k + U M = - k -∈I - M ∂ x k -U M
The mass flow into a lifted configuration (c, k + ) with k + ∈ I + M by itself satisfies global balance, so that there can be no additional lifting moves into (c, k + ). This implies that lifting moves are always as (c, k + ) → (c, k -), that is, from an active particle in I + M to a target particle in I - M . By contrast, the mass flow into the configuration (c, k -) is smaller than π M (c),

F mass (c,k + ) = π M (c )p Met M (c → c) = π M (c)p Met M (c → c ) = π M (c), (33)
F mass (c,k -) = π M (c )p Met M (c → c) = π M (c)p Met M (c → c ) = π M (c)(1 + β∂ x k -U M <0 (see Eq. (31)) dx). ( 34
)
The total lifting flow into (c, k -) comes from all lifted configurations (c, k + ) with k

+ ∈ I + M , F lift (c,k -) = π M (c) β k + ∈I + M ∂ x k + U M dx γ k + →k -, (35)
where γ k + →k -is the lifting probability from k + to k -once the displacement of k + has been rejected. In order for global balance to hold, Eqs. ( 34) and ( 35) must add up to π(c) for all k -∈ M -. Therefore, and for the algorithm to be rejection-free, one needs 16

∀k -∈ I - M : ∂ x k -U M <0 + k + ∈I + M ∂ x k + U M >0 γ k + →k -= 0, ( 36
)
∀k + ∈ I + M : k -∈I - M γ k + →k -= 1. ( 37
)
Equations ( 36) and ( 37) can be visualized as

|I + M | intervals of length ∂ x k + U M placed on the upper row of a two-row table and of |I - M | intervals of length |∂ x k -U M | on the lower row [see Figs. 2(b)-2(e)]
. The total lengths of the two rows are equal [see Eq. ( 32)], and γ k + →k -is the fraction of the interval k + on the upper row that lifts into k -on the lower row. Equation ( 36) describes a conservation of the interval lengths from the upper row to the lower row. 36) yields the unique branching probabilities 16 from k + to k - 1 and k - 2 ,

γ k + →k - 1 = - ∂ x k - 1 U M ∂ x k + U M ∝ |∂ x k - 1 U M |, (38)
γ k + →k - 2 = - ∂ x k - 2 U M ∂ x + k U M ∝ |∂ x k - 2 U M |, (39)
which is readily understood from Fig. 2(d). Analogously, for factors with |I M | > 3, the "ratio" lifting corresponds to cutting up each element in the upper row of the table into pieces of length proportional to the elements in the lower row so that (40) [see Fig. 2(e)]. For factors with more than three particles (|I M | > 3), the "ratio" lifting scheme is not unique. 16 We will make use of this freedom, in Secs. IV and V, for factors with up to six particles corresponding to the atoms of two H 2 O molecules.

γ k + →k -= ∂ x k -U M k -∈I - M ∂ x k -U M

C. Event-driven and cell-veto methods

The implementation of ECMC differs notably from that of the Metropolis algorithm, both because of the continuous-time nature of the Markov chain, which can be simulated without approximations using the event-driven approach, 45 and because of the consensus property, which can be checked in O(1) operations via the cell-veto method, even for infiniteranged interactions. 18 (This method can be understood as a "thinning" of the underlying nonhomogeneous Poisson process. 51 ) The event-driven formulation of ECMC and the efficient establishment of the consensus are explored in the present section. The intent is to overcome the limitations of timedriven ECMC which considers a finite move η êx of the active particle, r 1 , . . . , r a , . . . , r N → r 1 , . . . , r a + η êx , . . . , r N . (41) This move is either accepted (and then repeated) or it leads to a rejection (by a factor M ∈ M containing particle a), and it gives rise to a lifting (or possibly to multiple simultaneous liftings). The complexity of time-driven ECMC is O(| M : a ∈ I M |) per displacement η êx . Time-driven ECMC has a discretization error, as it becomes inconsistent if more than one factor simultaneously rejects the move in Eq. ( 41). The parameter η must be small enough for multiple rejections to be rare. Time-driven ECMC is thus slow, especially for long-ranged interactions, and inexact. It is useful only for testing.

The finite-move ECMC can be implemented as an eventdriven, rather than as a time-driven, algorithm, 45,52 and because all factors are independent, we may consider a single one of them. In the above time-driven ECMC, if the move in Eq. ( 41) (the first move, m = 1) is accepted, another displacement of magnitude η is attempted. The lth move is r 1 , . . . , r a + (l-1)η êx , . . . , r N → r 1 , . . . , r a + lη êx , . . . , r N .

(42) After m -1 acceptances, finally, the mth such move is rejected (and leads to a lifting). The parameter m is itself a random variable distributed with a factor-dependent probability

p M (m) = m-1 l=1 e -β∆U + M (l)
accepted; see Eq. ( 13)

move m rejected 1 -e -β∆U + M (m) , (43)
where ∆U + M (l) is the change ∆U + M corresponding to the lth move in Eq. ( 42). The variable m can be sampled from Eq. ( 43) and the move r a → r a + (m -1)η êx accepted in one step. Although the right-hand side of Eq. ( 43) gives a probability distribution for the displacement of the active particle a, it only depends on the positive increments of the factor potential. In the continuum limit η → 0, the second term on the right-hand side becomes βdU + M (r a + η M êx ), that is, the factor event rate of Eq. (20), where η M is the total displacement before a rejection by factor M takes place. In this limit, the exponent in the first term on the right-hand side contains the integral of the factor event rate for the displacement of r a between 0 and η M . This gives the probability density 45

p M U + M = βexp -β U + M . (44)
In Eq. ( 44), the exponential distribution is sampled by

βU + M = -log{ ran M (0, 1)}, (45)
where

βU + M (r a + η M êx )
sampled via Eq. ( 45)

= η M 0 β ∂ x a U M r a + η êx , r k : k ∈ I M +
factor event rate, see Eq. (20) dη. (46) In other words, βU + M is the cumulative event rate of Eq. ( 20). Equation ( 46) is an implicit relation for the limiting displacement η M at which the rejection takes place as a function of the sampled value of βU + M . For a two-particle factor M = a, k , pair , the integration of the pair event rate in Eq. ( 46) consists in the replacement of the potential U M by a related potential which is zero at r a and where all the negative increments are replaced by horizontal lines (see Fig. 3).

As mentioned, the factors are independent and each concerned factor M provides a value η M . The next event takes place at η = min

M:a∈I M η M ( 47
)
and the factor which realizes this minimum (that is, η),

argmin M:a∈I M η M , ( 48
)
is the one in which the lifting takes place. For a continuous potential, this factor is uniquely defined and possible simultaneous events, due to finite-precision arithmetic, are too rare to play a role.

FIG. 3. Event-driven ECMC 45 for a two-particle factor M. The integral of the factor derivative multiplied with β equals βU M , whereas the integral of the event rate (in red) must equal β U + M , which is sampled from Eq. ( 45). The calculation of the displacement η M from the sampled value of βU + M =log ran(0, 1) is indicated by arrows.

The integration of the factor event rate in Eq. ( 46) can be tedious if it cannot be cast into an explicit analytical form. This will, for example, be the case for the Coulomb potential in the merged-image framework of Sec. III C. In addition, the inversion of the factor potential [the computation of η M in Eq. ( 46)] can be non-trivial. Finally, this calculation must in principle be redone for all the factors that contain the active particle a. For a long-ranged potential, this requires

O(N) = O(| M ∈ M : i ∈ I M |) event-
rate integrations and inversions per event. The cell-veto algorithm, 18 by use of a comparison function, avoids the integration and the inversion of the event rate, and it moreover reduces the overall complexity of ECMC to O(1) per event.

We again first consider a pair factor 1, 2 , pair , with 1 being the active particle. The lifted position is (c, 1) [with c = (r 1 , r 2 )] and the displacement is again in direction êx (as in the situation in Fig. 1). We embed the two particles in disjoint cells C 1 and C 2 (see Fig. 4). The potentials that we consider here are singular only at r 1 = r 2 so that the event rate for factor M may be bounded by a constant "cell-event" rate

q cell T M (C 1 , C 2 ), q M,1 (r 1 , r 2 ) ≤ q cell T M (C 1 , C 2 ) ∀r 1 ∈ C 1 , r 2 ∈ C 2 , ( 49
)
where the right-hand side only depends on the factor type. This factor-type dependence may take into account separate cell schemes that could, for example, correspond to Coulomb interactions between isolated charges, dipole-dipole interactions, or to the Lennard-Jones potential. (We recall that we do not differentiate the different Coulomb types for 2, 4, 6 particles to ease notation.) In this work, the condition C 1 C 2 is adequate to ensure a reasonable value of the cell-event rate. In other cases, 18 The event-rate q M ,1 (r 1 , r 2 ) is bounded from above by the cell-event rate q cell T M (C 1 , C 2 ), which can be sampled trivially. A cell event may either be rejected (at point "A") or confirmed (at point "B") as a particle event [see Eq. ( 50)], while a cell event taking place outside C 1 (at point "C") means that the active particle 1 will advance toward the cell boundary.

local neighbors outside the cell-veto framework. Cell-event rates are easily tabulated in advance of the ECMC computation proper.

The probability of the event taking place for an infinitesimal displacement dx equals q M ,1 (r 1 , r 2 )dx. Since

q M,1 (r 1 , r 2 ) dx = q cell T M (C 1 , C 2 ) dx infinitesimal q M,1 (r 1 , r 2 )
q cell T M (C 1 , C 2 ) 1 , (50)
the event can initially be sampled as a "cell event" with the constant infinitesimal probability q cell T M (C 1 , C 2 )dx, before being confirmed with the finite probability q M,1 (r 1 , r 2 )/q cell T M (C 1 , C 2 ) ≤ 1. We may suppose that the cell event takes place at a lifted configuration (c , 1) with c = (r 1 + η êx , r 2 ), ( 51)

π(η) = exp -ηq cell T M (C 1 , C 2 ) , ( 52
)
where η can be sampled via

η = -log[ ran(0, 1)]/q cell T M (C 1 , C 2 ). ( 53
)
Three outcomes are possible for the sampled values of η and the subsequent confirmation step. First, the cell event may correspond to a configuration c [in Eq. ( 51)] that is already outside the active-particle cell (c C 1 ). In this case, the move is (c, 1) → (c , 1), where c is the configuration intersecting the trajectory of particle 1 with the boundary of C 1 . Such a cell-boundary event moves the particle, but does not trigger a lifting. Second, the cell event may take place at a configuration c ∈ C 1 but fails to be confirmed as an event (because a uniform random number ran 0, q cell T M (C 1 , C 2 ) > q M,1 (r 1 , r 2 )) [see the second term on the right-hand side of Eq. ( 50)]. In this case, the move is (c, 1) → (c , 1) and no lifting takes place. Third, a cell event may take place at a position c ∈ C 1 and it is confirmed as an event. This event induces a lifting (c , 1) → (c , 2) [see Fig. 4(b)]. In this whole process, the factor derivative qM,1 is evaluated only when a cell event is triggered from the exponential distribution in Eq. ( 52). The costly integration of the factor event rate in Eq. ( 46) is thus avoided.

For an N-particle system, the cell-veto algorithm organizes the search of the next lifting in O(1) operations. It suffices to choose a regular grid of cells such that, normally, only a single particle belongs to each cell. (Exceptional double-cell occupancies can be handled easily. 18 ) In this case, the total event rate with respect to the factor type T M for an active particle in C a is bounded by the total cell event rate,

Q cell T M (C a ) = cells C t C a q cell T M (C a , C t ). ( 54
)
In a translationally invariant system, the total cell event rate does not depend on the active cell so that

Q cell T M (C a ) ≡ Q cell T M
, a constant that is computed before the ECMC simulation starts from the total number of cells that scales as O(N). The next cell event is obtained from an exponential distribution with parameter Q cell T M (C a ). This event corresponds to cell C t with probability ∝ q cell T M (C a , C t ), posing a discrete sampling problem that can be solved in O(1) by Walker's algorithm. 18,53 The cell-veto algorithm samples the Boltzmann distribution without performing the event-rate integration in Eq. (46). It requires only O(1) factor-potential evaluations per event in an N-particle system. As a consequence, the total potential of Eq. ( 1) is not updated and the potential remains unknown as the Markov chain evolves. This is what sets ECMC apart from traditional simulation approaches.

III. ECMC COULOMB ALGORITHMS

In a three-dimensional simulation box with periodic boundary conditions, the Coulomb potential is only conditionally convergent for a charge-neutral system, and it is infinite for a system with a net charge. Finiteness of the potential can be recovered in both cases if each point charge is compensated by a background charge distribution. Traditionally, this is chosen as uniform within the simulation box. 17 The precise association of each background charge with its point charge is not unique. This leads to different electrostatic boundary conditions, which are linked to the polarization state of the simulation box. Consistency imposes a distinct fluctuation theorem 17 for each choice of the boundary condition when computing macroscopic physical properties such as the dielectric constant. Alternatively to the uniform compensating background charge, in ECMC, a line-charge model was introduced. 18 In this model, the background charge distribution is one-dimensional and the factor derivatives are absolutely convergent. The potential for different variants of the line-charge model can be absolutely or conditionally convergent.

As discussed in Sec. II A, ECMC allows for different Coulomb factor sets that may influence the convergence properties of the algorithm, although the steady state is invariably given by the Boltzmann distribution. Roughly, there are two inequivalent Coulomb factorizations. 18 First, the periodic twoparticle problem can be embedded on a three-dimensional torus and the potential merged from all the topologically inequivalent minimal paths between particles [see Fig. 5(a)]. For two particles, 1, 2 , this "merged-image" system has a single factor 1, 2 , Coulomb . For N particles, this gives the factor set i, j , Coulomb : i < j ∈ 1, . . . , N . In general, the merged-image factors may comprise more than two particles, but they do not distinguish between the different images of a local configuration (for example, an H 2 O molecule). Second, we may picture the three-dimensional periodic system as an infinite number of periodic images of the simulation box indexed by an integer vector n ∈ Z 3 . For two particles already, this "separate-image" system has an infinite number of factors and for N particles, the factor set is

i, j , Coulomb n : i < j ∈ 1, . . . , N , n ∈ Z 3 . ( 56
)
More generally, an individual "separate-image" factor may describe an image of certain particles inside the simulation box.

The aim of this section is threefold. First, we present the tin-foil and the line-charge Coulomb formulations and then demonstrate that, although the potentials differ, the Coulomb factor derivatives (that for pair factors yield the pair event rates) are identical. Second, we discuss two efficient algorithms for the merged-image Coulomb derivatives of a pair of particles, one algorithm from the tin-foil perspective and the other summing up line-charge derivatives. Third, we set up an ECMC simulation for two particles in a periodic three-dimensional simulation box in order to validate that the merged-image and the separate-image factor sets indeed show indistinguishable equilibrium properties. We then discuss possible applications for both factorizations.

A. Tin-foil electrostatics within ECMC

The traditional treatment of electrostatic interactions with periodic boundary conditions is based 17 on a large spherical aggregate of images of the three-dimensional cubic simulation box. The polarization state of the simulation box is expressed through electrostatic boundary conditions. With "tin-foil" boundary conditions, the potential of N particles i ∈ 1, . . . , N of charge c i (in units where the Coulomb potential between two point charges in free space is

U ij = c i c j /|r ij |), is 17 U C r 1 , . . . , r N , c 1 , . . . , c N = 1 2 N i=1 c i ψ(r i ) + U self (α), ( 57
) with the electrostatic potential ψ ψ(r i ) = N j i=1 c j        n∈Z 3 erfc(α|r ij + nL|) |r ij + nL| + 4π L 3 q (0,0,0) e -q 2 /(4α 2 ) q 2 cos q • r ij        , ( 58
)
where the Fourier-space sum is over q = 2πm/L with m ∈ Z 3 . The self-energy contribution U self (α) is independent of the particle positions and drops out of our considerations, which are only concerned with derivatives of the potential. The left-hand side of Eq. ( 57) is independent of the convergence factor α > 0, which however influences the speed of evaluation of Eq. ( 58). Direct evaluation of the sums for N point charges leads to an optimal choice α ∼ N 1/6 /L, and a scaling in operations O(N 3/2 ). The particle-mesh Ewald method uses an interpolating mesh to approximate the Fourier sum, leading to O(N log N) operations to evaluate the potential.

In merged-image ECMC, we only use Eq. ( 58) for N = 2 with α = O(1/L) and evaluate the derivative of the Coulomb potential to machine precision with O(1) effort. We continue, as in Sec. II B, with a two-particle factor 1, 2 , Coulomb . The tin-foil factor derivative is given by q({1,2}, Coulomb),1 (r 12 , c 1 , c 2 ) = qReal (r 12 ) + qFour. (r 12 ), [START_REF] Mori | Simulated tempering based on global balance or detailed balance conditions: S uwa-t odo, heat bath, and m etropolis algorithms[END_REF] with the real-space derivative qreal , qreal (r 12 ) = c 1 c 2 n∈Z 3

x 12 + n x L |r 12 + nL| 2 erfc(α|r 12 + nL|)

|r 12 + nL| + 2αe -α 2 |r 12 +nL | 2 π 1/2       , ( 60
)
and the Fourier-space derivative qFour. , qFour. (r 12 ) = c 1 c 2 4π L 3 q 0 q x e -q 2 /(4α 2 ) q 2 sin(q • r 12 ). ( 61)

For two particles and, more generally, for pair factors in an Nparticle system, the merged-image Coulomb pair-event rate, from Eq. ( 59), is given by

q ({1,2}, Coulomb),1 r 12 , c 1 , c 2 = β q({1,2}, Coulomb),1 r 12 , c 1 , c 2 + . (62)
In Secs. IV and V, we will consider dipole-dipole factors with an index set comprising the four or six particles of two molecules and the "Coulomb" type corresponding to all the Coulomb interactions between the two molecules. The factor potential in this case is the sum over Coulomb pairs within the factor, and the factor derivatives needed in Eq. ( 36) are the sum of a finite number of pairwise Coulomb derivatives as in Eq. ( 59). The evaluation of the dipole-dipole factor derivatives remains of complexity O(1) because the number of elements in each factor remains finite as N → ∞. In ECMC, at most a single factor has to be evaluated precisely for each move (see Sec. II C), whereas in traditional MCMC or MD computations the Coulomb potential in Eq. ( 57) or its derivatives are computed for all N particles.

B. Line-charge model

In a large periodically reproduced aggregate of the simulation box, the sum over the Coulomb derivatives between a charged active particle and multiple target images (without neutralizing backgrounds) is ill-defined. However, the compensating uniform volume charge is not the only option to regularize the sum, as the line-charge model 18 and its variants provide alternatives to tin-foil electrostatics. Here, straight lines of charges are associated with each copy of the target particle, and aligned with its direction of motion [in our example êx , see Fig. 5(b)]. Although the merged-image line-charge potential, in its simplest version, is itself not absolutely convergent, its factor derivatives are unequivocally defined and equivalent to those obtained with tin-foil boundary conditions. By itself, the line charge neutralizes the charge of the target particle and (because it is centered) also creates an object with zero dipole moment. Previous work 18 used line charges of length L. Here, we consider lengths pL with integer p [see Fig. 5(b)]. The line charges are replicated over a cubic lattice indexed by the lattice vector n. Lines of different images meet [see Fig. 5(b)]. The Coulomb potential of the line-charge model naturally differs from the one of the tin-foil model because the background charge distributions are manifestly different. However, the merged-image Coulomb derivative of the linecharge model, relevant to ECMC, is identical to the tin-foil expression.

Explicitly, the contribution to the Coulomb derivative from an image n [with n = (0, 0, 0) the original simulation box] is

q({1,2}, Coulomb n ),1 r 12 = c 1 c 2 x 12 + n x L |r 12 + nL| 3 + 1 pL 1 |r 12 + L(n + pê x )/2| - 1 |r 12 + L(n -pê x )/2| . (63)
The line charge generates an electrostatic potential at large separations, r = Ln, which varies with a quadrupolar form. Thus, in any given direction the Coulomb derivative decays as 1/|r| 4 . For this reason, the sum over the images of the Coulomb derivatives of Eq. ( 63) converges absolutely. The mergedimage Coulomb derivative, in the line-charge formulation, is thus tin-foil expression, Eq. ( 59)

q({1,2}, Coulomb),1 r 12 , c 1 , c 2 = n q({1,2}, Coulomb n ),1 r 12
sum over line charges, Eq. (

.

(64) To show this, we first consider the target particle 2 in the simulation box and all its images to be surrounded by a cube of neutralizing charge of volume L 3 centered on the particle 2 and its images. This volume-charge model [see Fig. 5(c)] is closely connected to the line-charge model [see Fig. 5(b)]. The point charge and associated volume charge have vanishing charge, dipole, and quadrupole moments (whereas the line-charge model, in its simplest form, has a finite quadrupole moment). We now compare spherical (radius R L) and cubic aggregates (of side 2R) of target images and study the electrostatic potential within the central simulation box. In this process, the active particle is not replicated, and it remains within the simulation box. Due to the vanishing quadrupole moment of the volume charges, the difference in the electrostatic potential on the particle 1 in the spherical and cubic aggregates decreases at least as fast as 1/R 2 . However the electrostatic potential in the center of the spherical aggregate corresponds to a zeropolarization state which is identical to the tin-foil expression of Eq. [START_REF] Todo | Geometric allocation approaches in Markov chain Monte Carlo[END_REF].

We now find explicit integral expression for the Coulomb derivative of an aggregate of line charges and volume charges and show that the difference is zero in the limit of a large assembly. We again consider the interaction between an active particle and the cubic aggregate of the (2K + 1) 3 copies of the target particle (the central simulation box and its images). (The active particle is placed inside the simulation box.) The Coulomb potential between the active particle and a single target particle is

U 12 = 4πc 1 ∞ -∞ d 3 q (2π) 3 e iq•r 12 ρ 2 (q) |q| 2 , (65)
where ρ 2 (q) is the structure factor of the target particle and the background. We now sum over the images, separated by a multiple of the simulation box size L along each axis. This requires evaluating the sum

D K (q x ) = K l=-K e iq x lL = sin q x L(K + 1/2) sin(q x L/2) , (66)
and analogously for q y and q z . With the product

DK (q) = D K (q x )D K (q y )D K (q z ), (67)
this gives the potential of the active particle in the aggregate of the target particle and its images,

U K = 4πc 1 ∞ -∞ d 3 q (2π) 3 DK (q) e iq•r 12 ρ 2 (q) |q| 2 . ( 68
)
Equation ( 66) is the Dirichlet kernel which converges, in a weak sense, to a sum of δ-functions in the limit of large K,

D K (q x ) ----→ K→∞ 2π L ∞ m=-∞ δ q x -m 2π L , (69)
and similarly for q y and q z . The width of the central peak of D K scales as 1/K for large K. Integrals over sufficiently well-behaved objects become summations in the limit of large K,

d 3 q (2π) 3 DK (q)f (q) → 1 L 3 q=2πm/L f (q). (70)
For the volume-charge model, the structure factor is

ρ 2 (q) = c 2 1 -sinc q x L 2 sinc q y L 2 sinc q z L 2 , (71)
where the first term on the right-hand side describes the point charge and the product of cardinal sine functions, sinc(q x ) = sin(q x )/q x , etc., the uniform background volume charge.

From Eqs. ( 68) and ( 71), the potential of a finite cubic array of images of the particle 2, with active particle 1, is

U volume K = c 1 c 2 d 3 q 2π 2 DK (q) e iq•r 12 |q| 2 × 1 -sinc q x L 2 sinc q y L 2 sinc q z L 2 . (72)
For line charges of length pL, we find

U line K = c 1 c 2 d 3 q 2π 2 DK (q) e iq•r 12 |q| 2 1 -sinc pq x L 2 . ( 73
)
The volume-charge model is equivalent to the tin-foil Coulomb potential. The line-charge model, whose potential is not absolutely convergent, is nevertheless equivalent for ECMC because, as we will see, the integrals in Eqs. ( 72) and ( 73) yield uniquely defined and equivalent Coulomb derivatives for large K. The difference between the two is given by

∆U K = (U line K -U volume K ) = c 1 c 2 d 3 q 2π 2 DK (q) e iq•r 12 |q| 2 × sinc q x L 2 sinc q y L 2 sinc q z L 2 -sinc pq x L 2 .
The Dirichlet kernels imply that the integral in this equation is dominated by contributions near q = 2πm/L. However, the function sinc(q i L/2) also has zeros at these same points (except when q i = 0, where the sinc function is equal to one). For large K, the potential differences is thus dominated by a sum over q y , q z , with q x = 0. This implies that the potential on the active particle equals (to within a constant) the tin-foil potential for motion parallel to the line-charges, but the difference of potentials is corrugated in the perpendicular y-z plane. This is a consequence of the fusion of multiple aligned line charges into a single uniform line when p is integer [see Fig. 5(b)].

We examine the derivative of ∆U K to show that the Coulomb derivatives converge to the same value,

∂ x 1 ∆U K = d 3 q 2π 2 DK (q) q x sin(q • r 12 ) |q| 2 × sinc q x L 2 sinc q y L 2 sinc q z L 2 -sinc pq x L 2 , (74)
which suppresses the contributions which remained for the calculation of the potential, due to the factor q x sin(q x x) near q x = 0. Finally, we consider explicitly the possible divergence at |q| = 0 in Eq. ( 74), due to the presence of the term 1/|q| 2 . We expand all the trigonometric functions in the integrand, ∆I K , to find

∆I K ---→ q→0 const × q 2 x (p 2 -1)q 2 x -q 2 y -q 2 z |q| 2 DK (q).
Even this contribution is thus driven to zero for large K.

We conclude that in a periodic three-dimensional system, the line-charge model becomes equivalent to the volumecharge model, and therefore to tin-foil electrostatics. The line charges must lie parallel to the direction of motion but can of course be switched at will. In contrast, the volumecharge model gives the tin-foil Coulomb derivatives in all directions.

C. Algorithms for Coulomb derivatives

The merged-image Coulomb derivatives are best computed from the tin-foil expressions of Eq. (62). To accelerate the evaluation, we reduce the Fourier-space component of Eq. ( 61) to a sum over non-negative components (m x , m y , m z ), qf (r 12 ) = A xyz sin(λ x 12 ) cos(λ

y 12 ) cos(λ z 12 ), (75)
where λ x 12 = 2πm x x 12 /L, and similarly in y and z and where

A xyz = 16c 1 c 2 m x L 2 |m| 2 2 δ my ,0 +δ mz ,0 exp - π 2 |m| 2 α 2 L 2 (76)
is a position-independent tensor that can be computed before the simulation starts. In Eq. ( 75), repeated indices (x, y, z) are summed over non-negative integers (m x , m y , m z ). The merged-image Coulomb derivatives can also be computed from the sum of the line-charge derivatives [see the right-hand side of Eq. ( 64)]. Because of the symmetry of the line charges, the quadrupolar contribution to the derivative is an odd function of x so that forward and backward terms cancel, and that the sum converges as 1/K 2 for large K. The convergence may be accelerated using Richardson extrapolation 54 (see Fig. 6). Denoting the finite line-charge sum over the range n ∈ [-K, K] 3 as S K and assuming that

S K = S ∞ + A K p , (77)
one may eliminate A as

S K+1 = (K + 1) p S K+1 -K p S K (K + 1) p -K p . ( 78
)
The sequence (S K+1 -S ∞ ) then decays as 1/K p+1 . The transformation of Eq. ( 78) can be iterated, each time gaining one power in the asymptotic behavior of the sequence. The merged-image line-charge derivatives converge to the tinfoil expression of Eq. ( 59), confirming that the two algorithms compute the same object and that individual factors in the line-charge model may be used to simulate tin-foil potentials.

As in the line-charge model, one may sum up the associated point charges and their compensating volume charges explicitly, rather than proceeding through Fourier transformation. However, the analytic formulas are difficult to work with. A further possibility consists in compensating each point charge with more than one line charge. Remarkably, four line charges arranged on a square of side L/ √ 12 in the y-z plane, cancel dipole and quadrupole moments in the multipole expansion and lead to an absolutely converging sum for the electrostatic potential. One may also construct more elaborate sheets FIG. 6. Comparison of the tin-foil expression for the Coulomb factor derivative and the sum over line charges for a given value of r 12 [see Eq. ( 64)] as a function of the cutoff K. The 8-fold iterated Richardson extrapolation for the line-charge expression agrees with the tin-foil expression to within 10 -12 for K ≈ 20. and volumes of screening charges to cancel higher orders in the multipole expansion. All of these screening objects presented here regularize the sum of the pair derivatives over images and allow for separate-image factor sets [analogous to Eq. ( 56); see Sec. III D]. Although the sequence S K decays faster, the Coulomb event rate is not reduced by these different objects.

D. Separate-image ECMC

As we have seen, all the Coulomb interactions in a finite system with periodic boundary conditions can be imagemerged into a single Coulomb type that sums over all the inequivalent minimal paths between two points on a torus, and that correspond to images in the rolled-out representation of periodic boundary conditions. For two particles 1 and 2, this is expressed through a single factor M = 1, 2 , Coulomb . The corresponding factor derivatives can then be computed with the traditional tin-foil expression [Eq. [START_REF] Mori | Simulated tempering based on global balance or detailed balance conditions: S uwa-t odo, heat bath, and m etropolis algorithms[END_REF]] or within the line-charge framework [Eq. [START_REF] Diaconis | Analysis of a nonreversible Markov chain sampler[END_REF]]. The choice of one over the other is a matter of efficiency only (the algorithmic complexity being the same). Each of the formulations suggests other choices for the interaction types. In the line-charge formulation, the choice of an infinite set of types Coulomb n : n ∈ Z 3 suggests itself. For two particles 1 and 2, the set of separateimage factors is 1, 2 , Coulomb n : n ∈ Z 3 . Within ECMC, these images are statistically independent but only one of them must be computed precisely for each event. This is because, as in Sec. II, we can use a variant of the cell-veto algorithm (supplemented with an asymptotic bounding function 18 ), in order to sample the relevant image index n and to then compute the corresponding factor derivative of M n .

Separate-image Coulomb factors generally come with larger pair event rates, as the contributions from different images do not compensate (see Fig. 7). On the other hand, evaluating a separate-image Coulomb derivative [as in Eq. ( 63)] to machine precision requires just a few operations, many fewer than what is required for its merged-image counterpart. Details of the separate-image Coulomb factors can influence the efficiency of the algorithm. As an example, the terminal point of the line charge is a singular point of Eq. ( 63) and should not approach another point charge in the system. This motivates our choice of length 2L (or multiples thereof), as the terminal point of one line charge then coincides with the position of an image of the original particle. For the Coulomb potential, the nonphysical line-charge singularity, confounded with the singularity of the point charge, no longer disrupts the ECMC dynamics.

The dynamic behavior of the different factor sets for the Coulomb problem has not yet been explored in detail. As a first step, for a system of two like Coulomb charges, merged-image and separate-image ECMC was validated against the regular tin-foil Metropolis algorithm (see Fig. 8). All three methods clearly sample the Boltzmann distribution in the asymptotic steady state.

IV. DIPOLE-DIPOLE FACTORS

In ECMC, one may tailor the factor sets to the problems at hand. In electrostatic systems made up of local dipoles, specific "dipole-dipole" Coulomb factors may thus contain all the atoms distributed over two molecules that can be far apart from each other. These factors yield much smaller event rates than "particle-particle" pair factors. In addition, a special "inside-first" lifting scheme can direct most of the lifting flow from the active particle to a target particle situated on the same molecule. Even for a non-local factor made up of two distant dipoles, the lifting flow will thus mostly be between an active particle and a target particle on the same molecule (the probability of an intramolecular lifting grows like log N, whereas all the intermolecular liftings remain constant). We expect such a local lifting scheme for extended factors to show interesting dynamic properties. In the present section, we explore dipole-dipole factors in a simple model of charge-neutral two-particle molecules before employing them, in Sec. V, to a model of liquid water. We expect dipoledipole factors and their variants to have useful applications in ECMC.

Concretely, for a simple model of two-particle dipoles in a three-dimensional periodic simulation box, the dipole-dipole factor for the particles 1, 2, 3, 4 is given by

1, 2, 3, 4 , Coulomb , (79)
[see Fig. 9(b)], where the corresponding Coulomb factor potential is

U ({1,2,3,4}, Coulomb) (r 1 , . . . , r 4 ) = 2 i=1 4 j=3 U C r ij , c i , c j . ( 80
)
The factor of Eq. ( 79) thus comprises the four Coulomb potentials between these particles, using the Coulomb potential of Eq. ( 57). The model excludes, as is usual, 30 Coulomb interactions within a dipole. For the same four particles, one may also use the "particle-particle" factors

with the "particle-particle" factor potential

U ({i,j }, Coulomb) r ij , c i , c j = U C r ij , c i , c j (82)
[see Fig. 9(a)]. We suppose that the particle 1 is active. The dipole-dipole event rate

β q({1,2 ,3,4}, Coulomb),1 + (83)
then allows the interactions U C (r 13 ) and U C (r 14 ) to compensate each other (and to give the event rate corresponding to a point charge interacting with a dipole), while the particle-particle event rate

β q({1,3}, Coulomb),1 + + β q({1,4}, Coulomb),1 + (84)
remains much larger (corresponding to a point charge separately interacting with two isolated point charges) because the unit-ramp functions are both non-negative [see Eq. ( 14)] and one of them is usually zero.

A. Event-rate scaling for Coulomb factors

We now consider a homogeneous system of dipoles of size |d| ∼ d small compared to the simulation box (see Fig. 10). For concreteness, we suppose that particle 1 is the active particle. The event rate, whose scaling with system size we compute in the present section, is the result of the interaction between the particle 1 and the distant dimer (in Fig. 9 made up of particles 3 and 4). As there is no Coulomb interaction between particles on the same dipole, the position of particle 2 (the dipole partner of particle 1) does not come into play for the event rate. We will see in Sec. IV B that this is no longer true for the lifting rates, which are influenced both by the distant dimer and by the local dimer of particle 1, that is, by the position of particle 2.

The electrostatic potential at a distance r from a point charge c k , within the merged-image (tin-foil) formulation in a box of side L, is given by the scaling form

ψ L (r) = c k |r| f E (r/L), (85)
which generalizes Coulomb's law valid in free space. The function f E (x) is smooth and remains O(1) for all x ∈ [-1/2, 1/2] 3 . For separations such that |r|/L 1, the potential given by Eq. ( 85) has the expansion 55

ψ(r) = c k 1 |r| + const L + 2π|r| 2 3L 3 + • • • . ( 86
)
The nth-order derivatives of f E (r/L) are also smooth and have an amplitude which scale as L -n . The Coulomb derivative between an active particle and a particle k, separated by a vector r ∈ [-L/2, L/2] 3 , also has the scaling form

β q({1,k}, Coulomb),1 = l B |r| 2 f 1 E (r/L). (87)
FIG. 10. Lifting schemes for a dipoledipole factor. (a) Dipole-dipole factor with four Coulomb interactions. It is assumed that

∂ x 1 U M > 0, ∂ x 4 U M > 0 and ∂ x 2 U M < 0, ∂ x 3 U M < 0. (b)
"ratio" lifting, (c) "inside-first" lifting (d) "outside-first" lifting.

Here, we have introduced the characteristic Bjerrum length l B = |e 2 | β, with e being the elementary charge, the distance at which the Coulomb interaction equals the thermal energy and used f 1 E as a new scaling function, which again remains O(1). An explicit form for Eq. ( 87) at small separations can be found from Eq. [START_REF] Lei | Event-chain Monte Carlo with factor fields[END_REF]. For a constant number density ρ of particles within the simulation cell, the mean total Coulomb event rate per particle, Q p-p , is given by the integral

Q p-p = k 1 q ({i,k }, Coulomb),1 (88)
=

[-L/2,L/2] 3 l B ρ |r| 2 f 1 E (r/L) d 3 r = l B ρL [-1/2,1/2] 3 1 x 2 f 1 E (x) d 3 x ∼ l B ρL. (89)
This mean total event rate thus diverges as O(L). The reciprocal of Q p-p sets the scale for the mean-free path due to charge-charge interactions, and it is of length scale O(1/L).

The result agrees with the naive free-space argument 18 based on the bare 1/|r| Coulomb interaction. At constant density, the divergence of Eq. ( 89) in L ∼ N 1/3 implies that the active and target particles are often widely separated from each other. With pair factors, one thus expects a complexity of O(N 4/3 ) for an O(1) displacement of all particles in the system.

The scaling form of the potential can also be used to determine the event rate for dipole-dipole factors [as in Fig. 9(b)], the interaction of point charges with dipoles, or the interaction of pairs of well-separated dipoles. The potential at a distance r from a dipole in the periodic box is found from Eq. ( 85) by applying the operator (-d•∇), with d the dipole moment. Using again |d| ∼ d implies that the event rate of the dipole-dipole factor, resulting from the interaction of the active particle 1 with the dipole at a distance r corresponds to a particledipole Coulomb interaction. The dipole-dipole event rate, for two dipoles separated by a vector r ∈ [-L/2, L/2] 3 is given by

β q({1,2,3,4}, Coulomb),1 ∼ dl B |r| 3 f 1 E (r/L), (90)
where r denotes the vector from the active particle to the dipole. Equation ( 90) implies that ECMC with dipole-dipole factors has a much lower mean total Coulomb event rate

Q Coulomb , Q Coulomb = [-L/2,L/2] 3 l B ρd |r| 3 f 2 E (r/L) d 3 r = l B ρd [-1/2,1/2] 3 1 |x| 3 f 2 E (x) d 3 x, (91)
where f 2 E is another scaling function. The second integral in Eq. ( 91) is weakly divergent near the origin (which simply means that in ECMC very nearby dipoles have to be treated individually). Excluding a region of radius O(d/L), the mean total Coulomb event rate using dipole-dipole factors is

Q Coulomb ∼ l B ρd log(L/d). (92)
This much reduced total event rate, obtained by limiting the contributions from large distances, is our main motivation for using dipole-dipole factors. The scaling obtained in Eqs. ( 90) and ( 92) is independent of the specific definition of the dipole model. It only relies on the use of dipole-dipole factors connecting two chargeneutral molecules that may be far apart (see Sec. V, where the dipoles are realized by H 2 O molecules). The scaling is also insensitive to the introduction of screening charge distributions, and it holds both for the merged-image and for the separate-image factor sets. Adapting this factorization framework to systems composed of molecules that behave as approximate higher-order multipoles would further improve the scaling.

B. Dipole-dipole lifting schemes

We now consider lifting schemes for dipole-dipole factors, and for concreteness, we consider a four-particle system of particles 1, 2 , forming a charge-neutral dipole d 12 and particles 3, 4 , forming an analogous dipole d 34 . In this two-dipole system, particle 1, for example, not only interacts with a charge-neutral dipole d 34 , but is itself inside such a dipole d 12 . Although the Coulomb lifting rate is oblivious to the position of 2 (as there is no Coulomb interaction between particles 1 and 2), particle 2 is part of the dipoledipole factor, and its position influences the relative lifting rates.

We obtain the derivatives with respect to particles 1 and 2 for the factor M = 1, 2, 3, 4 , Coulomb as follows:

β qM,1 = l B a |d 34 | |r| 3 + O |d 34 | 2 |r| 4 + O |d 34 | L 3 , ( 93
)
β qM,2 = l B -a |d 34 | |r| 3 + O |d 34 | 2 |r| 4 + O |d 34 | L 3 . ( 94
)
The dominant terms in these two equations are equal in magnitude yet opposite in sign, reflecting that particles 1 and 2 interact with the same distant dipole d 34 , are of opposite sign, and close to each other (on the dipole d 12 ). For the factor derivatives with respect to particles 3 and 4, we find

β qM,3 = l B ã |d 12 | |r| 3 + O |d 12 | 2 |r| 4 + O |d 12 | L 3 , (95)
β qM,4 = l B -ã |d 12 | |r| 3 + O |d 12 | 2 |r| 4 + O |d 12 | L 3 . (96)
[For ease of notation, we used here Eq. ( 86) for small |r|/L rather than the full scaling form.] The coefficient a (and analogously for ã) reflects the orientation of d 34 with respect to the distance vector between the two dipoles (see Fig. 10). Remarkably, the factor derivatives of M with respect to the particles within each dipole (q M,1 + qM,2 and qM,3 + qM,4 ) cancel at order 1/|r| 3 and leave a remainder of 1/|r| 4 . This dipole-dipole compensation to order 1/|r| 3 of the factor derivatives is a general feature for pairs of local dipoles (that can be composed of more than two atoms) inside a factor and occurs in the same manner with the full scaling functions in the merged-image potential.

We recall from Eq. ( 29) that the four factor derivatives exactly sum up to zero. As illustrated in Sec. II B (see Fig. 2), the lifting scheme corresponds to arranging the indices k + ∈ I + M on the upper row of a two-row table and the indices k -∈ I - M on the lower row. In a factor with large separation |r|, each row contains one element corresponding to each of the two dipoles (see Fig. 10).

The "ratio" lifting scheme is as described in Sec. II B. All elements fall off as O(1/|r| 3 ) [see Eq. ( 90)], and both rows contain elements representing each dipole. From Eqs. ( 94) and [START_REF] Bender | Advanced Mathematical Methods for Scientists and Engineers I: Asymptotic Methods and Perturbation Theory[END_REF], this leads to comparable proportions of intra-and inter-molecular liftings. Both rates fall off at the same rate, but their coefficients are different reflecting the orientations of the dipoles. The total inter-and intra-dipole lifting rates both scale as log L [see Fig. 10(b) andTable I].

In the "inside-first" lifting scheme, the elements corresponding to each dipole are aligned with each other. The two match to order ∼1/|r| 3 . The mismatch in bar length is O(1/|r| 4 ) in Eqs. ( 93) and ( 94). In the full scaling picture, the difference in length of the elements can be computed analogously. Coulomb liftings thus occur mostly within a dipole, and long-ranged inter-dipole liftings remain bounded in number for large system sizes [see Fig. 10(c) andTable I].

Finally, the "outside-first" lifting scheme consists in vertically aligning elements corresponding to different dipoles. Aligned elements are of length ∼|a| and ∼|ã| so that intraand inter-dipole lifting rates again both fall off as O(1/|r| 3 ). The situation is analogous to the one for the "ratio" lifting, and the "outside-first" scheme remains strongly non-local [see Fig. 10(d) andTable I].

In contrast to the above dipole-dipole factors, the "particle-particle" factor, as argued in Eqs. ( 87) and ( 89), produces events which occur at the scale of the simulation box at a rate which decreases as only 1/|r| 2 , leading to a total event rate increasing linearly with L. The lifting flow is between one dipole and the other, and the intra-dipole lifting rate is zero (see Table I).

C. Validation of factors and liftings

The dipole-dipole factors and their different lifting schemes can be checked for consistency for two chargeneutral dipoles with a short-ranged vibrational intra-dipole potential, a repulsive potential between oppositely charged TABLE I. Coulomb lifting rates for two dipoles separated by a distance |r|/L 1, together with full integrated rate in simulation box of size L 3 : One particle-particle and three dipole-dipole schemes ("ratio," "outside-first," and "inside-first"). q intra : lifting rate to the non-active particle within the active dipole. q inter : lifting rate to the triggering dipole. Q intra and Q inter denote the mean total event rates (using the full scaling form, as in Sec. IV A), integrated over the simulation box.

Lifting scheme

q intra q inter Q intra Q inter Lifting Particle 0 1/|r| 2 0 L inter-dipole Ratio 1/|r| 3 1/|r| 3 log L log L inter + intra Outside-first 1/|r| 3 1/|r| 3 log L log L inter + intra Inside-first 1/|r| 3 1/|r| 4 log L const inter-dipole
particles (needed to keep dipoles apart from each other), and intermolecular Coulomb interactions. With particles numbered as in Fig. 9, the model corresponds to a factor set 1, 2 , bond ,

with the harmonic bond factor potential,

U ({i,j }, bond) r ij = 1 2 k b |r ij | -r 0 2 , (98)
with k b > 0, a short-range repulsive potential

U ({i,j }, rep) r ij = 1 2 k 2 r 0 |r ij | 6 , (99)
with k 2 > 0, and a scalar separation r 0 , in addition to the dipole-dipole Coulomb factor potential of Eq. ( 80). The dipole-dipole Coulomb factor differs from the particle-particle Coulomb factors in the set, 1, 2 , bond , 3, 4 , bond , 1, 4 , rep , 2, 3 , rep , 1, 3 , Coulomb , 1,

where the factor potentials corresponding to bond vibrations and the repulsion between unlike charges are as in Eqs. ( 98) and ( 99) and the Coulomb factor potentials are those of Eq. ( 82).

In addition, since |I M | = 2 for each particle-factorized factor M, we have no freedom in choosing a lifting scheme (see Sec. IV B). The "ratio," "inside-first" and "outside-first" lifting schemes for the dipole-dipole factor are easily implemented and compared to the particle-particle lifting scheme. By construction, they yield identical thermodynamic correlations (see Fig. 11). Although the event rates are fixed by the decomposition of the total potential into factors, the different lifting schemes may differ in their dynamical behavior.

V. LIQUID WATER AND DIPOLE-DIPOLE FACTORS

To explore ECMC in a realistic context, we implement in this section the simple point-charge water model with flexible molecules (SPC/Fw), a well-studied all-atom model for liquid water. 30 This model combines the longranged Coulomb potential with hydrogen-oxygen bond-length vibrations, a flexible hydrogen-oxygen-hydrogen angle, and a specific oxygen-oxygen interaction of the Lennard-Jones type. The SPC/Fw model is closely related to one used in molecular-dynamics simulations of solvated peptides. 43 Naturally, each water molecule is charge-neutral and dipolar so that the dipole-dipole factorization of Sec. IV applies. This realizes a mean-free path for a single particle as ∼1/log N in the thermodynamic limit (an earlier ECMC Coulomb algorithm 18 had obtained a mean-free path scaling as ∼1/N 1/3 ).

A. Factors in the SPC/Fw water model

To simulate liquid water with the SPC/Fw potential, we use the following type set: bond, bending, LJ, Coulomb .

(

As an example, the factor set for two water molecules, containing particles 1, 2, 3 and 4, 5, 6 , respectively, [and with 2 and 5 being the oxygens, see Fig.

This factor set [see Fig. 12(b)] trivially generalizes to more than two H 2 O molecules. In Eq. (102), the "bond" factor potential of Eq. ( 98) describes oxygen-hydrogen bond vibrations with the equilibrium bond distance r 0 = 1.012 Å and k b = 1059.162 kcal mol -1 rad -2 , that correspond to the SPC/Fw parameters. The "bending" factor potential describes the fluctuations in the bond angle within each H 2 O molecule,

U ({i,j,k }, bending) (r i , r j , r k ) = 1 2 k a φ {i,j,k } -φ 0 2 ,
where φ {1,2,3} and φ {4,5,6} denote the internal angle between the two legs of each H 2 O molecule (see Fig. 12). We adopt the SPC/Fw parameters: φ 0 = 113.24 • and k a = 75.90 kcal mol -1 Å -2 . The specific Lennard-Jones interaction between oxygen atoms corresponds to the "LJ" factor potential

U ({2,5}, LJ) (r 25 ) = k LJ       σ |r 25 | 12 - σ |r 25 | 6      , (103)
where k LJ = 0.62 kcal mol -1 and σ = 3.165 Å are prescribed in the SPC/Fw model. The Lennard-Jones potential is truncated beyond 9.0 Å. This truncation, however, is unnecessary if the cell-veto algorithm is used. Finally, the dipoledipole "Coulomb" factor potential, in direct generalization of Eq. ( 80), is given by

U ({1,...,6}, Coulomb) (r 1 , . . . , r 6 ) = 3 i=1 6 j=4 U C (r ij , c i , c j ).
(104) Here, the Coulomb potential of Eq. ( 57) is used with the SPC/Fw parameters c 1 = c 3 = c 4 = c 6 = 0.41e and c 2 = c 5 = -0.82e (with e the elementary charge).

The type set of Eq. ( 101) is by no means unique. We could also break up the Lennard-Jones interaction into two types, corresponding to the two components of the Lennard-Jones potential (as discussed in Sec. II A). Also, instead of the merged-image Coulomb type, we could adopt any of the variants of the separate-image type, resulting in a type set, {bond, bending, LJ, Coulomb n : n ∈ Z 3 }.

Finally, it is possible to break up the "bond" and "bending" factors into N H 2 O -1 equal terms in order to construct a unique dipole-dipole factor for each pair of H 2 O molecules in such a way that the type set only contains a single element. All these choices are correct, but they may differ in the ease of implementation and in the speed with which they approach equilibrium.

B. Intrinsic rotations

Our version of ECMC is formulated in terms of displacements that, for a given event chain, are along one of the directions êx , êy , êz . Each individual event chain can strain the system, but is unable to rotate it, as the coordinates perpendicular to the direction of motion remain unchanged. The flexible SPC/Fw H 2 O molecule may itself get strained in a single event chain. Applying strain subsequently in different directions is known to be equivalent to a rotation on all levels, and, in particular, on the level of a single molecule. This guarantees that the algorithm is irreducible and can attain all of configuration space.

The rotation that is induced through subsequent event chains in the three directions can be illustrated in an ECMC simulation of a single H 2 O molecule, using only the intramolecular factor types in Eq. ( 101). The rotational dynamics of such a single molecule is easily tracked through the equilibrium autocorrelation function of the dipole moment d = r 21 + r 23 (see Fig. 12), given by

A(s) = d s • d s + s ∼ exp(-s/λ) for s → ∞,
where the variables s and s + s denote the ECMC displacement (proportional to the time of the continuous Markov process). A(s) decays exponentially at large s with a rate that gives the autocorrelation length λ of molecular orientation.

At temperature 300 K, the cumulative chain length it takes to rotate the molecule around itself is about one to two orders of magnitude larger than the H 2 O molecule itself (see Fig. 13). In the limit of large chain lengths , the autocorrelation length of the dipole moment is proportional to . This simply means that lengthening an already long chain does not add to the internal strain of the water molecule, as a local equilibrium is reached.

The sequence of chain directions need not be random: The switching of directions merely renders the Markov chain irreducible, whereas global balance is satisfied for any infinitesimal move (without the return move necessary for detailed balance). As a deterministic, cyclic, sequence êx êy êz êx êy . . . avoids repetitions, we find it to decorrelate the dipole moment faster than a uniform random sampling of chain directions (see Fig. 13). The rotations of molecules are thus generated as a byproduct of the switching of eventchain directions. In practical applications, it remains to be seen whether the rotations of molecular ensembles decay particularly slowly. In this case only, the ECMC algorithm will need to be modified in order to explicitly take into account rotations.

C. ECMC for liquid water

The SPC/Fw potential is adapted for liquid water at standard temperature 300 K and density 1 g/cm 3 . An ECMC simulation at these conditions is easily set up with factors FIG. 13. Autocorrelation length λ for the dipole moment in ECMC of a single H 2 O molecule (fixed chain length ) for the cyclic sequence of event-chain directions (ê x êy êz êx . . .) and for their random resampling. 102) with the inside-first lifting scheme. The random choice of directions was used with a fixed value of = 0.5 Å. The maximal difference between the two distributions is smaller than 10 -3 .

(including the dipole-dipole Coulomb factor) as in Eq. ( 102) generalized for N H 2 O > 2. The "ratio," "outside-first," and "inside-first" lifting schemes are taken over from the dipole case discussed in Sec. IV. However, the dipole is now constructed from three particles. For a far distant pair of H 2 O molecules, the factor derivatives with respect to the hydrogen positions are usually of the same sign and of opposite sign to that of the oxygen. In the notations of Fig. 12 and using M = 1, . . . , 6 , Coulomb , we thus have that to order 1/r 3 ,

∂ x 1 U M ∼ ∂ x 3 U M ∼ - 1 2 ∂ x 2 U M . (105)
This can again be used in the inside-first lifting scheme to keep most of the lifting flow inside the molecule of the active particle. Care must be exercised in these lifting schemes to arrange the particles in a fixed order that is independent of which particle is active (it is incorrect to place the active particle systematically on the left-most position on the upper row of the table in Fig. 10).

FIG. 15. Ensemble-averaged total "Coulomb," "bond," "LJ," and "bending" event rates as a function of the number of H 2 O molecules. The Coulomb event rate scales logarithmically. Event rates depend on the choice of factors but are independent of the lifting scheme.

FIG. 16. Histogram of distance |r|

between the active and the target particle for the Coulomb events for the "ratio," "outside-first," and "inside-first" lifting schemes and for 64, 128, and 256 H 2 O molecules. The integral of each histogram corresponds to Q Coulomb in Fig. 15. Dashed lines indicate |r| -z with exponents z: 1, 1, 2, which corresponds to q inter ∼ |r| -(z +2) in Table I.

For long simulation times, the ECMC algorithm exactly samples the Boltzmann distribution of this model, and thermodynamic observables can be compared with Metropolis Monte Carlo using the Ewald summation for the Coulomb potential. This can be verified for the oxygen-oxygen distances that agree to very high precision, demonstrating that the irreversible ECMC converges toward the same steady state as reversible Monte Carlo algorithms (see Fig. 14). To make sure that equilibrium is reached, the initial configurations were chosen randomly in a very dilute system and slowly compressed toward the target density.

In the liquid-water simulation for N H 2 O > 2, the factors M = (I M , T M ) belong to four different types (that is, T M ∈ T and |T | = 4), into which the ensemble-averaged total event rate [see Eq. ( 21)] can be split,

1 N N k=1 Q k r 1 , . . . , r N = T ∈T Q T . ( 106
)
Q Coulomb agrees with the definition in Sec. III [see Eq. ( 91)].

The three local factor types naturally give constant scaling of their associated mean event rates Q bond , Q LJ , and Q bending with system size, whereas Q Coulomb clearly features log N H 2 O scaling with the number of H 2 O molecules (see Fig. 15). The logarithmic scaling of the total Coulomb event rate validates the prediction of Eq. ( 92). The total event rate increases by 5 Å -1 when N H 2 O doubles. Finally we study the lifting flows for the dipole-dipole factors under the "ratio," "inside-first," and "outside-first" schemes (see Sec. IV B). As discussed in Sec. IV A, the event rates are independent of the lifting schemes for a given factor set. However, the probability distributions of the distance |r| between the active and the target particles are different (see Fig. 16). First, the peak at the oxygen-hydrogen bond length corresponding to a lifting within the molecule increases logarithmically with system size. Second, with increasing system size the distribution of event distances develops a powerlaw tail. In both the "ratio" and the "outside-first" lifting schemes, the tail of the probability distribution decreases as |r| -1 . The "inside-first" scheme decays as |r| -2 . These results, corresponding to the evolution of q inter in |r| -3 and |r| -4 , are summarized in Table I.

Remarkably, the "inside-first" lifting scheme induces mostly local lifting flows, even for Coulomb factors that associate H 2 O molecules that are far distant from one another. Most of the liftings are local and the central peak increases as log N H 2 O . We expect a local lifting to keep the dynamics of the system coherent and to lead to faster convergence toward equilibrium. It appears also possible to replace the interaction with far-away H 2 O molecules by the interaction with an effective medium (given that the lifting flow remains local). In the "ratio" and "outside-first" lifting schemes, this would probably not be possible as the lifting flow toward faraway dipoles is of the same order of magnitude as the local flow.

VI. CONCLUSIONS

In this work, we have outlined the ECMC framework for all-atom computations. Our algorithm advances a single particle in the presence of long-ranged electrostatic interactions in O(1) operations, with a mean-free path which decreases as O(1/ log N). This gives an overall complexity of O(N log N) to advance N particles, each by O(1). This speed can be achieved for locally charge-neutral systems, where particles can be grouped into local dipoles. The algorithm can take into account the presence of free point charges, and its performance worsens only gradually with their number. The algorithm is manifestly translation-invariant and event-driven. It is free of discretization errors and exactly samples the Boltzmann distribution, without needing a thermostat. Its outstanding property is that it neither computes total forces nor determines the system potential.

ECMC breaks with tradition in two ways. First, as a Markov-chain algorithm, it offers the freedom to choose among a variety of moves. Our approach of advancing single particles may be a first step only. Nevertheless, as we have shown, it effectively rotates dipoles and flexible water molecules in three-dimensional space and samples the entire configuration space. We have explored the great freedom to choose factors and liftings that suit the problem at hand. Second, ECMC breaks with tradition in that it is purely particle-particle: It treats electrostatic interactions between point charges, but is oblivious to the electrostatic field. This aspect liberates it from the interpolating mesh that in traditional particle-particle-particle-mesh methods approximates the Coulomb field. Rather, the algorithm is based on the interaction of pairs of particles and, more generally, of factors that may comprise pairs of local dipoles or even more complex objects.

In this work, we have checked that thermodynamic quantities from ECMC agree with those obtained with methods that satisfy detailed balance. As a next step for analyzing ECMC in all-atom systems, it will be important to study its relaxation dynamics in detail. This dynamics will certainly depend on the choice of factors and, for example, for the case of dipole-dipole factors treated here, on the choice of liftings. The inside-first lifting scheme yields mostly local dynamics, and we would expect it to lead to a faster decay of correlation functions. Besides this, we have discussed that the length and the probability distribution of the event-chain parameter and even the sequence of the directions of the event-chain can significantly influence the ECMC dynamics although, as we have verified extensively, the steady state is always given by the Boltzmann distribution. We would hope that, in addition to the overall favorable algorithmic scaling, the fast decay of density fluctuations carries over from short-range-interacting particle and spin systems. The influence of different factorization and lifting schemes on the dynamics of ECMC will also have to be understood. From an algorithmic implementation point of view, we think that the parallelization of the method 56 will have to be dealt with carefully. ECMC simulations of water will permit standardized comparison of run times with the ones of traditional molecular-dynamics algorithms. Other applications, such as solvated peptides 43 and polarizable models, appear within reach.

Introduction

Event-chain Monte Carlo (ECMC) is an irreversible continuoustime Markov-chain algorithm [1,2] that often equilibrates faster than its reversible counterparts [3][4][5][6][7]. ECMC has been successfully applied to the classic N-body all-atom problem in statistical physics [8,9]. The algorithm implements the time evolution of a piecewise non-interacting, deterministic system [10]. Each straight-line, non-interacting leg of this time evolution terminates in an event, defined through the event time at which it ✩ This paper and its associated computer program are available via the Computer Physics Communication homepage on ScienceDirect (http://www. sciencedirect.com/science/journal/00104655). ✩✩ The review of this paper was arranged by Prof. D.P. Landau. takes place and through the out-state, the updated starting configuration for the ensuing leg. An event is chosen as the earliest of a set of candidate events, each of which is sampled using information contained in a so-called factor. The entire trajectory samples the equilibrium probability distribution.

ECMC departs from virtually all Monte Carlo methods in that it does not evaluate the equilibrium probability density (or its ratios). In statistical physics, ECMC thus computes neither the total potential (or its changes) nor the total force on individual point masses. Rather, the decision to continue on the current leg of the non-interacting time evolution builds on a consensus which is established through the factorized Metropolis algorithm [2]. A veto puts an end to the consensus, triggers the event, and terminates the leg (see Fig. 1). In the continuous problems for which ECMC has been conceived, the veto is caused by a single factor. each factor must at all times independently accept the continued non-interacting evolution, and must determine a candidate event time at which this is no longer the case. The earliest candidate event time (which determines the veto) and its out-state yield the next event (the event E b is triggered by a 2 ). In JF-V1.0, after committing an event to the global state, candidate events with certain tags are trashed (tags t_1, t_3 at E b ) or maintained active (tags t_2, t_4 at E b ), and others are newly activated. JF introduces non-confirmed events and also pseudo-factors, which complement the factors of ECMC, and which may also trigger events.

The resulting event-driven ECMC algorithm is reminiscent of molecular dynamics, and in particular of event-driven molecular dynamics [11][12][13], in that there are velocity vectors (which appear as lifting variables). These velocities do not correspond to the physical (Newtonian) dynamics of the system. ECMC differs from molecular dynamics in three respects: First, ECMC is event-driven, and it remains approximation-free for any interaction potential [14], whereas event-driven molecular dynamics is restricted to hard-sphere or piecewise constant potentials. (Interaction potentials in biophysical simulation codes have been coarsely discretized [15] in order to fit into the event-driven framework [16][17][18].) Second, in ECMC, most point masses are at rest at any time, whereas in molecular dynamics all point masses typically have non-zero velocities. In ECMC, an arbitrary fixed number of independently active point masses with identical non-zero velocity vectors may be chosen. In most present applications of ECMC, only a single independent point mass is active at any time. The ECMC dynamics is thus very simple, yet it mixes and relaxes at a rate at least as fast as in molecular dynamics [4,6,7]. Third, ECMC by construction exactly samples the Boltzmann (canonical) distribution, whereas molecular dynamics is in principle micro-canonical, that is, energy-conserving. Molecular dynamics must therefore generally be coupled to a thermostat in order to sample the Boltzmann distribution. The thermostat also eliminates the drift in physical observables that is caused by integration errors. In contrast, ECMC is free from truncation and discretization errors.

ECMC samples the equilibrium Boltzmann distribution without being itself in equilibrium, as it violates the detailed-balance condition. Remarkably, it establishes the aforementioned consensus and proceeds from one event to the next with O(1) computational effort even for long-range potentials, as was demonstrated for soft-sphere models, the Coulomb plasma [4,19], and for the simple point-charge with flexible water molecules (SPC/Fw) model [20,21].

JeLLyFysh (JF) is a general-purpose Python application that implements ECMC for a wide range of physical systems, from point masses interacting with central potentials to composite point objects such as finite-size dipoles, water molecules, and eventually peptides and polymers. The application's architecture mirrors the mathematical formulation that was presented previously (see [21,Sect II]). The application can run on virtually any computer, but it also allows for multiprocessing and, in the future, for parallel implementations. It is being developed as an opensource project on GitHub. Source code may be forked, modified, and then merged back into the project (see Section 6 for access information and license issues). Contributions to the application are encouraged.

The present paper introduces the general architecture and the key features of JF. It accompanies the first public release of the application, JeLLyFysh-Version1.0 (JF-V1.0). JF-V1.0 implements ECMC for homogeneous, translation-invariant N-body systems in a regularly shaped periodic simulation box and with interactions that can be long-range. In addition, the present paper presents a cookbook that illustrates the application for simplified core examples that can be run from configuration files and validated against published data [21]. A full-scale simulation benchmark against the Lammps application is published elsewhere [22].

The JF application presented in this paper is intended to grow into a basis code that will foster the development of irreversible Markov-chain algorithms and will apply to a wide range of computational problems, from statistical physics to field theory [23]. It may prove useful in domains that have traditionally been reserved to molecular dynamics, and in particular in the all-atom Coulomb problem in biophysics and electrochemistry.

The content of the present paper is as follows: The remainder of Section 1 discusses the general setting of JF as it implements ECMC. Section 2 describes its mediator-based architecture [24]. Section 3 discusses how the eponymous events of ECMC are determined in the event handlers of JF. Section 4 presents system definitions and tools, such as the user interface realized through configuration files, the simulation box, the cell systems, and the interaction potentials. Section 5, the cookbook, discusses a number of worked-out examples for previously presented systems of atoms, dipoles or water molecules with Coulomb interactions [21]. Section 6 discusses license issues, code availability and code specifications. Section 7 presents an outlook on essential challenges and a preview of future releases of the application.

Configurations, factors, pseudo-factors, events, event handlers

In ECMC, configurations c = {s 1 , . . . , s i , . . . , s N } are described by continuous time-dependent variables where s i (t) represents the position of the ith of N point masses (although it may also stand for the continuous angle of a spin on a lattice [3]). JF is an event-driven implementation of ECMC, and it treats point masses and certain collective variables (such as the barycenter of a composite point object) on an equal footing. Rather than the time-dependent variables s i (t), its fundamental particles (Particle objects) are individually time-sliced positions (of the point masses or composite point objects). Non-zero velocities and time stamps are also recorded, when applicable. The full information can be packed into units (Unit objects), that are moved around the application (see Section 1.2).

Each configuration c has a total potential U({s 1 , . . . , s N }), and its equilibrium probability density π is given by the Boltzmann weight π({s 1 , . . . ,

s N }) = exp [-βU({s 1 , . . . , s N })] , (1)
that is sampled by ECMC (see [21]). The total potential U is decomposed as

U({s 1 , . . . , s N }) = ∑ M∈M U M ({s i : i ∈ I M }), (2)
and the Boltzmann weight of Eq. ( 1) is written as a product over terms that depend on factors M, with their corresponding factor potentials U M . A factor M = (I M , T M ) consists of an index set I M and of a factor type T M , and M is the set of factors that have a non-zero contribution to Eq. ( 2) for some configuration c. In the SPC/Fw water model, for example, one factor M with factor type T M = Coulomb might describe all the Coulomb potentials between two given water molecules, and the factor index set I M would contain the identifiers (indices) of the involved four hydrogens and two oxygens (see Section 5.3). ECMC relies on the factorized Metropolis filter [2], where the move from a configuration c to another one, c ′ , is accepted with probability

p Fact (c → c ′ ) = ∏ M∈M min [1, exp (-β∆U M )] , (3)
where

∆U M = U M (c ′ M )-U M (c M ).
Rather than evaluating the righthand side of Eq. ( 3), the product over the factors is interpreted as corresponding to a conjunction of independent Boolean random variables

X Fact (c → c ′ ) = ⋀ M∈M X M (c M → c ′ M ). (4)
In this equation, X Fact (c → c ′ ) is ''True'' (the proposed Monte Carlo move is accepted) if the independently sampled factorwise Booleans X M are all ''True''. Equivalently, the move c → c ′ is accepted if it is independently accepted by all factors. This realizes the aforementioned consensus decision (see Fig. 1).

For an infinitesimal displacement, the random variable X M of only a single factor M can be ''False'', and the factor M vetoes the consensus, creates an event, and starts a new leg. In this process, M requires only the knowledge of the factor in-state (based on the configuration c M , and the information on the move), and the factor out-state (based on c ′ M ) provides all information on the evolution of the system after the event. The event is needed in order to enforce the global-balance condition (see Fig. 2a). In this process, lifting variables [25], corresponding to generalized velocities, allow one to repeat moves of the same type (same particle, same displacement), as long as they are accepted by consensus. 1 Physical and lifting variables build the overcomplete description of the Boltzmann distribution at the base of ECMC, and they correspond to the global physical and global lifting states of JF, its global state.

JF, the computer application, is entirely formulated in terms of events, beyond the requirements of the implemented eventdriven ECMC algorithm. The application relies on the concept of pseudo-factors, which complement the factors in Eq. ( 2), but are independent of potentials and without incidence on the globalbalance condition (see Fig. 2b). In JF, the sampling of configuration space, for example, is expressed through events triggered by pseudo-factors. Pseudo-factors also trigger events that interrupt one continuous motion (one ''event chain'' [1]) and start a new one. Even the start and the end of each run of the application are formulated as events triggered by pseudo-factors.

In ECMC, among all factors M in Eq. ( 2), only those for which U M changes along one leg can trigger events. In JF, these factors are identified in a separate element of the application, the activator (see Section 2.4), and they are realized in yet other elements, the event handlers. An event handler may require an in-state. It then computes the candidate event time and its out-state (from the in-state, from the factor potential, and from random elements). The complex operation of the activator and the event handlers is organized in JF-V1.0 with the help of a tag activator, with tags essentially providing finer distinction than the factor types T M . A tagger identifies a certain pool of factors, and also singles out factors that are to be activated for each tag. The triggering of an event associated with a given tag entails the trashing of (non-triggered) candidate events with certain tags, while other candidate events are maintained (see Fig. 1). Also, new candidate events have to be computed by event handlers with given tags. This entire process is managed by the tag activator.

Global state, internal state

In the event-driven formulation of ECMC, a point mass with identifier σ and with zero velocity is simply represented through its position s σ , while an active point mass (with non-zero velocity) is represented through a time-sliced position s σ (t σ ), a time stamp σ (t σ ) and a velocity v σ :

s σ (t) = { s σ if v σ = 0 s σ (t σ ) + (t -t σ )v σ
else (active point mass).

(

) 5
An active point mass thus requires storing of a velocity v σ and of a time stamp t σ , in addition to the time-sliced position s σ (t σ ). In JF, the global state traces all the information in Eq. (5). It is broken up into the global physical state, for the time-sliced positions s σ , and the global lifting state, for the non-zero velocities v σ and the time stamps t σ . JF represents composite point objects as trees described by nodes. Leaf nodes correspond to the individual point masses. A tree's inner node may represent, for example, the barycenter of a part of a molecule, and the root node that of the entire molecule (see Fig. 3a-b). The velocities inside a composite point object are kept consistent, which means that the global lifting state includes non-zero velocities and time stamps of inner and root nodes. The storing element of the global state in JF is the state handler (see Section 2.3). The global state is not directly accessed by other elements of the application, but branches of the tree can be extracted (copied) temporarily, together with their unit information. Independent and induced units differentiate between those that appear in ECMC and those that are carried along in order to assure consistency (see Fig. 3).

For internal computations, the global state may be supplemented by an internal state that is kept, not in the state handler, but in the activator part of the application (see Section 2.4). In JF-V1.0, the internal state consists of cell-occupancy systems, which associate identifiers of composite point objects or point masses to cells. (An identifier is a generalized particle index with, in the case of a tree, a number of elements that correspond to the level of the corresponding node.) In JF, cell-occupancy systems are used for book-keeping, and also for cell-based bounding potentials. JF-V1.0 requires consistency between the time-sliced particle information and the units. This means that the time-sliced position s σ (t σ ) and the time-dependent position s σ (t) in Eq. ( 5) belong to the same cell (see Fig. 2b). Several cell-occupancy systems may coexist within the internal state (possibly on different tree-levels and with different cell systems, see Fig. 3c and Section 5.3.4). ECMC requires time-slicing only for units whose velocities are modified. Beyond the consistency requirements, JF-V1.0 performs time-slicing also for unconfirmed events, that is, for triggered events for which, after all, the out-state continues the straight-line motion of the in-state (see Section 3.1.2).

Lifting schemes

In its lifted representation of the Boltzmann distribution, ECMC introduces velocities for which there are many choices, that is, lifting schemes. The number of independent active units can in particular be set to any value n ac ≥ 1 and then held fixed throughout a given run. This generalizes easily from the known n ac = 1 case [26]. A simple n ac -conserving lifting scheme uses a factor-derivative table (see [21,Fig. 2]), but confirms the active out-state unit only if the corresponding unit is not active in the in-state (its velocity is None).

For |I M | > 3, the lifting scheme (the way of determining the out-state given the in-state) is not unique, and its choice influences the ECMC dynamics [21]. In JF-V1.0, different liftingscheme classes are provided in the JF lifting package. They all construct independent-unit out-state velocities for independent units that equal the in-state velocities. This appears as the most natural choice in spatially homogeneous systems [1].

Multiprocessing

In ECMC, factors are statistically independent. In JF, therefore, the event handlers that realize these factors can be run independently on a multiprocessor machine. With multiprocessor support enabled, candidate events are concurrently determined by event handlers on separate processes, using the Python multiprocessing module. Candidate event times are then first requested in parallel from active event handlers, and afterwards the outstate for the selected event. Given a sufficient number of available processors, out-states may be computed for candidate events in advance, before they are requested (see Section 2.1). The event handlers themselves correspond to processes that usually last for the entire duration of one ECMC run. When not computing, event handlers are either in idle stage waiting to compute a candidate event time or in suspended stage waiting to compute an out-state.

Using multiple processes instead of threads circumvents the Python global interpreter lock, but the incompressible time lag due to data exchange slows down the multiprocessor implementation of the mediator with respect to the single-processor implementation.

Parallelization

ECMC generalizes to more than one independent active unit, and a sequential, single-process ECMC computation remains trivially correct for arbitrary n ac (although JF-V1.0 only fully implements the n ac = 1 case). The relative independence of a small number of independent active units in a large system, for 1 ≪ n ac ≪ N, allows one to consider the simultaneous committing in different processes of n pr events to the shared global state. (A conflict arises if this disagrees with what would result by committing them in a single process.) If n pr ≪ N, conflicts between processes disappear (for short-range interacting systems) if nearby active units are treated in a single process (see Fig. 4a). The parallel implementation of ECMC, for short-range interactions, is conceptually much simpler than that of eventdriven molecular dynamics [27][28][29], and it may well extend to long-range interacting system. of the conflict between stripes is avoided (see [30]).

An alternative type of parallel ECMC, domain decomposition into n ac stripes, was demonstrated for two-dimensional hardspheres systems, and considerable speed-up was reached [30].

Here, stripes are oriented parallel to the velocities, with one active unit per stripe. Stripes are isolated from each other by immobile layers of spheres [30], which, however, cause rejections (or reversals of one or more components of the velocity). The stripe decomposition eliminates all scheduling conflicts. As with any domain decomposition [27], it is restricted to physical models with short-range interactions. It is not implemented in JF-V1.0 (see Fig. 4b).

JF architecture

JF adopts the design pattern based on a mediator [24], which serves as the central hub for the other elements that do not directly connect to each other. In this way, interfaces and data exchange are particularly simple. The mediator design maximizes modularity in view of future extensions of the application.

Mediator

The mediator is doubled up into two modules (with Sin-gleProcessMediator and MultiProcessMediator classes). The run method of either class is called by the executable run.py script of the application, and it loops over the legs of the continuous-time evolution. The loop is interrupted when an End-OfRun exception is raised, and a post_run method is invoked.

For the single-process mediator, all the other elements are instances of classes that provide public methods. In particular, the mediator interacts with event handlers. For the multi-process mediator, each event handler has its own autonomous iteration loop and runs in a separate process. It exchanges data with the mediator through a two-way pipe. Receiving ends on both sides detect when data is available using the pipe's recv method.

In JF-V1.0, the same event-handler classes are used for the single-process and multi-process mediator classes. The multiprocess mediator achieves this through a monkey-patching technique. It dynamically adds a run_in_process method to each created instance of an event handler, which then runs as an autonomous iteration loop in a process and reacts to shared flags set by the mediator. The multi-process mediator in addition decorates the event handler's send_event_time and send_out_ state methods so that output is not simply returned (as it is in the single-process mediator) but rather transmitted through a pipe. Only the mediator accesses the event handlers, and these re-definitions of methods and classes (which abolish the need for two versions for each event-handler class) are certain not to produce undesired side effects.

On one leg of the continuous-time evolution, the mediator goes through nine steps (see Fig. 5). In step 1, the active global Fig. 5. JF architecture, built on the mediator design pattern. The iteration loop takes the system from one event to the next (for example from E a to E b in Fig. 1). All elements of JF interact with the mediator, but not with each other. The multi-process mediator interacts with event handlers running on separate processes, and exchanges data via pipes. state (the part of the global state that appears in the global lifting state) is obtained from the state handler. (In the tree state handler of JF-V1.0, branches of independent units are created for all identifiers that appear in the lifting state.) Knowing the preceding event handler (which initially is None) and the active global state, it then obtains from the activator, in step 2, the event handlers to activate, together with their in-state identifiers. For this, the activator may rely on its internal state, but not on the global state, to which it has no access. In step 3, the corresponding in-states are extracted (that is, copied) from the state handler. In step 4, candidate event times are requested from the appropriate event handlers and pushed into the scheduler's push_event method.

In step 5, the mediator obtains the earliest candidate event time from the scheduler's get_succeeding_event method and asks its event handler for the event out-state (step 6) to be committed to the global state (step 7). The activator, in step 8, determines which candidate events are to be trashed (in JF-V1.0: based on their tags), that is, which candidate event times are to be eliminated from the scheduler. Also, the activator collects the corresponding event handlers, as they become available to determine new candidate events. In the optional final step 9, the mediator may connect (via the input-output handler) to an output handler, depending on the preceding event handler. A mediating method defines the arguments sent to the output handler (for example the extracted global state), and considerable computations may take place there.

The multi-process mediator uses a single pipe to receive the candidate event time and the out-state from an event handler. In order to distinguish the received object, the mediator assigns four different stages to the event handlers (idle, event_time_started, suspended, out_state_started stages). The assigned stage determines which flags can be set to start the send_event_time or send_out_state methods.

It also determines the nature of the data contained in the pipe.

In the idle stage, the mediator can set the starting flag after which the event handler will wait to receive the in-state through the pipe. This starts the event_time_started stage during which the event handler determines the next candidate event time and places it into the pipe. After the mediator has recovered the data from the pipe, it places the event handler into the suspended stage. If requested (by flags), the event handler can then either compute the out-state (out_state_started stage), or else revert to the event_time_started stage.

The strategy for suspending an event handler or for having it start an out-state computation (before the request) can be adjusted to the availability of physical processors on the multiprocessor machine. However, in JF-V1.0, the communication via pipes presents a computational bottleneck.

Event handlers

Event handlers (instances of a number of classes that inherit from the abstract EventHandler class) provide the send_event_time and send_out_state methods that return candidate events. These candidate events either become events of a factor or pseudo-factor or they will be trashed (see Fig. 6). 2 When realizing a factor or a pseudo-factor, event handlers receive the in-state as an argument of the send_event_time method. The send_out_state method then takes no argument.

In contrast, event handlers that realize a set of factors or pseudofactors request candidate event times without first specifying the complete in-state, because the element of the set that triggers the event is yet unknown at the event-time request (see Section 3.2.2 for examples of event handlers that realize sets of factors). The send_event_time method then takes the part of the in-state which is necessary to calculate the candidate event time. Also, it may return supplementary arguments together with the candidate event time, which are used by the mediator to construct the full in-state. The in-state is then an argument of the send_out_state method, as it was not sent earlier.

In JF-V1.0, each run requires a start-of-run event handler (an instance of a class that inherits from the abstract StartOfRun-EventHandler class), and it cannot terminate properly without an end-of-run event handler. Section 3 discusses several event-handler classes that are provided.

State handler

The state handler (an instance of a class that inherits from the abstract StateHandler class) is the sole separate element of JF to access the global state. In JF-V1.0, the global physical state (all positions of point masses and composite point objects) is contained in an instance of the TreePhysicalState class represented as a tree consisting of nodes (each node corresponds to a Node object). Each node contains a particle (a Particle object) which holds a time-sliced position. In JF-V1.0, each leaf node may in addition have charges as a Python dictionary mapping the name of the charge onto its value. Each tree is specified through its root node. Root nodes can be iterated over (in JF-V1.0, they are members of a list). Each node is connected to its parent and its children, which can also be iterated over. In JF-V1.0, the children are again members of a list.

2 A candidate event time may stem from a bounding potential, and not be confirmed for the factor potential. In JF-V1.0, unconfirmed and confirmed events are treated alike. Fig. 6. Basic stages of event handlers for factors and pseudo-factors (stages 1 and 3 relevant for the multi-process mediator only). In the idle and suspended stages, the event handler is halted (via flags controlled by the multi-process mediator), thus liberating resources for other candidate-eventtime computations. With the multi-process mediator, candidate out-states may be computed before the out-state request arrives.

These lists imply unique identifiers of nodes and their particles as tuples. The first entry of the tuple gives a node's root-node list index, followed by the indices on lower levels down to the node itself (see Fig. 3).

The global lifting state is stored in JF-V1.0 in a Python dictionary mapping the implicit particle identifier onto its time stamp and its velocity vector. This information is contained in an instance of the TreeLiftingState class. Both the physical and lifting states are combined in the TreeStateHandler which implements all methods of a state handler.

To communicate with other elements of the JF application (such as the event handlers and the activator) via the mediator, the state handler combines the information of the global physical and the global lifting state into units (that is, temporary Unit objects, see Fig. 7). For a given node in the state handler, its physical-state and lifting-state information is mirrored (that is, copied) to a unit containing its implicit identifier, position, charge, velocity and time stamp. All other elements can access, modify, and return units. This provides a common packaging format across JF. The explicit identifier of a unit allows the program to integrate changed units into the state handler's global state.

In the tree state handler of JF-V1.0, the local tree structure of nodes can be extracted into a branch of cnodes, that is, nodes containing units. 3 Each event handler only requires the global state reduced to a single factor in order to determine candidate event times and out-states. As a design principle in JF-V1.0, the event handlers keep the time-slicing of composite point objects and its point masses consistent. Information sent to event handlers via the mediator is therefore structured as branches, that is, the information of a node with its ancestors and descendants. The state handler's extract_from_global_state method creates a branch for a given identifier of a particle by constructing a temporary copy of the immutable node structure of the state handler using cnodes. Out-states of events in the form of branches can be committed to the global state using the insert_into_global_state method.

The extract_active_global_state method, the first of two additional methods provided by the state handler, extracts the part of the global state which appears in the global lifting state. The tree state handler constructs the minimal number of branches, where each node contains an active unit, so that all implicit identifiers appearing in the global lifting state are represented. The activator may then determine the factors which are to be activated. The method is also used to timeslice the entire global state (see Section 3.2.2). Second, the ex-tract_global_state method extracts the full global state. (For Fig. 7. Inner storage of the tree state handler and example of its extract_from_global_state method, applied to the global state of Fig. 3b.

the tree state handler of JF-V1.0, this corresponds to a branch for each root node.) This method does not copy the positions and velocities.

In JF-V1.0, the global physical state is initialized via the input handler within the input-output handler (see Section 2.6). The initial lifting state, however, is set via the out-state of the startof-run event handler, which is committed to the global state at the beginning of the program (see Section 3.2.2). This means that, in JF-V1.0, the lifting state cannot be initialized from a file.

Activator

The activator, a separate element of the JF application, is an instance of a class that inherits from the abstract Activator class. At the beginning of each leg, the activator provides to the mediator the new event handlers which are to be run, using the get_event_handlers_to_run method. (As required by the mediator design pattern, no data flows directly between the activator and the event handlers, although it initially obtains their references, and subsequently manages them.) The activator also returns associated in-state identifiers of particles within the global state. The extracted parts of the global state of these instate identifiers are needed by the event handlers to compute their candidate event times (the identifier may be None if no information is needed).

Once the mediator has committed the preceding event to the global state via the state handler, the activator finally prepares (in the get_trashable_events method) a list of trashable candidate events.

In JF-V1.0, the activator is an instance of the TagActivator class (that inherits from the Activator class). The tag activator's operations depend on the interdependence of tags of event handlers and their events. Event handlers receive their tag by instances of classes located in the activator and derived from the abstract Tagger class that are called ''taggers''.

A tagger centralizes common operations for identically tagged event handlers (see Fig. 8). On initialization, the tagger receives its tag (a string-valued tag attribute) and an event handler (that is, a single instance), of which it creates as many identical eventhandler copies as needed (using the Python deepcopy method). Each tagger provides a yield_identifiers_send_event_ time method which generates in-state identifiers based on the branches containing independent active units (this means that the taggers are implemented especially for the TreeState-Handler. The TagActivator, however, can be used with any state handler since it just transmits the extracted active global state). These in-states are passed (after extracting the part of the global state related to the identifiers from the state handler) to the send_event_time method of the tagger's event handlers.

The number of event handlers inside a tagger should meet the maximum number of events with the given tag simultaneously in the scheduler. In this paper, event handlers (and their candidate events) are referred to by tags, although in JF they do not have the tag attribute of their taggers.

On initialization, a tagger also receives a list of tags for event handlers that it creates, as well as a list of tags for event handlers that need to be trashed. The tag activator converts this information of all taggers into its internal _create_taggers and _trash_taggers dictionaries. Additionally, the tag activator creates an internal dictionary mapping from an event handler onto the corresponding tagger (_event_handler_ tagger_dictionary).

A call of the get_event_handlers_to_run method is accompanied by the event handler which created the preceding event and by the extracted active global state. The event handler is first mapped onto its tagger. The taggers returned by the _create_taggers dictionary then generate the in-state identifiers, which are returned together with the corresponding event handlers (in a dictionary). For the initial call of the get_event_handlers_to_run method no information on the preceding event handler can be provided. This is solved by initially returning the start-of-run event handler. Similarly the _trash_taggers dictionary is used on each call of get_ trashable_events. The corresponding event handlers are then also liberated, meaning that the activator can return them in the next call of the get_event_handlers_to_run method. 4 For this, the activator internally splits the pool of all event handlers of a given tag into those with a scheduled candidate event and the ones that are available to take on new candidate events. The activator also maintains the internal state. In JF-V1.0, the internal state consists of cell-occupancy systems. Therefore, the internal state is an instance of a class that inherits from the CellOccupancy class, which itself inherits from the abstract InternalState class. Taggers may refer to internal-state information to determine the in-states of their event handlers. The cell-occupancy system does not double up on the information available in the state handler. It keeps track of the identifier of a particle (which may correspond to a point mass or a composite point object), but does not store or copy the particle itself (see Section 4.3). The mediator can access the internal state via the get_info_internal_state method (see Fig. 8). To acquire consistency between the global state and the internal state (and between a particle and its associated unit), a pseudo-factor triggers an event for each active unit tracked by the cell-occupancy system that crosses a cell boundary (see Fig. 2b). The internal state is updated in each call of the get_event_handlers_to_run method. 4 The action of the _create_taggers and _trash_traggers dictionaries can be overruled with the concept of activated and deactivated taggers. Event handlers out of deactivated taggers are not returned to the mediator. Fig. 8. Tag activator, and its complex interaction with the mediator. It readies event handlers and in-state identifiers, provides internal-state information for an out-state request, and identifies the trashable candidate events, as a function of the preceding event.

Scheduler

The scheduler is an instance of a class inheriting from the abstract Scheduler class. It keeps track of the candidate events and their associated event-handler references. Its get_succeeding_ event method selects among the candidate events the one with the soonest candidate event time, and it returns the reference of the corresponding event handler. Its push_event method receives a new candidate event time and event-handler reference.

Its trash_event method eliminates a candidate event, based on the reference of its event handler. In JF-V1.0, the scheduler is an instance of the HeapScheduler class. It implements a priority queue through the Python heapq module.

Input-output handler

The input-output handler is an instance of the InputOut-putHandler class. The input-output handler connects the JF application to the outside world, and it is accessible by the mediator. The input-output handler breaks up into one input handler (an instance of a class that inherits from the abstract InputHandler class) and a possibly empty list of output handlers (instances of classes that inherit from the abstract Out-putHandler class). These are accessed by the mediator only via the input-output handler. Output handlers can also perform significant calculations.

The input handler enters the initial global physical state into the application. JF-V1.0 provides an input handler that enters protein-data-bank formatted data (.pdb files) as well as an input handler which samples a random initial state. The initial state (constructed as a tree for the case of the tree state handler) is returned when calling the read method of the input-output handler, which calls the read method of the input handler.

The output handlers serve many purposes, from the output in .pdb files to the sampling of correlation functions and other observables, to a dump of the entire run. They obtain their arguments (for example the entire global state) via its write method. The write method of the input-output handler receives the desired output handler as an additional argument through the mediating methods of specific event handlers. These are triggered for example after a sampling or an end-of-run event. The corresponding event handlers are initialized with the name of their output handlers.

JF event-handler classes

Event-handler classes differ in how they provide the send_ event_time and send_out_state methods. Event handlers split into those that realize factors and sets of factors and those that realize pseudo-factors and sets of pseudo-factors. The first are required by ECMC while the second permit JF to represent the entire run in terms of events.

Event handlers for factors or sets of factors

Event handlers that realize a factor M, or a set of factors, are implemented in different ways depending on the analytic properties of the factor potential U M and on the number of involved independent units.

Invertible-potential event handlers

In JF, an invertible factor potential U M (an instance of a class that inherits from the abstract InvertiblePotential class) has its event rate integrated in closed form along a straight-line trajectory (as in Fig. 1). The sampled cumulative event rate (U + M in [21, Eq. ( 45)]) provides the displacement method. Together with the time stamp and the velocity of the active unit, this determines the candidate event time. In JF-V1.0, the two-leaf-unit event handler (an instance of the TwoLeafUnitEventHandler class) is characterized by two independent units at the leaf level. It realizes a two-particle factor with an invertible factor potential.

The in-state (an argument of the send_event_time method) is stored internally, and it remains available for the subsequent call of the send_out_state method. Because of the two independent units, the lifting simply consists in these two units switching their velocities (using the internal _exchange_velocity method) and keeping the velocities of all induced units consistent.

Event handlers for factors with bounding potential

For a factor potential U M that is not inverted (by choice or by necessity because it is non-invertible), the cumulative event rate U + M is unavailable (or not used) and so is its displacement method. Only the derivative method is used. To realize such a factor without an inverted factor potential, an event handler then uses the displacement method of an associated bounding potential whose event rate at least equals that of U M and that is itself invertible. A non-inverted U M may be associated with more than one bounding potential, each corresponding to a different event handler (the molecular Coulomb factors in Section 5.2 associate the Coulomb factor potential in the same run with different bounding potentials). In JF-V1.0, a number of event handlers are instances of classes that inherit from the EventHandler-WithBoundingPotential class, and that realize factors with bounding potentials. Each of these event handlers translates the sampled displacement of the bounding potential into a candidate event time. On an out-state request (via the send_out_state method), the event handler confirms the event with a probability that is given by the ratio of the event rates of the factor potential and the bounding potential. The out-state consists of independent units together with their branches of induced units. For two independent units, the lifting simply consists in the application of a local _exchange_velocity method, which exchanges independent-unit velocities and enforces velocities for the induced units. For more than one independent unit, the outstate calculation requires a lifting. For an unconfirmed event, no lifting takes place. In JF-V1.0, confirmed and unconfirmed events have time-sliced out-states. The inefficient treatment of unconfirmed events is the main limitation of this version of the application.

A special case of a bounding potential is the cell-based bounding potential which features piecewise cell-bounded event rates. The two independent units are localized within their respective cells, and the bounding potential's rate is for all positions of the units larger than the factor potential event rate. In JF-V1.0, the constant cell-bounded event rate is determined for all pairs of cells on initialization (see Section 4.4.4). The resulting displacement may move the independent active unit outside its cell. The proposed candidate event will then, however, be preempted by a cell-boundary event and therefore trashed (see Section 3.2.1).

Cell-veto event handlers

Cell-veto event handlers (instances of a number of classes that inherit from the abstract CellVetoEventHandler class) realize sets of factors, rather than a single factor. The factor in-states (for each element of the set) are not transmitted with the candidateevent-time calculations. Instead, the branch of the independent active unit is an argument of the send_event_time method. The sampled factor in-state is transmitted with the out-state request.

The cell-veto event handler implements Walker's algorithm [31] in order to sample one element in the set of factors in O(1) operations.

Cell-veto event handlers are instantiated with an estimator (see Section 4.6). In addition, they obtain a cell system which is read in through its initialize method (see Section 4.2). The estimator provides upper limits for the event rate (in the given direction of motion) for the independent active unit anywhere in one specific cell (called the ''zero-cell'', see Section 4.3), and for a target unit in any other cell, except for a list of excluded cells. These upper limits can be translated from the zero-cell to any other active-unit cell, because of the homogeneity of the simulation box. In JF-V1.0, the cell systems for the cell-veto event handler can be on any level of the particles' tree representation (see Section 5.3.4, where a molecule-cell system tracks individual water molecules on the root level, while an oxygen-cell system tracks only the leaf nodes corresponding to oxygens).

A Walker sampler is an instance of the Walker class in the event_handler package. It provides the total event rate (total_rate), which, for a homogeneous periodic system, is a constant throughout a run. On a candidate-event-time request, a cell-veto event handler computes its displacement no longer through the displacement method of a factor potential or a bounding potential, but simply as an exponential random number divided by the total event rate. (The particularly simple send_event_time method of a cell-veto event handler is implemented in the abstract CellVetoEventHandler class, see [21] for a full description.) The Walker sampler's sam-ple_cell method samples the cell of the target unit in O(1). It is returned, together with the candidate event time, as an argument of the send_event_time method. The out-state request is accompanied by the branch of the independent unit in the target cell, if it exists. Confirmation of events and, possibly, lifting are handled as in Section 3.1.2.

Event handlers for pseudo-factors or sets of pseudo-factors

The pseudo-factors of JF unify the description of the ECMC time evolution entirely in terms of events. The distinction between event handlers that realize pseudo-factors and those that realize sets of pseudo-factors remains crucial. In the former, the factor in-state is known at the candidate-event-time request. It is transmitted at this moment and kept in the memory of the event handler for use at the out-state request. For a set of pseudofactors, the factor in-state can either not be specified at the candidate-event-time request, or would require transmitting too much data (one in-state per element of the set). It is therefore transmitted later, with the out-state-request (see Fig. 9).

Cell-boundary event handler

In the presence of a cell-occupancy system, JF-V1.0 preserves consistency between the tracked particles of the global physical state and the corresponding units (which must both belong to the same cell). This is enforced by a cell-boundary event handler, an instance of the CellBoundaryEventHandler class. This event handler has a single independent unit and realizes a pseudofactor with a single identifier. A cell-boundary event leads to the internal state being updated (see Section 2.4).

On instantiation, a cell-boundary event handler receives a cell system. (Each cell-occupancy system requires one independent cell-boundary event handler.) A candidate-event-time request by the mediator is accompanied by the in-state contained in a single branch and a single unit on the level tracked by the cell-occupancy system. An out-state request is met with the celllevel-unit's position corresponding to the minimal position in the new cell.

Event handlers for sampling, end-of-chain, start-of-run, endof-run

Sampling event handlers are instances of classes that inherit from the abstract SamplingEventHandler class. Sampling event handlers are expected to produce output (they inherit from the EventHandlerWithOutputHandler class and are connected, on instantiation, with their own output handler which is used in the mediating method of this event handler). Several sampling event handlers may coexist in one run. Their output handler is responsible for computing physical observables at the sampling event time (see Section 2.6). JF-V1.0 implements sampling events as the time-slicing of all the active units. A sampling event handler thus realizes a set of single-unit pseudo-factors, and the in-state is not specified at the candidate-event-time request. In JF-V1.0, the candidate event times of the sampling event handler are equally spaced. The out-state request is accompanied by branches of all independent active units, which are then all timesliced simultaneously. Sampling candidate events are normally trashed only by themselves or by an end-of-run event.

End-of-chain event handlers are instances of classes that inherit from the abstract EndOfChainEventHandler class. They effectively stop one event chain and reinitialize a new one. This is often required for the entire run to be irreducible (see [21]). The end-of-chain event handler clearly realizes a set of pseudofactors, rather than a single pseudo-factor (see Fig. 9a). An endof-chain event handler implements a method to sample a new direction of motion. In addition, it implements a method to determine a new chain length (that gives the time of the next end-of-chain event) and, finally, the identifiers of the next independent active cnodes. For this, the end-of-chain event handler is aware of all the possible cnode identifiers (see Section 4.2).

On an event-time request, the end-of-chain event handler returns the next candidate event time (computed from the new chain length) and the identifier of the next independent active cnode. The out-state request is accompanied by the current and the succeeding independent active units and their associated branches (see Fig. 9b). For the out-state, the event handler determines the next direction of motion (see Fig. 9c).

A start-of-run event handler (an instance of a class that inherits from the abstract StartOfRunEventHandler class) is the sole event handler whose presence is required. The start-of-run event is the first one to be committed to the global state, because its candidate event time is set equal to the initial time of the run (usually zero) and because the activator will initially only activate the start-of-run event handler. The start-of-run event handler serves two purposes. First, it sets the initial lifting state. Second, the activator uses the start-of-run event handler as an entry point. Its tag (the start_of_run tag in the configuration files of Section 5) is then used to determine the events that should be activated and created thereafter.

The end-of-run event handler (an instance of a class that inherits from the abstract EndOfRunEventHandler class) terminates a run by raising an end-of-run exception and thus ends the mediator loop. An end-of-run event handler is usually connected, on instantiation, with its own output handler. In JF-V1.0, its send_event_time method returns the total run-time, which transits from the configuration file. On the send_out_state request, all active units are time-sliced. The end-of-run output handler may further process the global state which it receives via the mediating method of the end-of-run event handler.

Event handlers for rigid motion of composite point objects, mode switching

The event handlers of JF-V1.0 are generally suited for the rigid motion of composite point objects (root mode), that is, for independent non-leaf-node units (as implemented in Section 5.2.4). This is possible because all event handlers keep the branches of independent units consistent. As the subtree-node units of an independent-unit node move rigidly, the displacement is not irreducible. Mode switching into leaf mode (with single active leaf units) then becomes a necessity in order to have all factors be considered during one run and to assure the irreversibility of the implemented algorithm. In JF-V1.0, the corresponding event handlers are instances of the RootLeafUnitActiveSwitcher class. On instantiation, they are specified to switch either from leaf mode to root mode or vice versa.

These event handlers resemble the end-of-chain event handler, but only one of them is active at any given time. They provide a method to sample the new candidate event time based on the time stamp of the active independent unit at the time of its activation. An out-state request from one of these event handlers is accompanied by the entire tree of the current independent active unit of one mode and met with the tree of the independent active unit on the alternate mode.

JF run specifications and tools

The JF application relies on a user interface to select the physical system that is considered, and to fully specify the algorithm used to simulate it. Inside the application, some of these choices are made available to all modules (rather than having to be communicated repeatedly by the mediator). The application also relies on a number of tools that provide key features to many of its parts.

Configuration files, logging

The user interface for each run of the JF application consists of a configuration file that is an argument of the executable run.py script. 5 It specifies the physical and algorithmic parameters (temperature, system shape and size, dimension, type of point masses and composite point objects, and also factors, factor potentials, lifting schemes, total run time, sampling frequency, etc.).

A configuration file is composed of sections that each correspond to a class requiring input parameters. The [Run] section specifies the mediator and the setting. The ensuing sections choose the parameters in the __init__ methods of the mediator and of the setting. Each section contains pairs of properties and values. The property corresponds to the name of the argument in the __init__ method of the given class, and its value provides the argument (see Fig. 12). The content of the configuration file is parsed by the configparser module and passed to the JF factory (located in the base.factory module) in run.py.

Standard Python naming conventions are respected in the classes built by the JF factory, which implies the naming conventions in the configuration file (see Section 6.3 for details). Within the configuration file, sections can be written in any order, but their explicit nesting is not allowed. Nesting is, however, implicit in the structure of the configuration file.

The JF application returns all output via files under the control of output handlers. Run-time information is logged (the Python logging module is used). Logged information can range from identification of CPUs to the initialization information of classes, run-time information, etc. Logging output (to standard output or to a file) can take place on a variety of levels from DEBUG to INFO to WARNING that are controlled through command-line arguments of run.py. An identification hash of the run is part of the logging output. It also tags all the output files so that input, output and log files are uniquely linked (the Python uuid module is used).

Globally used modules

JF-V1.0 requires that all trees representing composite point objects are identical and of height at most two. Furthermore, in the NVT physical ensemble, the particle number, system size and temperature remain unchanged throughout each run. After initialization, as specified in the configuration file, these parameters are stored in the JF setting package and the modules therein, which may be imported by all other modules, which can then autonomously construct identifiers. Helper functions for periodic boundary conditions (if available) and for the sampling of random positions are also accessible.

JF-V1.0 implements hypercubic and hypercuboid setting modules. Both settings define the inverse temperature and also the attributes of all possible particle identifiers, which are broadcast directly by the setting package. In contrast, the parameters of the physical system are accessed only using the modules of the specific setting (for example the setting.hypercubic_ setting module). 6 The setting package and its modules are initialized by classes which inherit from the abstract Setting class. The HypercuboidSetting class defines only the hypercuboid setting, the HypercubicSetting class, however, sets up both the hypercubic_setting and the hypercuboid_ setting modules together with the setting package. This allows modules that are specifically implemented for a hypercuboid setting to be used with the hypercubic setting. The periodic-cell system's origin is given by the zero_cell property.

Each setting can implement periodic boundaries, by inheriting from the abstract PeriodicBoundaries class and by implementing its methods. Since many modules of JF only rely on periodic boundaries but not on the specific setting, the setting package gives also access to the initialized periodic boundary conditions. Similarly, a function to create a random position is broadcast by the setting package. All the configuration files in Section 5 are for a three-dimensional cubic simulation box, that is, use the hypercubic setting with dimension = 3.

Additional useful modules are located in the JF base package. The abstract Initializer class located in the initializer module enforces the implementation of an initialize method. This method must be called ahead of other public methods of the inheriting class. The strings module provides functions to translate strings from snake to camel case and vice versa, as well as to translate a package path into a directory path. Helper functions for vectors, such as calculating the norm or the dot product, are located in the vectors module.

Cell systems and cell-occupancy systems

A cell-occupancy system is an instance of a class that inherits from the abstract CellOccupancy class, located in the activator.

Any cell-occupancy system is associated with a cell system, itself an instance of a class that inherits from the abstract Cells class.

In JF-V1.0, the cell system consists of a regular grid of cells that are referred to through their indices. Cells can be iterated over with the yield_cells method. For a given cell, the excluded cells are accessed by the excluded_cells method, the successor cell in a suitably defined direction by the successor method and the lower and the upper bound position in each direction through the cell_min and cell_max methods (see Fig. 10a). Finally, the position_to_cell method returns the cell for a given position. Cell systems with periodic boundary conditions are described as periodic cell systems (instances of classes that inherit from the abstract PeriodicCells class, which itself inherits from the Cells class). Their zero_cell property corresponds to the cell located at the origin. Their relative_cell method receives a cell and a reference cell, and establishes equivalence between the relative and the zero-cell. The inverse to this is the translate method (see Fig. 10b).

A cell-occupancy system (which is located in the activator) associates the identifiers of cell-based particles and of surplus particles with a cell. It also stores active cells, that is, cells that contain an active unit (see Fig. 11). Cell-based and surplus particles in the state handler correspond to units with zero velocity, so that there is no real distinction between units and particles for them. The cell-occupancy system inherits from the abstract InternalState class and therefore provides __getitem__ and update methods. The former returns a particle identifier based on a cell, whereas the latter updates the cell occupancies based on the currently active units. This keeps the internal state consistent with the global state. Moreover, the cell-occupancy may iterate over surplus particle identifiers via the yield_surplus method.

The active cells and the corresponding identifiers of the active units are generated using the yield_active_cells method (see Fig. 11).

JF-V1.0 implements the SingleActiveCellOccupancy class which features only a single active cell and which keeps the active unit identifier among its private attributes. The cell-based particle identifiers are stored in an internal _occupant list, and surplusparticle identifiers are stored in an internal _surplus dictionary mapping the cell indices onto the surplus-particle identifiers.

The stored cell-occupancy system can address different levels of composite particles: one cell-occupancy system may track particles (and units) associated to root nodes, while another may track particles associated with leaf nodes. This is set on initialization via the cell_level property which equals the length of the particle identifier tuple. The concerned cell system is itself set on initialization. An indicator charge allows one to select specific particles on a given level for tracking.

A single run can feature several internal states stored within the activator. These instances may rely on different cell-occupancy systems and cell systems. For consistency between internal states and the global state, each cell-occupancy system requires its own cell-boundary event handler.

Inter-particle potentials and bounding potentials

In JF, potentials play a dual role, not only as factor potentials U M in event handlers but also as bounding potentials for factor potentials U M . Potentials are located in the JF potential package. They inherit from the abstract Potential class and provide a derivative method. They may also inherit from the abstract InvertiblePotential class, and must then additionally provide a displacement method. In JF-V1.0, derivatives and displacements are with respect to the positive change of the active unit along one of the coordinates (indicated through the direction argument). For a potential U(r j -r i ) and direction = 0, the derivative is, for example, given by [ ∂/∂x i U(r j -r i ) ]

.

Inverse-power-law potential, Lennard-Jones potential

The inverse-power-law potential (an instance of the Inverse-PowerPotential class that inherits from the abstract Invert-iblePotential class) concerns the separation vector r ij = r j -r i (without periodic boundary conditions, in d-dimensional space) between a unit j and an active unit i as

U ({i,j}, inv) (r ij , c i , c j ) = c i c j k ⏐ ⏐ ⏐ ⏐ 1 r ij ⏐ ⏐ ⏐ ⏐ p . (6)
Here, k and p > 0 correspond to the prefactor and power parameters set on initialization. The charges c i and c j are entered into the methods of the potential as parameters charge_one and charge_two. This allows one instance of the InversePowerPotential class to be used for different charges. The derivative method is straightforward, while the displacement method distinguishes the repulsive (c i c j k > 0) and the attractive (c i c j k < 0) cases. 11. Cell-occupancy system, an internal state of the activator, with active units accounted for differently from surplus and cell-based particles. Only a fixed number of cell-based particle identifiers are allowed per cell (here one per cell). Surplus-particle identifiers may be iterated over from the outside of the cell-occupancy system with the yield_surplus method. In JF-V1.0, surplus particles form an internal dictionary mapping the cell onto the particle identifier.

The Lennard-Jones potential (an instance of the Lennard-JonesPotential class) implements the Lennard-Jones potential

U ({i,j}, LJ) (r ij ) = k LJ [ ( σ |r ij | ) 12 - ( σ |r ij | ) 6 ] , (7)
where r ij = r j -r i is the separation vector (without periodic boundary conditions, in d-dimensional space) between a unit j and an active unit i. The parameters prefactor and charac-teristic_length set on instantiation correspond to k LJ and σ . This Lennard-Jones potential provides a straightforward derivative method. Its displacement method relies on an algebraic inversion.

Displaced-even-power-law potential

An instance of the DisplacedEvenPowerPotential class that inherits from the abstract InvertiblePotential class, the displaced-even-power-law potential, concerns the separation vector r ij = r j -r i (without periodic boundary conditions, in d-dimensional space) between a unit j and an active unit i

U ({i,j}, depp) (r ij ) = k depp ( |r ij | -r 0 ) p , (8)
where k depp > 0, p ∈ {2, 4, 6, . . . }, and r 0 , respectively, are the parameters prefactor, power, and equilibrium_separation parameters set on instantiation. The derivative and displacement methods are provided analytically.

Merged-image Coulomb potential and bounding potential

An instance of the MergedImageCoulombPotential class that inherits from the abstract Potential class, the mergedimage Coulomb potential is defined for a separation vector r ij = r j -r i (with periodic boundary conditions in a three-dimensional cubic simulation box of side L) between a unit j and an active unit i as

U C (r ij , c i , c j ) = ∑ n∈Z 3 c i c j /|r ij + nL|. (9)
The conditionally convergent sum in Eq. ( 9) can be consistently defined in terms of ''tin-foil'' boundary conditions [32]. It then yields an absolutely convergent sum, partly in real space and partly in Fourier space (see [21, Sect. IIIA]), Eq. ( 10) differs from the tin-foil Coulomb potential in a constant self-energy term that does not influence the derivatives.)

U C (r ij , c i , c j ) = c i c j ⎡ ⎣ ∑ n∈Z 3 erfc(α|r ij + nL|) |r ij + nL| + 4π L 3 ∑ q̸ =(0,0,0) e -q 2 /(4α 2 ) q 2 cos ( q • r ij ) ⎤ ⎦ , (10)
The merged-image Coulomb potential is not invertible. When it serves as a factor potential, bounding potentials provide the required displacement method. JF-V1.0 provides a merged-image Coulomb bounding potential as an instance of the InversePow-erCoulombBoundingPotential class, with

U C,Bounding (r ij , c i , c j ) = c i c j k C /|r ij,0 |. (11)
Here, r ij,0 is the minimum separation vector, that is, the vector between r i and the closest image of r j under the periodic boundary conditions. (The merged-image Coulomb bounding potential thus involves no sum over periodic images.) The constant k C must satisfy

k C ≥ max r∈[-L/2,L/2] 3 |r| 3 x ∂U C (r, 1, 1) ∂x , (12)
so that the factor-potential event rate is bounded. A value k C ≳ 1.5836 (the parameter prefactor) is appropriate for a cubic simulation box. The merged-image Coulomb bounding potential is closely related to the inverse-power-law potential of Eq. ( 6)

with p = 1, although the restriction to the minimum separation vector makes that the latter cannot be used directly.

Cell-based bounding potential

A cell-based bounding potential is an instance of a class that inherits from the abstract InvertiblePotential class.

It bounds the derivative of the factor potential inside certain cell regions by constants. These constants can be computed analytically on demand or even sampled using a separate Monte Carlo algorithm. On initialization, a cell-based bounding potential receives an estimator (see Section 4.6). Also the information about the cell system is transmitted. Then, the cell-based bounding potential iterates over all pairs of cells (making use of periodic boundary conditions) and determines an upper and a lower bound derivative for the factor units being in those cells for each possible direction of motion using the estimator. Here, the cell-based bounding potential is not applied to excluded cells, where the cell-bounded event rate diverges, is simply too large, or otherwise inappropriate. The constant-derivative bound leads to a piecewise linear invertible bounding potential. The call of the displacement method is accompanied by the direction of motion, the charge product, the sampled potential change and the cell separation.

In JF-V1.0, any cell-based bounding potential requires a cellboundary event handler, that detects when the displacement proposed by the displacement method in fact takes place outside the cell for which it is computed.

Three-body bending potential

The SPC/Fw water model of Section 5.3 includes a bending potential (an instance of the BendingPotential class), which describes the fluctuations in the bond angle within each molecule.

For the three units i, j, and k within such a molecule (with j being the oxygen), it is given by

U ({i,j,k}, bending) (r ij , r jk ) = 1 2 k b [ φ {i,j,k} (r ij , r jk ) -φ 0 ] 2 . (13)
Here, φ {i,j,k} (r ij , r jk ) denotes the internal angle between the two hydrogen-oxygen legs. The constants k b and φ 0 are set on initialization of the potential (see [21]). The derivative method is provided explicitly for this potential, which is, however, not invertible.

In JF-V1.0, an associated piecewise linear bounding potential is constructed dynamically by an event handler. 7 Here, the event handler speculates on a constant bounding derivative through its position between two subsequent time-sliced positions of the active unit: q bounding = max{q(r), q(r + v∆t)} + const where q(r) is the potential derivative at r. The interval length |v∆t| and the constant offset are input from the configuration file. Finetuning provides an efficient bounding potential that does not under-estimate the event rate, yet limits the ratio of unconfirmed events.

Lifting schemes

Event handlers with more than two independent units require a lifting scheme (an instance of a class that inherits from the Lifting class). The event handler calls a method of the lifting scheme to compute its out-state. At first, the event handler prepares factor derivatives of relevant time-sliced units. The derivative table (see [21,Figs 2 and 10]) is filled with unit identifiers, factor derivatives and activity information through its insert method. Finally, the event handler calls the get_ active_identifier method that returns the identifier of the next independent active unit. The lifting scheme's reset method deletes the derivative table. It is called before the first derivative is inserted. JF-V1.0 implements the ratio, inside-first and outsidefirst lifting schemes for a single independent active unit (see [21, Sect. IV]).

Estimator

Estimators (instances of a class that inherits from the abstract Estimator class) determine upper and lower bounds on the factor derivative in a single direction between a minimum and maximum corner of a hypercuboid for the possible separations.

For this, they provide the derivative_bound method. Both upper and lower bounds are useful when the potential can have either positive and negative charge products (as happens for example for the merged-image Coulomb potential as a function of the two charges). In general, an estimator compares the factor derivatives for different separations in the hypercuboid to obtain the bounds. These are corrected by a prefactor and optionally by 7 Instance of the FixedSeparationsEventHandlerWithPiecewiseCon-stantBoundingPotential class.

an empirical bound, which are set on instantiation (together with the factor potential).

JF-V1.0 provides estimators which either regard regularly or randomly sampled separations within the hypercuboid. The inner-point and boundary-point estimators vary the separation evenly within the hypercuboid or on the edge of the hypercuboid, respectively. For these separations, the factor potential derivatives (optionally including charges) are compared. Two more estimators consider the interaction between a charged active unit and two oppositely charged target units within a dipole. Here, the factor derivative is summed for the two possible active-target pairs. A Monte-Carlo estimator distributes both the separation and the dipole orientation randomly. The dipoleinner-point estimator varies the separations evenly but aligns the dipole orientation along the direction of the gradient of the factor derivative. The implemented estimators are appropriate for the cookbook examples of Section 5, where the upper and lower bounds on the factor derivatives (and equivalently on the event rates) must be computed for a small number of cell pairs only.

JF cookbook

The configuration files8 in JF-V1.0 introduce the key features of the application by constructing runs for two charged point masses, for two interacting dipoles of charges, and for two interacting water molecules (using the SPC/Fw model). All configuration files are for a three-dimensional cubic simulation box with periodic boundary conditions, and they reproduce published data [21].

As specified in their [Run] sections, the configuration files use a single-process mediator (an instance of the SinglePro-cessMediator class), and the setting package is initialized by an instance of the HypercubicSetting class (see for example Fig. 12). All configuration files in the directory use a heap scheduler (an instance of the HeapScheduler class), a tree state handler (instance of the TreeStateHandler class), as well as a tag activator (an instance of the TagActivator class) in order to activate event handlers, trash candidate events and prepare in-states.

The start_of_run, end_of_run, end_of_chain, and sampling event handlers (that realize common pseudo-factors) are implemented in largely analogous sections across all the configuration files, although their parent sections (that define the corresponding taggers) provide different tag lists for trashing and activation of event handlers. The corresponding tagger sections are presented in detail in Section 5.1.1, and only briefly summarized thereafter.

Interacting atoms

The configuration files in the coulomb_atoms directory of JF-V1.0 implement the ECMC sampling of the Boltzmann distribution for two identical charged point masses. They interact with the merged-image Coulomb pair potential and are described by a Coulomb pair factor. One of the two point masses is active, and it moves either in the +x, +y, or +z direction. Statistically equivalent output is obtained for the merged-image Coulomb pair potential (the factor potential) associated with the inversepower bounding potential (Section 5.1.1), or else with a cell-based bounding potential, either realized directly (Section 5.1.2), or through a cell-veto event handler (Section 5.1.3). Although the configuration files use the language of Section 1.2 for the representation of particles, all trees and branches are trivial, and each root node is also a leaf node.

Atomic factors, inverse-power Coulomb bounding potential

The configuration file coulomb_atoms/power_bounded.ini implements a single Coulomb pair factor with the merged-image Coulomb factor potential that is associated with its inverse-power Coulomb bounding potential. The same event handler realizes this factor for any separation of the point masses. The activator requires no internal state.

Although it would be feasible to directly implement (that is, hard-wire) all event handlers for this simple system, the tag activator is used. All event handlers are thus accessed via taggers that are listed, together with their tags, in the [TagActivator] section (see Fig. 13 for a tree representation of the sections).

The coulomb tagger is an instance of the FactorTypeMapIn-StateTagger class, indicating that its event handlers require a specific in-state created from a pattern stored in a file indicated in the [FactorTypeMaps] section. This pattern mirrors the factor index sets and factor types for a system with two root nodes. The entry [0, 1], Coulomb in this file indicates that, for two point masses, a Coulomb potential would act between particles 0 and 1. From this information, the tagger's yield_identifiers_send_event_time method generates all the in-state identifiers for any number of point masses.

The [Coulomb] section specifies input for the coulomb tagger's tag lists (the creates list and the trashes list). Here, a coulomb event creates and trashes only coulomb candidate events (see the configuration file of Section 5.3.1 for different tag lists for the same coulomb event handlers).

The [Coulomb] section further specifies that the coulomb event handler is an instance of the TwoLeafUnitBoundingPo-tentialEventHandler class and that, for two point masses, only one coulomb event handler is needed. The corresponding section 9 specifies the factor potential to be an instance of the MergedImageCoulombPotential class. It specifies the bounding potential as an instance of the InversePowerCoulomb-BoundingPotential class. The sampling, end_of_chain, start_of_run and end_of_run taggers are all instances of the NoInStateTagger class (their event handlers require no instate), and also provide their event handlers and their tag lists, which are then transmitted to the tag activator. Each of these taggers' yield_identifiers_send_event_time methods yields 9 The [TwoLeafUnitBoundingPotentialEventHandler] section. The section name may be replaced by an alias to respect the tree structure of the configuration file (see Section 5.2.1). ⃝). The configuration file coulomb_atoms/power_bounded. ini can be modified for N point masses. In the [RandomIn-putHandler] section, the number of root nodes must then equal N. In the [Coulomb] section, the number of event handlers must be set to at least N -1 (this instructs the Coulomb tagger to deepcopy the required number of event handlers). Without changing the factor-type map with respect to the N = 2 case, each event handler will be presented with the correct in-state corresponding to a pair of units with one of them being the active unit. The complexity of the implemented algorithm is O(N) per event.

Atomic factors, cell-based bounding potential

The configuration file coulomb_atoms/cell_bounded.ini implements a single Coulomb pair factor with the merged-image Coulomb potential, just as the configuration file of Section 5.1.1. However, a cell-occupancy internal state associates the factor potential with a cell-based bounding potential. The target (nonactive) unit may be cell-based or surplus (see Fig. 11). The target unit may also be in an excluded nearby cell of the active cell (see Fig. 10), for which the cell-based bounding potential cannot be used. In consequence, three taggers correspond to distinct event handlers that together realize the Coulomb pair factor. The consistency requirement of JF-V1.0 assures that particles and units are always associated with the same cell.

Taggers and their tags are listed in the [TagActivator] section. The coulomb_cell_bounding tagger, for example, appears as an instance of the CellBoundingPotentialTagger class. The coulomb_cell_bounding event handler then realizes the Coulomb factor unless the cell of the target particle is excluded with respect to the active cell and unless it is a surplus particle (in these cases the tagger does not generate any in-state for its event handler). Otherwise, the Coulomb pair factor is realized by a coulomb_surplus or a coulomb_nearby event handler. (For two units, as the active unit is taken out of the cell-occupancy system, no surplus candidate events are ever created.)

The cell-occupancy systems (an instance of the SingleActiveCellOccupancy class) are also declared in the [TagActivator] section and further specified in the [Single-ActiveCellOccupancy] section. The associated cell system is described in the [CuboidPeriodicCells] section. The internal state, set in the [SingleActiveCellOccupancy] section, has no charge value. This indicates that the identifiers of all particles at the cell level (here cell_level = 1) are tracked (see Section 5.3.2 for an example where this is handled differently).

The coulomb_nearby tagger, an instance of the Exclud-edCellsTagger class, yields the identifiers of particles in excluded cells of the active cell, by iterating over excluded cells and by checking whether they contain appropriate identifiers.

In the same way, the coulomb_surplus tagger relies on the yield_surplus method of the cell-occupancy system to generate in-states.

To keep the internal state consistent with the global state, a cell-boundary event handler is used in the CellBoundary-Tagger class (together, this builds cell_boundary candidate events). The cell-boundary tagger just yields the active-unit identifier as the in-state used in the corresponding event handler. The configuration file coulomb_atoms/cell_bounded.ini reproduces published data (see Fig. 14,3 ⃝). To adapt the configuration file for N > 2 point masses (from the N = 2 case that is provided), in the [RandomIn-putHandler] section, number_of_root_nodes must be set to N. The number of coulomb_cell_bounding, coulomb_nearby, and coulomb_surplus event handlers must be increased. Surplus particles can now exist. The number of event handlers to allow for depends on the cell system, whose parameters must be adapted in order to limit the number of surplus particles, and also to retain useful cell-based bounds for the Coulomb event rates.

Atomic factors, cell-veto

The configuration file coulomb_atoms/cell_veto.ini implements a Coulomb pair factor together with the merged-image Coulomb potential. A cell-occupancy internal state is used. The Coulomb pair factor is then realized, among others, by a cellveto event handler, which associates the merged-image Coulomb potential with a cell-based bounding potential.

All the Coulomb pair factors of the active particle with target particles that are neither excluded nor surplus are taken together in a set of Coulomb factors, and realized by a single coulomb_cell_veto event handler. The candidate event time can be calculated with the branch of the active unit as the instate, which is implemented in the CellVetoTagger class. (The cell-veto tagger returns the identifier of the active unit.) The event handler returns the target cell (in which the target unit is to be localized) together with the candidate event time. The outstate request is accompanied by the branch of the target unit (if it exists), and the out-state computation is in analogy with the case studied in Section 5.1.2.

The configuration file features the coulomb_cell_veto tag together with the coulomb_nearby, coulomb_surplus, cell_boundary, sampling, end_of_chain, start_of_run, and end_of_run tags. The configuration file reproduces published data (see Fig. 14,4 ⃝).

To adapt the configuration file for N point masses, the number of root nodes must be set to N in the [RandomInputHandler] section. The number of event handlers for the coulomb_nearby and coulomb_surplus events might have to be increased. However, a single cell-veto event handler realizes any number of factors with cell-based target particles whereas in Section 5.1.2 each of them required its own event handler.

Interacting dipoles

The configuration files in the dipoles directory of JF-V1.0 implement the ECMC sampling of the Boltzmann distribution for two identical finite-size dipoles, a model that was introduced previously [21]. Point masses in different dipoles interact via the merged-image Coulomb potential (pairs 1-3, 1-4, 2-3, 2-4 in Fig. 15). Point masses within each dipole interact with a short-range potential (pairs 1-2 and 3-4). A repulsive shortrange potential between oppositely charged atoms in different dipoles counterbalances the attractive Coulomb potential at small distances (pairs 1-4 and 2-3). Each dipole is a composite point object made up of two oppositely charged point masses. It is represented as a tree with one root node that has two children. The number of root nodes in the system is set in the [RandomInputHandler] section of the configuration file, where the dipoles are created randomly through the fill_root_node method in the DipoleRandomNodeCreator class. In the setting package, the input handler specifies that there are two root nodes (number_of_root_nodes = 2). Each of them contains two nodes (which is coded as number_of_nodes_per_root_node = 2) and the number of node levels is two (number_of_node_levels = 2). As these numbers are set in the setting package, all the JF modules can autonomously construct all possible particle identifiers.

Statistically equivalent output is obtained for pair factors for all interactions (Section 5.2.1), for dipole-dipole Coulomb factors and their factor potential associated with a cell-based bounding potential (Section 5.2.2), for dipole-dipole Coulomb factors with the cell-veto algorithm (Section 5.2.3), and by alternating between concurrent moves of the entire dipoles with moves of the individual point masses (Section 5.2.4). The latter example showcases the collective-motion possibilities of ECMC integrated into JF. All configuration files here implement the short-range potential as an instance of the DisplacedEvenPowerPotential class with power = 2 and the repulsive short-range potential as an instance of the InversePowerPotential class with power = 6.

Atomic Coulomb factors

The configuration file dipoles/atom_factors.ini implements for each concerned pair of point masses a Coulomb pair factor, with the merged-image Coulomb potential associated with the inverse-power Coulomb bounding potential. Several event handlers that are instances of the same class realize these factors, and the number of event handlers must scale with their number. No internal state is declared. Pair factors are implemented for each pair of point masses that interact with a harmonic or a repulsive potential. One of the four point masses is active at each time, and it moves either in the +x, +y, or +z direction.

The configuration file represents composite point objects as trees with two levels (see Section 1.2). Positions and velocities are kept consistent on both levels, although the root-unit properties are not made use of. The tree structure only serves to identify leaf units on the same dipole.

In the configuration file, taggers and tags are listed in the

[TagActivator] section. The coulomb, harmonic, and repulsive taggers are separate instances of the same FactorType MapInStateTagger class, and the corresponding sections set up the corresponding event handlers. Both the harmonic and the repulsive event handlers are instances of the TwoLeafU-nitEventHandler class. Aliasing nevertheless assures a treestructured configuration file (the harmonic tagger is for example declared with a HarmonicEventHandler class which is an alias for the TwoLeafUnitEventHandler class). The coulomb tagger and its event handlers are treated as in Section 5.1.1.

The sampling, start-of-run, end-of-run and end-of-chain pseudo-factors are realized by event handlers that are set up in the same way as in all other configuration files. However, the parent sections differ: the parent of the [InitialChain-StartOfRunEventHandler] section sets the start_of_run tagger, which specifies that after the start_of_run event, new coulomb, harmonic, repulsive, sampling, end_of_chain, and end_of_run event handlers must be activated. The tag lists thus differ from those of the [StartOfRun] section in other configuration files. The configuration file dipoles/atom_factors .ini reproduces published data (see Fig. 15,2 ⃝).

Molecular Coulomb factors, cell-based bounding potential

The configuration file dipoles/cell_bounded.ini implements for each pair of dipoles a Coulomb four-body factor. (The sum of the merged-image Coulomb potentials for pairs 1-3, 1-4, 2-3, 2-4 in Fig. 15 constitutes the Coulomb factor potential.) The event rates for such factors decay much faster with distance than for Coulomb pair factors, and the chosen lifting scheme considerably influences the dynamics (see [21,Sect. IV]). The configuration file installs a cell-occupancy internal state on the dipole level (rather than for the point masses). A cell-bounded event handler then realizes a Coulomb four-body factor with its factor potential associated with an orientation-independent cell-based bounding potential for dipole pairs that are not in excluded cells relative to each other. The configuration file furthermore implements pair factors for the harmonic and the repulsive interactions. One of the four point masses is active at each time, and it moves either in the +x, +y, or +z direction. The configuration file's [TagActivator] section defines all taggers and their corresponding tags. Among the taggers for event handlers realizing the Coulomb four-body factor, the coulomb_cell_bounding tagger differs markedly from the set-up in Section 5.1.2, as the event handler 10 is for a pair of composite point objects. The lifting scheme is set to inside_first 10 Set in the [TwoCompositeObjectCellBoundingPotentialEventHandler] section.

_lifting. The bounding potential is defined in the [Cell-BoundingPotential] section. A dipole Monte Carlo estimator is used for simplicity (see Section 4.6). As it obtains an upper bound for the event rate from random trials for each relative cell orientations, its use is restricted to there being only a small number of cells. The coulomb_nearby and coulomb_surplus taggers are for event handlers realizing the Coulomb four-body factor when the bounding potential cannot be used. In this case, the merged-image Coulomb potential is summed not only for the factor potential, but also for the bounding potential. 11 The standard sampling, end_of_chain, end_of_run, and start_of_run taggers as well as the ones responsible for the harmonic and repulsive potentials are set up in a similar way as in Section 5.2.1.

The [TagActivator] section defines the internal state that is used by the coulomb_cell_bounding, coulomb_nearby, and coulomb_surplus taggers. The [SingleActiveCellOccupancy] section specifies the cell level (cell_level = 1 indicates that the particle identifiers have length one, corresponding to root nodes, rather than length two, which would correspond to the dipoles' leaf nodes). Positions and velocities must thus be kept consistent on both levels. The cell-occupancy system requires the presence of a cell_boundary event handler, again on the level of the root nodes. This event handler is aware of the cell level, and it ensures consistency of the events triggered by the cell-based bounding potential with the underlying cell system. The configuration file dipoles/cell_bounded.ini reproduces published data (see Fig. 15,3 ⃝).

Molecular coulomb factors, cell-veto

The configuration file dipoles/cell_veto.ini implements the same factors and pseudo-factors and the same internal state as the configuration file of Section 5.2.2. A single cell-veto event handler then realizes the set of factors that relate to cells that are not excluded for any number of cell-based particles, whereas in the earlier implementation, the number of cell-bounded event handlers must exceed the possible number of particles in nonexcluded cells of the active cell. This is what allows to implement ECMC with a complexity of O(1) per event.

The configuration file resembles that of Section 5.2.2. It mainly replaces the latter file's coulomb_cell_bounding event handlers with a coulomb_cell_veto event handler. Slight differences reflect the fact that a cell-veto event handler uses no displacement method of the bounding potential but obtains the displacement from the total event rate (see the discussion in Section 3.1.3). The configuration file dipoles/cell_veto.ini reproduces published data (see Fig. 15,4 ⃝).

Atomic Coulomb factors, alternating root mode and leaf mode

The configuration file dipoles/dipole_motion.ini implements two different modes. In leaf mode, at each time one of the four point masses is active, and it moves either in the +x, +y, or +z direction (see Fig. 16a). In root mode, at each time the point masses of one dipole moves as a rigid block, in the same direction (see Fig. 16b). (The root mode, by itself, does not assure irreducibility of the Markov-chain algorithm, as the orientation and shape of any dipole molecule would remain unchanged throughout the run.) JF-V1.0 represents the dipoles as trees, and both modes are easily implemented. In leaf mode, the Coulomb factors are realized by coulomb_leaf event handlers that are instances of the same class 12 as the coulomb_nearby event handlers in 11 The tree structure of the configuration file is hidden in this case, as the JF factory (which builds instances of classes based on its content) creates separate instances for all the descendants of a section, not requiring the use of aliases.

12 Instances of the TwoCompositeObjectSummedBoundingPotential-EventHandler class. Sections 5.2.2 and 5.2.3. The root mode, in turn, is patterned after the simulation of two point masses (as in Section 5.1.1): all inner-dipole potentials are constant. The inter-dipole Coulomb potentials sum up to an effective two-body potential, the factor potential of a two-body factor realized in a Coulomb-dipole event handler. The repulsive short-range potential between oppositely charged atoms in different dipoles also translates into a potential between the dipoles in rigid motion, and serves as a factor potential of a two-body factor, realized in a specific event handler.

Taggers and their tags are listed in the [TagActivator] section. The harmonic_leaf, repulsive_leaf (leaf-mode) taggers, as well as all those related to event handlers that realize pseudo-factors are as in Section 5.2.1. The coulomb_leaf tagger corresponds to the coulomb_nearby tagger in Section 5.2.2. The coulomb_root and repulsive_root taggers are analogous to those in Section 5.1.1 for the two-atom case.

As all other operations that take place in JF, the switches between leaf mode and root mode are also formulated as events. They are related to two pseudo-factors and realized by a leaf_to_root event handler and by a root_to_leaf event handler, respectively. (These two event handlers are aliases for instances of the RootLeafUnitActiveSwitcher class.) The root_to_leaf and leaf_to_root taggers, in addition to the create and trash lists, set up separate activate and deactivate lists (see Section 2.4). The configuration file reproduces published data (see Fig. 15,5 ⃝). Of particular interest is that the tree representation of composite point objects preserves consistency between leaf-node units and root-node units: the event handlers return branches of cnodes for all independent units (see Fig. 7) whose unit information can be integrated into the global state.

Interacting water molecules (SPC/Fw model)

The configuration files in the water directory implement the ECMC sampling of the Boltzmann distribution for two water molecules, using the SPC/Fw model that was previously studied with ECMC [21]. Molecules are represented as composite point objects with three charged point masses, one of which is positively charged (representing the oxygen) and the two others are negatively charged (representing the hydrogens). Point masses in different water molecules interact via the mergedimage Coulomb potential. In addition, point masses within each molecule interact with a three-body bending interaction, and a harmonic oxygen-hydrogen potential. Finally, any two oxygens interact through a Lennard-Jones potential [21].

In the tree state handler (defined in the [TreeStateHandler] section, a child of the [SingleProcessMediator] section), water molecules are represented as trees with a root node and three children (the leaf nodes of the tree). The total number of water molecules (that is, of root nodes) is set in the [RandomInputHandler] section of each configuration file. The molecules are created through the fill_root_node method in the WaterRandomNodeCreator class. There are two node levels (number_of_node_levels = 2) and three nodes per root node (number_of_nodes_per_root_node = 3). The charges of a molecule are set in the [ElectricChargeValues] section (a descendant of the [WaterRandomNodeCreator] section).

All the configuration files in the water directory of JF-V1.0 implement the pair harmonic factors that are realized through harmonic event handlers. The corresponding taggers are defined in the [Harmonic] sections, with the displaced even-power potential and its parameters set in the [HarmonicEventHandler] and [HarmonicPotential] sections. The configuration files furthermore implement the taggers corresponding to the threebody bending factors in their [Bending] sections. The bending event handler has three independent units (attached to branches). It thus requires a lifting scheme (which is chosen in the [BendingEventHandler] section), which is, however, unique (see [21,Fig. 2]). In all these configuration files, one of the six point masses is active, and it moves either in the +x, +y, or +z direction (the optional rigid displacement of the entire water molecule, could be set up as in Section 5.2.4).

Statistically equivalent output is obtained for a simple set-up featuring pair factors for the Coulomb potential and a Lennard-Jones interaction that is inverted (Section 5.3.1), or for a molecular-factor Coulomb potential associated with a power-law bounding potential and a cell-based Lennard-Jones bounding potential (Section 5.3.2). In addition, the cell-veto algorithm for the Coulomb potential coupled to an inverted Lennard-Jones potential (Section 5.3.3) is also provided. Finally, cell-veto event handlers take part in the realization of complex molecular Coulomb factors and also realize Lennard-Jones factors between oxygens (Section 5.3.4). This illustrates how multiple independent celloccupancy systems may coexist within the same run.

Atomic Coulomb factors, Lennard-Jones inverted

The configuration file water/coulomb_power_bounded_ lj_inverted.ini implements pair Lennard-Jones, harmonic and Coulomb factors. The Coulomb factors are realized for any distance of the point masses by event handlers that associate the merged-image Coulomb potential with its inverse-power Coulomb bounding potential. The Lennard-Jones potential is inverted. This configuration file needs no internal state.

In the configuration file, the [TagActivator] section lists all the taggers together with their tags, which in addition to the taggers related to pseudo-factors, are reduced to coulomb, harmonic, bending, and lennard_jones. The merged-image Coulomb potential, with its associated power-law bounding potential (both for attractive and repulsive charge products), is specified in the [Coulomb] section of the configuration file. The Lennard-Jones potential is invertible and its displacement method is used rather than that of a bounding potential. The output handler is defined in the [OxygenOxygenSeparationOut-putHandler] section, a child of the [InputOutputHandler] section. It obtains all the units, extracts the oxygens through their unit identifier, and records the oxygen-oxygen separation distance. This reproduces published data (see Fig. 17,2 ⃝).

Molecular Coulomb factors, Lennard-Jones cell-bounded

The configuration file water/coulomb_power_bounded_lj_ cell_bounded.ini for the water system corresponds to pair factors for the Lennard-Jones and the harmonic potentials and to molecular factors for the Coulomb interaction. The Coulomb factor potential is the sum of the merged-image Coulomb potential for the nine relevant pairs of point masses (pairs across two molecules). It is realized in a particular event handler, 13 analogously to how this is done for the Coulomb interaction in Sections 5.2.2 and 5.2.3. The associated bounding potential (both for attractive and repulsive charge combinations) is given by the sum over all the individual pairs. Although the Lennard-Jones interaction can be inverted, the configuration file sets up a cell-occupancy internal state that tracks the identifiers for the oxygens. As in previous cases, this leads to three types of events, corresponding to the nearby, surplus, and cell-based particles, in addition to cell-boundary events.

Taggers and their tags are listed in the [TagActivator] section. Taggers are generally utilized as in other configuration files. The internal state is specified in the [TagActivator] section. As set up in the [SingleActiveCellOccupancy] section, it features an oxygen_indicator charge (set in the [Oxy-genIndicator] section). The oxygen-indicator charge is nonzero only for the oxygens. In consequence, the oxygen cell system (defined in the [OxygenCell] section) tracks only oxygens. This reproduces published data (see Fig. 17,3 ⃝).

Molecular Coulomb cell-veto, Lennard-Jones inverted

The configuration file water/coulomb_cell_veto_lj_ inverted.ini for the water system corresponds to the same factors as in Section 5.3.2. As a preliminary step towards the treatment of all long-range interactions with the cell-veto algorithm, in Section 5.3.4, molecular Coulomb factors are realized here (for non-excluded cells of the active cell) with a cell-veto event handler.

Taggers and their tags are listed in the [TagActivator] section, and they are generally similar to those of other configuration files. In addition, the internal state for the Coulomb system is defined in the [TagActivator] section and further described in the [SingleActiveCellOccupancy] section. The latter describes the cell level (which serves for the water molecules) as on the root node level (cell_level = 1), the barycenter of the leaf-node positions of each water molecule. (Root-node and leafnode positions are set in the random input handler, which itself uses a water random node creator.)

The event handlers consistently update all leaf-node positions and root-node positions from a valid initial configuration obtained in an instance of the WaterRandomNodeCreator class. 13 An instance of the TwoCompositeObjectSummedBoundingPoten-tialEventHandler class.

Fast sequential Markov chains

Liang Qin, 1, * Philipp Höllmer, 2, † and Werner Krauth We discuss non-reversible Markov chains that generalize the sweeps commonly used in particle systems and spin models towards a sequential choice from a set of directions of motion. For a simplified dipole model, we show that direction sweeps leave the stationary probability distribution unchanged, but profoundly modify the trajectory of the Markov chain. Choosing a larger direction set can lead to much shorter mixing times. The sequential order is faster than the random sampling from the set. We discuss possible applications of sequential Monte Carlo in polymer physics and molecular simulation.

Since its introduction in 1953, the Markov-chain Monte Carlo (MCMC) method [1] has developed into an essential tool in science and engineering as well as into a ramified mathematical research discipline. [2] The concept of sampling is central to the method. Sampling may consist in generating (representative) integrands or addends to approximate a high-dimensional integral or a sum. Sampling may also refer to the evaluation of representative Feynman diagrams in order to approximate, with purely statistical errors, a perturbative series in quantum field theory. [3,4] The randomness in MCMC, its trademark property, corresponds to samples j at Monte-Carlo time step t being produced from samples i at time step t -1 with the independent probabilities contained in a transition matrix P = P (i, j). The stationary distribution π of samples satisfies the global-balance condition πP = π.

The randomness of the moves may often be reduced without destroying the convergence to π. This was understood for particle systems in the original 1953 reference where, instead of moving randomly sampled particles, ". . . we move each of the particles in succession . . . " (see [1, p.22]). The sequential MCMC algorithm for particle systems is non-reversible, [5,6] as it violates the detailedbalance condition π i P (i, j) = P (j, i)π j that characterizes reversible Markov chains. However, it still satisfies the global-balance condition that is a prerequisite for convergence towards π. The sequential algorithm is somewhat more efficient. [7][8][9] In the Ising model and related systems, sequential spin updates (so called "sweeps") also break detailed balance, and they also lead to moderate speedups compared to the detailed-balance chains that flip spins randomly. [10] In the event-chain Monte Carlo (ECMC) algorithm, [11,12] randomness is drastically reduced in that a particle move, if accepted, is identically repeated for the same particle. If the move is rejected for a given particle, it is identically repeated for the particle that caused the rejection. Lifting variables [13] allow one to formulate the sequential Markov chains and, in particular, ECMC as time-independent transition matrices acting on an extended configuration space. In the present paper, we reduce randomness in MCMC through a sequential selection of directions from a possibly large set D. Specifically, we study a model of a two-dimensional simple dipole. For k steps, all moves of the two atoms composing these dipoles are in direction ±φ, after which all moves are in direction ±(φ+∆φ), etc. (Directions are parametrized by an angle with respect to a fixed axis, say, the x-axis.) We show the special interest of choosing small ∆φ, where, paradoxically, the mixing time of the algorithm can be much shortened. This sequential MCMC algorithm leaves the stationary distribution strictly unchanged. For a single dipole, the nontrivial random walk of the sequence of samples exhibits a statistical force that may accelerate ECMC simulations of long-range interacting N -body systems of extended elements, e.g., complex liquids made up of dipoles, such as water molecules (see [14,15]). It may also apply to reversible or non-reversible MCMC simulations of polymers, dipolar systems or glass models.

For concreteness, we consider a two-dimensional dipole with atoms at x 1 and x 2 and a flat inner-dipole interaction

U (ρ) = 0 if ρ ∈ [r, R], ∞ otherwise, (1)
2 with ρ = |x 2 -x 1 |. This dipole can be envisaged as part of a more complex system of many dipoles with hard-sphere interactions between any two atoms. Periodic boundary conditions are assumed throughout (see Fig. 1a). A standard reversible Metropolis sampling of this system would propose a random displacement of one of the two atoms in a way that satisfies detailed balance. The move would be rejected if it proposes a dipole extension outside the range allowed by eq. ( 1). The sampling can be easily extended to the presence of other dipoles with hard-sphere interactions between atoms. The ECMC algorithm for this system would move an atom in a given direction until ρ = r or until ρ = R and then move the other atom in the same direction (hard-sphere interactions with other dipoles are implemented easily).

With periodic boundary conditions, the configuration space for a single dipole is given by T 2 × Ω with a uniform Euclidean measure, where T 2 is the two-dimensional torus, and Ω a two-dimensional ring of inner radius r and outer radius R. With the potential of eq. ( 1), the Boltzmann weight π factors out translations in T 2 . We may thus set x 1 = (0, 0). The position of the atom 2 is then described by the dipole length ρ and the dipole angle θ (see Fig. 1b). The uniform Euclidean measure translates into a dipole-length distribution π(ρ) = 2ρ/ r 2 η 2 -1 for ρ ∈ [r, R] with η = R/r. The dipole angle θ is uniformly distributed in (-π, π].

In our sequential Markov-chain algorithm, we consider a direction set D = {φ 0 , φ 1 ...φ n-1 }, but propose them in a specific time order t = 0, 1, 2, . . . , rather than to sample from this set at each t. Any direction set spanning R 2 and any sequence taken from this set yields the same stationary distribution π as long as the choice of directions is independent of the configuration. Any continuous stepsize distribution implies that the Markov chain converges towards π. For concreteness, we analyze the case where φ k+1 -φ k = ∆φ is constant, with positive ∆φ. Each value φ l is repeated for k Monte Carlo moves, and we consider the limit k → ∞, in which local equilibrium is reached. For simplicity of notation, we increment the Monte Carlo time t by one at the choice of a new direction (rather than to increment it by k). In the limit k → ∞, the Metropolis algorithm (with an additional non-hopping condition that corresponds to small step size) and ECMC both realize a direct sample [16] under the constraint given by the direction of motion.

We now analyze the motion of the dipole for a given direction φ. Because of x 1 = (0, 0), this is equivalent to the move of atom 2 on a straight line. At time t, the dipole moves on the line l t (which forms the angle φ t ) from x 2 (t) to x 2 (t + 1) (see Fig. 1b). Because of the implicit limit k → ∞, x 2 (t+1) is a uniform random point on the segment of l t ∩ Ω that also contains x 2 (t). The nature of this move depends on the impact parameter:

λ t = sin(θ t -φ t )ρ t /r, (2)
in other words on the signed distance (in units of r) of l t to the origin. (In a reference frame where φ = 0, λ is positive for x 2 in the upper half plane and negative in the lower half plane.) If |λ t | > 1, the line l t forms a single segment S t in Ω. In contrast, if |λ t | < 1, there are two such segments, namely S - t (to the left, in the reference frame in which φ = 0) and S + t (to the right). Then, if |λ t+1 | < 1 (in addition to |λ t | < 1), the dipole is trapped in its segment from time t to t + 1, and the impact parameter decreases if in S + and increases if in S -. This trapping gives rise to a deterministic counter-rotation of the dipole angle with respect to the rotation of the directions, as we will describe later.

The evolution of the impact parameter λ can be described through drift and diffusion terms. The expectation (mean value) of λ t+1 , for a fixed value of λ t , is

E λ t+1 =      λ t cos
For small |∆φ|, the drift E (λ t+1 )λ t (from eq. ( 3)) is proportional to (∆φ) 2 for |λ| > 1, and proportional to ∆φ for |λ| < 1. The fluctuation term of eq. ( 4) is always proportional to (∆φ) 2 . This can be compared to the discrete-time Langevin equation ξ t+1 = ξ t + D (1) (ξ t , t t )τ + D (2) (ξ t , t t )τ w t , (5) where D (1) and D (2) are Kramers-Moyal expansion coefficients, τ is the time step, and w t are Gaussian random numbers (see [17, eq. (3.138)]). For |λ t | > 1, the impact parameter performs what we can call an "excursion", a random walk in the quantity τ = (∆φ) 2 . Such an excursion corresponds to a total number ∆t of time steps (that is, changes of ∆φ) that scales as ∆t ∼ const/(∆φ) 2 and a total angle that diverges as φt -φ0 = ∆t∆φ ∝ 1/∆φ. ( φ differs from φ in that it is rolled out, rather than folded into the interval (-π, π].) During the excursion, the dipole rotates (for ∆φ > 0) in the positive sense (see inset of Fig. 2a). Thus, the difference in the rolled-out dipole angle θ during an excursion diverges as ∼ const/∆φ. This is evidenced by typical trajectories of θt ∆φ as a function of φt ∆φ for different values of ∆φ (see Fig. 2a andb).

For |λ t | < 1, the fluctuation term of eq. ( 4) is negligible for small |∆φ|, and eq. ( 3) (for the upper case) leads to the non-linear differential equation dλ = -A(λ)dφ. Its solution agrees with the trajectories (for |λ| < 1) obtained by numerical simulation (see inset of Fig. 2a). The half-period (in φ), that is, the difference in φ which corresponds to one move from λ = 1 to λ = -1 (or vice versa), is always smaller than π. In the reference frame of constant φ, it rotates in the mathematically negative sense (see the trajectory from B to point D in the inset of Fig. 2a). After one such half-period (which corresponds to roughly constant θ), the dipole either jumps to the other segment (from S + to S -or from S -to S + ) and continues to rotate in the negative sense (creating a "zigzag" for |λ| < 1) or else goes over to an excursion with |λ| > 1. In trajectories of θt ∆φ as a function of φt ∆φ, the zigzags become ever steeper as ∆φ → 0 unlike the excursions, that approach a well-defined limit (see Fig. 2a andb, again).

One zigzag corresponds to a constant negative rotation of θ (as ∆φ → 0) whereas one excursion corresponds to a positive rotation diverging as ∼ const/∆φ. Nevertheless, positive and negative rotations balance, and the expectations E ( θt+∆t -θt ) are all zero. This is trivial for ∆t = 1, as the distribution π( θt+1 -θt ) is symmetric around zero because of detailed balance (see Fig. 3a). Furthermore, θt -θ0 = θtθt-1 + • • • + θ1 -θ0 yields E θt -θ0 = E θtθt-1 + E θt-1 -θt-2 + . . . + E θ2 -θ1 + E θ1 -θ0 = 0, (6) because the expectation of a sum of (possibly dependent) random variables equals the sum of expectations. For ∆t > 1, the distribution of the rolled-out dipole angle can be highly asymmetric, although the random walk remains unbiased (see Fig. 3b). For ∆t const/(∆φ) 2 , the distribution peaks for large θ that corresponds to trajectories that remain on long excursions. For ∆t const/(∆φ) 2 , the distribution approaches a Gaussian (and becomes again symmetric), because excursions and zigzags then compensate for each interval [t, t + ∆t] (see Fig. 3c).

The vanishing of E ( θt+∆t -θt ) implies that many (∝ 1/∆φ) zigzags follow one another in between two excursions of the dipole. Microscopically, this can be understood through the existence of a cutoff value λ cut of the impact parameter (see Fig. 1c). A dipole with |λ t | > λ cut leads to |λ t+1 | > 1, while a dipole with λ cut > |λ t | > 1 may either produce |λ t+1 | > 1 or |λ t+1 | < 1, in which case it may remain trapped in its corresponding segment.

We quantify the convergence of the complicated random walk composed of zigzags and excursions through the total variation distance (TVD) [2,18],

||π t -π|| TVD = 1 2 dx|P t π 0 (x) -π(x)|, (7)
where x stands for all the variables describing the configuration space and π 0 is the most unfavorable initial probability distribution. The time t after which the TVD reaches = 1/4 is defined as the mixing time t mix = t mix (1/4). For < , t mix ( ) is easily bounded through the value for = 1/4. [2] In our case, the distribution π t depends on three variables θ, ρ, and φ. However, ρ relaxes very quickly and φ is a lifting variable without influence on π. We thus consider the TVD for the distribution π θ , that only depends on θ (that is, we integrate over ρ and φ). Finally, we use a δ-function at most unfavorable ρ 0 and θ 0 as an initial distribution π 0 . With these approximations, we systematically study t mix for our sequential MCMC as a function of the set D characterized by ∆φ. We compare the sequential algorithm with random discrete MCMC where the new direction is randomly sampled from D and with random continuous MCMC where ∆φ = ran(0, π). Several properties stand out (see Fig. 4). First, we find that accessing the elements of D sequentially is generically better than randomly sampling the direction from D (see Fig. 4a). (This no longer holds as ∆φ → 0 where the mixing time naturally diverges for sequential MCMC.) The benefits of sequential MCMC are reminiscent of what is known for the sequential particle labeling [7] or for spin sweeps [10]. The mixing time is very sensitive to the size of D. Second, we find that sequential MCMC is faster than the random continuous choice of directions except when |D| is very small. Third, we confirm that for small ∆φ, the very special Markov chain described in the core of this paper indeed has the smallest mixing time. This, in our model, can of course only be observed for η-1 1 because the speedup for small ∆φ is cut off by the divergence of t mix for ∆φ → 0 (see inset of Fig. 4a). Fourth, we find that the sequential Markov chains for generic ∆φ remain peculiar (as they are for small ∆φ). They feature intriguing patterns for λ t and the rolled-out dipole angle θt (see Fig. 4c).

In conclusion, we have discussed in this paper a class of Markov chains with reduced randomness. Our example consisted in the choice of directions from a set. Sequentially accessing the elements of this set left the stationary probability distribution unchanged. It profoundly changed the properties of the Markov chain and clearly reduced mixing times. In real-world MCMC, mixing times and correlation times are often counted in weeks or months. There, the potential benefits of what corresponds in our simplified dipole model to small ∆φ may not be cut off by the ∆φ → 0 divergence of the mixing time. It will thus be fascinating to understand the usefulness of sequential MCMC in applications such as polymer physics and, also, systems of long-range interacting extended molecules at the core of the JeLLyFysh project. [15]

Figure 1 . 1 :

 11 Figure 1.1: Orientational order parameter field of configurations obtained with the massively parallel Monte Carlo algorithm for N = 1024 2 disks. With increasing density, (a) pure liquid (low density), (b) a bubble of hexatic phase (middle density), and (c) a stripe regime of hexatic phase (high density) are visible. (d) A scale bar illustrates the size of the fluctuations. (From Ref [11].)

Figure 1 . 2 :

 12 Figure 1.2: Two simulated states of SARS-CoV-2 protein dynamics. (a) The virus spike protein (orange) is binding human ACE2 (white and blue). (b) A drug molecule (center, multiple colors) is binding the virus' trimetric spike protein. This drug is said to have been approved or investigated by the Food and Drug Agency of the U.S. (From Ref [12].)

Figure 1 . 3 :

 13 Figure 1.3: Examples of Markov chain that motivate aperiodicity and the ergodic theorem. (a) A 4-state space with homogeneous probability, in which the Markov chain switches between {1, 4} and {2, 3}. This chain has period 2. (b) A state violating irreducibility. If many chains start with state 3, they can still reach the distribution π 1 = π 2 = 1/2, π 3 = 0. But for a single chain, it either stays at state 1 or state 2.

Figure 1 . 4 :

 14 Figure 1.4: Schema of stochastic potential switching. The target distribution π is divided into π and π , each simulated with a specific Monte Carlo algorithm. The overall Monte Carlo is fast if one of the subsystems is fast.

Figure 1 . 5 :

 15 Figure 1.5: Different degrees of irreversibility. (a) Reversible Monte Carlo that satisfies f ij = f ji . (b) Locally irreversible Monte Carlo which has the same complexity in traveling the whole space. (c) Globally irreversible Monte Carlo traveling at lower complexity.

1. 4 .

 4 Figure 1.6: Schema of probability allocations under global balance condition. Three algorithms are compared: Metropolis-Hastings, Gibbs samples and Suwa-Todo. Each column represents a state with a solid rectangle and a frame. A valid Markov chain allocates rectangles into frames and the rejection is indicated with self-allocation. (From Ref [57, 58].)

Figure 1 . 7 :

 17 Figure 1.7: Schematic representation of the state space replicas. Dashed lines represent replica switching transitions, which compensate for compressibility of the probability flows associated with solid lines. (From Ref [52].)

  Consider a lifted configuration ((x 1 , ..., x N ), a). The incoming probability flow consists in two parts, as shown in Fig. 2.2, the mass flow (c , a) → (c, a) and the lifting flow (c, b = a) → (c, a) where c = (x 1 , ..., x N ), c = (x 1 , ..., x a -, ..., x N ) and is a small

Figure

  Figure2.1: Process of ECMC evolution with three particles on a plane. We demonstrate here the system evolution under ECMC with three particles in a periodic box. The nine subfigures are the event moments, including eight physical events and one direction switching.

Figure 2 . 2 :

 22 Figure 2.2: Mass flow and lifting flow into the lifted configuration (c, 1), where c is a two-particle state in a box. The mass flow comes from (c , 1) where c is distance behind c. The lifting flow is from the state with particle 2 active. (From Ref [1].)

Figure 2 . 3 :

 23 Figure 2.3: Graphic interpretation of lifting schemes. (a) Two-body factor. (b) (c) Three-body factors. Choices for |I M | ≤ 3 is unique. (d) (e) Five-body factor, for which there are infinite ways to allocate positive bars to negative bars. (From Ref [1].)

Figure 2 . 4 :

 24 Figure 2.4: Redundant flow loop caused by factorization. Three boxes represent the lifted configurations with a common physical state. Each of them has incoming and outgoing mass flows to other physical states, and their potential induces lifting flow in between. By splitting the potential into more than one factor, we effectively impose extra loop to the lifting flow.

Chapter 2 .

 2 Event-chain Monte Carlo p(η), satistifies the equation condition p(0) = 1. By integrating over η, we get p(η) = e -β xa+η xa [∂xU ] + dx = e -βU + (η) (2.3.2) where U + (η) = xa+η xa [∂ x U ] + dx keeps the positive-derivative part of U and is flat otherwise, as exemplified in Fig. 2.5.

Figure 2 . 5 :

 25 Figure 2.5: Sampling of the displacement in an event-driven manner for a potential U M . U + M represents the part of U M with positive derivative. Then an exponential random number is drawn as the energy change. The displacement is calculated and matches the energy change of U + M . (From Ref [1].)

Figure 2 . 6 :

 26 Figure 2.6: Sampling the displacement with the help of bounding potential.

Figure 3 . 1 :

 31 Figure 3.1: Representations of a two-dimensional periodic system. (a) A torus, to which the system is topologically equivalent. (b) Unfolded representation, with repeated images of particles. (Panel (a) is from Ref [1].)

Figure 3 . 2 :

 32 Figure 3.2: Pairwise Coulomb event rates q Clb (r = (x 12 , y 12 , z 12 )) at five different z sections for β = L = c 1 = c 2 = 1, with (a)(b)z 12 = 0.1, (c)(d)z 12 = 0.2, (e)(f)z 12 = 0.3,(g)(h)z 12 = 0.4, and (i)(j)z 12 = 0.5. Subfigures on the left are event rates with the merged-image approach given by Eqs. 3.2.9 and 3.2.10, while those on the right are for separate-image event rates by Eq. 3.2.37. (From Ref[1].)

.2. 14 )Figure 3 . 4 :

 1434 Figure 3.4: Screening charge models. (a) Line-charge model with p = 1. (b) Linecharge model with p = 2. (c) Sheet-charge model. (Panels (b) and (c) are from Ref [1].)

( 3 . 2 . 23 )Figure 3 . 5 :

 322335 Figure 3.5: Two constructs of compensating charge with vanishing quadrupole moment. (a) Volume-charge model. (b) "Kite" model with each line of length L. The target image is in the center of the kite, and four legs of the kite make up a square of side length L/ √ 3.

Figure 3 . 6 :

 36 Figure 3.6: qf,1 (left column) and qf,2 (right column) at six z sections, with each row one z value. They are for z = 0.0, 0.1, 0.2, 0.3, 0.4, 0.5 from top row to bottom row.

Figure 3 . 7 :

 37 Figure 3.7: Distributions of |q Clb | values and errors of several methods. Blue: reference values by Ewald's sum with α = 3.45, real-space cutoff 2 and Fourier-space cutoff 6. Orange: Line-charge method with 5 3 images. Green: Kite-charge method with 5 3 images. Red: Trilinear interpolation using 100 3 grids. Purple: Tricubic interpolation using 100 3 grids. Results are gained through direct sampling, and separation r 12 are drawn evenly from the simulation box.

2 . 39 )Figure 3 . 8 :

 23938 Figure 3.8: Cumulative distribution of |r 12 | of two-charge system with c 1 = c 2 = L = 1 and β = 2.0. We tested three algorithms: Metropolis-Hastings MC, ECMC with merged images, ECMC with separate images. (From Ref [1].)

Figure 3 . 9 :

 39 Figure 3.9: Cell-veto algorithm. (a) Division of simulation box into cells. (b)The cell setup provides a piecewise-constant bounding potential for the two-body interaction, and there are three kinds of events related to it-unconfirmed physical event, confirmed event, and cell-boundary event (labeled by A, B and C respectively). (From Ref[1].)

1 3

 1 at constant density. For O(N ) particles to move constant distance each, it takes O(N 4 3

Figure 3 . 10 :

 310 Figure 3.10: Schema of Walker's algorithm. (a) Cell system. Gray cells are treated as exceptions, while others are to be sampled through Walker's method, but we take five with color for simplicity. (b) Values of q cell with the horizontal line indicating their average. (c) The resulting Walker's table. (Adapted from Ref [95].)

  12 ) = k b c 1 c 2 /|r 12 | serves as a good candidate for Coulomb bounding potential, because they both have a 1/|r| at the origin. The constant k b has to be big enough to bound the Coulomb derivative from above. According to section 3.2.4 k b ≥ max r qf,1 (r) ≈ 1.5836. (3.4.1)

Figure 3 . 11 :

 311 Figure 3.11: Dipole systems. (a) Water model with charged atoms. (b) A big neutral molecule, with each atom charged. (c) Decomposition of the big molecule into dipoles.

.5. 2 )Figure 3 . 12 :

 2312 Figure 3.12: Factorization of Coulomb for two dipoles. (a) Atom factorization. There are four factors, {1,3}, {1,4}, {2,3}, and {2,4}, but only {1,3} is shown. (b) Dipole factorization, and there is only one dipole factor. (From Ref [1].)

Figure 3 . 13 :

 313 Figure 3.13: Lifting schemes for a dipole factor. (a) Two dipoles whose Coulomb interactions are included in a dipole factor. It is assumed that∂ x 1 U M > 0, ∂ x 4 U M > 0, ∂ x 2 U M < 0 and ∂ x 3 U M <0. (b) Ratio lifting scheme. (c) Inside-first lifting scheme. The outflow to activate atoms in the other dipoles is indicated by the mismatch of ∂ x 1 U M and |∂ x 4 U M | that is proportional to 1/|r| 4 . (d) Outside-first lifting scheme. (From Ref [1].)

  2.2 that a factor is represented by (I M , T M ) which are the index set and the type respectively. Two possible factorizations of the Coulomb interaction are Particle factorization :{({1, 3}, Coulomb), ({1, 4}, Coulomb), ({2, 3}, Coulomb), ({2, 4}, Coulomb)},

Figure 3 . 15 : 9 )Fig. 3 .

 31593 Figure 3.15: SPC/Fw water model and corresponding factors. (a) Two H 2 O molecules consisting of six point charges indexed from 1 to 6. (b) Examples of four types of factors: bond, bending, Lennard-Jones, and Coulomb (via dipole factorization). (From Ref [1].)

Figure 3 . 16 :

 316 Figure 3.16: Distribution of the oxygen-oxygen separation through the traditional Monte Carlo and ECMC with a dipole factor and the inside-first lifting scheme. The simulation is done for 32 molecules in a time-driven manner, at temperature 300K and density 1g/cm 3 . (From Ref[1].)

Figure 3 . 18 :

 318 Figure 3.18: Distributions of |r at | at moments when events occur, of Coulomb dipole factor through ratio, inside-first and outside-first lifting schemes. (From Ref [1].)

Figure 3 . 19 :

 319 Figure 3.19: Autocorrelation length λ for the dipole moment in ECMC of a single H 2 O molecule (fixed chain length ) for the cyclic sequence of event-chain directions (xyzxyz...) and for random direction sequence. (From Ref [1].)

Figure

  Figure 4.1: JF event flow. Events occurs at moments E a , E b and E c selected as soonest of candidates. At each event time, some events are trashed while some are created. It refers to specific factors ({a 1 , a 2 , ..., a 5 }, {b 1 , b 2 , ..., b 6 }) in order to generate new candidate events with tags t_1,..., t_5. (From Ref [2].)

Figure 4 . 2 :

 42 Figure 4.2: Example of JF events. (a) Event of a three-body factor. Lifting variables change when the event happens. (b) Cell-boundary crossing as a pseudo-event, in which only the internal state has to change. (From Ref [2].)

Fig. 4 .

 4 3 (a) and (b) show an example of a tree representation of several units and their velocities.

Figure 4 . 3 :

 43 Figure 4.3: Global state and the internal state of JF. (a) Point masses with composite objects. Two composite objects are for the barycenter of molecular components, and a top composite object represents the whole molecule. (b) The tree structure for the molecule in (a). The top node and children of all nodes are numbered so that identifiers can be handily acquired by listing numbers along a path. Solid arrows reflect velocities in (a) while hollow arrows are the induced velocities. (c) Cell occupancies as examples of internal states. JF can simultaneously be equipped with multiple cell occupancies. Here, one is for point mass units, and the other is for composite object units. (From Ref [2].)

  Fig. 4.3 (a) and (b) provide examples of independent active point masses and composite objects, as well as induced active units.

Figure 4 . 4 :

 44 Figure 4.4: JF-V1.0 architecture and the main loop inside the mediator. Boxes indicate modules of JF, each contained in a python package. Arrows imply directional data communication (requests sent from the mediator are not deemed as data). Red dashed boxes represent processes of our multiprocessing trial. Steps inside the mediator describe the main loop's procedure, with each iteration being a leg in Fig. 4.1. (From Ref [2].)

Figure 4 . 5 :

 45 Figure 4.5: Stages of event handlers. Two mandatory methods send_event_time and send_out_state are called by the mediator during the stage of requesting candidate event times and requesting the out-state. idle and suspended stages are for multiprocessing, and actually they are labels in the multi-process mediator. (From Ref [2].)

Figure 4 . 6 :

 46 Figure 4.6: Inner state of tag activator and its interaction with the mediator. Tag activator maintains one or more internal states, a list of taggers and a event handler pool. It communicates with the mediator through three interface functions. Arguments and return values of the functions are shown above and below the method names respectively. (From Ref [2].)

Figure 4 . 7 :

 47 Figure 4.7: Fig:Inner mechanism of tree state handler, with an example of extract_from_global_state.The whole state is stored separately as physical state and lifting state. When the method is called with an argument (0, 3, 0), a new branch is created with new unit instances attached on it and it is passed back to the mediator. (From Ref[2].)

Figure 4 . 8 :

 48 Figure 4.8: Methods of cell system. (a) excluded_cells, successor, cell_min and cell_max for the cell labeled with c. Horizontal and vertical directions are indexed as 0 and 1. These methods are required by Cells abstract class. (b) translate, relative_cell and zero_cell of PeriodicCells class. Two blue-striped cells are identical due to periodic boundary conditions. (From Ref [2].)

Figure 4 . 9 :

 49 Figure 4.9: Cell occupancy classifies the global state into cell-based particles, surplus particles, and active units. (From Ref [2].)

Figure 5 . 1 :

 51 Figure 5.1: Schema of event handler with bounding potential. Displacements concerning only bounding potentials are drawn during send_event_time. Event confirmations and lifting changes are done within send_out_state.

5. 1 .Figure 5 . 2 :

 152 Figure 5.2: Workings of the end-of-chain event handlers. (a) Its operation can be regarded as being triggered by a set of pairwise pseudo-factors containing all particle pairs. The global state at the moment of calling send_event_time is not used to infer the out-state. (b) Global state when the mediator requests the end-of-chain out-state. One of the pseudo-factor triggers the event, and the relevant state is sent to the event handler. (c) The event-handler advances the currently active unit then passes the activity to a new unit, and changes to a new direction of motion. Then it sends back the out-state. (From Ref [2].)

Figure 5 . 3 :Figure 5 . 4 :

 5354 Figure 5.3: Configuration file coulomb_atoms/power_bounded.ini. (a) Signature of the single_process_mediator.__init__ method. (b) Excerpt of configuration file with some lines split for readability (which is not allowed in reality). A configuration file consists of sections, each having several properties and values. The section, properties and values correspond to the class name, __init__ argument names and assigned values, as indicated by the color code of (b). (From Ref [2].)

Figure 5 . 5 :

 55 Figure 5.5: Modification of the configuration file to replace the Coulomb potential with a harmonic potential. Left: Part of the configuration file for Coulomb potential. Right: Part for the harmonic potential.

Fig. 5 .

 5 Fig. 5.5 shows how to change simulated Coulomb potential to a harmonic one.The bounding potential is no longer needed due to the invertibility of harmonic potential.

Figure 5 . 6 :

 56 Figure 5.6: Validation with a two-atom system of section 5.3.1. The cumulative distribution of |r 12 | is plotted on the left and the errors via four methods are given on the right. 1 : Traditional Monte Carlo. 2 : Method described in section 5.3.1.1. 3 : Method described in section 5.3.1.2. 4 : Method described in section 5.3.1.3. (From Ref [2].)

Figure 5 . 7 :

 57 Figure 5.7: Validation with a two-dipole system of section 5.3.2. The cumulative distributions of |r 13 | and |r 14 | are plotted on the left and the errors via five methods are given on the right. 1 : Traditional Monte Carlo. 2 : Method described in section 5.3.2.1. 3 : Method described in section 5.3.2.2. 4 : Method described in section 5.3.2.3. 5 : Method described in section 5.3.2.4. (From Ref [2].)

  3.6.3 ∼ 3.6.5 consisting of harmonic, repulsive and Coulomb interactions. We prepare seven different simulation methods in the directory src/config_files/2018_JCP_149_064113/dipoles. All dipole simulations have parameters β = 1.0, c 1 = -c 2 = c 3 = -c 4 = 1.0, L = 1.0, = 0.78965 with potential prefactors k b = 400, k 2 = 1.0 and r 0 = 0.1.

  .8 (a) and (b) respectively. Results and errors for π(|r 13 |) < 0.22 and π(|r 14 |) < 0.22 are compared in the right table ofFig. 5.7.

Figure 5 . 8 :

 58 Figure 5.8: Two-dipole systems. (a) Leaf mode, in which one atom is independently active and its parent node acquires an induced velocity. (b) Root mode.In the root mode one dipole is translated as a whole, so the root has an independent active unit while its leaves have induced active units.

Figure 5 . 9 :

 59 Figure 5.9: Validation with a two-water-molecule system of section 5.3.3. The cumulative distribution of |r OO | is plotted on the left and the errors via four methods are given on the right. 1 : Traditional Monte Carlo. 2 : Method described in section 5.3.3.1. 3 : Method described in section 5.3.3.2. 4 : Method described in section 5.3.3.3. 5 : Method described in section 5.3.3.4. (From Ref [2].)

Figure 6 . 4 :

 64 Figure 6.4: Cumulative distribution of molecule-center separations for rejected cellveto events. Variable cell sizes are tested and excluded layers are set so that nearest possibility remains the same. Events from empty cells are not counted.

6. 3 .Figure 6 . 5 :

 365 Figure 6.5: Normalized and non-normalized autocorrelation function of P for eight molecules. (a) Non-normalized autocorrelation denoted as C P . (b) Normalized autocorrelation referred to as CP . The time unit here is defined as total displacement divided by eight.

Figure 6 . 6 :

 66 Figure 6.6: P as a function of t for the abnormal case in Fig. 6.5 whose C P (0) ≈ 2.

Figure 6 . 7 :Figure 6 . 8 :

 6768 Figure 6.7: Visualization of an eight-molecule simulation that transitions to a highpolarization state. (a) A normal state, where molecules cluster into a drop. (b) An intermediary state. (c) The high-polarization state, in which eight molecules form a chain crossing the simulated box.

Figure 6 . 9 :

 69 Figure 6.9: CP with variable molecule numbers through the cyclic direction switching scheme with = 0.2N .

Figure 6 . 10 :Figure 6 . 11 :

 610611 Figure 6.10: Normalized C P of eight-molecule simulations with variable molecule translation lengths between cyclic atom mode. (a) Pure atom mode m = 0. (b)

Chapter 7 .Figure 7 . 1 :

 771 Figure 7.1: Configurations and notations of the two-dimensional dipole system. (a) Left: Dipoles on a plane, with the active particle moving in a given direction. Particles interact with hard-disk potential and intra-dipole hard repulsive potential. Middle: The series of direction φ 0 , φ 1 , .... Right: The potential between two particles of a dipole. (b)∼(d) Important notations, with dotted lines representing the direction of motion. (b) and (c) illustrate the case with |λ| < 1 and (d) is for |λ| > 1. (Adapted from Ref [3].)

Figure 7 . 2 :

 72 Figure 7.2: Probability distributions of ρ, |λ| and x = (x, y) with η = 2.0. Results are simulated through Algo. 3 and compared with analytic solutions. Statistics are drawn from 10 8 samples and put into 400 bins in (a) and (b), and into 100 2 grids in (c).

Figure 7 . 3 :Figure 7 . 4 :

 7374 Figure 7.3: Sample trajectories of the rolled-out dipole angle θ and the impact parameter λ, with respect to φ. Axes are rescaled with ∆φ to highlight the similarity with different values of ∆φ. The right column is the initial potions of those in the left column. (a) η = 2.0, ∆φ = π/180. (b) η = 2.0, ∆φ = 0.1π/180. (c) η = 1.01, ∆φ = 85π/180. (Styles are from Ref [3].)

Figure 7 . 6 :

 76 Figure 7.6: Distributions of θt+∆t -θt for different values of ∆t. η = 1.1 and ∆φ = π/180 are taken throughout. Blue dotted vertical lines indicate their zero mean values. Statistics are gained by 10 6 initial points randomly drawn from Ω. (a) ∆t = 1, with the dashed line obtained by numerical integral. (b) Moderate ∆t's. (c) Large ∆t limit. (From Ref Ref [3].)

Figure 7 . 7 :

 77 Figure 7.7: (a) Mixing times for various initial points, with η = 1.1 and ∆φ = π/180. (b) and (c) show the total variation distance with respect to time, for different values of ∆φ. (b) is for η = 1.1 and (c) is for η = 1.01. (Panel (a) is adapted from Ref [3].)

Figure 7 . 8 :Figure 7 . 9 :

 7879 Figure 7.8: Mixing times with respect to D n , for random order (R) and sequential order (S). Dark blue lines in three panels are t mix 's for (D n , S). We compare it with : (a) inverse number of set elements |D n | -1 ; (b) random order (D n , R), and random arbitrary directions D ∞ ; (c) other η values. (Adapt from Ref [3].)

  Michael F. Faulkner,1 Liang Qin, 2 A. C. Maggs,3 and Werner Krauth 2,4 1 H. H. Wills Physics Laboratory, University of Bristol, Tyndall Avenue, Bristol BS8 1TL, United Kingdom 2 Laboratoire de Physique Statistique, Département de physique de l'ENS, Ecole Normale Supérieure, PSL Research University, Université Paris Diderot, Sorbonne Paris Cité, Sorbonne Universités, UPMC Université Paris 06, CNRS, 75005 Paris, France 3 CNRS UMR7083, ESPCI Paris, PSL Research University, 10 rue Vauquelin, 75005 Paris, France 4 Max-Planck-Institut für Physik komplexer Systeme, Nöthnitzer Str. 38, 01187 Dresden, Germany (Received 17 April 2018; accepted 21 July 2018; published online 13 August 2018)

FIG. 1 .

 1 FIG. 1. Mass flow [from (c , 1)] and lifting flow [from (c, 2)] into a lifted configuration (c, 1), corresponding to an accepted and a rejected particle move, respectively [see Eq. (26)]. The total flow should equal the Boltzmann weight π(c) in order to satisfy the global balance condition of Eq. (22).

FIG. 2 .

 2 FIG. 2. Factors and lifting schemes. (a) A factor M consisting of |I M | = 5 particles split into non-empty sets I + M (particles that increase the factor potential) and I - M [see Eqs. (30) and (31)]. [(b)-(e)] Lifting schemes. Unit branching γ k + →k -= 1 and γ k + 1 →k -= 1, γ k + 2 →k -= 1 for a pair-particle factor [(b)] and a three-particle factor with |I - M | = 1 [(c)], and "ratio" lifting scheme for |I M | = 3, |I + M | = 1 [(d)] and for |I M | > 3 [(e), see Eq. (40)].

  For a pair factor (|I M | = 2), each row has one element and the lifting is unique [γ = γ k + →k -= 1; see Fig. 2(b)]. For a three-particle factor (|I M | = 3), if |I + M | = 2, again clearly γ k + →k -= 1 for each one of the particles k + ∈ I + M [see Fig. 2(c)]. If |I + M | = 1 and |I - M | = 2, then Eq. (

  FIG. 4. Cell-veto algorithm for a two-particle factor M. (a) Active particle 1 in cell C 1 and target particle 2 in cell C 2 . (b) The event-rate q M ,1 (r 1 , r 2 ) is bounded from above by the cell-event rate q cell

( 55 )FIG. 5 .

 555 FIG. 5. Periodic two-particle Coulomb system. (a) Toroidal representation corresponding to a merged-image factor. (b) Line-charge representation. The target point-charge particle and each of its copies are compensated by line charges of length 2L. The active particle inside the central simulation box 0, L 3 is not replicated. (c) Compensating volume-charge representation corresponding to "tin-foil" boundary conditions.

FIG. 7 .

 7 FIG. 7. Comparison of the sum of the separate-image event rates n β q({1,2}, Coulombn),1 r 12 + (upper row) and the merged-image event rate β q({1,2}, Coulomb),1 r 12 + (lower row). In all panels r 12 = (x 12 , y 12 , z 12 ) with (a) z 12 = 0.1, (b) z 12 = 0.2, (c) z 12 = 0.3, and (d) z 12 = 0.4. L = 1 and βc 1 c 2 = 1 throughout.

FIG. 8 .

 8 FIG. 8. Cumulative histogram of the pair separation |r 12 | for two particles of equal charge in a periodic three-dimensional simulation box (βc 1 c 2 = 2, L = 1).

FIG. 9 .

 9 FIG. 9. Model of two-particle dipoles. (a) Particle-particle factor associating two point charges that belong to different dipoles. (b) "dipole-dipole" factor comprising four Coulomb interactions.

FIG. 11 .

 11 FIG. 11. Cumulative histograms of the distances |r 13 | [like charges, see Fig. 10(a)] and |r 14 | [opposite charges, see Fig. 10(a)] for the particle-particle factor set of Eq. (100) and also for the factor set of Eq. (97) using dipoledipole Coulomb factors, using the three lifting schemes of Figs. 10(b)-10(d). Also separate-image dipole-dipole factors with inside-first lifting. Periodic cubic simulation box with L = 1, c i = ±1 point charges, β = 1, k b = 400, k 2 = 1, and r 0 = 0.1.

FIG. 12 .

 12 FIG. 12. SPC/Fw water model and ECMC factors. (a) Two H 2 O molecules, with particles 1, 2, 3 and 4, 5, 6 , respectively (2 and 5 being the oxygens). Each of the molecules has a finite dipole moment. (b) "bond," "bending," "LJ," and "Coulomb" factors implementing the SPC/Fw model. Factors contain between two and six particles.

FIG. 14 .

 14 FIG. 14. Cumulative histogram of the oxygen-oxygen separation |r OO | for 32 H 2 O molecules at standard density and temperature via conventional reversible Monte Carlo and ECMC using the factor set of Eq. (102) with the inside-first lifting scheme. The random choice of directions was used with a fixed value of = 0.5 Å. The maximal difference between the two distributions is smaller than 10 -3 .

  https://doi.org/10.1016/j.cpc.2020.107168 0010-4655/© 2020 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY license (http://creativecommons.org/licenses/by/4.0/).

Fig. 1 .

 1 Fig. 1. ECMC time evolution. At events E a , E b , E c , . . . , a number of factors ({a 1 , a 2 , . . . , a 5 }, {b 1 , b 2 , . . . , b 6 }, . . .) are activated. For each leg ((E a → E b ), (E b → E c ), . . . ),

Fig. 2 .

 2 Fig. 2. Factors and pseudo-factors. (a) In-state and sampled out-state (each with two active units) for a three-unit factor M (implementing, for example, the inter-molecular bending potential U M of Section 4.4.5). (b) In-and out-states for a cell-boundary event handler realizing a pseudo-factor. Times at which units are time-sliced are indicated. t out is the event time.

Fig. 3 .

 3 Fig. 3. Tree representation of composite point objects in JF-V1.0. (a) Molecule with functional parts. (b) Tree representation, with leaf nodes for the individual atoms and higher-level nodes for barycenters. Nodes each have a particle (a Particle object) containing a position vector and charge values. A unit (a Unit object), associated with a node, copies out the particle's identifier and its complete global-state information. (c) Internal representation of composite point objects with separate cell systems for particle identifiers on different levels. On the leaf level, only one kind of particle is tracked.

Fig. 4 .

 4 Fig. 4. Parallel ECMC with local potentials (interaction range d). (a) Multiprocess version with n ac ≪ N active units. Nearby active units avoid conflict in a single process. (b) Domain decomposition with separated stripes. Particles in between stripes are immobile. The separation region (of width ∆) is wider than d, so that all

Fig. 9 .

 9 Fig. 9. Set of pseudo-factors realized by the end-of-chain event handler. (a) Set of end-of-chain pair pseudo-factors for four point masses coupling the final active unit of the old chain and the beginning active unit of the new chain. (b) At the event time, the realized pseudo-factor with the incoming active unit and the outgoing unit is known. (c) A new event chain is started. The outgoing active unit is shown.

5

  Configuration files follow the INI-file format and, in JF, feature the extension .ini.6 Attributes in the setting package are copied to the modules for convenience.

Fig. 10 .

 10 Fig. 10. Cell methods. (a) excluded_cells, successor, cell_min and cell_max methods required by the abstract Cells class. Horizontal and vertical directions are indexed as 0 and 1, respectively. (b) translate and relative_cell methods (illustrated by vectors) required by the Periodic-Cells class, in addition to the methods of the Cells class. Periodic boundary conditions are required, and the two blue (north-east hatched) cells are identical.

Fig.

  Fig.11. Cell-occupancy system, an internal state of the activator, with active units accounted for differently from surplus and cell-based particles. Only a fixed number of cell-based particle identifiers are allowed per cell (here one per cell). Surplus-particle identifiers may be iterated over from the outside of the cell-occupancy

  with α a tuning parameter and q = 2π m/L, m ∈ Z 3 . JF-V1.0 provides this class for a cubic simulation box only. Its parameters are optimized to reach machine precision for its derivative method. Summations over n and m are taken within spherical cutoffs, namely for all |n| ≤ position_cutoff and |m| ≤ fourier_cutoff excluding m = (0, 0, 0). (The potential in

Fig. 12 .

 12 Fig. 12. Configuration file coulomb_atoms/power_bounded.ini. (a) A typical __init__ method of a JF class. (b) Excerpts of the configuration file (some lines split for clarity). Sections with properties and values that correspond to the argument names in the __init__ methods of JF classes.

Fig. 13 .

 13 Fig.13. Tree representation of the sections in the configuration file coulomb_atoms/power_bounded.ini. Only part of the tree is shown and names of event handlers for sampling and end-of-chain are shortened. The children of the[TagActivator] section correspond to all the declared taggers, which point towards sections for their associated event-handler classes.

Fig. 14 . 2 ⃝: 4 ⃝:

 1424 Fig. 14. Cumulative histogram of the pair separation |r 12 | (nearest image) for two charges in a periodic three-dimensional cubic simulation box with periodic boundary conditions (βc 1 c 2 = 2, L = 1). 1 ⃝: Reversible Markov-chain Monte Carlo (see [21, Fig. 8]) 2 ⃝: Method of Section 5.1.1 3 ⃝: Method of Section 5.1.2

Fig. 15 . 4 ⃝:

 154 Fig. 15. Cumulative histogram of the pair separation |r 13 | and |r 14 | (nearest image) for two dipoles (see the inset) in a periodic three-dimensional cubic simulation box with periodic boundary conditions (βc i c j = ±1, L = 1). 1 ⃝: Reversible Markov-chain Monte Carlo (see [21, Fig. 11]) 2 ⃝: Method of Section 5.2.1 3 ⃝: Method of Section 5.2.2 4 ⃝: Method of Section 5.2.3 5 ⃝: Method of Section 5.2.4, each with standard errors for π(|r 13 | < 0.22) and π(|r 14 | < 0.22).

Fig. 16 .Fig. 17 . 2 ⃝: 4 ⃝:

 161724 Fig. 16. Two moves implemented in dipoles/dipole_motion.ini. (a) In leaf mode, a single independent active leaf unit has velocity v. The corresponding dipole center (the active root unit) is induced to move at v/2. (b) In root mode, one dipole (independent active root unit) has velocity v, and both its active leaf units have induced velocity v.

FIG. 1 .

 1 FIG. 1. Ring representation of dipole. (a): Dipole atom moving along a fixed direction. (b): Single dipole, with segments S -and S + for impact parameter |λ| < 1. (c): Intersection of lt and lt+1 at x2(t + 1). (d): For φt = 0: lines lt; impact parameter λcut for which all xt+1 satisfy λt+1 > 1.

FIG. 2 .

 2 FIG. 2. Sample trajectories of the rolled-out dipole angle θ (blue, upper) and of |λ| (yellow, lower) for η = 2. Axes are rescaled with ∆φ. Insets: Initial portion of the trajectories. (a): ∆φ = π/180. Sketch I illustrates "excursions" , sketch II "zigzags". (b): ∆φ = 0.1π/180.

FIG. 3 .

 3 FIG. 3. Distributions π( θt+∆t -θt) for η = 1.1 and ∆φ = π/180. (a): ∆t = 1. (b): Distributions for moderate ∆t. (c): Rescaled large-∆t distributions compared to a Gaussian.

FIG. 4 .

 4 FIG. 4. Mixing times and trajectories for general ∆φ (a): tmix at η = 1.005 compared to mixing times of random discrete and continuous MCMC. Inset: tmix for small ∆φ and η 1. (b): Optimal speedup with respect to ∆φ = π/2 and to random continuous MCMC. Inset: Dependence on ρ0 and θ0 for η = 1.1 and ∆φ = π/180. (c): θt and λt for η = 1.01 and ∆φ = 85π/180.

  = (µ

		(p) 1 , µ	(p) 2 , ..., µ	(p) n )
	are defined as
	µ	(p)

i = 1 p number of i s in (X 1 , X 2 , ..., X p ) . (

1

.3.8)

  = (ν

		(p) 1 , ν	(p) 2 , ..., ν	(p) n ) are defined
	as
	ν	(p)

i = 1 p number of i s in (X a 1 , X a 2 , ..., X ap ) . (

1

.3.10)

  3 is the separation of their nearest images. qf,2 has branch cuts at the surfaces x = ±L/2 since x 12 changes its sign when passing from ±L/2to ±L/2 + . Nevertheless, the singularity at the origin disappears, and qf,1 and qf,2 are both continuous for r 12 ∈ [-L/2, L/2] 3 . Fig.3.6 shows their values at six z-sections.

					3.2.8. It is
	noteworthy that the Coulomb derivative with respect to x direction, contains an x/|r| 3
	singularity at the origin. Instead of interpolating qClb we approximate the following
	functions	qf,1 (r 12 ) = qClb	|r 12 | 3 x 12	(3.2.35)
	and	qf,2 (r 12 ) = qClb -	x 12 |r 12 | 3 ,	(3.2.36)
	where r 12 ∈ [-L/2, L/2]

Table 6 .

 6 1: JF speed for 8000-molecule system with variable numbers of cells per side and exclusion layers. The first six columns from left to right are the number of cells, the number of excluded cells, the total cell-veto event rate for Coulomb and Lennard-Jones interactions, the number of surplus particles in molecular cell (for Coulomb), and that for oxygen cell (for Lennard-Jones). The speed in last column is measured in Å per second. Each case is run for 50Å on 2.10GHz Intel Xeon Gold 6230 CPU. The derivative bounds for Coulomb are gained through inner point charge-dipole estimator by treating water molecule as dipole of 0.82 elementary charge and 1.3Å separation, and results are multiplied by 1.2. Lennard-Jones derivative bounds are obtained through a particle-particle inner point estimator with a prefactor of 1.5. All data come from one 8000-molecule configuration in equilibrium produced by LAMMPS. And they are run with a JF version under development so only the relative speeds make sense.

	s)

  and, more generally, to

	0021-9606/2018/149(6)/064113/21/$30.00	149, 064113-1	Published by AIP Publishing.

  3, each with standard errors for π (|r 12 | < 0.6).the in-state identifiers needed by the taggers' event handlers in order to realize corresponding factors or pseudo-factors.The configuration file's [InputOutputHandler] section specifies the input-output handler. It consists of the separationoutput handler (an instance of the SeparationOutputHandler class), which is connected to the sampling event handler. In the present example, it samples the nearest-image separation (under periodic boundary conditions) of any two point masses. The initial global physical state is created randomly by the randominput handler (an instance of the RandomInputHandler class). The configuration file coulomb_atoms/power_bounded.ini reproduces published data (see Fig.14, 2

  1, ‡ 1 Laboratoire de Physique de l'Ecole normale supérieure, ENS, Université PSL, CNRS, Sorbonne Université, Université Paris-Diderot, Sorbonne Paris Cité, Paris, France 2 Bethe Center for Theoretical Physics, University of Bonn, Nussallee 12, 53115 Bonn, Germany (Dated: August 7, 2020)

  ∆φ -A t sin ∆φ if x 2 (t) ∈ S + , λ t cos ∆φ + A t sin ∆φ if x 2 (t) ∈ S -, λ t cos ∆φ if |λ t | > 1,(3)whereA t = 1 2 (B t + C t ) with B t = η 2λ 2 t and C t = 1λ 2 t . The fluctuation term (variance) of the impact parameter λ t+1 is σ 2 (λ t+1 ) = 1 12 sin 2 (∆φ) (B t -C t )

2 if |λ t | < 1 , 1 3 sin 2 (∆φ) B 2 t if |λ t | > 1 .

Direct sampling can be an example of non-Markovian Monte Carlo, but it is not a simulation method.

In Understanding Molecular Simulation by Frenkel and Smit[15], they use Monte Carlo throughout as well, though the Markovian property is obvious.

Imagine that we are simulating protein folding events, then we must have prior knowledge, that is, what configurations are favorable of the folding event.

Typically, if we alternate our Monte Carlo algorithm among MC1, MC2,..., MCn, each with O(1) switching probability, the resulting performance is determined on the fastest one and has minimal dynamic exponent as the fastest one too.

At high temperature, the Ising model has small clusters, so it is easy; at low temperature, it is easy too if the entire-system flipping is introduced.

Converting a discrete space to a continuous one is possible, with artificial constraints and potentials, but there is no study on whether ECMC keeps its advantages under such environment.

Most of the literature classifies hybrid Monte Carlo as a reversible method, perhaps due to the key step 2, which alone is reversible. However, for α > 0 case, (q, p) travels with clear direction.

In the mean-field Ising model, all spins are identical because interactions exist identically for all pairs. Thus for a model of N spins, a state can be represented by a number N + indicating the number of up-spins. This model is essentially a one-dimensional (N + 1)-state model.

In some cases, an observable is also expressed as a complex number, then Eq. 1.5.3 becomes

Using spherical cutoffs for both real-space and Fourier-space terms, instead of cubic cutoffs.

Tuning the parameter α to include more Fourier-space terms than real-space terms, to reduce calls of the error function.

Atom indices must be fixed a priori. Orders in both tables for one physical configuration are invariable throughout the Markov chain. One easy pitfall is that one may tend to place the dipole containing the active atom always to the left, which proves to be wrong. One good practice is to index an atom by a tuple of molecule and atom number (i M , i A ), and sort with relation (i 1 , j 1 ) ≤ (

i 2 , j 2 ) ⇔ i 1 < i 2 or (i 1 = i 2 and j 1 ≤ j 2 ).

It is possible to decompose a H 2 O molecule into two dipoles each with moment 0.41er OH but we believe that it does not make any significant difference from treating a water molecule as one dipole.

It fetches the in-state from the state handler. Identifiers returned by the activator are replaced by corresponding units.

Exceptional cells depend in principle on the potential, while in JF-V1.0 users have to set up in configuration files how many exceptional layers are around the current cell.

 2 It is not like a continuous real number. Two adjacent float numbers always have a tiny gap due to finite-bit

representation.3 Strictly speaking, they return finite-bit floats. Otherwise, the maximum or minimum may not exist in real number set that is not closed.

Strictly speaking, one must call initialize of the base class, so super().initialize has to be called in child class.

Initialization of the state handler is called in SingleProcessMediator.__init__. For the activator, it is called in MediatorAbstractClass.__init__. And for internal state, they are called in Activator. initialize. For event handlers, they are initialized by corresponding tag activators.

Signatures (i.e. the arguments of the __init__ method) of each option must be specified with types as exemplified in Fig.5.3 (a) . If an argument is a JF class, it points to a child node package, and an option must be given. Any JF class is capable of including other JF classes as its signature, thus the object tree can be constructed in an iterative way.

For reference, see https://doc.pypy.org/en/latest/extending.html and https:// cffi.readthedocs.io/en/latest/goals.html.

In addition, a small change is added to avoid intra-molecule Coulomb interaction.

It takes more than two days to run N = 212 by 10 6 Å, to make up Fig.6.11(d)

m = 1Å . (c) m = 5Å . (d) m = 20Å . Error bars are obtained through bootstrapping method. Dotted lines are for y = 1/e.

Note that set elements cannot repeat, and directions that differ by multiples of π are regarded identical. So |D 1 | = 180, |D 30 | = 6, and |D 90 |

= 2.

For concreteness, the lifting variables in this paper are referred to as ''velocities'', although they are not derived from mechanical equations of motions and their conservation laws. The concept of lifting variables is more general[25].

The distinction between particles and units, as well as between nodes and cnodes stresses that the state handler can only be accessed by the mediator, although information on the physical and the lifting state must of course travel throughout the application.

Configuration files in the src/config_files/2018_JCP_149_064113 directory tree are described in this section.

ACKNOWLEDGMENTS M.F.F. acknowledges financial support from EPSRC Fellowship No. EP/P033830/1 and hospitality at Ecole normale supérieure. This work was initiated at the Aspen Center for Physics, which is supported by the National Science Foundation Grant No. PHY-1066293. We thank Matthew Downton for illuminating discussions and Matthias Staudacher for helpful comments. W.K. acknowledges support from the Alexander von Humboldt Foundation and thanks the Santa Fe Institute for hospitality. Acknowledgments P.H. acknowledges support from the Bonn-Cologne Graduate School of Physics and Astronomy honors branch, Germany and from Institut Philippe Meyer. L.Q. and M.F.F. acknowledge hospitality at the Max-Planck-Institut für Physik komplexer Systeme, Dresden, Germany. M.F.F. acknowledges financial support from EPSRC fellowship EP/P033830/1 and hospitality at Ecole normale supérieure. W.K. acknowledges support from the Alexander von Humboldt Foundation. All program files are freely available at http://dx.doi.org/10.17632/srrjt9493d.1, including the configuration files with which all figures can be reproduced. ACKNOWLEDGEMENTS W.K. acknowledges support from the Alexander von Humboldt Foundation. We thank A. C. Maggs for helpful discussions.

The application is complete with sample configuration files, docstrings, and unittests.

Contents

does not necessarily imply changes in the internal state. Luckily, CellBoundary-EventHandler can fully consider this matter and return the event time at which the relevant node crosses a boundary.

Dipole Coulomb factors, cell-veto

The configuration file cell_veto.ini is similar to cell_bounded.ini but uses the cell-veto algorithm instead. It treats dipole factors in normal cells by a Composite-ObjectCellVetoEventHandler instance, which is activated by CellVetoTagger just like the one for atomic factors. The configuration for cell-occupancy, excluded-cell events and cell surplus events are the same as in section 5.3.2.2.

Dipole Coulomb factors, alternating leaf mode, and root mode

The configuration file dipole_motion.ini realizes dipole motion as a whole and switches between the dipole and the atom mode with dipole Coulomb factors. Fig. 5.8 illustrates the two modes. Factor events consist of two kinds-leaf mode events and root mode events. Taggers with a suffix "leaf" activate the leaf mode events. The corresponding tagger classes, event handlers, and other specifications are the same as the file dipole_factor_inside_first.ini.

The root mode has Coulomb and repulsive factor events which are created also by the FactorTypeMapInStateTagger. Then, the root-mode Coulomb event is passed to the RootUnitActiveTwoCompositeObjectSummedBoundingPotentialEventHandler and the root-mode repulsive event is given to the RootUnitActiveTwoLeafUnit-EventHandler. The former requires a pairwise bounding potential and takes the sum over all inter-dipole pairs as the dipole-dipole bounding potential for the dipole Coulomb factor. The latter treats invertible potential exclusively.

In addition, two root-leaf switchers are needed which are activated by the Active-RootUnitInStateTagger. They feature special lists of activation and deactivation as described in section 5.1.4. The root-to-leaf event deactivates all root mode events and activates all leaf mode events while the leaf-to-root event does the contrary.

SPC/Fw water

In order to put JF into a more realistic application, we also test it for two sets of cells and a three-body potential. System parameters are identical to those in section 3.6.2 except that we restrict to two molecules and the system length is L = 10.0Å. The chain length here is set to be 2.12345Å.

We present four methods differing in how to treat the Coulomb and the Lennard-Jones factors. Confirmations and errors are shown in Fig. 5.9. The initial state is created randomly using a WaterRandomNodeCreator instance. We take the oxygenoxygen separation as the observable that are calculated in the OxygenOxygenSepara-tionOutputHandler. Configuration files used in this section are in the JF directory src/config_files/2018_JCP_149_064113/water. For the moment, we concentrate on two water molecules for the sake of demonstration and verification. In chapter 6, we will simulate much larger water systems through JF for performance benchmark. Chapter 6. Realistic water system Figure 6.3: Differences between one and cumulative distribution of charge-water derivative. The simulated box is divided into 40 3 cells indexed from (0, 0, 0) to (39,39,39), and here we focus on two cells, each with 1.28 × 10 9 samples randomly drawn from zero cell and the target cell. (a) Target cell is (4, 1, 0), whose maximum returned by scipy optimization is 8.12. (b) Target cell is (5,6,7), whose maximum is 0.157. Note that q c-w has roughly symmetric distribution around 0, so the curves here starts from (0, 0.5). estimated the cell-based charge-water event rate (at the same time, violations are still reported that the true event rate exceeds the bounding event rate for some cells). Eq. 6.2.1 accounts for 0.918. A factor of eight comes from the occupancy rate, and another factor of four comes from dipole orientations as derived in Eq. 3.5.13. JF may have overestimated 13549/8/4 * 0.918/43 = 9.04 fold.

To understand this loss, we first invoked the scipy estimator for more reliable upper bounds, which returns 9917Å -1 . It accounts for 1.37 of the factor 9.04, and the remaining 6.62 must stem from the molecule's positional variation within a cell, and from simplifying the water molecule as a dipole. Therefore, we employ increasingly finer cells, with 20 3 , 40 3 , and 80 3 cells in total, and set the exclusion cells as 3 3 , 5 3 , and 9 3 so that the nearest molecular pairs treated by the cell-veto algorithm are invariant. We measured the distribution of cell-veto rejection events, namely unconfirmed events from occupied cells. The distribution of molecule-center separations is shown in Fig. 6.4.

The occupied event rates for 20 3 , 40 3 , and 80 3 cells are measured to be 2034Å -1 , 1133Å -1 and 701Å -1 respectively (The event rate for 40 3 cells agrees with total cellveto event rates because 1133 = 9917 * 0.918/8). If 80 3 cells are small enough to eliminate the molecular variation in position, it follows that a factor of 1133/701 = 1.62 originates from finite cell size, and the remaining 701/(43 * 4) = 4.08 is from treating water molecules as ideal dipoles.

In summary, for our standard 8000-molecule-40 3 -cell test case, a typical upper bound of the derivative given by the charge-dipole estimator (here we take 13549Å -1 ) implies Coulomb computations are based on Ewald's formula of electrostatics and the linecharge method. We adapted Ewald's formula to the sum of two-body interactions, and proposed other methods that all converge to tin-foil electrostatics. The dipole factor is an application of the many-body ECMC method. It groups all pairs of Coulomb interactions between two dipoles into one factor. By exploiting the charge-dipole interaction, it is the first Monte Carlo algorithm that achieves O(N log N )-per-sweep complexity. Two specific lifting schemes are also proposed favoring intra-dipole or inter-dipole probabilities flows.

We test our methods with Coulomb atom, dipole, and SPC/Fw water systems.

Appendix B

Publication II This paper summarizes our work described in chapters 4 and 5. There, we lay the foundation of JF, an open-source python application for all-atom simulations. All operations become events in JF. We design the mediator architecture to organize application modules and to realize the event processing. It introduces various modules, including those essential to prepare events and those to implement long-range methods in chapter 3. This paper also features an introduction to JF's development and usage. We give examples, with the same physical systems as in appendix A, to show the functions of event handlers and the way to write configuration files, and to verify JF with high precision.

Consistency will be deteriorated over long runs, but this is of little importance for the simple example case presented here. The configuration file reproduces published data (see Fig. 17,4 ⃝).

Molecular Coulomb cell-veto, Lennard-Jones cell-veto

The configuration file water/coulomb_cell_veto_lj_cell _veto.ini offers no new factors compared to Sections 5.3.2 and 5.3.3, but it uses, for illustrative purposes, two cell-occupancy systems and two cell-veto event handlers. As nearby and surplus particles are excluded from the cell-veto treatment, this implies two sets of cell-veto, nearby, and surplus event handlers in addition to two cell-boundary event handlers. For the molecular Coulomb factors, the cell-veto event handler receives as a factor potential the sum of pairwise merged-image Coulomb potentials with attractive and repulsive charge combinations. The corresponding cell-occupancy system tracks the barycenter of individual water molecules, and consistency between root-node units and leaf-node units is of importance. Although the Lennard-Jones potential can be inverted, the configuration file sets up a second cell-occupancy system for the Lennard-Jones potential. The cell-occupancy system tracks only leaf-node particles that correspond to oxygen atoms.

Taggers and their tags are listed in the [TagActivator] section. This section is of interest as it sets up the internal state as two cell-occupancy systems, both instances of the same Single-ActiveCellOccupancy class. They require different parameters, and are therefore presented under aliases, in the [OxygenCell] and [MoleculeCell] sections. Each of these cell-occupancy systems uses a separate cell system instance of the same class. As the two cell systems have the same parameters, they do not need to be aliased in the configuration file. The configuration file reproduces published data (see Fig. 17,5 ⃝).

License, GitHub repository, Python version

JF, the Python application described in this paper, is an opensource software project that grants users the rights to study and execute, modify and distribute the code. Modifications can be fed back into the project.

License information, used software

JF is made available under the GNU GPLv3 license (for details see the JF LICENSE file). The use of the Python MDAnalysis package [33,34] for reading and writing .pdb files, of the Python Dill package [35,36] for dumping and restarting a run of the application, and of the Python Matplotlib [37] and NumPy [38,39] packages for the graphical analysis of output is acknowledged.

GitHub repository

JeLLyFysh, the public repository for all the codes and the documentation of the application, is part of a public GitHub organization. 14 The repository can be forked (that is, copied to an outside user's own public repository) and from there studied, modified and run in the user's local environment. Users may contribute to the JF application via pull requests (see the JF README.md and CONTRIBUTING.md files for instructions and guidelines). All communication (bug reports, suggestions) take place through GitHub ''Issues'', that can be opened in the repository by any user or contributor, and that are classified in GitHub projects on JeLLyFysh.

14 The organization's url is https://github.com/jellyfysh.

Python version, coding conventions

JF-V1.0 is compatible with Python 3.5 (and higher) and with PyPy 7 (and higher), a just-in-time compiling Python alternative to interpreted CPython (see the JF documentation for details). JF code adheres to the PEP8 style guide for Python code, except for the linewidth that is set to 120 (see the CONTRIBUTING.md file for details).

Following the PEP8 Python naming convention, JF modules and packages are spelled in snake case and classes in camel case (the state_handler module thus contains the StateHandler class). In configuration files, section titles are in camel case and enclosed in square brackets (see Fig. 13).

Versioning of the JF project adopts two-to-four-field version numbers defined as Milestone.Feature.AddOn.Patch. Version 1.0, as described, represents the first development milestone which reproduces published data [21]. Patches and bugfixes of this version will be given number 1.0.0.1, 1.0.0.2, etc. (Finer-grained distinction between versions is obtained through the hashes of master-branch GitHub commits.) New configuration files and required extensions are expected to lead to versions 1.0.1, 1.0.2, etc. Version 1.1 is expected to fully implement different dimensions and arbitrary rectangular and cuboid shapes of the JF potential package. Versions 1.2 and 1.3 will consistently implement n ac ≥ 1 independent active particles (on a single processor) and eliminate unnecessary time-slicing for some events triggered by pseudo-factors and for unconfirmed events. All development from Versions 1.0 to 2.0 can be undertaken concurrently. Fully parallel code is planned for Version 3.0. In JF development, twofield versions (2.0, 3.0, etc.) may introduce incompatible code, while three-and four-field version numbers are intended to be backward compatible.

Conclusions, outlook

As presented in this paper, JF is a computer application for ECMC simulations that we hope will be useful for researchers in different fields of computational science. The JF-V1.0 constitutes its first development milestone: built on the mediator design pattern, it systematically formulates the entire ECMC time evolution in terms of events, from the start-of-run to the end-of-run, including sampling, restarts (that is, end-of-chain), and the factor events. A number of configuration files validate JF-V1.0 against published test cases for long-range interacting systems [21].

For JF-V1.0, consistency has been the main concern, and code has not yet been optimized. Also, the handling of exceptions remains rudimentary, although this is not a problem for the cookbook examples of Section 5.

All the methods are written in Python. Considerable speed-up can certainly be obtained by rewriting time-consuming parts of the application in compiled languages, in particular of the potential package. One of the principal limitations of JF-V1.0 is that pseudo-factor-related and unconfirmed events are time-sliced, leading to superfluous trashing and re-activation of candidate events. Optimized bounding potentials for many-particle factor potentials also appear as a priority.

The consistent implementation of an arbitrary number n ac of simultaneously active particles is straightforward, although it has also not been implemented fully in JF-V1.0. (As mentioned, this is planned for JF (Version 2.0)). This will enable full parallel implementations on multiprocessor machines. Simplified parallel implementations for one-dimensional systems and for hard-disk models in two dimensions are currently being prototyped. The parallel computation of candidate events (using the MultiProcessMediator class implemented in JF-V1.0) is at present rather slow. Bringing the full power of parallelization and of multi-process ECMC to real-world applications appears as its outstanding challenge for JF.

Declaration of competing interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Appendix C

Publication III

Fast sequential Markov chains Liang Qin, Philipp Höllmer, andWerner Krauth arXiv:2007.15615 (2020) This paper is the published result that we obtained in chapter 7. Usually, the naive implementation of ECMC relaxes particles along orthogonal coordinate axes. Here, we propose a scheme with gradual direction changes in order for fast mixing of the dipole angle. A simple dipole with hard potential on a plane is selected for testing purposes. We find that, in contrast to traditional Monte Carlo methods, the sequential Monte Carlo method exhibits distinct patterns in the evolution of the dipole angle, though the estimate of the angle change remains zero. Further tests show that the efficiency of this scheme agrees with the number of elements of the direction set, and the sequential order is always preferable over the random choice from the set.

Appendix

MOTS CLÉS

Méthode de Monte Carlo, chaîne de Markov irréversibles, interaction coulombienne, système de longue portée, simulation moléculaire ABSTRACT This thesis studies the behavior of event-chain Monte Carlo (ECMC) in long-range particle systems. We propose the formula for ECMC to sample in a Coulomb system under periodic boundary conditions. By grouping all Coulomb pairs between two molecules, the dipole factor induces smaller event rates. Together with the cell-veto method, we obtain an O(NlogN)-per-sweep algorithm for dipole systems. Also, we develop a scientific application called JeLLyFysh for molecular simulations through ECMC. JeLLyFysh is designed in a highly extensible way, and is open-source online.

Using JeLLyFysh, we profile the performance of ECMC for large water systems. The resulting dynamics imply that a more sophisticated scheme is needed to equilibrate the polarization. Thus, we test the sampling strategy with sequential direction changes. The dipole evolution exhibits distinct dynamics, and the set of direction choices and the order of selection prove both crucial in mixing the dipole's orientation.

KEYWORDS

Monte Carlo method, irreversible Markov chain, Coulomb interaction, long-range system, molecular simulation