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/haar_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 / haar_shell_probe.py` 43 lines ยท 2302 bytes Raw Blame History 1 """Product Haar on the unframed radius-one outer sheets; not an orbit search.""" 2 import numpy as np 3 4 from haar_slab_bound import bounds 5 from vertex_slab_orbit import SlabOrbit, direct_outer_J, transform_second 6 7 8 COLUMNS = ('inner_j', 'outer_j', 'center', 'variance', 'draws', 'negative', 'draw_min', 9 'draw_max', 'log_draw_loss', 'log_p_upper', 'log_loss_upper') 10 11 12 class HaarProbe: 13 def __init__(self): 14 # Separate from lattice updates. Replaying an invocation in its original 15 # beta/start/sample order also replays the auxiliary fields. 16 self.rng = np.random.default_rng(`2026112301`) 17 18 def measure(self, lat, u, beta, verify, mul, inv): 19 orbit = SlabOrbit(lat, u, beta, mul, inv) 20 center = orbit.constant.sum() 21 variance, log_p, log_loss = bounds(center, orbit.B, orbit.dim) 22 q = self.rng.normal(size=(128, *orbit.sites.shape, orbit.dim)) 23 q /= np.linalg.norm(q, axis=-1, keepdims=True) 24 r, b = (q[:, :, parity].reshape(len(q), 2, -1) for parity in (0, 1)) 25 x = np.einsum('ski,ski->k', r.transpose(1, 0, 2) @ orbit.B, b.transpose(1, 0, 2)) 26 js = center + x 27 outer = orbit.sheet_values(orbit.identity()).sum() 28 inner_mask = lat.masks['slab'][0] 29 def inner_field(pair): 30 swapped = np.where(inner_mask[None, ..., None], pair[::-1], pair) 31 return (beta/2)*(lat.traces(pair)-lat.traces(swapped)).sum() 32 inner = inner_field(u) 33 if verify: 34 pair = transform_second(lat, u, orbit.site_field(q[0]), mul, inv) 35 np.testing.assert_allclose(lat.traces(pair), lat.traces(u), atol=2e-12, rtol=0) 36 np.testing.assert_allclose([direct_outer_J(lat, pair, beta), inner_field(pair)], 37 [js[0], inner], atol=1e-9*max(1., beta), rtol=0) 38 # X and -X have the same Haar law. Its signed tanh mean has sign C. 39 # Antithetic partners improve the loss estimate but are not extra IID trials. 40 y = np.concatenate((center+x, center-x)) * np.sign(center) 41 log_draw_loss = np.log(2.) + np.logaddexp.reduce(-np.logaddexp(0., 2*y)) - np.log(len(y)) 42 return (inner, outer, center, variance, len(q), (js < 0).sum(), js.min(), js.max(), 43 log_draw_loss, log_p, log_loss)