  For $d \ge 2$ and all $q\geq q_{0}(d)$ we give an efficient algorithm to
approximately sample from the $q$-state ferromagnetic Potts and random cluster
models on finite tori $(\mathbb Z / n \mathbb Z )^d$ for any inverse
temperature $\beta\geq 0$. This shows that the physical phase transition of the
Potts model presents no algorithmic barrier to efficient sampling, and stands
in contrast to Markov chain mixing time results: the Glauber dynamics mix
slowly at and below the critical temperature, and the Swendsen--Wang dynamics
mix slowly at the critical temperature. We also provide an efficient algorithm
(an FPRAS) for approximating the partition functions of these models at all
temperatures.
  Our algorithms are based on representing the random cluster model as a
contour model using Pirogov--Sinai theory, and then computing an accurate
approximation of the logarithm of the partition function by inductively
truncating the resulting cluster expansion. The main innovation of our approach
is an algorithmic treatment of unstable ground states, which is essential for
our algorithms to apply to all inverse temperatures $\beta$. By treating
unstable ground states our work gives a general template for converting
probabilistic applications of Pirogov-Sinai theory to efficient algorithms.
