Introduction

The free-energy landscapes of complex interacting systems1 such as spin glasses2,3,4, Lennard-Jones clusters5, supercooled liquids6, proteins7, lattice gas in porous media8, etc. are often characterised by many local minima which are separated by free-energy barriers. Understanding system’s behaviour in such landscapes is a great challenge for experimental, analytical and numerical approaches9.

Exponentially large number of states, the system can be in, restricts exact analysis to only small systems with the number of particles N ~ 102. The state space of the larger systems can be explored approximately by means of numerical techniques such as Monte Carlo (MC) sampling. However, at sufficiently low temperatures the use of conventional MC methods is prohibited by exponentially long transition times over the free-energy barriers. At low temperatures, the system can be trapped in one of the local free-energy minima and thus it fails to ergodically explore the entire state space and achieve equilibrium. This behaviour is know as quasi-nonergodic and it has been, as well as a related broken-ergodicity problem, widely addressed in the literature (see e.g. refs 2, 9,10,11,12,13,14).

Over last decades, numerous MC methods have been developed in order to alleviate the quasi-nonergodicity problem13, 15,16,17. In this paper, we revisit one of the possible approaches developed in refs 18, 19, i.e. the jump-walking (JW) algorithm. As suggested by its name, the JW algorithm allows the system evolving in quasi-nonergodic regime (e.g. at low temperature) to jump into the states sampled from a different distribution (j-distribution) constructed for the system in ergodic regime (high-temperature) prior the beginning of the main simulation. This enables the algorithm to address the quasi-nonergodicity problem, i.e. to overcome free-energy barriers by means of such jumps and ergodically explore the state space even at low temperatures. However, the original JW algorithm used for studying dynamics of small atomic clusters20,21,22 had several drawbacks. First, it did not strictly satisfy the detailed balance23,24,25,26 and thus did not guarantee to achieve correct (Boltzmann) limiting distribution for finite-length simulations. Second, the acceptance rate for jumps can be very low due to small overlap between high- and low-temperature distributions27. Third, high amount of slowly accessible computer memory on hard drive (rather than random-access memory (RAM) at that time) required for construction of the j-distribution highly limited the applicability of the method only to relatively small systems20,21,22. The main rout in further development of the JW algorithm and removing these constraints was through use of multiple walkers. In particular, the constraints of the JW method were addressed by developing several algorithms such as smart-walking28, smart-darting29, cool-walking27, replica-exchange method24, 30, 31 (REM) (also known as parallel tempering3, multiple Markov chain method32, parallel annealing33) and combination of REM with other algorithms34, 35. The key feature of the majority of such approaches is in parallel running and exchange of multiple non-interacting replicas of the original system3, 17, 25 in contrast to a single-replica simulation employed by the JW. Currently, the multiple-replica methods dominate in studying quasi-nonergodic behaviour.

In this paper, we revisit the original JW algorithm, develop it further for the current state of computing technology and explore its new capabilities for studying quasi-nonergodic behaviour of spin and lattice-gas models, which it has never been applied to. We demonstrate, that all the three major drawbacks of the original JW algorithm can be eliminated for a single-replica (single walker) version of the algorithm. This gives an opportunity to study low-temperature dynamics of lattice models of relatively large size (~105 particles) using just a single-core simulations as contrasted to massively parallel (\(\mathop{ > }\limits_{ \tilde {}}\)103 cores36, 37) simulations by REM or similar methods.

The structure of the paper is the following. The description of the original JW algorithm and its development are presented in Section Method. The performance of the improved JW algorithm is discussed for the Ising and lattice-gas models in Section Results and Discussion. Some technical details are shown in Supplementary Information (SI).

Method

The original JW algorithm

Consider a system described by a Hamiltonian H = H(Q) which is in equilibrium with the thermal bath at temperature T (measured in energy units) where Q denotes a state from the set {Q} of all possible states the system can be in (canonical ensemble). Assume that the target temperature T is low enough so that the system is quasi-nonergodic at T. The JW algorithm18, 19 explores the state space by means of the standard MC sampling at T augmented by jumps to the states which have been sampled at higher temperature T′ > T. The temperature T′ is chosen high enough to ensure that the system is ergodic at T′. The states, to which the jumps are attempted to, are sampled according to the equilibrium Boltzmann distribution (thus constructing the j-distribution),

$${P}_{{\rm{B}}}(Q,\beta ^{\prime} )=\frac{{e}^{-{\beta }^{^{\prime} }H(Q)}}{{\sum }_{\{Q\}}{e}^{-{\beta }^{^{\prime} }H(Q)}}=\frac{1}{Z(\beta ^{\prime} )}{e}^{-{\beta }^{^{\prime} }H(Q)},$$
(1)

where Z(β′) stands for the partition function at the inverse temperature β′ = (T′)−1. These additional jumps from states Q i (conventionally sampled at T) to states Q j (sampled at T′) allow for the ergodic sampling of the state space at temperature T if they preserve the detailed balance,

$${\mathbb{P}}({Q}_{i}\to {Q}_{j}){P}_{{\rm{B}}}({Q}_{i},\beta )={\mathbb{P}}({Q}_{j}\to {Q}_{i}){P}_{{\rm{B}}}({Q}_{j},\beta ),$$
(2)

with \({\mathbb{P}}({Q}_{i}\to {Q}_{j})\) being the transition probability between states Q i and Q j .

The transition probability, \({\mathbb{P}}({Q}_{i}\to {Q}_{j})\), can be split into sampling and acceptance probabilities,

$${\mathbb{P}}({Q}_{i}\to {Q}_{j})={P}_{{\rm{s}}}({Q}_{j},\beta ^{\prime} ){P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{i},{Q}_{j}),$$
(3)

where P s(Q j , β′) is proportional to the Boltzman probability at T′. The detailed balance condition given by Eq. (2) imposes a constrain on the acceptance probability P acc,

