  We describe a general method for turning quantum circuits into sparse quantum
subsystem codes. The idea is to turn each circuit element into a set of
low-weight gauge generators that enforce the input-output relations of that
circuit element. Using this prescription, we can map an arbitrary stabilizer
code into a new subsystem code with the same distance and number of encoded
qubits but where all the generators have constant weight, at the cost of adding
some ancilla qubits. With an additional overhead of ancilla qubits, the new
code can also be made spatially local.
  Applying our construction to certain concatenated stabilizer codes yields
families of subsystem codes with constant-weight generators and with minimum
distance $d = n^{1-\epsilon}$, where $\epsilon = O(1/\sqrt{\log n})$. For
spatially local codes in $D$ dimensions we nearly saturate a bound due to
Bravyi and Terhal and achieve $d = n^{1-\epsilon-1/D}$. Previously the best
code distance achievable with constant-weight generators in any dimension, due
to Freedman, Meyer and Luo, was $O(\sqrt{n\log n})$ for a stabilizer code.
