  In this paper we develop a general approach to dimer models analogous to
Krichever's scheme in the theory of integrable systems. We start with a Riemann
surface and the simplest generic meromorphic functions on it and demonstrate
how to obtain integrable dimer models. These are dimer models on doubly
periodic bipartite graphs with quasi-periodic positive weights. Dimer models
with periodic weights and Harnack curves are recovered as a special case. This
generalization from Harnack curves to general M-curves leads to transparent
algebro-geometric structures. In particular explicit formulas for the Ronkin
function and surface tension as integrals of meromorphic differentials on
M-curves are obtained. Furthermore we describe the variational principle for
the height function in the quasi-periodic case. Based on Schottky
uniformizations of Riemann surfaces we present concrete computational results
including computing the weights and sampling dimer configurations with them.
The computational results are in complete agreement with the theoretical
predictions.
