""" networks.py -- checks the results on electrical networks from section 12. With the quantum incidence map B from section 8, in orthonormal bases, it checks the Thomson principle (the minimal energy of the flows theta with divergence B^* theta = x is the effective resistance R(x) = , attained at the current B L^+ x), the Rayleigh monotonicity (adding positively weighted edges decreases the resistances), the Foster theorem (the sum over the edge coordinates of the resistances R(B^* eps) is N - 1), and the transfer current theorem (the probability that a random quantum spanning tree contains the edge coordinate eps is R(B^* eps)). Examples: K_4, the quantum square, random graphs over C + M_2 and M_2 + M_2. Results are written to networks.log. """ import itertools import numpy as np from qspace import QSpace, Logger, close from trees import graph log = Logger("networks.log") rng = np.random.default_rng(14) def random_kraus(q, pairs): kraus = [] for r, s in pairs: K = rng.normal(size=(q.blocks[r], q.blocks[s])) + 1j * rng.normal(size=(q.blocks[r], q.blocks[s])) kraus += [(r, s, K), (s, r, np.sqrt(q.blocks[s] / q.blocks[r]) * K.conj().T)] return kraus def laplacian_on(q, d): L = np.sqrt(q.G) @ q.laplacian(d) @ np.sqrt(q.Ginv) return (L + L.conj().T) / 2 def study(name, q, kraus, extra): d, B = graph(q, kraus) L = laplacian_on(q, d) Lp = np.linalg.pinv(L) v = np.array([np.sqrt(q.size[j]) if a == b else 0 for j, (r, a, b) in enumerate(q.index)]) thomson = True for t in range(5): x = rng.normal(size=q.N) + 1j * rng.normal(size=q.N) x = x - (v @ x) / (v @ v) * v theta = np.linalg.lstsq(B.conj().T, x, rcond=None)[0] # minimal norm flow with divergence x thomson &= close(B.conj().T @ theta, x) and close(theta, B @ Lp @ x) \ and np.isclose(np.linalg.norm(theta) ** 2, (x.conj() @ Lp @ x).real) d2, _ = graph(q, kraus + extra) Lp2 = np.linalg.pinv(laplacian_on(q, d2)) D = Lp - Lp2 P = np.eye(q.N) - np.outer(v, v) / (v @ v) rayleigh = np.min(np.linalg.eigvalsh(P @ ((D + D.conj().T) / 2) @ P)) > -1e-9 M = B.shape[0] R = np.array([(B[e] @ Lp @ B[e].conj()).real for e in range(M)]) i = [j for j, (r, a, b) in enumerate(q.index) if a == b][0] Bi = np.delete(B, i, 1) tot, marg = 0.0, np.zeros(M) for S in itertools.combinations(range(M), q.N - 1): w = abs(np.linalg.det(Bi[list(S)])) ** 2 if w > 1e-12: tot += w marg[list(S)] += w log(f"{name}: N = {q.N}, edge coordinates {M}, Thomson principle {thomson}, Rayleigh monotonicity {rayleigh}, " f"Foster sum = {R.sum():.6f}, transfer current: tree marginals = resistances {np.allclose(marg / tot, R)}") q = QSpace([1, 1, 1, 1]) study("K_4", q, [(r, s, np.eye(1)) for r in range(4) for s in range(4) if r != s], random_kraus(q, [(0, 1)])) q = QSpace([2]) sx, sz = np.array([[0, 1], [1, 0]], dtype=complex), np.diag([1, -1]).astype(complex) study("quantum square", q, [(0, 0, sx), (0, 0, sz)], random_kraus(q, [(0, 0)])) q = QSpace([1, 2]) study("random graph over C + M_2", q, random_kraus(q, [(0, 1), (1, 1)]), random_kraus(q, [(1, 1)])) q = QSpace([2, 2]) study("random graph over M_2 + M_2", q, random_kraus(q, [(0, 1)]) + [(0, 0, sx)], random_kraus(q, [(0, 0), (1, 1)])) log.save()