$$\frac{{P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{i},{Q}_{j})}{{P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{j},{Q}_{i})}={e}^{({\beta }^{^{\prime} }-\beta )(H({Q}_{j})-H({Q}_{i}))},$$
(4)

which is satisfied by the following choice18,

$${P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{i},{Q}_{j})=\,{\rm{\min }}(1,{e}^{(\beta ^{\prime} -\beta )(H({Q}_{j})-H({Q}_{i}))}).$$
(5)

The standard Metropolis expression for P acc is recovered from Eq. (5) as T′ goes to infinity (β′ → 0), since the j-distribution is then uniformly random. On the other hand, if the state space is sampled at the same temperature as that of the j-distribution (β = β′), the detailed balance is maintained with the acceptance probability independent of the state parameters, since the j-distribution itself would already encompass the required transition probability.

Development of the algorithm

Although the original JW algorithm successfully tackled the quasi-nonergodicity problem, its implementation faced technical constraints at time of its creation. As mentioned in the Introduction, they were related to (i) inability to maintain the detailed balance, (ii) inefficiency of jumps between low- and high-temperature states with increasing temperature difference and (iii) low access rate of states in the j-distribution stored on hard drive. In this section, we discuss solutions to these problems and suggest an updated protocol for the JW algorithm, which addresses the mentioned issues. Namely, we show that (i) the detailed balance can be maintained exactly within the new protocol presented below, (ii) the standard temperature-sequence approach can be employed for the JW to increase the jump-acceptance probability and (iii) RAM can be used for accessing the j-distribution.

We start with reviewing of the MC algorithms using “jumpy” protocols for dealing with quasi-nonergodicity which can be considered as developments of the original JW algorithm aiming to improve its performance and avoid its limitations and constrains. They can be broadly classified into two groups one based on multiple walkers (multiple replicas) and another one using one or two walkers. Multiple-replica methods with replica exchange are used to simulate a broad set of systems ranging from spin glasses to bio-systems3, 17, 38, 39 while single-(two-)walker approaches are less popular and mainly used for modelling small atomic clusters20,21,22, 27,28,29. Multiple-walkers algorithms such as multiple-stage JW40, REM30, 31 (parallel tempering23, 24, 41 which originated from simulated tempering42, 43) and annealed swapping26 run in parallel several walkers at temperatures covering the gap between high (ergodic) and low (target) temperature. This allows to increase the jump acceptance probability and preserve the detailed balance in REM and annealed swapping although demanding massively parallel computations36, 37.

Smart-walking (SW) method28, in contrast to REM and similar to JW, uses only two walkers running at high and low temperatures. In contrast to JW, SW before making a jump to a high-temperature distribution performs energy minimisation for high-temperature state and then makes a jump. SW significantly improves the acceptance probability for jumps and permits effective exploration of the energy landscapes especially for protein systems although it does not maintain the detailed balance. This drawback of SW (lack of detailed balance) is addressed by smart-darting (SD)29 algorithm which makes jumps only to neighbouring energy minima, although finding all relevant minima can be problematic for SD in complex landscapes. Cool walking27 suggests a different method for achieving detailed balance in two-walker approach by means of statistical quench performed on configurations sampled by high-temperature walker.

Technically, the detailed-balance problem for the JW algorithm was tackled by two approaches. The first one40 requires multiple parallel simulations at high temperature T′, as well as one run at the target temperature, T < T′. The j-distribution is sampled at runtime by randomly choosing one of the systems simulated at T′ and attempting a transition to its current state. Use of several systems for sampling at high temperature prevents possible correlations, which may appear if sampling from the same simulation is done before it loses memory of the previously sampled state. While this method does not use large amount of memory since the states are sampled at runtime, it is based, similarly to REM, on multiple simulations running at the same time and it was replaced by well established REM maintaining the detailed balance25.

The second approach18 is to perform the initial sampling of the j-distribution at T′ prior to the main simulation and save the recorded states. During the main simulation at T, a random state is periodically chosen from the saved j-distribution. The state could be accepted or rejected according to the Metropolis rule (Eq. (5)). Due to insufficient amount of RAM, the set of states, {Q rec(T′)}, recorded at temperature T′, was kept on hard-drive storage, thus severely limiting access speed and manipulation capabilities. In order to maintain the detailed balance, one had to ensure that the same state from {Q rec(T′)} is not chosen twice25, 44. Within this strategy, the probability of picking the same element in {Q rec(T′)} more than once, decreases as the ratio of the initially recorded and eventually required states increases. However, even if significantly more states were recorded than the simulation at T ultimately needed, this probability would remain finite and the detailed balance would be only approximately obeyed.

Below we suggest a new algorithm which resolves the detailed-balance problem for a single-walker JW method. The key point of our approach is in using RAM for j-distribution which permits easy manipulations with recorded states. In particular, the recorded states stored in RAM can be easily removed once chosen for a possible jump-transition, whether it occurred or not. Moreover, only necessary number of states from j-distribution for its unbiased sampling can be stored thus avoiding any storage overhead.

A further challenge faced by JW as well as REM and related methods arises due to the transition acceptance probability vanishing as the difference between temperatures T and T′ increases25. This hinders access to the states sampled at T′ and thus prevents efficient equilibration of the system. The standard solution to this problem for the JW algorithm45 is to run the simulation sequentially at several temperatures, {T α } \((\alpha =1,\ldots ,n)\), with \({T}_{1} > {T}_{2} > \cdots > {T}_{n}\). The initial temperature T 1, is set high enough so that the system is fully ergodic at T 1 (see SI 1). Any two consecutive temperatures T α and T α+1 are chosen in such a way that the Boltzmann distributions at these temperatures overlap, i.e. there exist states which the system can visit with non-vanishing probabilities at both temperatures. At each temperature T α , the target states Q j for the jump transitions are sampled from {Q rec(T α−1)}, and simultaneously the new j-distribution is constructed by recording the states to {Q rec(T α )}. This way the system remains ergodic at each successive temperature down to T n . In case of REM, a typical solution to the equivalent problem is to employ multiple different temperature replicas running concurrently46, 47.

