  We provide the first tensor network method for computing quantum weight
enumerator polynomials in the most general form. If a quantum code has a known
tensor network construction of its encoding map, our method is far more
efficient, and in some cases exponentially faster than the existing approach.
As a corollary, it produces decoders and an algorithm that computes the code
distance. For non-(Pauli)-stabilizer codes, this constitutes the current best
algorithm for computing the code distance. For degenerate stabilizer codes, it
can be substantially faster compared to the current methods. We also introduce
novel weight enumerators and their applications. In particular, we show that
these enumerators can be used to compute logical error rates exactly and thus
construct (optimal) decoders for any i.i.d. single qubit or qudit error
channels. The enumerators also provide a more efficient method for computing
non-stabilizerness in quantum many-body states. As the power for these speedups
rely on a Quantum Lego decomposition of quantum codes, we further provide
systematic methods for decomposing quantum codes and graph states into a
modular construction for which our technique applies. As a proof of principle,
we perform exact analyses of the deformed surface codes, the holographic
pentagon code, and the 2d Bacon-Shor code under (biased) Pauli noise and
limited instances of coherent error at sizes that are inaccessible by brute
force.
