1 Introduction

Standard algorithms for lattice QCD are well-known to suffer from topology freezing [1,2,3,4]. Near the continuum limit, distinct topological sectors are poorly sampled due to the large energy barriers separating them, leading to exponentially increasing autocorrelation times as the continuum limit is approached in a finite volume. This problem has received a lot of attention, and several algorithmic strategies have been proposed over the years [5,6,7,8,9,10], but there is no fully satisfactory solution.

In this paper, we study a modification of the Hybrid Monte Carlo (HMC) algorithm, named winding HMC (wHMC), that incorporates Metropolis–Hastings steps [11] with tailored reversible jumps between topological sectors. The idea is similar to an old attempt under the name of instanton hit [12, 13]. We will test our algorithm in the U(1) gauge theory in 2D with and without fermion content. This model has been recently used as benchmark in machine-learned flow-based sampling algorithms [14, 15], as well as in tensor network approaches [16, 17] (see Ref. [18] for a review).

We first test the algorithm in a compact U(1) pure gauge theory, which suffers from topology freezing, but is solvable. Exact results on topological and non-topological observables exist in the literature for the lattice regularization [19,20,21], i.e., at finite lattice spacing. Therefore, we can accurately test the approach to the continuum limit of the topological susceptibility and the plaquette. We then include two degenerate flavours of Wilson fermions and study the pion mass dependence of the topological susceptibility. In both cases we compare the scaling of the autocorrelation time with that of the standard HMC.

It is a general belief that algorithms with topology freezing do nevertheless well in observables computed at fixed topology – failing only in the weights of the different sectors. We can test this hypothesis accurately in this model by comparing the plaquette (in the pure gauge) and the pion mass (in the fermionic case) at fixed topology with the exact results or between the two algorithms, HMC and wHMC.

Finally, since topology freezing can be circunvented altogether by working with very large physical volumes and taking local averages [22,23,24], we also compare our topology-sampling algorithm with HMC in a very large lattice of size \(V=8192^2\).

We comment on the prospects to extend the wHMC algorithm to other gauge theories and higher dimensions in the outlook section.

2 Analytical results

The Schwinger model [25] is a U(1) gauge theory with one or more massless fermions. It is a solvable quantum field theory that shares many properties with Yang–Mills in four dimensions [26]. In particular, Euclidean gauge configurations can be classified according to their topological charge

$$\begin{aligned} \nu = {1 \over 2 \pi } \int d^2 x ~\epsilon ^{\mu \nu } F_{\mu \nu } \subset {\mathbb {Z}}, \end{aligned}$$
(1)