There has been a lot of work done to optimise the set of selected temperatures for REM48, 49 as well as the JW44, 45 and other methods50. Typically, the temperatures are selected to follow geometric sequence51. If the free-energy landscapes are sufficiently similar across the temperature range (which is not necessary the case e.g. for lattice polymers52 and Lennard-Jones clusters12, 25), the resultant overlaps between the subsets of the state space explored at different consecutive temperatures are comparable. This, in turn, leads to approximately the same acceptance probabilities for replica exchanges or JW jumps. However, in general, the free-energy landscape can be significantly different for different problems (e.g. for proteins39 and structural glasses53, 54). Therefore, the temperature-sequence optimisation strategy can depend on a particular system and preliminary simulations are often necessary to examine the subsets of available states at each temperature and optimise {T α }24. The question of such optimisation is outside the scope of this work. Instead, we provide a general-purpose multi-stage protocol for the JW algorithm given an optimised set of temperatures {T α }. Using this protocol the JW MC simulation run on a single thread can ergodically explore the state space of the system exhibiting quasi-nonergodic behaviour below a certain characteristic temperature T c .

The protocol is as follows:

  1. (i)

    Run the standard single-flip MC simulation at temperature T 1 > T c . Record the current state of the system at equal intervals between the regular MC steps, so that R states are recorded into array {Q rec(T 1)} until the total required number, S, of MC steps is executed.

  2. (ii)

    Decrease the temperature to T α , where T α is the next element in the optimised set of temperatures {T α }, and run the standard single-flip MC simulation again. Choose R step indexes at random from 1 to S and once each of them is reached in the simulation, attempt a transition to a state randomly picked from {Q rec(T α−1)} with the acceptance probability P acc defined by Eq. (5). Whether the transition is accepted or not, remove the suggested state from {Q rec(T α−1)}, so that it cannot be chosen again. In the meantime, continue to record the states as in (i) into the new array {Q rec(T α )}, which now contains an ergodic sample of the state space at T α . Proceed until S MC steps are executed.

  3. (iii)

    Set {Q rec(T α )} as the new {Q rec(T α−1)} from which to sample the j-distribution. Repeat (ii) and (iii) until the final temperature T n in the list {T α } is reached.

The algorithm provides us with two free parameters: R and S. The constraint on precision naturally sets the required number of MC steps, S, to be completed. The interval between the attempted jumps, S/R, is determined by the desired frequency of the jumps, (R/S) × P acc, and limited by how many states R it is feasible to store in memory. For REM, it has been shown that given there were no computational constraints, equilibration accelerates as the replica-exchange frequency increases55, 56. However, since the JW algorithm simulates only one copy of the system at any time, the jump transition, unlike the replica-exchange process in REM, requires to modify larger amounts of data associated with the state of the system. Computational cost of the transition is thus system dependent and could impose an upper bound on the optimal jump rate. Since the attempted states are removed from the storage independently of their acceptance, it is efficient to keep P acc as high as possible, minimising the number of stored states. Therefore, we are only free to adjust R in order to set the required jump rate.

For the purpose of clarity, the above analysis assumes that the average acceptance probability P acc is the same for each {T α }. However, in general, P acc depends on temperature and the constant jump-rate can be achieved by adjusting the number of stored states {R α } for each temperature T α . All simulation parameters used for testing the algorithm are given in SI 1.

Finally, it is straightforward to generalise the JW method for parameter-dependent Hamiltonians in a similar way to that used in the case of multidimensional REM57. For a system described by a Hamiltonian H = H(Q, {λ m }), where {λ m } is a set of parameters (e.g. chemical potential in the case of grand-canonical ensemble), an equivalent formalism leads to a generalised version of the expression for P acc,

$${P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{i},\{{\lambda }_{m}\},{Q}_{j},\{{\lambda }_{m}^{^{\prime} }\})=\,{\rm{\min }}(1,{e}^{\beta ^{\prime} (H({Q}_{j},\{{\lambda }_{m}^{^{\prime} }\})-H({Q}_{i},\{{\lambda }_{m}^{^{\prime} }\}))-\beta (H({Q}_{j},\{{\lambda }_{m}\})-H({Q}_{i},\{{\lambda }_{m}\}))}).$$
(6)

This allows us to sample the non-local transitions from a distribution constructed not only at a different temperature, but also based on Hamiltonian characterised by different values of parameters \({\lambda }_{m}^{^{\prime} }\). An example of such analysis is presented below for the lattice-gas model.

To summarise, the updated JW algorithm described above maintains the detailed balance by storing the j-distribution in RAM and, given an optimised set of temperatures, is able to explore ergodic behaviour of the system for relatively low temperatures at least for some lattice models as demonstrated in Sec.

Results and Discussion

In order to demonstrate the updated JW MC method and further clarify its performance, the algorithm has been implemented for two systems: a standard 3d Ising model and lattice-gas model for condensation of fluid in porous media. Both models, their implementation details and simulation results are described in the following subsections.

Ising model

The Ising model is one of the simplest models exhibiting phase transitions, making it well suited to test the performance of the JW algorithm. Since the memory required to record the states of such system grows linearly with the system size N, the total memory needed to store the multiple recorded states has been prohibitively high and the original JW method18, 19 has never been implemented for the Ising or other spin models. Here, we demonstrate that the updated JW algorithm is capable of handling relatively large systems (N ~ 105) using only the memory of a regular contemporary personal computer and a single CPU core.

As a test example we study a 3d Ising model on a body centred cubic (bcc) lattice of N = 2 × L 3 ferromagnetically interacting spins (with periodic boundary conditions), where L is the number of unit cells along the edge of a cubic sample. The dimensionality and lattice type are convenient for comparison with the lattice-gas models considered below.

