  We map the dynamics of entanglement in random unitary circuits, with finite
on-site Hilbert space dimension $q$, to an effective classical statistical
mechanics, and develop general diagrammatic tools for calculations in random
unitary circuits. We demonstrate explicitly the emergence of a `minimal
membrane' governing entanglement growth, which in 1+1D is a directed random
walk in spacetime (or a variant thereof). Using the replica trick to handle the
logarithm in the definition of the $n$th R\'enyi entropy $S_n$, we map the
calculation of the entanglement after a quench to a problem of interacting
random walks. A key role is played by effective classical spins (taking values
in a permutation group) which distinguish between different ways of pairing
spacetime histories in the replicated system. For the second R\'enyi entropy,
$S_2$, we are able to take the replica limit explicitly. This gives a mapping
between entanglement growth and a directed polymer in a random medium at finite
temperature (confirming Kardar-Parisi-Zhang (KPZ) scaling for entanglement
growth in generic noisy systems). We find that the entanglement growth rate
(`speed') $v_n$ depends on the R\'enyi index $n$, and we calculate $v_2$ and
$v_3$ in an expansion in the inverse local Hilbert space dimension, $1/q$.
These rates are determined by the free energy of a random walk, and of a bound
state of two random walks, respectively, and include contributions of
`energetic' and `entropic' origin. We give a combinatorial interpretation of
the Page-like subleading corrections to the entanglement at late times and
discuss the dynamics of the entanglement close to and after saturation. We
briefly discuss the application of these insights to time-independent
Hamiltonian dynamics.
