  Random quantum circuits have played a central role in establishing the
computational advantages of near-term quantum computers over their conventional
counterparts. Here, we use ensembles of low-depth random circuits with local
connectivity in $D\ge 1$ spatial dimensions to generate quantum
error-correcting codes. For random stabilizer codes and the erasure channel, we
find strong evidence that a depth $O(\log N)$ random circuit is necessary and
sufficient to converge (with high probability) to zero failure probability for
any finite amount below the optimal erasure threshold, set by the channel
capacity, for any $D$. Previous results on random circuits have only shown that
$O(N^{1/D})$ depth suffices or that $O(\log^3 N)$ depth suffices for all-to-all
connectivity ($D \to \infty$). We then study the critical behavior of the
erasure threshold in the so-called moderate deviation limit, where both the
failure probability and the distance to the optimal threshold converge to zero
with $N$. We find that the requisite depth scales like $O(\log N)$ only for
dimensions $D \ge 2$, and that random circuits require $O(\sqrt{N})$ depth for
$D=1$. Finally, we introduce an "expurgation" algorithm that uses quantum
measurements to remove logical operators that cause the code to fail by turning
them into additional stabilizers or gauge operators. With such targeted
measurements, we can achieve sub-logarithmic depth in $D\ge 2$ below capacity
without increasing the maximum weight of the check operators. We find that for
any rate beneath the capacity, high-performing codes with thousands of logical
qubits are achievable with depth 4-8 expurgated random circuits in $D=2$
dimensions. These results indicate that finite-rate quantum codes are
practically relevant for near-term devices and may significantly reduce the
resource requirements to achieve fault tolerance for near-term applications.
