""" trees.py -- checks the quantum matrix-tree theorem of section 8. For quantum graphs given by Kraus operators K in the blocks M_{n_r x n_s}, it builds the quantum incidence map B(x) = (sqrt(n_s/2)(x_r K - K x_s)), in orthonormal bases, checks that L = B^*B, that tau = det(L_(i))/n_i for the diagonal indices i, and that tau equals the Cauchy-Binet sum (1/n_i) sum_S |det B_S,(i)|^2 over the sets S of N-1 edge coordinates, recording the number of quantum spanning trees (the S with nonzero minor) and the range of their weights. Examples: the complete graph K_4, the quantum square, the quantum star over C + M_2, a random graph over C + M_2, and the connected graph over M_2 + M_2 from section 7. Results are written to trees.log. """ import itertools import numpy as np from qspace import QSpace, Logger, close rng = np.random.default_rng(9) def normalized(q, r, s, K): """rescale K so that x -> K^* x_r K is a Hadamard projection""" def f(x): out = [np.zeros((n, n), dtype=complex) for n in q.blocks] out[s] = K.conj().T @ x[r] @ K return out A = q.matrix_of(f) B = q.schur_fast(A, A) lam = (np.vdot(A.flatten(), B.flatten()) / np.vdot(A.flatten(), A.flatten())).real return K / np.sqrt(lam) def graph(q, kraus): """d and the incidence matrix B (orthonormal bases), from a list of (r, s, K)""" def f(x): out = [np.zeros((n, n), dtype=complex) for n in q.blocks] for r, s, K in kraus: out[s] += K.conj().T @ x[r] @ K return out d = q.matrix_of(f) rows = [] for r, s, K in kraus: nr, ns = q.blocks[r], q.blocks[s] for a in range(nr): for b in range(ns): row = np.zeros(q.N, dtype=complex) for j in range(q.N): e = np.zeros(q.N, dtype=complex) e[j] = 1 / np.sqrt(q.size[j]) # orthonormal basis f_j x = q.to_blocks(e) row[j] = np.sqrt(ns / 2) * (x[r] @ K - K @ x[s])[a, b] rows.append(row) return d, np.array(rows) def check(name, q, kraus): d, B = graph(q, kraus) L = q.laplacian(d) Lon = np.sqrt(q.G) @ L @ np.sqrt(q.Ginv) # L in the basis f_j ev = np.linalg.eigvalsh((Lon + Lon.conj().T) / 2) tau = np.prod(ev[1:]) / q.N diag = [j for j, (r, a, b) in enumerate(q.index) if a == b] cof = [np.linalg.det(np.delete(np.delete(Lon, j, 0), j, 1)).real / q.size[j] for j in diag] i = diag[0] Bi = np.delete(B, i, 1) weights = [] for S in itertools.combinations(range(B.shape[0]), q.N - 1): w = abs(np.linalg.det(Bi[list(S)])) ** 2 / q.size[i] if w > 1e-10: weights.append(w) log(f"{name}: N = {q.N}, edge coordinates {B.shape[0]}, undirected {close(q.adjoint(d), d)}, " f"L = B*B {close(Lon, B.conj().T @ B)}, connected {abs(ev[1]) > 1e-8}, tau = {tau:.6f}, " f"diagonal cofactors {np.allclose(cof, tau)}, Cauchy-Binet {np.isclose(sum(weights), tau)}, " f"quantum spanning trees {len(weights)}, weights in [{min(weights):.4g}, {max(weights):.4g}]") if __name__ == "__main__": log = Logger("trees.log") q = QSpace([1, 1, 1, 1]) kraus = [(r, s, np.eye(1)) for r in range(4) for s in range(4) if r != s] check("complete graph K_4", q, kraus) q = QSpace([2]) sx, sz = np.array([[0, 1], [1, 0]], dtype=complex), np.diag([1, -1]).astype(complex) check("quantum square", q, [(0, 0, sx), (0, 0, sz)]) q = QSpace([1, 2]) kraus = [] for a in range(2): K = np.zeros((1, 2), dtype=complex) K[0, a] = 1 kraus += [(0, 1, normalized(q, 0, 1, K)), (1, 0, normalized(q, 1, 0, K.conj().T))] check("quantum star over C + M_2", q, kraus) kraus = [] for r, s in [(0, 1), (1, 1)]: K = rng.normal(size=(q.blocks[r], q.blocks[s])) + 1j * rng.normal(size=(q.blocks[r], q.blocks[s])) kraus.append((r, s, K)) kraus.append((s, r, np.sqrt(q.blocks[s] / q.blocks[r]) * K.conj().T)) check("random graph over C + M_2", q, kraus) q = QSpace([2, 2]) K = np.diag([1.0, 2.0]).astype(complex) kraus = [(0, 1, normalized(q, 0, 1, K)), (1, 0, normalized(q, 1, 0, K.conj().T)), (0, 0, normalized(q, 0, 0, sx))] check("connected graph over M_2 + M_2 from section 7", q, kraus) log.save()