The Hamiltonian \({ {\mathcal H} }_{{\rm{I}}}\) of the Ising model with the interaction strength between two neighbouring spins J > 0 (J = 1) in external field H (measured in units of J) is given by,

$${ {\mathcal H} }_{{\rm{I}}}=-\,J\sum _{\langle ij\rangle }{\tau }_{i}{\tau }_{j}-H\sum _{i}^{N}{\tau }_{i},$$
(7)

where the first sum is taken over all the nearest-neighbour spin pairs 〈ij〉 and \({\tau }_{i}\in \{\,+\,1,-\,1\}\) is the spin variable for a spin on site i.

In order to visualise the multi-dimensional state space of the spin system, it is convenient to study its projection onto two dimensions representing magnetisation \(M(\{{\tau }_{i}\})={N}^{-1}{\sum }_{i}^{N}{\tau }_{i}\) (the order parameter) and energy \({ {\mathcal H} }_{{\rm{I}}}(\{{\tau }_{i}\})\) of a microstate {τ i } (see the upper panels in Fig. 1). In general, several spin configurations can have the same values of M and \({ {\mathcal H} }_{{\rm{I}}}\) and it is convenient to define a macrostate \(Q(M,{ {\mathcal H} }_{{\rm{I}}})\), with the degeneracy \(g(Q(M,{ {\mathcal H} }_{{\rm{I}}}))\), as a set of g microstates with the same values of M({τ i }) and \({ {\mathcal H} }_{{\rm{I}}}(\{{\tau }_{i}\})\). As MC sampling is running, the number of MC steps (or total time for kinetic MC58) the system spends in a macrostate \(Q(M,{ {\mathcal H} }_{{\rm{I}}})\) is recorded. In the ergodic regime, this quantity is proportional to the probability distribution for system to be in a certain macrostate and below we refer to it as distribution of visits. The probability to visit some macrostates can be very small and domains of the state space containing such states (far tails of the probability distribution) cannot be explored by the JW algorithm for finite value of parameter S 12 (see Section Development of the algorithm). The results for the distribution of visits are displayed on the M-\({ {\mathcal H} }_{{\rm{I}}}\) plane using the following colour-scheme. On the white background of unexplored state space, the most to the least visited macrostates are coloured in yellow to dark blue, respectively.

Figure 1
figure 1

(a) Upper panel: the probability distribution of visits to macrostates characterised by energy (per spin) \({ {\mathcal H} }_{{\rm{I}}}\) (vertical axis) and magnetisation M (horizontal axis) for the zero-field Ising model described in the text. The distributions of visits at four labelled temperatures are shown. Two distributions for β = 0.17 and β = 0.19 consist of two disconnected regions each located at approximately the same horizontal level. The most visited macrostates are shown in yellow while the less visited ones are in the dark-blue. The white background refers to unvisited macrostates. Lower panel: Free-energy landscapes, i.e. f(M), obtained for four distributions shown in the upper panel. The curves marked by different symbols refer to different temperatures labelled accordingly in the upper panel. (b) The same as in (a) but for non-zero external field H = −5 × 10−4. The values M + and M in the lower panel indicate the positions of minima of f(M) for β = 0.17. The values of other parameters used in simulations are given in SI 1.

Figure 1a illustrates the results of the updated JW MC simulations on a 18 × 18 × 18 bcc lattice (N = 11664) for zero external field H = 0 and several temperatures. At sufficiently high temperatures, all transitions between microstates are approximately equally likely, and therefore mainly the degeneracy of the macrostates determines which part of the state space is visited within the simulation time (see the single-peak distribution of visits around zero magnetisation for β = 0.13 in the upper panel of Fig. 1a). As temperature decreases and occupation of the low-energy states becomes exponentially more probable (according to Eq. (1)), the subspace of explored states shifts to the lower energies (cf. distributions at β = 0.13 and β = 0.16). Moreover, with decreasing temperature, the distribution of visits becomes bi-modal (see e.g. the distribution for β = 0.16) reflecting the symmetry of the spin system with respect to the change of the spin orientation. This is due to the fact that the degeneracy of macrostates with approximately zero magnetisation decreases (with decreasing energy) more rapidly than of those with finite magnetisation. The two peaks in the distribution of visits become more pronounced with further decrease in temperature (cf. distributions at β = 0.17 and β = 0.19) and at T = 0 only two lowest energy states retain non-zero probability, each corresponding to all spins aligned either up or down.

This picture can be described by using the language of the free-energy landscapes, referring to the dependence of the relative free energy \(f(M)\equiv \beta (F(M)-F)\) solely on M, where

$$F=-\,{\beta }^{-1}\,\mathrm{ln}\,Z=-\,{\beta }^{-1}\,\mathrm{ln}\,[\sum _{\{\tau \}}{e}^{-\beta { {\mathcal H} }_{{\rm{I}}}}],$$
(8)
$$F(M)=-\,{\beta }^{-1}\,\mathrm{ln}\,Z(M)=-\,{\beta }^{-1}\,\mathrm{ln}\,[\sum _{{ {\mathcal H} }_{{\rm{I}}}}g(Q(M,{ {\mathcal H} }_{{\rm{I}}})){e}^{-\beta { {\mathcal H} }_{{\rm{I}}}}].$$
(9)

The summation for free energy is taken over all microstates {τ} in Eq. (8) and over all macrostates \(\{Q(M,{ {\mathcal H} }_{{\rm{I}}})\}\) with fixed magnetisation M in Eq. (9). It follows from Eqs (8) and (9) that the value of f(M) = −ln(P(M)) is related to the probability P(M) for the system to be in a state with fixed magnetisation, P(M) = Z(M)/Z. This probability can be estimated from the simulations by integrating the distribution of visits over the energies for fixed value of M. Thus obtained free-energy landscapes, f(M), are shown in the bottom panels of Fig. 1.

