""" walks.py -- checks the random walk on a positively weighted undirected quantum graph (section 12): P(x) = d(1)^(-1/2) d(x) d(1)^(-1/2) is unital, and psi(d(1) .) is stationary. For the quantum square, which is bipartite, it checks that P(sigma_y) = -sigma_y, so that P^m(sigma_y) oscillates, while the averages of the first m powers converge, and that e^{-tL} = e^{kt(P-1)} in the regular case. Also checks that the components algebra ker L is a *-algebra, for the Weyl cycle (section 6). Results are written to walks.log. """ import numpy as np from qspace import QSpace, Logger, close, random_cp, weyl, ad rng = np.random.default_rng(2026) log = Logger("walks.log") for blocks in [[2, 1], [2, 2], [3], [3, 1]]: qs = QSpace(blocks) N = qs.N T = random_cp(qs, rng) d = T + qs.adjoint(T) sq = [] for m in qs.to_blocks(qs.degree(d)): ev, W = np.linalg.eigh(m) sq.append(W @ np.diag(ev ** -0.5) @ W.conj().T) P = qs.matrix_of(lambda x: [sq[r] @ qs.to_blocks(d @ qs.to_vec(x))[r] @ sq[r] for r in range(len(x))]) rho = qs.degree(d) stat = all(abs(qs.psi(qs.product(rho, P @ e)) - qs.psi(qs.product(rho, e))) < 1e-8 for e in np.eye(N, dtype=complex)) log(f"=== V with blocks {blocks}: P unital {close(P @ qs.one(), qs.one())}, psi(d(1) .) stationary {stat}") for n in [3, 4, 5]: qs = QSpace([n]) U = weyl(n, (1, 0)) d = ad(qs, U) + ad(qs, U.conj().T) w, Vec = np.linalg.eig(qs.laplacian(d)) K = Vec[:, np.abs(w) < 1e-9] Pk = K @ np.linalg.pinv(K) ok = all(np.max(np.abs(Pk @ qs.product(K[:, a], K[:, b]) - qs.product(K[:, a], K[:, b]))) < 1e-8 for a in range(K.shape[1]) for b in range(K.shape[1])) ok = ok and all(np.max(np.abs(Pk @ qs.star(K[:, a]) - qs.star(K[:, a]))) < 1e-8 for a in range(K.shape[1])) log(f"=== Weyl cycle on M_{n}: dim ker L = {K.shape[1]}, ker L is a *-algebra {ok}") # the quantum square: regular of valence 2, bipartite, so the walk oscillates on sigma_y from scipy.linalg import expm q = QSpace([2]) d = ad(q, weyl(2, (1, 0))) + ad(q, weyl(2, (0, 1))) P = d / 2 sy = q.to_vec([np.array([[0, -1j], [1j, 0]])]) osc = all(close(np.linalg.matrix_power(P, m) @ sy, (-1) ** m * sy) for m in range(1, 7)) x = q.to_vec([rng.normal(size=(2, 2)) + 1j * rng.normal(size=(2, 2))]) avg = sum(np.linalg.matrix_power(P, m) for m in range(400)) / 400 @ x lim = q.psi(x) * q.one() / q.N heat = all(close(expm(-t * q.laplacian(d)), expm(2 * t * (P - np.eye(4)))) for t in [0.3, 1.7]) log(f"=== quantum square: P(sigma_y) = -sigma_y, P^m(sigma_y) = (-1)^m sigma_y {osc}, Cesaro averages of P^m(x) " f"-> psi(x)1/N {np.allclose(avg, lim, atol=1e-2)}, e^(-tL) = e^(kt(P-1)) {heat}") log.save()