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/probe_open_collar.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 / probe_open_collar.py` 131 lines ยท 5705 bytes Raw Blame History 1 """Coupled Wilson heat baths on an open SU(2) box with two fixed boundary conditions.""" 2 import argparse 3 from itertools import product 4 5 import numpy as np 6 from replica_shell_probe import mul, inv 7 8 9 def conditional(staples, beta, rng): 10 """Common random numbers for normalized exp(beta Re(q*staple)) dHaar(q).""" 11 norm = np.linalg.norm(staples, axis=-1) 12 field = beta*norm 13 shape = norm.shape 14 done = np.zeros(shape, dtype=bool) 15 scalar = np.zeros(shape) 16 while not done.all(): 17 u, accept = rng.random((2, shape[1])) 18 # Truncated exponential proposal for the scalar component on [-1,1]. 19 proposed = np.broadcast_to(2*u-1, shape).copy() 20 numerator = np.log1p((1-u)*np.expm1(-2*field)) 21 np.divide(numerator, field, out=proposed, where=field>0) 22 proposed = np.where(field>0, 1+proposed, proposed).clip(-1,1) 23 take = ~done & (accept**2 <= 1-proposed**2) 24 scalar[take] = proposed[take] 25 done |= take 26 direction = rng.normal(size=(shape[1],3)) 27 direction /= np.linalg.norm(direction, axis=-1, keepdims=True) 28 q = np.concatenate([scalar[...,None], np.sqrt(1-scalar**2)[...,None]*direction],axis=-1) 29 pole = np.zeros_like(staples) 30 pole[...,0] = 1 31 np.divide(inv(staples), norm[...,None], out=pole, where=field[...,None]>0) 32 return mul(q,pole) 33 34 35 class Box: 36 def __init__(self, side): 37 self.side = side 38 shape = (side,)*4 39 coords = np.indices(shape).reshape(4,-1) 40 directions = np.eye(4,dtype=int) 41 self.plus = np.array([np.ravel_multi_index((coords+d[:,None])%side,shape) for d in directions]) 42 self.minus = np.argsort(self.plus,axis=1) 43 self.classes = [] 44 for axis in range(4): 45 # An edge on a boundary hyperplane is fixed. No wrapped link is used. 46 other = np.delete(coords,axis,axis=0) 47 active = (coords[axis]0)&(other= mid) & (coords[3] == 0) 83 u[0, cut, 0] = -1 84 elif name == "rough": 85 rng = np.random.default_rng([self.side, 230, 314159]) 86 for axis in range(4): 87 tangential = np.delete(coords, axis, axis=0) 88 mask = (coords[axis] < self.side-1) & ((tangential == 0) | (tangential == self.side-1)).any(axis=0) 89 values = rng.normal(size=(mask.sum(), 4)) 90 u[axis, mask] = values / np.linalg.norm(values, axis=1, keepdims=True) 91 else: 92 raise ValueError(f"unknown collar {name}") 93 return u 94 95 def pair(self, beta, seed, burn, keep, identical, collar="identity"): 96 rng=np.random.default_rng([self.side,round(100*beta),seed,261123]) 97 u = np.repeat(self.initial_collar(collar)[None], 2, axis=0) 98 if seed%2: 99 hot=rng.normal(size=(4,self.side**4,4)) 100 hot/=np.linalg.norm(hot,axis=-1,keepdims=True) 101 for i,x in self.classes: 102 u[:,i,x]=hot[i,x] 103 if not identical: 104 u[1,0,self.changed] *= -1 105 pinned = u[:,0,self.changed].copy() 106 for _ in range(burn): 107 self.sweep(u,beta,rng) 108 rows=[] 109 for _ in range(keep): 110 self.sweep(u,beta,rng) 111 rows.append(self.observe(u)) 112 if identical and not np.array_equal(u[0],u[1]): 113 raise ValueError("identical collars diverged") 114 if not np.array_equal(u[:,0,self.changed], pinned): 115 raise ValueError("fixed collar moved") 116 sample=np.array(rows) 117 diff=sample[:,1]-sample[:,0] 118 return [*sample.mean(axis=0), diff.mean(), np.abs(diff).mean()] 119 120 121 if __name__ == "__main__": 122 p=argparse.ArgumentParser(description=__doc__) 123 p.add_argument("side",type=int,choices=(4,6)) 124 p.add_argument("beta",type=float,choices=(0,2,2.3)) 125 p.add_argument("seed",type=int) 126 p.add_argument("--burn",type=int,default=64) 127 p.add_argument("--keep",type=int,default=128) 128 p.add_argument("--identical",action="store_true") 129 a=p.parse_args() 130 v=Box(a.side).pair(a.beta,a.seed,a.burn,a.keep,a.identical) 131 print(a.side,a.beta,a.seed,a.burn,a.keep,int(a.identical),*(f"{y:.12g}" for y in v),sep="\t")