For temperatures above some critical value, T c, the relative free energy f(M) has a single minimum at zero magnetisation (see yellow line marked by solid squares in the bottom panel of Fig. 1a). At \(T\approx {T}_{{\rm{c}}}\), two symmetric minima at finite values of M separated by a barrier at \(M\simeq 0\) appear (see red line marked by open squares). With decreasing temperature, the barrier between minima increases, the minima become deeper (see lines marked by the circles) and their positions tend to M = ±1 at zero temperature.

The picture described above cannot be seen by means of MC simulations governed only by the standard single-flip mechanism, because the transitions through the free-energy barrier become exponentially rare with decreasing temperature. Eventually, within the standard single-flip MC simulations, the system settles down in one of the free-energy minima shown in Fig. 1a, thus violating the equilibrium and breaking ergodicity. This does not happen for the JW MC simulations for which the multiple-flip jump transitions to the states recorded at higher temperatures are possible. These transitions enable exploration of all the states proportionally to the canonical distribution at the current temperature thus maintaining an ergodic sampling of the state space and all free-energy minima present at sufficiently low temperatures become achievable within a single JW simulation.

In the presence of the finite external field, e.g. H < 0, (see Fig. 1b), similarly to the zero-field regime, the free-energy minima develop at positive, M +, and negative, M , values of magnetisation (see e.g. the solid line marked by open circles for β = 0.16 in the bottom panel of Fig. 1b). The negative external field breaks the symmetry and makes the minimum at M deeper. The JW algorithm samples the states at both free-energy minima according to the canonical probability distribution. This means that only the energy difference at these minima is significant for their relative occupation and the barrier between the minima is irrelevant for the JW sampling. As the macrostates around M + become ever less probable with decreasing temperature, the jump-transitions from this minimum to the minimum at M are favoured over the reverse ones (see the asymmetric bi-modal distributions of visits at β = 0.16 and β = 0.17 in the upper panel of Fig. 1b). Therefore, the amount of time that the system spends exploring the M + minimum gradually decreases with decreasing temperature (because the energy difference between minima increases) until it eventually vanishes completely for the precision set up within the JW algorithm (see the single-peaked distribution at β = 0.19 in Fig. 1b).

An example of equilibrium behaviour of the Ising model obtained by means of the JW MC simulations contrasted with the results of the single-flip MC is presented in Fig. 2. The standard way to investigate M(H) is to run a conventional single-flip MC simulations at fixed temperature gradually incrementing the external field from sufficiently negative (so that \(M\simeq -\,1\)) to high positive values (\(M\simeq 1\)) and then back again. Under this protocol, a hysteresis loop is observed59 (the areas between solid and dashed lines in Fig. 2 for β = 0.17, 0.19, 0.21). In this hysteresis loop (in some systems found experimentally as well), the magnetisation of the sample starts to align with the external field and then reverse in response to the change in H. Such a hysteresis loop is still observed even if the change of the field takes place adiabatically slowly. This implies that the magnetic material is not in equilibrium and is stuck in a state which it cannot leave on the single-flip MC (or experimental) time-scales with the thermal energy available, i.e. the system gets stuck in a metastable state.

Figure 2
figure 2

Magnetisation reversal, i.e. the mean magnetic moment M vs external field H, for the Ising model defined on bcc lattice with the same parameters as in Fig. 1, for several temperatures as marked in the legend. The data represented by solid (dashed) lines refer to increasing (decreasing) magnetic field and were obtained by the single-flip conventional (kinetic) MC simulations. For equilibrium isotherm at β = 0.13 (\(\blacktriangle \)), the solid and dashed lines coincide. For β = 0.16 (\(\blacktriangledown \)), a small hysteresis loop exists but is not distinguishable on the scale of the graph. The symbols represent results of the JW MC simulations. The inset shows magnified region around H = 0. The solid (open) symbols in the inset refer to the mean magnetisation at energetically favourable (unfavourable) minimum of the free energy. The dotted horizontal lines in the inset serve as a guide for eye representing the value of magnetisation at the deepest minimum in the free-energy landscape. The dotted vertical line marks the transition at H = 0.

The JW MC algorithm provides a possibility to avoid trapping in metastable states, i.e. to remove the hysteresis loop, by sampling the state space according to the canonical equilibrium distribution. Indeed, Fig. 2 (see the solid symbols corresponding to the JW data) shows a clear and expected phase transition at H = 0 below the critical temperature T c (for bcc lattice, \({T}_{{\rm{c}}}^{-1}\simeq 0.157371(1)\) 60). Therefore, the JW MC simulations produce equilibrium isotherms, i.e. M(H), which are obfuscated by hysteresis phenomenon in the single-flip MC simulations or experiment. The inset in Fig. 2 magnifies the transition region. In this region for fixed temperature (below critical) and H close to zero, the JW MC simulations detect two minima of the free-energy, energetically favourable (solid symbols) and unfavourable (open symbols), which are also shown in lower panel of Fig. 1b. The probability to visit these minima follows the canonical equilibrium distribution and thus the accessibility of the energetically unfavourable minimum becomes exponentially small with increasing energy difference between the minima. Eventually, the energetically unfavourable minimum cannot be detected by the JW sampling with fixed precision. This occurs for relatively small deviations of the external field from zero, e.g. |H| ~ 10−3 for β = 0.17. For the single-flip MC simulations, the height of the barrier between the free-energy minima matters and energetically unfavourable minima, in this case, act as traps, i.e. they become metastable states from which the system can escape only due to action of relatively large external fields, e.g. H ~ 10−1 for β = 0.17.

The behaviour of the Ising model described above is well established and served as a test for the JW MC simulations. As we can see from the results presented in Figs 1 and 2, the JW MC simulations reproduce all expected phenomena and, in addition, allow the magnetisation equilibrium isotherms, i.e. M(H), to be obtained for sufficiently low temperatures.

Lattice-gas model

