""" heat.py -- checks the results on the Laplacian and the heat flow from section 6. For random positively weighted undirected quantum graphs, given by Kraus operators, it checks the Lindblad form of -L, the complete positivity of e^{-tL} via the Choi matrices of its block components, its unitality, the invariance of psi, the symmetry, and the limit t -> infinity, which must be the orthogonal projection onto ker L. It then checks the examples: the simplex (depolarizing channel, and the Choi matrix of J - 1), the quantum square (Pauli channel), the Weyl cycle (dephasing), the heat trace and its small and large time behavior, governed by the smallest positive eigenvalue of L, which for the disconnected Weyl cycle over M_3 is 3, while lambda_2 = 0, and the failure of positivity for a negative classical weight. For a classical graph with 2 components, it checks that e^{-tL} has entries >= 0, which are > 0 inside the components, and 0 between them, and that a negative loop weight cancels in L. Results are written to heat.log. """ import numpy as np from scipy.linalg import expm, null_space from qspace import QSpace, Logger, close, weyl, ad, random_cp log = Logger("heat.log") rng = np.random.default_rng(6) def kraus_graph(q, nk=2): """random positively weighted undirected graph, with its Kraus operators in B(H)""" n, off = q.blocks, np.cumsum([0] + q.blocks) H, Ks = off[-1], [] for r in range(len(n)): for s in range(len(n)): for k in range(nk): K = np.zeros((H, H), dtype=complex) K[off[r]:off[r + 1], off[s]:off[s + 1]] = rng.normal(size=(n[r], n[s])) + 1j * rng.normal(size=(n[r], n[s])) Ks += [K, np.sqrt(n[s] / n[r]) * K.conj().T] # adding the Kraus operators of d^* def big(x): M = np.zeros((H, H), dtype=complex) for r, b in enumerate(x): M[off[r]:off[r + 1], off[r]:off[r + 1]] = b return M def small(M): return [M[off[r]:off[r + 1], off[r]:off[r + 1]] for r in range(len(n))] d = q.matrix_of(lambda x: small(sum(K.conj().T @ big(x) @ K for K in Ks))) lindblad = q.matrix_of(lambda x: small(sum(K.conj().T @ big(x) @ K - (K.conj().T @ K @ big(x) + big(x) @ K.conj().T @ K) / 2 for K in Ks))) return d, lindblad def is_cp(q, T): for r, nr in enumerate(q.blocks): for s, ns in enumerate(q.blocks): C = np.zeros((nr * ns, nr * ns), dtype=complex) for a in range(nr): for b in range(nr): e = np.zeros(q.N, dtype=complex) e[q.pos[(r, a, b)]] = 1 E = np.zeros((nr, nr)) E[a, b] = 1 C += np.kron(E, q.to_blocks(T @ e)[s]) if np.min(np.linalg.eigvalsh((C + C.conj().T) / 2)) < -1e-9: return False return True def kernel_projection(q, L): """orthogonal projection onto ker L, in L^2(V)""" Z = np.sqrt(q.G) @ null_space(L) Q, _ = np.linalg.qr(Z) return np.sqrt(q.Ginv) @ Q @ Q.conj().T @ np.sqrt(q.G) for blocks in [[2], [1, 2], [1, 1, 2], [3]]: q = QSpace(blocks) d, lind = kraus_graph(q) L = q.laplacian(d) psi = np.array([q.psi(e) for e in np.eye(q.N)]) cp = all(is_cp(q, expm(-t * L)) for t in [0.05, 0.3, 1, 3]) unital = all(close(expm(-t * L) @ q.one(), q.one()) for t in [0.3, 1]) inv = all(close(psi @ expm(-t * L), psi) for t in [0.3, 1]) sym = close(q.adjoint(L), L) lim = close(expm(-60 * L), kernel_projection(q, L), 1e-6) log(f"=== V with blocks {blocks}: undirected {close(q.adjoint(d), d)}, -L Lindblad {close(-L, lind)}, " f"e^(-tL) completely positive {cp}, unital {unital}, psi invariant {inv}, symmetric {sym}, " f"limit = projection onto ker L {lim}, dim ker L = {null_space(L).shape[1]}") for blocks in [[2], [3], [1, 2]]: q = QSpace(blocks) N, J = q.N, q.J() L = q.laplacian(q.simplex()) ok = all(close(expm(-t * L), np.exp(-N * t) * np.eye(N) + (1 - np.exp(-N * t)) * J / N) for t in [0.1, 0.7]) log(f"simplex over blocks {blocks}: L = N - J {close(L, N * np.eye(N) - J)}, heat flow formula {ok}") for n in [2, 3]: q = QSpace([n]) C = np.zeros((n * n, n * n), dtype=complex) S = q.simplex() for a in range(n): for b in range(n): E = np.zeros((n, n)) E[a, b] = 1 C += np.kron(E, q.to_blocks(S @ q.to_vec([E]))[0]) v = sum(np.kron(np.eye(n)[a], np.eye(n)[a]) for a in range(n)) / np.sqrt(n) log(f"Choi matrix of J - 1 over M_{n} equals n(1 - P) {close(C, n * (np.eye(n * n) - np.outer(v, v)))}") q = QSpace([2]) U, Lam = weyl(2, (1, 0)), weyl(2, (0, 1)) sx, sz, sy = U, Lam, np.array([[0, -1j], [1j, 0]]) L = q.laplacian(ad(q, U) + ad(q, Lam)) vec = lambda m: q.to_vec([m]) eig = [(np.eye(2), 0), (sx, 2), (sz, 2), (sy, 4)] a = rng.normal(size=4) x = a[0] * np.eye(2) + a[1] * sx + a[2] * sy + a[3] * sz t = 0.37 y = a[0] * np.eye(2) + np.exp(-2 * t) * (a[1] * sx + a[3] * sz) + np.exp(-4 * t) * a[2] * sy log(f"quantum square: eigenvectors 1, sx, sz, sy with eigenvalues 0, 2, 2, 4 " f"{all(close(L @ vec(m), lam * vec(m)) for m, lam in eig)}, Pauli channel {close(expm(-t * L) @ vec(x), vec(y))}") for n in [3, 5]: q = QSpace([n]) U = weyl(n, (1, 0)) L = q.laplacian(ad(q, U) + ad(q, U.conj().T)) w, V = np.linalg.eig(U) P = [np.outer(V[:, k], V[:, k].conj()) for k in range(n)] deph = q.matrix_of(lambda x: [sum(p @ x[0] @ p for p in P)]) trace = [np.trace(expm(-t * L)).real for t in [0, 60]] log(f"Weyl cycle over M_{n}: heat flow limit = dephasing {close(expm(-60 * L), deph, 1e-6)}, " f"heat trace from {trace[0]:.4f} to {trace[1]:.4f}") q = QSpace([3]) d = ad(q, weyl(3, (1, 0))) + ad(q, weyl(3, (2, 0))) + ad(q, weyl(3, (0, 1))) + ad(q, weyl(3, (0, 2))) L = q.laplacian(d) lam = 4 t = 0.3 series = np.exp(-lam * t) * sum(np.trace(np.linalg.matrix_power(d, k)) * t ** k / np.prod(range(1, k + 1)) for k in range(40)) log(f"quantum torus over M_3: Tr(e^(-tL)) = e^(-lambda t) sum c_k t^k / k! {np.isclose(np.trace(expm(-t * L)), series)}") d = np.array([[0, 1, -0.5], [1, 0, 1], [-0.5, 1, 0]]) L = np.diag(d.sum(axis=1)) - d log(f"classical graph with a negative weight: min entry of e^(-tL) at t = 0.05 is {np.min(expm(-0.05 * L)):.5f}") # heat traces: small time expansion N - t Tr(L), Tr(L) = 2E - Tr(d), and large time behavior rng_h = np.random.default_rng(12) okS, okL = True, True for blocks in [[2], [2, 1], [3]]: q = QSpace(blocks) Tm = random_cp(q, rng_h) d = Tm + q.adjoint(Tm) L = q.laplacian(d) E = q.psi(d @ q.one()).real / 2 okS &= np.isclose(np.trace(L).real, 2 * E - np.trace(d).real) t = 1e-6 okS &= np.isclose((q.N - np.trace(expm(-t * L)).real) / t, np.trace(L).real, rtol=1e-3) ev = np.sort(np.linalg.eigvals(L).real) c = int(np.sum(np.abs(ev) < 1e-9)) lam2 = ev[c] t1, t2 = 10 / lam2, 20 / lam2 rate = -(np.log(np.trace(expm(-t2 * L)).real - c) - np.log(np.trace(expm(-t1 * L)).real - c)) / (t2 - t1) okL &= np.isclose(rate, lam2, rtol=0.05) log(f"heat traces of random graphs: Tr(e^(-tL)) = N - t Tr(L) + O(t^2), with Tr(L) = 2E - Tr(d) {okS}; " f"Tr(e^(-tL)) - c decays at rate lambda_+, the smallest positive eigenvalue of L {okL}") # the Weyl cycle over M_3 is disconnected: lambda_+ = 3, while lambda_2 = 0 q3 = QSpace([3]) dW = ad(q3, weyl(3, (1, 0))) + ad(q3, weyl(3, (2, 0))) LW = q3.laplacian(dW) evW = np.sort(np.linalg.eigvals(LW).real) okW = all(np.isclose(np.trace(expm(-t * LW)).real, 3 + 6 * np.exp(-3 * t)) for t in [0.1, 0.7, 2.5]) log(f"Weyl cycle over M_3: Tr(e^(-tL)) = 3 + 6e^(-3t) {okW}, eigenvalues of L {(np.round(evW, 6) + 0.0).tolist()}, " f"so lambda_+ = 3 and lambda_2 = 0; for d = 0, L = 0 and the heat trace is constant, equal to N") # classical: entries of e^{-tL}, for a weighted graph with components {0,1,2} and {3,4} rng = np.random.default_rng(8) dcl = np.zeros((5, 5)) for i, j in [(0, 1), (1, 2), (3, 4)]: dcl[i, j] = dcl[j, i] = rng.uniform(0.5, 2) Lcl = np.diag(dcl.sum(1)) - dcl comp = [0, 0, 0, 1, 1] okc = True for t in [0.01, 0.5, 3]: H = expm(-t * Lcl) okc &= all((H[i, j] > 0) if comp[i] == comp[j] else abs(H[i, j]) < 1e-14 for i in range(5) for j in range(5)) dloop = dcl.copy() dloop[0, 0] = -1.5 Lloop = np.diag(dloop.sum(1)) - dloop log(f"classical graph with 2 components: e^(-tL) > 0 inside the components, 0 between them {okc}; " f"a negative loop weight cancels in L {close(Lloop, Lcl)}") log.save()