interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / scripts / replay_aligned_cut.py

87 lines · 3400 bytes Raw Blame History
1"""Test a reversible residual SU(2) alignment on the archived narrow exchange masks."""
2import csv
3from pathlib import Path
4
5import numpy as np
6from middle_cut_probe import MiddleCut
7from replica_shell_probe import Lattice, inv, mul
8
9ROOT = Path(__file__).resolve().parents[1]
10BETA = 2.3
11
12
13def rotate(q, rotation):
14 out = q.copy()
15 out[...,1:] = q[...,1:] @ rotation
16 return out
17
18
19def exchange(links, mask, frame):
20 out = links.copy()
21 out[0,mask] = rotate(links[1,mask],frame)
22 out[1,mask] = rotate(links[0,mask],frame.T)
23 return out
24
25
26def residual(links, exterior):
27 # Orthogonal Procrustes on the traceless components of the two exterior fields.
28 # These components are untouched by the exchange, so the reverse computes the same frame.
29 a,b=links[:,exterior,1:]
30 left, _, right=np.linalg.svd(b.T @ a)
31 left[:,-1] *= np.linalg.det(left @ right)
32 return left @ right
33
34
35def score(links, faces):
36 p=links[:,faces]
37 return mul(mul(p[:,:,0],p[:,:,1]), inv(mul(p[:,:,3],p[:,:,2])))[...,0].sum()
38
39
40def main():
41 lat=Lattice(8,"SU2")
42 cut=MiddleCut(lat,geometry="local")
43 archive=list(csv.DictReader((ROOT/"evidence/wilson_local_beta23.tsv").open(),delimiter="\t"))
44 pins=cut.pinned.ravel()
45 print("start","sample","mask","original_J","aligned_J","exterior_links",sep="\t")
46 if len(archive)!=128:
47 raise ValueError("archived design changed")
48 for start,seed in (("hot",41123),("cold",41124)):
49 rng=np.random.default_rng(seed)
50 u=rng.normal(size=(2,4,len(lat.sites),4))
51 u/=np.linalg.norm(u,axis=-1,keepdims=True)
52 if start=="cold":
53 u[:]=0; u[...,0]=1
54 for _ in range(64):
55 lat.sweep(u,BETA,rng)
56 for observation in range(64):
57 for _ in range(2):
58 lat.sweep(u,BETA,rng)
59 g=lat.tree_frame(u,cut.layers,False)
60 g[:,cut.pinned]=(1.,0.,0.,0.)
61 links=g.reshape(2,-1,4)
62 row=archive[observation + (64 if start=="cold" else 0)]
63 if (row["start"],int(row["sample"]),int(row["seed"]))!=(start,observation,seed):
64 raise ValueError("archive mismatch")
65 for k in (1,2):
66 mask=cut.masks[k]
67 faces=cut.split[k]
68 exterior=np.unique(faces[(~mask & ~pins)[faces]])
69 frame=residual(links,exterior)
70 orig=exchange(links,mask,np.eye(3))
71 alt=exchange(links,mask,frame)
72 before=score(links,faces)
73 j=(before-score(orig,faces))*BETA/2
74 aligned=(before-score(alt,faces))*BETA/2
75 if abs(j-float(row[f"narrow{k}_j"]))>2e-8:
76 raise ValueError("ordinary exchange differs from archived pair")
77 if observation%8==0:
78 np.testing.assert_allclose(frame.T@frame,np.eye(3),atol=2e-14)
79 np.testing.assert_allclose(exchange(alt,mask,residual(alt,exterior)),links,atol=3e-14)
80 # On completely exchanged faces all links share one conjugation.
81 allfaces=lat.faces.reshape(-1,4)
82 np.testing.assert_allclose((score(links,allfaces)-score(alt,allfaces))*BETA/2,aligned,atol=3e-10)
83 print(start,observation,f"narrow{k}",f"{j:.12g}",f"{aligned:.12g}",len(exterior),sep="\t")
84
85
86if __name__=="__main__":
87 main()