In order to test the applicability of the updated JW MC algorithm to relatively large and complex systems, we have implemented the method for a lattice-gas model to study fluid sorption in porous media. Condensation of gas in porous materials occurs differently from that in free space, e.g. it takes place at a lower pressure (or chemical potential) compared to the bulk saturation value61, 62. While studies of fluids confined in single pores of simple geometry have clarified the mechanism for such shifted transitions62,63,64,65,66, the situation in real materials such as mesoporous glasses and silica gels, that consist of an interconnected network of pores of various shape and size, is still under active investigation67,68,69,70,71,72,73,74.

In this work, porous media is represented by two models: (i) a small lattice toy model for which exact numerical solution is available (see SI 2.2) and (ii) structural model of silica aerogel (see SI 2.3 for structural details of the model).

In the lattice-gas model4, 75,76,77, each out of N tot lattice site can be occupied by a fluid or a matrix particle, as described by the occupancy variables τ i and 1 − η i , respectively, which are equal to unity (zero) for occupied (unoccupied) sites. The matrix sites do not change their state, i.e. cannot be occupied by the fluid, and their concentration is quantified by porosity, \(\varphi ={N}_{{\rm{tot}}}^{-1}{\sum }_{i}^{{N}_{{\rm{tot}}}}{\eta }_{i}\). In the simulation setup, the porous material is assumed to be an open system of N = ϕN tot pore sites connected to a reservoir of fluid particles. The number of the fluid particles \({N}_{{\rm{f}}}={\sum }_{i}^{{N}_{{\rm{tot}}}}{\eta }_{i}{\tau }_{i}\) in the system and thus the energy \( {\mathcal H} \) (see SI 2.1 for lattice-gas Hamiltonian) of the system can vary, but the chemical potential μ, temperature T and volume V (or equivalently N) of the system are fixed. For a given set of μ, T and N, the system can be in a set of states which form a grand canonical ensemble described by the following grand partition function,

$${Z}_{\mu }=\sum _{\{\tau \}}{e}^{-\beta \tilde{ {\mathcal H} }},$$
(10)

where \(\tilde{ {\mathcal H} }= {\mathcal H} -\mu {N}_{{\rm{f}}}\), and the sum runs over all possible fluid occupation configurations {τ} of non-matrix sites, with the matrix variables η i being quenched. For the JW MC algorithm, the jump-transition acceptance probability (see Eq. (6)) for such a system is given by the following expression,

$${P}_{{\rm{acc}}}(\beta ,\beta ^{\prime} ,{Q}_{i},\mu ,{Q}_{j},\mu ^{\prime} )=\,{\rm{\min }}[1,{e}^{{\beta }^{^{\prime} }(\tilde{ {\mathcal H} }({Q}_{j},{\mu }^{^{\prime} })-\tilde{ {\mathcal H} }({Q}_{i},{\mu }^{^{\prime} }))-\beta (\tilde{ {\mathcal H} }({Q}_{j},\mu )-\tilde{ {\mathcal H} }({Q}_{i},\mu ))}],$$
(11)

where the non-local multiple-flip transitions from a current microstate of the system simulated at β and μ to a state in the j-distribution previously sampled at β′ and μ′ are allowed. However, to assure clarity and simplicity of the illustrative examples, the results presented below refer to a value of μ fixed within a single JW simulation.

The quantity of interest in our analysis is the mean equilibrium fluid density (order parameter), 〈ρ〉 = 〈N f〉/N as a function of chemical potential and temperature. The angular brackets mean thermodynamic averaging over the states {τ} of the grand canonical ensemble, i.e.

$$\langle \rho \rangle ={Z}_{\mu }^{-1}\sum _{\{\tau \}}\rho (\{\tau \}){e}^{-\beta \tilde{ {\mathcal H} }}.$$
(12)

The lattice-gas model is a discrete model and thus the density ρ takes N + 1 discrete values, \(\rho ({N}_{{\rm{f}}})={N}_{{\rm{f}}}/N=0,1/N,\ldots ,(N-1)/N,1\). Therefore, similarly to Eq. (9) it is convenient to rearrange the summation in Eq. (12) by first summing over all macrostates \(Q(\rho ,\tilde{ {\mathcal H} })\) (constructed in the same way as \(Q(M,{ {\mathcal H} }_{{\rm{I}}})\) for the Ising model) with fixed number of fluid sites (i.e. fixed ρ) but variable energy \(\tilde{ {\mathcal H} }\) and then over fluid densities, ρ,

$$\langle \rho \rangle ={Z}_{\mu }^{-1}\sum _{\rho }\rho \sum _{\{\tau (\rho )\}}{e}^{-\beta \tilde{ {\mathcal H} }(\rho )}=\sum _{\rho }\rho \sum _{\tilde{ {\mathcal H} }}P(Q(\rho ,\tilde{ {\mathcal H} })).$$
(13)

The probability, \(P(Q(\rho ,\tilde{ {\mathcal H} }))\), introduced in Eq. (13), to find the system in a certain macrostate \(Q(\rho ,\tilde{ {\mathcal H} })\) is given by

$$P(Q(\rho ,\tilde{ {\mathcal H} }))={Z}_{\mu }^{-1}g(Q(\rho ,\tilde{ {\mathcal H} })){e}^{-\beta \tilde{ {\mathcal H} }(\rho )},$$
(14)

where \(g(\rho ,\tilde{ {\mathcal H} })\) stands for the degeneracy of macrostate \(Q(\rho ,\tilde{ {\mathcal H} })\), and thus the probability of the system to be in a state with a particular ρ is \(P(\rho )={\sum }_{\tilde{ {\mathcal H} }}P(Q(\rho ,\tilde{ {\mathcal H} }))\).

