Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/yang/blob/main/scripts/vertex_shell_probe.py # yang This project has not described itself yet. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `yang / scripts / vertex_shell_probe.py` 63 lines ยท 2994 bytes Raw Blame History 1 """Fixed local gauge averages of the unframed two-slab Wilson estimator.""" 2 import numpy as np 3 4 from vertex_slab_orbit import analyze 5 6 7 COLUMNS = ('inner_j', 'outer_j', 'witness_j', 'dual_lower_j', 'checker_j', 'pattern_j', 8 'pattern_checker_j', 'inner_abs', 'weighted_mean_abs', 'weighted_abs_mean', 9 'weighted_cancellation', 'log_weighted_loss') 10 11 12 class VertexProbe: 13 def __init__(self, lat): 14 mask = lat.masks['slab'][1][0] 15 top = lat.plus[3, mask != mask[lat.plus[3]]] 16 # Outside these sheets every gauge is the identity. Fixed auxiliary seed: 17 # fields are the same across chain starts and beta, independent of samples. 18 identity = np.zeros((len(lat.sites), 4)) 19 identity[:, 0] = 1 20 checker = np.ones((len(lat.sites), 1)) 21 checker[top, 0] = 1 - 2*lat.parity[top] 22 pattern = identity.copy() 23 q = np.random.default_rng(`20261123`).normal(size=(len(top), 4)) 24 if lat.group == 'U1': 25 q[:, 2:] = 0 26 pattern[top] = q / np.linalg.norm(q, axis=1, keepdims=True) 27 self.fields = (identity*checker, pattern, pattern*checker) 28 29 def measure(self, lat, u, beta, verify, mul, inv): 30 outer, witness, lower = analyze(lat, u, beta, verify, mul, inv) 31 traces = lat.traces(u) 32 score = traces.sum() 33 inner_mask, outer_mask = lat.masks['slab'] 34 35 def exchange(pair, mask): 36 swapped = np.where(mask[None, ..., None], pair[::-1], pair) 37 return beta*(score - lat.traces(swapped).sum())/2 38 39 inner = exchange(u, inner_mask) 40 if verify: 41 np.testing.assert_allclose(outer, exchange(u, outer_mask), atol=1e-9, rtol=0) 42 pair = u.copy() 43 js = [outer] 44 for h in self.fields: 45 pair[1] = mul(mul(h, u[1]), inv(h[lat.plus])) 46 js.append(exchange(pair, outer_mask)) 47 if verify: 48 np.testing.assert_allclose(lat.traces(pair), traces, atol=1e-10, rtol=0) 49 np.testing.assert_allclose(exchange(pair, inner_mask), inner, atol=1e-9, rtol=0) 50 if verify: 51 # Bipartite center flip negates every crossed dot product, not the 52 # original plaquette traces. Both pairs must have the same midpoint. 53 np.testing.assert_allclose(js[0]+js[1], js[2]+js[3], atol=1e-9, rtol=0) 54 a = abs(np.tanh(inner)) 55 t = np.tanh(js) 56 pos, neg = np.maximum(t, 0).mean(), np.maximum(-t, 0).mean() 57 cancel = 2*min(pos, neg) 58 # 1-|mean t| = mean(1-|t|) + cancel. Keep the logarithm even 59 # where all four factors round to one or the loss itself underflows. 60 s = -2*np.abs(js) 61 log_tail = np.logaddexp.reduce(np.log(2.)+s-np.logaddexp(0., s))-np.log(len(s)) 62 log_loss = -np.inf if a == 0 else np.log(a)+np.logaddexp(log_tail, np.log(cancel) if cancel else -np.inf) 63 return (inner, outer, witness, lower, *js[1:], a, a*(pos+neg), a*abs(pos-neg), a*cancel, log_loss)