yang
This project has not described itself yet.
Brought by drakestapleton
yang / scripts / vertex_slab_orbit.py
| 1 | """Radius-one outer slab, unframed pair, second-replica vertex gauges only. |
| 2 | |
| 3 | The coordinate witness is feasible, not a claimed minimum. The spectral lower |
| 4 | bound is a binary64 diagnostic, not an interval or exact-arithmetic proof. |
| 5 | """ |
| 6 | import numpy as np |
| 7 | |
| 8 | |
| 9 | class SlabOrbit: |
| 10 | """Outer field C + r.B.b on each of two spatial checkerboards. |
| 11 | |
| 12 | `sites[s,color,v]` lists the actual top vertices. Coordinates at those |
| 13 | sites are unit quaternions (SU2) or unit real-i pairs (embedded U1). |
| 14 | The other vertices have identity gauge. Each crossing face has a top |
| 15 | link T and a complementary path P with the *same oriented endpoints*. |
| 16 | For vertex coordinates x,y, <P,x T y*> = <P y,x T>. Subtract the two |
| 17 | crossed pairings from the uncrossed pairings, all in beta/2 units. |
| 18 | """ |
| 19 | |
| 20 | def __init__(self, lat, u, beta, mul, inv): |
| 21 | side = round(len(lat.sites)**0.25) |
| 22 | if side not in (4, 6) or side**4 != len(lat.sites): |
| 23 | raise ValueError('dense per-sheet orbit diagnostic supports even sides 4 and 6 only') |
| 24 | if lat.group not in ('SU2', 'U1') or u.dtype != np.float64 or not np.isfinite(beta): |
| 25 | raise ValueError('expected a binary64 SU2 or embedded U1 replica pair and finite beta') |
| 26 | self.dim = d = 2 if lat.group == 'U1' else 4 |
| 27 | self.beta = beta |
| 28 | self.volume = len(lat.sites) |
| 29 | mask = lat.masks['slab'][1][0] |
| 30 | bottom = lat.sites[mask != mask[lat.plus[3]]] |
| 31 | top = lat.plus[3, bottom] |
| 32 | times = np.unique(top % side) # time is last in the sampler's unravel_index |
| 33 | if len(times) != 2: |
| 34 | raise ValueError('expected two separate top sheets') |
| 35 | self.sites = np.array([[top[(top % side == t) & (lat.parity[top] == color)] |
| 36 | for color in (0, 1)] for t in times]) |
| 37 | _, _, m = self.sites.shape |
| 38 | # Local vertex number within a color, separately for each sheet. |
| 39 | number = np.full(self.volume, -1, dtype=int) |
| 40 | number[self.sites] = np.arange(m) |
| 41 | sites = self.sites.reshape(2, 2*m) |
| 42 | bottom = lat.minus[3, sites] |
| 43 | basis = np.eye(4)[:d] |
| 44 | self.constant = np.zeros(2) |
| 45 | blocks = np.zeros((2, m, d, m, d)) |
| 46 | for i in range(3): |
| 47 | top_link = u[:, i, sites] |
| 48 | path = mul(mul(inv(u[:, 3, bottom]), u[:, i, bottom]), u[:, 3, lat.plus[i, bottom]]) |
| 49 | self.constant += (beta/2) * (path*top_link).sum(axis=(0, 2, 3)) |
| 50 | # Row a, column b: <e_a T1, P0 e_b> + <e_a P1, T0 e_b>. |
| 51 | def pairing(p, t): |
| 52 | return mul(basis, t[..., None, :]) @ mul(p[..., None, :], basis).swapaxes(-1, -2) |
| 53 | edges = (-beta/2) * (pairing(path[0], top_link[1]) + pairing(top_link[0], path[1])) |
| 54 | dst = number[lat.plus[i, sites]] |
| 55 | for s in range(2): |
| 56 | v = np.arange(m) |
| 57 | blocks[s, v, :, dst[s, :m], :] += edges[s, :m] |
| 58 | blocks[s, dst[s, m:], :, v, :] += edges[s, m:].swapaxes(-1, -2) |
| 59 | self.B = blocks.reshape(2, m*d, m*d) |
| 60 | |
| 61 | def identity(self): |
| 62 | q = np.zeros((*self.sites.shape, self.dim)) |
| 63 | q[..., 0] = 1. |
| 64 | return q |
| 65 | |
| 66 | def generic(self): |
| 67 | """Fixed, site-varying, configuration-independent control/start field.""" |
| 68 | q = np.random.default_rng(1977).normal(size=(*self.sites.shape, self.dim)) |
| 69 | return q / np.linalg.norm(q, axis=-1, keepdims=True) |
| 70 | |
| 71 | def site_field(self, q): |
| 72 | """Expand sheet coordinates to a full site field (including U1 padding).""" |
| 73 | g = np.zeros((self.volume, 4)) |
| 74 | g[:, 0] = 1. |
| 75 | g[self.sites, :self.dim] = q |
| 76 | return g |
| 77 | |
| 78 | def _field(self, q, color): |
| 79 | other = q[:, 1-color].reshape(2, -1) |
| 80 | B = self.B if color == 0 else self.B.swapaxes(-1, -2) |
| 81 | return np.einsum('sij,sj->si', B, other).reshape(q[:, color].shape) |
| 82 | |
| 83 | def sheet_values(self, q): |
| 84 | return self.constant + np.einsum('sva,sva->s', q[:, 0], self._field(q, 0)) |
| 85 | |
| 86 | def optimize(self): |
| 87 | """Exact independent single-vertex updates per color; two fixed starts.""" |
| 88 | best = self.identity() |
| 89 | values = self.sheet_values(best) |
| 90 | for q in (best.copy(), self.generic()): |
| 91 | previous = self.sheet_values(q) |
| 92 | for _ in range(96): |
| 93 | for color in (0, 1): |
| 94 | field = self._field(q, color) |
| 95 | norm = np.linalg.norm(field, axis=-1, keepdims=True) |
| 96 | np.divide(-field, norm, out=q[:, color], where=norm != 0) |
| 97 | current = self.sheet_values(q) |
| 98 | better = current < values |
| 99 | best[better] = q[better] |
| 100 | values = np.minimum(values, current) |
| 101 | if np.all(previous-current <= 1.e-10 * np.maximum(1., np.abs(previous))): |
| 102 | break |
| 103 | previous = current |
| 104 | return best |
| 105 | |
| 106 | def dual_lower(self, q): |
| 107 | """H=[[0,B],[B.T,0]]/2; shift each vertex block by lambda_v I. |
| 108 | |
| 109 | For K=H-diag(lambda), ||q||^2=N gives per-sheet lower bound |
| 110 | C + sum(lambda) + N*eigmin(K). Choose lambda_v=q_v.(Hq)_v |
| 111 | at the feasible witness; the inequality holds even off stationarity. |
| 112 | Only one (N*d)^2 shifted matrix is needed at a time, never a 4D |
| 113 | volume-wide matrix. No claim that these multipliers optimize the dual. |
| 114 | """ |
| 115 | n = self.sites.shape[1]*self.sites.shape[2] |
| 116 | k = n*self.dim |
| 117 | h = k//2 |
| 118 | eps = np.finfo(float).eps |
| 119 | shifts = np.stack([np.einsum('sva,sva->sv', q[:, c], self._field(q, c))/2 |
| 120 | for c in (0, 1)], axis=1).reshape(2, n) |
| 121 | K = np.zeros((k, k)) |
| 122 | lower = 0. |
| 123 | for s in range(2): |
| 124 | K[:h, h:] = self.B[s]/2 |
| 125 | K[h:, :h] = K[:h, h:].T |
| 126 | np.fill_diagonal(K, -np.repeat(shifts[s], self.dim)) |
| 127 | eig = np.linalg.eigvalsh(K)[0] |
| 128 | # Conservative binary64 *allowance*, not a certified LAPACK error |
| 129 | # bound. Include beta even if the assembled coefficients cancel; |
| 130 | # the final N-fold subtraction also cushions the constant and sum. |
| 131 | margin = 128*eps*k*max(1., abs(self.beta), np.linalg.norm(K, np.inf)) |
| 132 | lower += self.constant[s] + shifts[s].sum() + n*(eig-margin) |
| 133 | return float(lower) |
| 134 | |
| 135 | |
| 136 | def transform_second(lat, u, g, mul, inv): |
| 137 | """Full directed-link gauge transform, independent of the crossing faces.""" |
| 138 | pair = u.copy() |
| 139 | pair[1] = mul(mul(g, u[1]), inv(g[lat.plus])) |
| 140 | return pair |
| 141 | |
| 142 | |
| 143 | def direct_outer_J(lat, pair, beta): |
| 144 | """Both complete Wilson actions, before and after exchanging outer links.""" |
| 145 | mask = lat.masks['slab'][1] |
| 146 | swapped = np.where(mask[None, ..., None], pair[::-1], pair) |
| 147 | return (beta/2)*(lat.traces(pair) - lat.traces(swapped)).sum() |
| 148 | |
| 149 | |
| 150 | def analyze(lat, u, beta, verify, mul, inv): |
| 151 | """Return raw identity J, feasible witness J, and floating dual lower J.""" |
| 152 | orbit = SlabOrbit(lat, u, beta, mul, inv) |
| 153 | identity = orbit.identity() |
| 154 | q = orbit.optimize() |
| 155 | raw, witness = (float(orbit.sheet_values(field).sum()) for field in (identity, q)) |
| 156 | lower = orbit.dual_lower(q) |
| 157 | if not (np.isfinite([lower, witness, raw]).all() and lower <= witness <= raw): |
| 158 | raise ArithmeticError('nonfinite or unordered vertex-orbit diagnostic') |
| 159 | # Check both endpoints whenever a negative witness might be reported, even |
| 160 | # off schedule. The caller must still use a sign tolerance in classification. |
| 161 | if verify or witness < 0: |
| 162 | baseline = lat.traces(u) |
| 163 | fields = (identity, q, orbit.generic()) if verify else (identity, q) |
| 164 | for field in fields: |
| 165 | pair = transform_second(lat, u, orbit.site_field(field), mul, inv) |
| 166 | np.testing.assert_allclose(lat.traces(pair), baseline, atol=2e-12, rtol=0) |
| 167 | np.testing.assert_allclose(direct_outer_J(lat, pair, beta), orbit.sheet_values(field).sum(), |
| 168 | atol=1e-9*max(1., abs(beta)), rtol=0) |
| 169 | return raw, witness, lower |