and there is a mass gap. The spectrum contains a free boson that can be interpreted as the singlet pseudoscalar meson, \(\eta '\), with mass

$$\begin{aligned} m_{\eta '}^2={N_f e^2 \over \pi } \equiv {N_f\over \pi \beta }, \end{aligned}$$
(2)

where \(N_f\) is the number of degenerate flavours.

Interestingly, the Witten-Veneziano formula is exact in the Schwinger model [27, 28],

$$\begin{aligned} \chi _t|_{\mathrm{quenched}} \equiv \chi ^q_t={F_{\eta '}^2 m_{\eta '}^2\over 2 N_f} = {e^2 \over 4 \pi ^2} = {1\over 4 \pi ^2 \beta }, \end{aligned}$$
(3)

where \(F_{\eta '}\) is the decay constant, \(F_{\eta '}= 1/\sqrt{2\pi }\), and the quenched topological susceptibility \(\chi _{t}^{q}\) can be obtained in the pure gauge U(1) theory in 2D.

Since this theory can be solved on the lattice and in a finite volume [19,20,21], it is therefore a good starting test-bed for Monte Carlo (MC) algorithms.

2.1 Compact U(1) in 2D

The Wilson lattice formulation of the theory is

$$\begin{aligned} Z = \int \prod _{l} d U_l ~e^{-S_p[U]} \equiv \int \prod _{l} d U_l ~e^{{\beta \over 2} \sum _p U_p+U_p^\dagger }, \end{aligned}$$
(4)

where \(U_l\) and \(U_p\) are the standard link and \(1 \times 1\) Wilson loop, respectively. We use periodic boundary conditions. Note that \(\beta = 1/e^2\) is dimensionful, but all dimensionful quantities are assumed in lattice units in the following. Therefore, as we approach the continuum limit, \(\beta \sim a^{-2}\).

We will be considering the plaquette and the topological susceptibility:

$$\begin{aligned} P \equiv {\left\langle \sum _p \mathrm{Re}[U_p] \right\rangle \over V}, ~~~\chi _t \equiv {\langle Q^2\rangle \over V}, \end{aligned}$$
(5)

where the lattice definition of topological charge is

$$\begin{aligned} Q \equiv {-i \over 2\pi } \sum _p \ln U_p. \end{aligned}$$
(6)

The result for these quantities is known in terms of modified Bessel functions for finite \(\beta \) and V [19,20,21]:

$$\begin{aligned} P&= {\sum _n I'_n[\beta ] I_n[\beta ]^{V-1}\over \sum _n I_n[\beta ]^V}, \nonumber \\ \chi _t&=-{\sum _n A_n(\beta ) I_n(\beta )^{V-1}\over \sum _n I_n(\beta )^V} \nonumber \\&\quad - (V-1) \frac{\sum _n B^2_n(\beta ) I_n(\beta )^{V-2}}{\sum _n I_n(\beta )^V} , \end{aligned}$$
(7)

where

$$\begin{aligned} A_n(x)\equiv & {} -{1 \over 2 \pi } \int _{-\pi }^\pi \left( {\phi \over 2 \pi }\right) ^2 e^{i n \phi + x \cos \phi } d \phi ,\nonumber \\ B_n(x)\equiv & {} {i \over 2 \pi } \int _{-\pi }^\pi {\phi \over 2 \pi } \ e^{i n \phi + x \cos \phi } d \phi , \end{aligned}$$
(8)

and the sums in n are over all integers. The infinite volume limits are

$$\begin{aligned} \lim _{V\rightarrow \infty } P={I_1(\beta )\over I_0(\beta )}, ~~~\lim _{V\rightarrow \infty } \chi _t=-{A_0(\beta )\over I_0(\beta )}. \end{aligned}$$
(9)

In the continuum limit, \(\beta \rightarrow \infty \), we recover the well-known results

$$\begin{aligned} \lim _{\beta \rightarrow \infty } \lim _{V\rightarrow \infty } P&=1-{\mathcal {O}}(\beta ^{-1}), \nonumber \\ \lim _{\beta \rightarrow \infty }\lim _{V\rightarrow \infty } \beta \chi _t&={1\over 4 \pi ^2 } + {\mathcal {O}}(\beta ^{-1}). \end{aligned}$$
(10)

The partition function in fixed topology can also be easily derived from the known partition function in the \(\theta \) vacuum [19,20,21]. At sufficiently large volume

$$\begin{aligned} Z_Q(\beta ,V) \equiv \int _{-\pi }^{\pi } d\theta e^{-i \theta Q} Z_\theta (\beta , V), \end{aligned}$$
(11)

with

$$\begin{aligned} Z_\theta (\beta , V) = \left[ I_{\theta \over 2\pi }(\beta )\right] ^V. \end{aligned}$$
(12)

An interesting quantity is the average of the plaquette in fixed topology sectors, which shows a subtle dependence on Q, and it is analytically known also at finite \(\beta \):

$$\begin{aligned} P_Q\equiv & {} {1\over V} {1\over Z_Q} {d Z_Q\over d\beta } \nonumber \\= & {} {1\over Z_Q} \int _{-{1\over 2}}^{{1\over 2}} dz ~e^{-i 2 \pi z Q} I'_{z}(\beta ) \left[ I_{z}(\beta )\right] ^{V-1}. \end{aligned}$$
(13)

As we will see, this is a golden observable to test how algorithms perform in sampling sectors of fixed-topology, given its high precision.

Fig. 1
figure 1

Monte Carlo history of the topological charge Q for increasing values of \(\beta \) in a Markov chain of \(10^6\) HMC configurations

2.2 \(N_f\) Schwinger model

In the theory with \(N_f > 1\) fermions, the flavour symmetry group is \(SU(N_f)_L\times SU(N_f)_R\). Even though spontaneous chiral symmetry breaking cannot occur in 2D and the condensate vanishes in the massless limit, the scaling of the condensate with the quark mass is non-trivial. The Gell–Mann–Oakes–Renner (GMOR) relation follows from the Ward identity (WI)

$$\begin{aligned} F_{\pi }^2 M_\pi ^2 = {2 m\Sigma (m)\over N_f}, \end{aligned}$$
(14)

where m is the quark mass. The condensate is expected to scale with the quark mass [29] as

$$\begin{aligned} \Sigma (m) \propto m^{N_f-1 \over N_f+1} e^{2\over N_f+1}, \end{aligned}$$
(15)

and therefore the pion mass scales with the quark mass as

$$\begin{aligned} M_\pi ^2 \propto m^{2 N_f\over N_f+1}. \end{aligned}$$
(16)

The topological susceptibility vanishes in the limit of massless fermions. From the WI and the GMOR relation it follows

$$\begin{aligned} \chi _t^{N_f} = {M_\pi ^2 F_\pi ^2\over 2 N_f}+{\mathcal {O}}(m^2), \end{aligned}$$
(17)

and combining this with the Witten-Veneziano formula (and neglecting mass corrections to \(F_\pi \)), we expect

$$\begin{aligned} \chi ^{N_f}_t ={ {M_\pi ^2 F_\pi ^2\over 2 N_f}\over 1 +{M_\pi ^2 F_\pi ^2\over 2 N_f \chi _t^q}} ={1\over 4\pi \beta } {{M_\pi ^2\beta }\over N_f+ \pi M_\pi ^2\beta }, \end{aligned}$$
(18)

which nicely interpolates between the pure gauge case, Eq. (3), for \(M_\pi \rightarrow \infty \), and the flavoured result of Eq. (17), even though it is strictly derived close to the chiral limit.

3 Winding HMC

Even in this simple model, standard MC algorithms such as the HMC algorithm fail to reproduce the continuum limit expectations due to the bad sampling of topological sectors. In Fig. 1 we plot an HMC history of the topological charge Q, showing the well-known topology freezing phenomenon. This results in the exponential growth of the autocorrelation time as \(\beta \rightarrow \infty \) shown in Fig. 4 for \(Q^2\).

Fig. 2
figure 2

Sketch of a winding transformation of size \(L_w\). Gauge links whose starting and ending points are both in the blue region transform according to Eq. (19), while the others stay the same. Only the \(1\times 1\) Wilson loops in the violet region change

The basic idea of our proposal is to combine HMC steps with a Metropolis–Hastings accept-reject step, where the trial configuration is obtained from the previous one by performing a winding. The winding transformation acts on the link variables whose starting and ending points are within a square region \(S_w\) of size \(L_w\),

$$\begin{aligned} U_\mu (x) \rightarrow U^\Omega _\mu (x) \equiv \Omega (x) U_\mu (x) \Omega ^\dagger (x+\hat{\mu }), \end{aligned}$$
(19)

if both \(x, x+\hat{\mu }\in S_w\). By contrast, the other links remain unchanged. The anatomy of the winding step is depicted in Fig. 2.

We only have to define the gauge transformation \(\Omega \). We set \(\Omega = 1\) except at the boundary where it is chosen to have a winding number. If \(x_n\) are the points on the boundary of \(S_w\), ordered from \(n=1,\ldots ,4 L_w\), we pick

$$\begin{aligned} \Omega ^\pm (x_n) = e^{\pm i {\pi \over 2}{n \over L_w}}, \end{aligned}$$
(20)

where the \(+\) denotes a winding and the − an antiwinding. The sign is chosen with 50% probability, and is common for the n points, ensuring that the transformation will yield a change in the topological charge of \(\Delta Q = \pm 1\) in smooth configurations. The invariance of the measure ensures that this transformation has a trivial Jacobian, \(dU^\Omega = dU\).

The transition probability for \(U\rightarrow U'\) of this Metropolis–Hastings step is

$$\begin{aligned} q(U'|U)&= T(U\rightarrow U') p_{\mathrm{acc}}(U'|U) \nonumber \\&\quad + \delta (U'-U) \sum _{U''} T(U\rightarrow U'') \nonumber \\&\quad \times \left( 1-p_{\mathrm{acc}}(U''|U)\right) , \end{aligned}$$
(21)

with

$$\begin{aligned} T(U \rightarrow U') = {1\over 2} \delta (U'- U^{\Omega ^+}) +{1\over 2} \delta (U'-U^{\Omega ^-}). \end{aligned}$$
(22)

Since \(q(U'|U) = q(U|U')\) due to the 50% probability of performing a winding or antiwinding, \(p_{\mathrm{acc}}\) is just the usual Metropolis [30] accept-reject probability

$$\begin{aligned}&p_{\mathrm{acc}}(U'|U) = \mathrm{min}\left\{ 1,{p(U')\over p(U)}\right\} , \nonumber \\&\qquad \mathrm{with }\quad p (U) = e^{-S[U]} \end{aligned}$$
(23)

being the target probability distribution. In the pure gauge theory S[U] is the plaquette action, whereas in the dynamical theory it includes the fermionic determinant. The latter is evaluated stochastically using one pseudofermion.

It is easy to check that p(U) is the equilibrium distribution of such a Markov chain, i.e.,

$$\begin{aligned} \int dU p(U) q(U'|U)&= p(U'), \end{aligned}$$
(24)
$$\begin{aligned} \int d U' q(U'|U)&= 1. \end{aligned}$$
(25)

Substituting Eq. (21) into Eq. (24), we get

$$\begin{aligned} \int dU p(U) q(U'|U)&= {1\over 2} \sum _{\Omega =\Omega ^\pm } \left[ p(U^{\prime \Omega }) p_{\mathrm{acc}} (U'|U^{\prime \Omega }) \right. \nonumber \\&\qquad \left. + p(U') (1-p_{\mathrm{acc}}(U^{\prime \Omega }|U'))\right] \nonumber \\&=\,p (U'), \end{aligned}$$
(26)

where the last step can be easily obtained after considering the two cases \(p(U')<p(U^{\prime \Omega })\), or \(p(U')>p(U^{\prime \Omega })\) for each \(\Omega \).

By itself this algorithm is obviously not ergodic, since only a predefined change is performed. Ergodicity should be ensured by combining one or several winding steps with a standard HMC step. We refer to this algorithm as wHMC.

3.1 Pure gauge case

We have carried out a simulation of this algorithm for volumes with fixed \(V/\beta \sim 80\) at various values of the lattice spacing, \(\beta \), for the pure gauge theory. Table 1 includes the parameters and results from these simulations for both HMC and wHMC.

Table 1 Simulation parameters and results for the pure gauge model using \( N_{conf}=5 \times 10^5\) configurations in each case. The column “# jumps” indicates the number of transitions in which the topological charge changes by at least one unit. The integrator of the HMC step is tuned such that the acceptance is \(\sim 90\%\)
Fig. 3
figure 3

Monte Carlo history of the topological charge for the two algorithms with \(10^6\) configurations at \(\beta =8.45\)

Fig. 4
figure 4

Autocorrelation time of \(Q^2\) as a function of \(\beta \propto a^{-2}\), as obtained with the wHMC and HMC algorithms

Two MC histories of the topological charge for HMC and wHMC are compared in Fig. 3, where the freezing of topology is absent for wHMC. This can be quantified more precisely by looking at the scaling of the autocorrelation times with \(a^{2} \sim \beta ^{-1}\). As shown in Fig. 4, there is an enourmous improvement with respect to standard HMC. The curves in Fig. 4 correspond to the two-parameter fits:

$$\begin{aligned} \tau _{Q^2}(\beta ) \big |_{\mathrm{HMC}} = A \exp ( b \beta ), \quad \ \tau _{Q^2}(\beta ) \big |_{\mathrm{wHMC}} = A \beta ^{b}. \end{aligned}$$
(27)

The best fit parameters are \(b=1.47(14)\) for the exponential fit to HMC, and \(b=0.565(53)\) for the power-law fit to wHMC. Therefore we find an exponential scaling of the autocorrelation time with the lattice spacing for HMC, in agreement with previous findings [1,2,3,4], versus a scaling proportional to \(\sim \sqrt{\beta }\) for wHMC.

Fig. 5
figure 5

Dependence on the winding size, \(L_w\), of the plaquette autocorrelation time (top panel), the topological charge autocorrelation time (middle) and the acceptance of one winding step (bottom panel), at \(\beta =5\)

We have also studied the dependence on the size of the winding region, \(L_{w}\). In Fig. 5 we show the autocorrelation times for P, Q and the acceptance rate of the winding step as function of \(L_{w}\): the acceptance of the winding grows with \(L_{w}\) reaching \(50\%\) at the largest \(L_{w}\) considered, and \(\tau _Q\) improves in a correlated fashion, while \(\tau _P\) is insensitive to \(L_{w}\).

Fig. 6
figure 6

Average topological susceptibility (top) and plaquette (bottom) normalized to the exact result of Eq. (7) as a function of \(\beta ^{-1}\) for both algorithms

One can understand the improvement of the acceptance rate of the winding step with \(L_{w}\). The change in the action when a winding is performed is restricted to the plaquettes at the boundary of \(S_{w}\), and is due to the change in the links at the boundary – see violet region in Fig. 2. The change in the phase of the plaquette, \(\delta \theta _p\), is therefore \(\pm {\pi \over 2 L_{w}}\), depending on the face of the square. We refer to \(\partial S_{w}^\pm \) as the boundary where the change is positive or negative. For sufficiently large \(L_{w}\) the change in the phase of the plaquette is small and we can approximate

$$\begin{aligned} \Delta S&\simeq {\beta \pi \over 2 L_{w}} \left( \sum _{p \subset \partial S_{w}^+} \sin \theta _p -\sum _{p \subset \partial S_{w}^-}\sin \theta _p\right) \nonumber \\&\quad +{\beta \pi ^2\over 8 L^2_{w}} \sum _{p\subset \partial S_{w}} \cos \theta _p. \end{aligned}$$
(28)

The average of the first term of \(\Delta S\) vanishes, while the last term averages to

$$\begin{aligned} \langle \Delta S \rangle \simeq {\beta \pi ^2\over 2 L_{w}}. \end{aligned}$$
(29)

The acceptance increases as \(L_{w} \rightarrow \infty \) at fixed \(\beta \), since the change in the action averages to zero. We therefore conclude that the most efficient approach is to set the winding size to the largest possible value in this case.

The result for the average plaquette and the topological susceptibility normalized to the analytical results of Eq. (7) are shown in Fig. 6. The agreement with the exact results for both observables is very good for the wHMC algorithm, while for HMC both observables differ significantly from the theoretical expectation close to the continuum limit. Although the divergence from the analytical result is more significant for the topological susceptibility, the plaquette also differs at various \(\sigma \)’s of confidence level.

Fig. 7
figure 7

Acceptance of a winding step in wHMC as a function of \(L_w\) for various bare quark masses at \(\beta =5.0\)

3.2 \(N_f=2\) case

Fig. 8
figure 8

Acceptance of a winding step in wHMC as a function of \(M_{\pi }\sqrt{\beta }\) for \(L_w=3\) at various \(\beta \)’s

Table 2 Simulation parameters and results from the \(N_f=2\) simulations

The inclusion of the fermion determinant is challenging in the wHMC algorithm, because the acceptance becomes very small. The reason is that the change in the action induced by the winding can no longer be circumscribed to the boundary plaquettes, since the determinant is non-local. In Fig. 7 we show the acceptance of a winding Metropolis–Hastings step as a function of \(L_w\). The acceptance is seen to be below 1%, and the highest acceptance is no longer reached for large \(L_w\): the optimal \(L_w\) is roughly 2-3 with a mild dependence on the quark mass. The value of the optimal acceptance is however very sensitive to \(\beta \) and to the quark mass, decreasing as the chiral limit is approached. This is shown in Fig. 8, where we plot the acceptance as a function of the pion mass for fixed \(L_w=3\) for various \(\beta \). There is indeed room for optimizing \(L_w\) as a function of \(\beta \) and the quark mass.

On the other hand, one winding accept-reject step involves one inversion of the Dirac operator, while an HMC step involves as many as the number of steps in the integrator, \(n_{\mathrm{HMC}}\), which is of order \({\mathcal {O}}(10-100)\). Therefore, instead of one winding, we could perform \({\mathcal {O}}(100)\) winding accept-reject steps between HMC steps at a similar cost. A step of the wHMC is then defined as one HMC step + \(n_{\mathrm{W}}\)-winding accept-reject steps. This increases the computational cost of each wHMC step compared to a HMC one by a factor

$$\begin{aligned} r_{c} \equiv \frac{n_{\mathrm{HMC}} + n_{\mathrm{W}}}{n_{\mathrm{HMC}}}, \end{aligned}$$
(30)

while significantly improving the scaling with \(\beta \) of the autocorrelation time of the topological charge.

We have performed a series of simulations at several \(\beta \)’s, computing the pion mass and the topological susceptibility for various values of the bare quark mass, \(m_0\). The summary of our results is in Table 2.

In Fig. 9 we show the topological susceptibility as a function of the pion mass, together with the fit to the continuum expectation, Eq. (18), plus generic cutoff effects that in the theory with unimproved Wilson fermions are expected to scale with \({\mathcal {O}}(a) \sim \beta ^{-1/2}\). We fit the various results at various \(\beta \) and quark masses to the ansatz

$$\begin{aligned} \chi _t^{N_f=2} = \mathrm{Eq}.(18) + (c + d M_\pi ^2) \beta ^{-1/2} , \end{aligned}$$
(31)

where c and d are the fitting parameters. The agreement of wHMC with the expectation is good, even at values of \(\beta \) where the topology in HMC is completely frozen and does not allow to measure the topological susceptibility. Cutoff effects are significant and larger than in the pure gauge theory, as expected from the presence of Wilson fermions.

Even though the autocorrelation is larger than in the pure gauge theory, we still see a major improvement in the scaling towards the continuum limit as shown in Fig. 10. Note that the autocorrelation time is multiplied by the factor in Eq. (30), which accounts for the increase in computational cost. In our simulations, this factor goes from \(r_{c} \approx 2.53\) to \(r_{c}=6\) in the range \(\beta \in [ 5, 9 ]\).

Fig. 9
figure 9

Topological susceptibility in the \(N_f=2\) theory as a function of the pion mass. The coloured solid lines are fits to the expression in Eq. (31) for five \(\beta \)’s, while the black line is the continuum result. The horizontal dashed lines are the quenched expectations at the various \(\beta \) and the continuum

Fig. 10
figure 10

Scaling of the autocorrelation time for \(Q^2\) times the cost ratio, Eq. (30), with \(\beta \) for HMC and wHMC. The pion mass is kept approximately constant, \(M_\pi \sqrt{\beta } \sim 0.65\)

4 Results at fixed topological sector

A way to overcome the topology freezing problem consists in extracting physical quantities of interest from simulations at fixed topology and correcting for the finite-size dependence [31, 32] (see also [33] for applications in the context of finite size scaling). A key ingredient in this approach is that algorithms that suffer from topology freezing can nevertheless sample correctly sectors of fixed topology. In this sense only the relative weights of different topological sectors are difficult to compute for an algorithm suffering topology freezing. This hypothesis can be studied very accurately in the context of our simple 2D model: on the one hand we can compare with the analytical results in the pure gauge case, and on the other hand we can compare the results with our wHMC algorithm for the \(N_{f}=2\) case.

4.1 Pure gauge

Let us start with the pure gauge model. In Fig. 11 we show the result for the weights of the different topological sectors obtained with the two algorithms at \(\beta =11.25\), compared to the expectations in Eq. (11). Clearly HMC fails at evaluating these weights, while wHMC succeeds.

Fig. 11
figure 11

\(Z_Q/Z\) versus Q at \(\beta =11.25\) for HMC and wHMC, versus the analytical result

Fig. 12
figure 12

\(P_Q\) versus Q at \(\beta =8.45\) for wHMC and HMC versus the analytical result

Fig. 13
figure 13

\((\Delta P)_{\mathrm{th}} \equiv P_{\mathrm{x}} - P^{\mathrm{th}}_{\mathrm{x}}\) normalized with the standard deviation \(\sigma \) for \(\mathrm{x} = All\ Q\) (full symbols) or at fixed topology \(\mathrm{x} = |Q|\) (open symbols), at \(\beta =11.25\) for wHMC, HMC and master field, compared to the analytical result (dashed line)

In the pure gauge model, the plaquette at fixed topology has a small but measurable Q dependence (see Eq. (13) and Fig. 12). We can therefore test whether the algorithm samples properly within each topological sector and reproduces the correct Q dependence. We consider the projected observable O to the topological sector n

$$\begin{aligned} O_n = \frac{ \langle O \, \delta _{n}(Q)\rangle }{\langle \delta _{n}(Q)\rangle }, \end{aligned}$$
(32)

where

$$\begin{aligned} \delta _{n}(Q) = \left\{ \begin{array}{ll} 1&{}\quad |Q| = n\\ 0&{}\quad \text {otherwise} \end{array}\right. . \end{aligned}$$
(33)

Figure 13 shows the difference between the measured plaquette and the analytical expectation, \((\Delta P)_{\mathrm{th}} =P-P_{\mathrm{th}}\), in units of the error of the measured plaquette. We see that HMC fails to reproduce the correct expectation value of the plaquette (label “All Q”) by 5 standard deviations. This is expected since HMC is completely frozen and only \(Q=0\) is present in the Monte Carlo history, while the plaquette shows a small (but noticeable) dependence on Q. On the other hand the expectation value of the plaquette projected to the \(Q=0\) sector is perfectly predicted by HMC. We also see that the wHMC, which is able to sample all topological sectors, reproduces correctly the value of the plaquette projected to all values of the charge from 0 to 6. It also reproduces the expectation value of the plaquette.

4.2 \(N_f=2\) results

We now turn to the model with dynamical fermions. Simulations at fixed topology have been performed in previous works using the HMC algorithm for this model [34,35,36].

Again, Fig. 14 shows that HMC is not able to sample the different topological sectors correctly at \(\beta =9.0\). Focusing on the pion mass as the observable of interest, we see in Fig. 15 that it shows a dependence on the topological sector, explaining why HMC fails to correctly reproduce its value in Fig. 16 (label “All Q”) by more than 8 standard deviations. Nevertheless the values of \(M_\pi \) projected to the topological sector with \(|Q|=0, 1\) are correctly reproduced (labels \(|Q|=0,1\)).

Fig. 14
figure 14

\(Z_Q/Z\) versus Q at \(\beta =9.0\) for HMC and wHMC with \(N_{f} = 2\). A Gaussian fit to the wHMC distribution is also shown

Fig. 15
figure 15

Pion mass at fixed topology, \((M_\pi )_Q\), versus Q at \(\beta =9.0\) for wHMC and HMC

Fig. 16
figure 16

\(\Delta M_{\pi } \equiv \langle M_{\pi }\rangle _{\mathrm{x}}^{\mathrm{HMC}} - \langle M_{\pi } \rangle _{\mathrm{x}}^{\mathrm{wHMC}}\), averaged over all sectors, \(\mathrm{x} = All\ Q\) (full symbol), or sectors of fixed \(\mathrm{x} = |Q|\) (open symbols) as in Eq. (32), versus Q at \(\beta =9.0\)

5 Master-field simulations

We now turn to the computation of physical observables by means of simulations in large lattices, the so-called master fields [22]. Using this approach, observables and their errors are computed from volume averages over a handful (even a single) of configurations, instead of from averages over Monte Carlo time. Details on the determination of statistical uncertainties using this approach are explained in appendix A.

This approach requires large volumes for reasonable error estimates (see appendix A). At these large values of the volume we expect the effects of the global topology to be suppressed. Master-field simulations therefore bypass the effects of topology freezing as long as fixed topological sectors are sampled correctly. In Sect. 4 we have argued that HMC, even suffering severely from topology freezing, can determine correctly observables on sectors of fixed topology. Therefore we expect master-field simulations to produce correct numbers, even if simulations are performed in a region of parameter space where topology is frozen. In this section we will confirm this expectation.

We have performed simulations on lattice volumes of \(8192\times 8192\) using the standard HMC algorithm at the same values of \(\beta \) as in the wHMC case (see Sect. 3.1). For each case we have generated a single configuration by a process of thermalization (using 2000 trajectories of length 0.5), followed by an unfolding in the two periodic directions. We start with a small lattice \(16\times 16\). After unfolding 9 times, we reach our target size \(8192\times 8192\).

Fig. 17
figure 17

Results for the plaquette and the topological susceptibility in the master-field simulations of the pure gauge theory. We plot the difference with respect to the theoretical value \((\Delta {\mathcal {O}})_{th}={\mathcal {O}} - {\mathcal {O}}_{th}\), normalized by the error, as a function of \(\beta ^{-1}\)

On this single configuration, we measure the plaquette and the susceptibility. Given the value of the \(1\times 1\) Wilson loop \(U_p(x)\) at a point x, we use its real part and argument to estimate the value of the plaquette and the topological charge density respectively

$$\begin{aligned} P(x) = \mathrm{Re}[U_p(x)],\qquad q(x) = \frac{-i}{2\pi }\ln U_p(x). \end{aligned}$$
(34)

The susceptibility can be determined from q(x) using the local observable

$$\begin{aligned} \chi _R(x) = \sum _{x_i-y_i \le R} q(x)q(x+y). \end{aligned}$$
(35)

If the value of R is taken larger than the correlation length of the system, the expectation value of \(\chi _R(x)\) will coincide with the topological susceptibility.

In the infinite volume limit the partition function Eq. (11) factorizes. This implies that the values of q(x) are not correlated among different x, and therefore \(\langle \chi _t \rangle = \langle \chi _R(x) \rangle \) for any value of R. Moreover the variables \(\chi _R(x)\) are also uncorrelated. It is easy to check that the variance of the observable \(\chi _R(x)\) increases as

$$\begin{aligned} \frac{\mathrm{Var}[\chi _R(x)]}{\mathrm{Var}[\chi _0(x)]} \approx 1+2R^2, \end{aligned}$$
(36)

which implies that the best estimate of the topological susceptibility is obtained by using \(R=0\). Incidentally, this also suggests that in theories with a non-zero correlation length R has to be taken as small as possible.

Figure 17 shows that the values of the plaquette and the susceptibility agree perfectly with the theoretical expectations. Further details in the evaluation of the error in master field simulations can be found in appendix A.

Finally let us comment on the cost comparison. The key element for master field simulations is the cost of thermalization. For our case (due to the small numerical cost of our simulations) this thermalization has been performed by brute force. Whether a thermalization process performed with more care would result in a cost comparable to the one of wHMC or HMC is beyond the scope of this work. Any conclusion in this regard would be anyway difficult to extrapolate to other gauge theories in more dimensions, since this particular model shows no spatial correlations among observables.

6 Outlook

We have presented a new algorithm based on Metropolis–Hastings steps that are tailored to induce jumps in the topological charge. This algorithm satisfies detailed balance, and ergodicity is ensured when alternated with standard HMC steps. As we have shown, it successfully improves the problem of topology freezing and exponentially-growing autocorrelation times in the 2D model considered – both with and without fermion content. The integrated autocorrelation time of wHMC in the pure gauge case is very similar to the one obtained in machine-learned flow-based sampling algorithms [14, 15], however without the additional training cost.

In spite of the shortcomings of algorithms with topology freezing, we have been able to confirm that averages in fixed topology sectors are not affected, and agree in wHMC and HMC. This is seen both in the pure gauge theory, where the analytical results are known at finite \(\beta \), as well as in the theory with fermions.

We have finally compared the wHMC algorithm with the results by local averages in very large lattices of size up to \(L \sim 8000\). Our results indicate that master-field simulations are satisfactory in the controlled setup of this 2D model, since analytical results are reproduced with very high accuracy.

The interesting question is whether wHMC can be equally successful in the case of other gauge theories in higher dimensions. In fact, the winding step is trivial to extend to, for instance, a SU(2) theory in 4D. We have indeed carried out the naive implementation of wHMC in that context, and found very poor acceptances – the “curse” of dimensionality. We hope that less trivial implementations in 4D could resolve this matter; we are currently exploring modifications of the algorithm that incorporate the idea of normalizing flows [14].