  Minimum-weight perfect matching (MWPM) has been been the primary classical
algorithm for error correction in the surface code, since it is of low runtime
complexity and achieves relatively low logical error rates [Phys. Rev. Lett.
108, 180501 (2012)]. A Markov chain Monte Carlo (MCMC) algorithm [Phys. Rev.
Lett. 109, 160503 (2012)] is able to achieve lower logical error rates and
higher thresholds than MWPM, but requires a classical runtime complexity which
is super-polynomial in L, the linear size of the code. In this work we present
an MCMC algorithm that achieves significantly lower logical error rates than
MWPM at the cost of a polynomially increased classical runtime complexity. For
error rates p close to the threshold, our algorithm needs a runtime complexity
which is increased by O(L^2) relative to MWPM in order to achieve a lower
logical error rate. If p is below an L-dependent critical value, no increase in
the runtime complexity is necessary any longer. For p->0, the logical error
rate achieved by our algorithm is exponentially smaller (in L) than that of
MWPM, without requiring an increased runtime complexity. Our algorithm allows
for trade-offs between runtime and achieved logical error rates as well as for
parallelization, and can be also used to correct in the case of imperfect
stabilizer measurements.