Similarly to F(M) in the case of the Ising model, the grand-potential landscape can be defined as the ρ-dependence of the grand potential \({\rm{\Omega }}(\rho )=-\,{\beta }^{-1}\,\mathrm{ln}\,{Z}_{\mu }(\rho )\), where Z μ  = Z μ P(ρ). The shape of \({\rm{\Omega }}(\rho )\) can describe possible phases of the system. For example, if \({\rm{\Omega }}(\rho )\) has one minimum then the system is characterised by a single phase. However, if two minima appear in \({\rm{\Omega }}(\rho )\) this might be an indication of coexistence of two phases with different densities. In order to visualize the grand-potential landscape, similarly to f(M) for the Ising model, we plot \(\omega (\rho )\equiv \beta ({\rm{\Omega }}(\rho )-{\rm{\Omega }})=-\,\mathrm{ln}(P(\rho ))\) 78 (calling this quantity as grand-potential landscape), where Ω = −β −1 ln Z μ is the total grand-potential of the system (see the bottom panels in Fig. 3).

Figure 3
figure 3

Upper panel: The probability distribution of visits of macrostates characterised by relative energy per pore site, \(\tilde{ {\mathcal H} }\) (vertical axis), and density ρ (horizontal axis) for the lattice-gas model applied to aerogel sample as described in the text. The distributions at five labelled temperatures for (a) μ = −4.18 and (b) μ = −4.145 are shown using the same colour scheme for density of visits as in Fig. 1. The estimates for the upper and lower boundaries of the state space are shown by the dashed (red) and solid (green) lines. The arrows A, B, C and D point to the states characterised by different fluid densities (see SI 2.4 for graphical illustrations of fluid configurations). Bottom panels: Grand-potential landscapes, i.e. ω(ρ), obtained for three temperatures: (a) β = 0.71 (\(\blacksquare \)), β = 0.94 (\(\square \)) and β = 153 (); (b) β = 0.80 (), β = 0.91 (\(\square \)) and β = 1.07 () (see SI 1 for the values of other parameters).

The state space of the lattice-gas model can be sampled by means of the JW MC algorithm in a similar way as that of the Ising model. The distribution of visits of different macrostates is displayed in the ρ-\(\tilde{ {\mathcal H} }\) plane (see the upper panels in Fig. 3), where the same colour-scheme is used as in Fig. 1. Approximate high- and low-temperature boundaries of the state space are also computed (see SI 3 for details) and displayed for reference in the upper panels of Fig. 3 (the red (dashed) and green (solid) lines, respectively).

Figure 3 presents the results of the JW MC simulations for sorption of fluid in a model sample of aerogel for two different values of μ and several temperatures. At low temperatures for both values of μ shown in Fig. 3, the grand-potential landscape has two minima, as can be inferred from the shape of the low-temperature boundary, \({\tilde{ {\mathcal H} }}_{{\rm{\min }}}(\rho )\) (the solid green line in the upper panels). The low-density minimum (e.g. at \(\rho \simeq 0.15\) for μ = −4.18) represents the fluid distribution in the system for which the sites occupied by fluid are concentrated only around and nearby the quenched matrix sites (see SI 2.4). The minimum at the higher values of ρ corresponds to the aerogel sample filled with fluid, and only the added surface layers left unoccupied (see SI 2.4). As temperature is decreased, the explored part of the state space shifts down until the system eventually settles in a minimum (see the sequences of distribution of visits corresponding to gradually decreasing temperature in the top panels of Fig. 3). For sufficiently low or high values of μ the system straightforwardly descents to the low- or high-density minimum, respectively (the descent to the low-density minimum is shown in Fig. 3a). However, at the intermediate values of μ (see Fig. 3b) the state space sampled by the JW MC simulation splits into several regions and thus the distribution of visits has several peaks (see e.g. the distribution at β = 0.91 in the top panel of Fig. 3b). In this case, the right peak in the distribution (see colour-map for β = 0.80 in Fig. 3b) becomes dominant with decreasing temperature and eventually the system settles down in the high-density minimum of the grand-potential. The single-flip MC simulations would not be able to follow such equilibration of the system for μ = −4.145. This is due to development of the large entropic barrier between two minima leading to significant slowing down of single-flip dynamics. Without the jump-transitions provided by the JW MC simulations, the region of the state space corresponding to the high-density peak could not be sufficiently visited and system would remain in the low-density state, i.e. in the metastable state.

Figure 3b also shows the existence of the secondary split of the high-density peak in the distribution of visits into two peaks (see the two neighbouring bright spots on the right in the colour map for β = 0.91) corresponding to two minima in the grand-potential landscape at \(\rho \simeq 0.35\) and \(\rho \simeq 0.45\) (see the solid line marked by the open squares in the bottom panel). This feature (two high-density peaks in the distribution of visits) is an aerogel-sample specific (see SI 2.4). In addition to these two high-density configurations at β = 0.91, there is a low-density one with \(\rho \simeq 0.25\) (see the corresponding minimum of \(\omega \,(\rho \simeq \mathrm{0.25)}\) in the bottom panel). For this configuration, mainly the pore sites surrounding the matrix sites are occupied by fluid.

The JW MC simulations performed for fixed temperature and different values of chemical potential provide equilibrium isotherms, i.e. ρ(μ), for sorption in aerogel (see the data points labelled by circles, squares and diamonds in Fig. 4a). The solid symbols refer to the densities corresponding to the deepest minimum of ω(ρ) while the open symbols (see the inset in Fig. 4a) are related to other minima of ω(ρ) available for given values of μ and β. A typical evolution of the grand-potential landscape with chemical potential for relatively low temperature (β = 0.89) is shown in Fig. 4b. In two bottom panels (μ = −4.147 and −4.146), the low-density minimum (marked by solid square) is the deepest one and system mainly has the density corresponding to this minimum. One (for μ = −4.147) and two (for μ = −4.146) higher-density minima marked by open squares are weakly occupied in equilibrium. They are separated by a large barrier (not fully shown) from the low-density minimum and cannot be detected by the single-flip MC simulations due to large height of this barrier as compared to temperature. For μ = −4.145, the low- and intermediate-density minima become of approximately the same depth (they both marked by solid squares) and the system, in equilibrium, can be in one of them with approximately equal probability but, again, this cannot be detected by the single-flip MC simulations due to high barrier between the minima. In the relatively narrow range of chemical potential, −4.145 \(\leqslant \)μ\(\leqslant \) −4.144, the most likely fluid density is related to the middle minimum of ω(ρ) (see the inset in Fig. 4a) which becomes approximately of the same depth as the high-density minimum at \(\mu \simeq -\,4.144\) (both minima are marked by solid squares in Fig. 4b). For greater values of chemical potential, μ\(\geqslant \) −4.144, the system in thermal equilibrium is in the high-density state (see the top panel in Fig. 4b where the high-density minimum is marked by solid square and two other states with lower density by open squares).

