Can we define partition function for a classical field theory? I heard that $d$ dimensional relativistic quantum field theory can be viewed as a $d+1$-dimensional statistical mechanics. Can a relativistic/non-relativistic classical field theory be also looked upon as a statistical mechanical system? If yes, how to write down a partition function for such a system?
EDIT: If there is no such general rule, can in certain special cases, a classical field theory be looked upon as a statistical mechanical system and write down a partition function for it?
 A: The answer to your question depends on which type of partition function we consider. There are essentially two types: the (complex) time and finite-temperature partition functions, defined in the quantum case as, respectively,
$$ Z_\textrm{time}(z) \equiv \textrm{Tr} \; e^{-i z \hat H / \hbar}  \qquad \textrm{and} \qquad Z_\textrm{temp}(\beta) \equiv \textrm{Tr}  \;e^{- \beta \hat H}.$$
The former, $Z_\textrm{time}(z)$, naturally appears when studying the (time-dependent) properties of quantum theories at zero temperature. Note that $z$ has units of time, which necessitates the $\hbar$ to make the units work out. Commonly, one either considers real time $z =t$ or imaginary time $z = - i \tau$, which are related by a Wick rotation. The latter, $Z_\textrm{temp}(\beta)$, is the object of interest when studying finite-temperature statistical-mechanical properties of a quantum systems. Note that $\beta$ has units of inverse energy (setting $k_B = 1$), hence there is no need for $\hbar$.
It is often sloppily said that the imaginary time partition function coincides with the finite-temperature one. This is true if we set $\hbar = 1$, but we see that more generally $Z_\textrm{time}(-i \tau) = Z_\textrm{temp}(\tau / \hbar)$. In particular, this means their classical limits $\hbar \to 0$ are very different.
To obtain their classical limits, it is useful to express both in a path integral formulation. This can be derived as usual, i.e., by inserting a bunch of resolutions of identity. The outcomes are:
$$ Z_\textrm{time}(z) = \int e^{\frac{i}{\hbar} \int_0^z  \mathrm d z' \int \mathrm d^d x \left( \frac{1}{2}(\partial_{z'} \varphi)^2 - V(\varphi) \right)} \mathrm D[\varphi(x,z')] ,$$
$$ Z_\textrm{temp}(\beta) = \int e^{- \int_0^\beta  \mathrm d \beta' \int \mathrm d^d x \left( \frac{1}{2\hbar^2}(\partial_{\beta'} \varphi)^2 + V(\varphi) \right)} \mathrm D[\varphi(x,\beta')]. $$
(If you are curious how $\hbar$ entered into the second expression (despite the aforementioned definition not containing $\hbar$), it arose by virtue of the resolutions of identity and $\langle \Pi|\varphi\rangle \propto e^{\frac{i}{\hbar} \int \Pi(x) \varphi(x) \mathrm d^d x}$.)
It is now straight-forward to obtain the classical limits. For $Z_\textrm{time}(z)$, the stationary phase/method of steepest descent (depending on whether $z$ is real or imaginary) tells us that the partition function is dominated by the trajectories determined by the Euler-Lagrange equations. For $z=t$, these are exactly the classical equations of motion, hence $\lim_{\hbar \to 0 } Z_\textrm{time}(t)$ is the expression given in Prof. Legolasov's answer. Note that this expression still contains $\hbar$, and hence it is an intrinsically non-classical object, despite being evaluated for classical trajectories. As such, it is perhaps not surprising that this ``classical'' partition function does not really appear on its own right in classical physics.
For $Z_\textrm{temp}(\beta)$, however, we see that $\hbar$ only appears in the kinetic term. Hence, for $\hbar \to 0$, the stationary phase approximation tells us that we basically need to kill this term, i.e., we should only consider static solutions. In conclusion,
$$ \boxed{\lim_{\hbar \to 0} Z_\textrm{temp}(\beta) \propto  \int e^{- \beta \int \mathrm d^d x \; V(\varphi) } \mathrm D[\varphi(x)] } \;. $$
We thus recover the classical statistical-mechanical partition function! Indeed,
$$ Z_\textrm{class}(\beta) \equiv \int e^{-\beta H(\Pi,\varphi)} \mathrm D[\varphi(x)] \mathrm D[\Pi(x)] \propto \int e^{-\beta \int \mathrm d^d x V(\varphi)} \mathrm D[\varphi(x)],$$
since one can always perform the trivial gaussian integral over the momentum field (since the kinetic term $\propto \Pi^2$), which just gives an uninteresting overall prefactor.
A: In quantum mechanics, the partition function is given by the path integral
$$ Z = \int Dq \exp \left( i \hbar^{-1} S[q] \right). $$
Its classical limit is
$$ Z_{\hbar \rightarrow 0} \sim \exp \left( i \hbar^{-1} S[q_c] \right), $$
where the classical trajectory $q_c(t)$ is the solution of the equations of motion.
However, it might not play a major role in either the formulation of the theory nor in practical calculations.
