yang
This project has not described itself yet.
Brought by drakestapleton
yang / scripts / outer_slab_spectrum.py
| 1 | """CPU diagnostic for the radius-one slab in replica_shell_probe (not a sampler).""" |
| 2 | import numpy as np |
| 3 | |
| 4 | |
| 5 | COLUMNS = ('identity', 'four_min', 'rigid_min', 'rigid_max', 'site_min_sum', 'face_min_sum', |
| 6 | 'sites_straddling_zero') |
| 7 | |
| 8 | |
| 9 | def _dot_form(a, b): |
| 10 | """Matrix of q -> a dot (q b q^-1) on unit quaternions (Euclidean dot).""" |
| 11 | x, y = a[..., 1:], b[..., 1:] |
| 12 | xy = (x*y).sum(axis=-1) |
| 13 | m = np.empty((*xy.shape, 4, 4)) |
| 14 | m[..., 0, 0] = xy |
| 15 | m[..., 1:, 0] = m[..., 0, 1:] = np.cross(y, x) |
| 16 | outer = x[..., :, None]*y[..., None, :] |
| 17 | m[..., 1:, 1:] = outer + outer.swapaxes(-1, -2) - xy[..., None, None]*np.eye(3) |
| 18 | return m + (a[..., 0]*b[..., 0])[..., None, None]*np.eye(4) |
| 19 | |
| 20 | |
| 21 | def measure(lat, u, beta, verify, mul, inv): |
| 22 | """Min/max of the signed field before tanh; local extrema are relaxations only.""" |
| 23 | frame = lat.tree_frame(u, lat.layers, verify) |
| 24 | mask = lat.masks['slab'][1] |
| 25 | # Each crossing temporal plaquette has a lone spatial link at its top. |
| 26 | sites = lat.sites[mask[0] != mask[0, lat.plus[3]]] |
| 27 | forms = [] |
| 28 | for i in range(3): |
| 29 | top = frame[:, i, lat.plus[3, sites]] |
| 30 | path = mul(mul(inv(frame[:, 3, sites]), frame[:, i, sites]), |
| 31 | frame[:, 3, lat.plus[i, sites]]) |
| 32 | before = (path*top).sum(axis=(0, 2)) |
| 33 | crossed = _dot_form(path[0], top[1]) + _dot_form(top[0], path[1]) |
| 34 | forms.append((beta/2)*(before[:, None, None]*np.eye(4)-crossed)) |
| 35 | face = np.stack(forms) |
| 36 | # U(1) allows only q in the real-i plane, not arbitrary SU(2) conjugators. |
| 37 | dim = 2 if lat.group == 'U1' else 4 |
| 38 | face = face[..., :dim, :dim] |
| 39 | site = face.sum(axis=0) |
| 40 | whole = site.sum(axis=0) |
| 41 | eig, vec = np.linalg.eigh(whole) |
| 42 | site_eig = np.linalg.eigvalsh(site) |
| 43 | if verify: |
| 44 | # Both extremizers and a generic off-axis orientation against the *full* |
| 45 | # rotated/swapped Wilson action, without reusing the crossing-face formula. |
| 46 | before = lat.traces(frame).sum() |
| 47 | generic = np.arange(1, dim+1, dtype=float) |
| 48 | for v in (vec[:, 0], vec[:, -1], generic/np.linalg.norm(generic)): |
| 49 | q = np.pad(v, (0, 4-dim)) |
| 50 | rotated = frame.copy() |
| 51 | rotated[1] = mul(mul(q, frame[1]), inv(q)) |
| 52 | swapped = np.where(mask[None, ..., None], rotated[::-1], rotated) |
| 53 | direct = beta*(before-lat.traces(swapped).sum())/2 |
| 54 | np.testing.assert_allclose(v @ whole @ v, direct, atol=1e-9, rtol=0) |
| 55 | if dim == 2: |
| 56 | np.testing.assert_allclose(face, face[..., :1, :1]*np.eye(2), atol=1e-12, rtol=0) |
| 57 | return (whole[0, 0], whole.diagonal().min(), eig[0], eig[-1], site_eig[:, 0].sum(), |
| 58 | np.linalg.eigvalsh(face)[..., 0].sum(), ((site_eig[:, 0]<0) & (site_eig[:, -1]>0)).sum()) |