Figure 4
figure 4

(a) The dependence of the mean fluid density ρ in structural model of aerogel versus chemical potential μ for several temperatures as marked in the figure. The results of the single-flip conventional MC simulations for adsorption (increasing μ) and desorption (decreasing μ) are shown by solid and dashed lines, respectively. The symbols refer to results of the JW MC simulations. For equilibrium isotherm at β = 0.71, the solid and dashed lines coincide with each other and with the solid circles. The inset shows magnification of the isotherms obtained by the JW MC simulations for the values of μ where the discontinuous transitions occur at low temperatures. The solid (open) symbols correspond to the deepest minimum (other minima) in the grand-potential landscape, ω(ρ). (b) Grand potential landscapes, ω(ρ), for β = 0.89 and several values of μ specified on the right from each panel. The solid and open squares mark the deepest and other minima of ω(ρ), respectively, in the same way as in (a).

In contrast to the JW MC simulations, both experimental studies73, 79 and single-flip MC simulations80, 81 are not able to access the equilibrium for sufficiently low temperatures due to presence of the hysteresis effect. Indeed, the results of the single-flip MC simulations for adsorption (solid lines in Fig. 4a) and desorption (dashed lines) for the same aerogel model exhibit hysteresis (area between solid and dashed lines) for β = 0.89 and β = 1.39, although both adsorption and desorption curves coincide producing the equilibrium isotherm (solid line marked by circles representing the JW MC data) for β = 0.71. Therefore, obtaining the equilibrium isotherms for sorption in aerogel and other porous materials is often problematic, and requires techniques such as mean-field scanning curves68. However, despite those efforts conclusive answers have not yet been obtained to even the key questions such as about existence of the discontinuous phase transition in aerogel samples of different porosity73. The JW algorithm is designed to avoid hysteresis and thus can be an invaluable tool in detecting phase transitions and resolving such problems. A detailed analysis of equilibrium sorption isotherms in aerogel samples of different porosity is outside the scope of this paper and will be presented elsewhere.

Conclusions

To conclude, we have revisited the JW algorithm18 which has been originally designed to tackle quasi-nonergodicity problem, a known problem in dynamics of interacting particles. However, due to demanding (at the time of its creation) memory requirements the algorithm lost in competition with other approaches such as REM. Bearing in mind significant improvements in RAM available in contemporary computers we have updated the JW algorithm, tested it for the Ising model and demonstrated its performance for sorption in lattice-gas models (a toy model and aerogel model).

The efficiency of the JW algorithm stems from the fact that only a single non-local (multiple-flip) jump is needed to cross the free-energy barriers as opposed to multiple replica exchanges in the case of REM. Even though each particular replica within REM is allowed to cross energy barriers by configuration exchange with a replica at a slightly different temperature, REM overall simply swaps the two replicas, and computer resources continue to be used for exploring the same free-energy minima. Therefore, if the minimum is deep enough the algorithm based on REM can spend vast amount of time randomly diffusing in the temperature dimension while exploring the same local free-energy minimum. In contrast, as temperature decreases the JW algorithm naturally drives the system to escape from the energetically unfavourable local minima and therefore, the system is maintained in the equilibrium throughout the entire duration of the simulation.

The principal differences between the two methods, the JW and REM, suggest the types of problems that can be tackled by each approach. Since the REM replicas tend to explore the local minima for extended periods of time throughout the simulation, the method is well suited for tasks such as mapping of the entire free-energy landscape, weight factor estimation for multicanonical algorithms and, more generally, for investigating the properties of the whole state space of the system. The JW algorithm is more appropriate for studying equilibrium behaviour of the system. As temperature decreases, the system simulated by the JW algorithm naturally approaches the most favourable explored minimum, thus this method is well suited to search for the global free-energy minimum and investigate system’s behaviour at the lowest temperatures. Since significantly less CPU resources is required by the JW algorithm as discussed above, it can either enable to study systems that have previously been prohibited by the lack of computing power, or to allow a more efficient investigation of the parameter space, provided that the analysis is mainly focused on the equilibrium behaviour of the system. In particular, the JW MC algorithm can be used on a single computing thread to investigate equilibrium properties of a system, especially near discontinuous phase transitions where the standard single-flip MC simulations are inefficient due to critical slowing down of dynamics and REM is too expensive in terms of computational resources.

Successful application of the updated JW algorithm to lattice-spin and lattice-gas models might promise its relevance to other models facing quasi-nonergodic behaviour, such as spin-facilitated models for glassy dynamics54 and lattice models for proteins52. Another possible area for application of the updated JW method could be in studying the systems exhibiting weak ergodicity breaking14 with non-Boltzmann limiting distributions82.

The description of the improved JW MC method was intentionally given as simple and general as possible. Therefore, despite certain advantages in its current form, the algorithm leaves much room for further optimisation and improvements. Moreover, due to key similarities with REM, numerous developments that studies of REM provided throughout the last two decades are readily available to implement for the updated JW algorithm (e.g. the temperature set {T α } and jump frequency optimisation as well as combinations with Wang-Landau, multicanonical or simulated tempering algorithms).