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 / middle_cut_probe.py

126 lines · 6404 bytes Raw Blame History
1"""Pinned Wilson exchange families with a full-orbit check of the signed product."""
2from itertools import product
3
4import numpy as np
5
6from face_min_cut import minimum_middle
7
8COLUMNS = ('source_faces', 'cut_faces', 'slab_faces', 'target_faces',
9 'source_j', 'cut_j', 'slab_j', 'target_j')
10INTERIOR_COLUMNS = ('source_faces', 'radius1_faces', 'radius2_faces', 'target_faces',
11 'source_j', 'radius1_j', 'radius2_j', 'target_j')
12LOCAL_COLUMNS = tuple(name+suffix for suffix in ('_faces', '_j') for name in
13 ('source', 'narrow1', 'narrow2', 'wide1', 'wide2', 'target'))
14
15
16class MiddleCut:
17 def __init__(self, lat, *, geometry='cut'):
18 side = 6 if geometry == 'cut' else 8
19 shape = (side,) * 4
20 coords = np.array(np.unravel_index(lat.sites, shape))
21 depth = coords.sum(axis=0)
22 # Each nonroot site backs up one step along its first nonzero coordinate.
23 self.layers = []
24 self.pinned = np.zeros((4, lat.sites.size), dtype=bool)
25 for k in range(1, depth.max()+1):
26 child = lat.sites[depth == k]
27 direction = np.argmax(coords[:, child] != 0, axis=0)
28 parent = lat.minus[direction, child]
29 assert np.all(depth[parent] == k-1)
30 self.layers.append((parent, child, direction, np.zeros_like(child)))
31 self.pinned[direction, parent] = True
32 assert self.pinned.sum() == lat.sites.size-1
33 pins = self.pinned.ravel()
34 self.target_site = np.ravel_multi_index((0, 0, 0, side//2), shape)
35 faces = lat.faces.reshape(-1, 4)
36 if geometry == 'local':
37 from local_neighborhood import neighborhood_masks
38 self.masks = neighborhood_masks(lat, self.pinned)
39 self.families = ((0, 1, 2, 5), (0, 3, 4, 5))
40 elif geometry == 'interior':
41 from interior_geometry import interior_geometry
42 self.masks = interior_geometry(lat, self.pinned)
43 self.families = ((0, 1, 2, 3),)
44 elif geometry == 'cut':
45 self.masks, minimum = self._side_six_masks(lat, pins, coords, faces)
46 self.families = ((0, 1, 3), (0, 2, 3))
47 else:
48 raise ValueError(f'unknown exchange geometry: {geometry}')
49 active = ~pins[faces]
50 self.boundaries = []
51 for mask in self.masks:
52 on = mask[faces]
53 self.boundaries.append((active & on).any(axis=1) & (active & ~on).any(axis=1))
54 self.counts = tuple(int(b.sum()) for b in self.boundaries)
55 self.split = [faces[b] for b in self.boundaries]
56 for family in self.families:
57 assert np.max(np.sum([self.boundaries[j] for j in family], axis=0)) <= 1
58 if geometry == 'cut':
59 self._check_side_six(lat, pins, faces, minimum)
60
61 def _side_six_masks(self, lat, pins, coords, faces):
62 def endpoint(site):
63 mask = np.zeros_like(pins)
64 mask[lat.faces[0, site]] = True
65 return mask & ~pins
66 source, target = endpoint(0), endpoint(self.target_site)
67 cut, minimum = minimum_middle(faces, pins, source, target)
68 slab = np.tile(np.minimum(coords[3], 6-coords[3]) <= 1, 4) & ~pins
69 return (source, cut, slab, target), minimum
70
71 def _check_side_six(self, lat, pins, faces, minimum):
72 source, cut, _, target = self.masks
73 assert self.counts[1] == minimum <= self.counts[2]
74 assert source.any() and target.any() and not (source & target).any()
75 for i in (1, 2):
76 assert self.masks[i][source].all() and not self.masks[i][target].any()
77 # The residual-reachable minimum is already the largest admissible free
78 # source side: only the forced target neighborhood is outside it.
79 forced_target = target.copy()
80 forced_target[faces[self.boundaries[3]].ravel()] = True
81 np.testing.assert_array_equal(cut, ~pins & ~forced_target)
82 # These free, parallel endpoint links are joined by three successive
83 # temporal plaquettes. Each separating mask must split one of the three.
84 path = lat.faces[lat.pairs.index((1, 3)), lat.plus[0, :3]]
85 assert source[path[0, 0]] and target[path[-1, 2]]
86 assert np.array_equal(path[:-1, 2], path[1:, 0])
87 assert not pins[path[:, [0, 2]]].any()
88
89 def measure(self, lat, u, beta, verify, mul, inv):
90 v = lat.tree_frame(u, self.layers, verify)
91 # Mathematical pins are exactly one; remove transport roundoff on those links.
92 v[:, self.pinned] = (1., 0., 0., 0.)
93 links = v.reshape(2, -1, 4)
94 def score(q):
95 return mul(mul(q[:, :, 0], q[:, :, 1]), inv(mul(q[:, :, 3], q[:, :, 2])))[..., 0].sum()
96 fields = []
97 for mask, face in zip(self.masks, self.split):
98 local = links[:, face]
99 other = np.where(mask[face][None, ..., None], local[::-1], local)
100 fields.append((beta/2)*(score(local)-score(other)))
101 if verify:
102 raw = lat.traces(u)
103 np.testing.assert_allclose(lat.traces(v), raw, atol=2e-12, rtol=0)
104 def difference(tr):
105 diff = tr[0, 0]-tr[1, 0]
106 return diff[0]*diff[self.target_site]
107 delta = difference(raw)
108 for family in self.families:
109 js = np.array([fields[i] for i in family])
110 orbit = []
111 for bits in product((0, 1), repeat=len(family)):
112 exchange = np.zeros(links.shape[1], dtype=bool)
113 for bit, i in zip(bits, family):
114 if bit:
115 exchange ^= self.masks[i]
116 pair = np.where(exchange[None, :, None], links[::-1], links).reshape(v.shape)
117 tr = lat.traces(pair)
118 logw = beta*(tr-raw).sum()
119 np.testing.assert_allclose(logw, -2*np.dot(bits, js), atol=2e-8, rtol=0)
120 obs = difference(tr)
121 np.testing.assert_allclose(obs, (-1)**sum(bits)*delta, atol=2e-12, rtol=0)
122 orbit.append((logw, obs))
123 weights, obs = np.transpose(orbit)
124 weights = np.exp(weights-weights.max())
125 np.testing.assert_allclose(weights @ obs / weights.sum(), delta*np.tanh(js).prod(), atol=1e-10, rtol=0)
126 return (*self.counts, *fields)