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

183 lines · 8508 bytes Raw Blame History
1"""Two sharp interior cuts between whole spatial slices on the pinned side-eight torus."""
2import numpy as np
3
4
5def interior_geometry(lat, pinned):
6 """Free-link masks: source plaquette, radius 1, radius 2, target plaquette."""
7 n = lat.sites.size
8 if n != 8**4 or pinned.shape != (4, n) or pinned.dtype != np.bool_:
9 raise ValueError('expected a side-eight lattice and its boolean tree pins')
10 free = ~pinned.ravel()
11 time = lat.sites % 8 # time is the last coordinate in C site order
12 radius = np.tile(np.minimum(time, 8-time), 4)
13
14 def endpoint(site):
15 mask = np.zeros_like(free)
16 mask[lat.faces[lat.pairs.index((0, 1)), site]] = True
17 return mask & free
18
19 target = np.ravel_multi_index((0, 0, 0, 4), (8,)*4)
20 return endpoint(0), (radius <= 1) & free, (radius <= 2) & free, endpoint(target)
21
22
23def _boundary(lat, pinned, mask):
24 faces = lat.faces.reshape(-1, 4)
25 active = ~pinned.ravel()[faces]
26 labels = mask[faces]
27 return (active & labels).any(axis=1) & (active & ~labels).any(axis=1)
28
29
30def _tree_pins(lat, side):
31 coords = np.array(np.unravel_index(lat.sites, (side,)*4))
32 child = lat.sites[1:]
33 direction = np.argmax(coords[:, child] != 0, axis=0)
34 parent = lat.minus[direction, child]
35 assert np.all(coords[:, parent].sum(axis=0) == coords[:, child].sum(axis=0)-1)
36 pinned = np.zeros((4, lat.sites.size), dtype=bool)
37 pinned[direction, parent] = True
38 assert pinned.sum() == lat.sites.size-1
39 return pinned
40
41
42def _packing(lat, pinned, side, separation):
43 """Enumerate free-link paths and actual face IDs on both temporal arcs."""
44 n = lat.sites.size
45 paths = []
46 per_direction = []
47 for direction in range(3):
48 bases = lat.sites[(lat.sites % side == 0) & ~pinned[direction]]
49 per_direction.append(len(bases))
50 plane = lat.pairs.index((direction, 3))
51 for base in bases:
52 for step, length in ((1, separation), (-1, side-separation)):
53 sites = [int(base)]
54 face_ids = []
55 for _ in range(length):
56 old = sites[-1]
57 new = int((lat.plus if step == 1 else lat.minus)[3, old])
58 face_site = old if step == 1 else new
59 face_ids.append(plane*n+face_site)
60 sites.append(new)
61 links = direction*n+np.array(sites)
62 face_ids = np.array(face_ids)
63 assert not pinned.ravel()[links].any()
64 assert sites[0] % side == 0 and sites[-1] % side == separation
65 rows = lat.faces.reshape(-1, 4)[face_ids]
66 assert np.all((rows == links[:-1, None]).any(axis=1))
67 assert np.all((rows == links[1:, None]).any(axis=1))
68 paths.append((links, face_ids))
69 all_faces = np.concatenate([faces for _, faces in paths])
70 assert len(np.unique(all_faces)) == len(all_faces)
71 assert any(np.any(faces % n % side == side-1) for _, faces in paths)
72 assert len(paths) == 2*(2*side**3+1)
73 return paths, per_direction
74
75
76def _controls():
77 from replica_shell_probe import Lattice
78
79 lat = Lattice(8, 'SU2')
80 pinned = _tree_pins(lat, 8)
81 masks = interior_geometry(lat, pinned)
82 n = lat.sites.size
83 assert isinstance(masks, tuple) and len(masks) == 4
84 assert all(m.dtype == np.bool_ and m.shape == (4*n,) for m in masks)
85 assert all(not (m & pinned.ravel()).any() for m in masks)
86 source, inner, outer, target = masks
87 assert source.any() and target.any() and not (source & target).any()
88 assert (source <= inner).all() and (inner <= outer).all()
89 assert not (outer & target).any()
90 boundaries = [_boundary(lat, pinned, m) for m in masks]
91 assert np.max(np.sum(boundaries, axis=0)) == 1
92 paths, per_direction = _packing(lat, pinned, 8, 4)
93 slice0 = np.tile(lat.sites % 8 == 0, 4) & ~pinned.ravel()
94 slice4 = np.tile(lat.sites % 8 == 4, 4) & ~pinned.ravel()
95 slice0[3*n:] = False
96 slice4[3*n:] = False
97 faces = lat.faces.reshape(-1, 4)
98 for mask, boundary in zip((inner, outer), boundaries[1:3]):
99 assert mask[slice0].all() and not mask[slice4].any()
100 assert boundary.sum() == len(paths)
101 witnesses = []
102 for links, face_ids in paths:
103 assert mask[links[0]] and not mask[links[-1]]
104 split = mask[links[:-1]] != mask[links[1:]]
105 assert split.sum() == 1 and boundary[face_ids[split]].all()
106 witnesses.extend(face_ids[split])
107 np.testing.assert_array_equal(np.sort(witnesses), np.flatnonzero(boundary))
108 # Inspect actual vertices, including link heads, rather than base times.
109 row = faces[boundary]
110 directions, bases = row//n, row % n
111 times = np.concatenate((bases.ravel() % 8,
112 lat.plus[directions, bases].ravel() % 8))
113 assert not np.isin(times, (0, 4)).any()
114 sheets = np.unique((np.flatnonzero(boundary) % n) % 8).tolist()
115 print(f'interior: faces={int(boundary.sum())} lower_base_times={sheets} '
116 f'vertex_times={np.unique(times).tolist()} paths_hit_once={len(witnesses)}')
117 endpoint_spatial = []
118 for time in (0, 4):
119 vertices = np.flatnonzero(slice0 if time == 0 else slice4)
120 adjacency = {int(v): set() for v in vertices}
121 face_ids = np.concatenate([
122 i*n+lat.sites[lat.sites % 8 == time]
123 for i, pair in enumerate(lat.pairs) if 3 not in pair])
124 endpoint_spatial.extend(face_ids)
125 for row in faces[face_ids]:
126 free_row = row[~pinned.ravel()[row]]
127 for link in free_row:
128 adjacency[int(link)].update(map(int, free_row))
129 seen = set()
130 components = 0
131 for vertex in adjacency:
132 if vertex in seen:
133 continue
134 components += 1
135 queue = [vertex]
136 seen.add(vertex)
137 while queue:
138 for neighbor in adjacency[queue.pop()]:
139 if neighbor not in seen:
140 seen.add(neighbor)
141 queue.append(neighbor)
142 assert components == 1 and len(seen) == len(vertices)
143 anchor = source if time == 0 else target
144 assert np.count_nonzero(anchor[vertices]) == 1
145 print(f'endpoint_spatial_graph: time={time} vertices={len(vertices)} '
146 f'components={components} local_anchor_count={int(anchor[vertices].sum())}')
147 print(f'side8: free_spatial_per_direction={per_direction} '
148 f'path_count={len(paths)} boundary_counts={[int(b.sum()) for b in boundaries]} '
149 'all_four_boundaries_pairwise_disjoint=True wraparound_checked=True')
150
151 # Endpoint separation (even with boundary collars) is a weaker class.
152 local = source.copy()
153 touched = faces[boundaries[0]].ravel()
154 local[touched] = ~pinned.ravel()[touched]
155 local_boundary = _boundary(lat, pinned, local)
156 assert local[source].all() and not local[target].any()
157 assert not (local_boundary & (boundaries[0] | boundaries[3])).any()
158 assert local_boundary.sum() < len(paths) and not local[slice0].all()
159 assert local_boundary[np.array(endpoint_spatial)].any()
160 print(f'wrong_class: endpoint_collar_faces={int(local_boundary.sum())} '
161 'endpoint_separates=True endpoint_boundaries_disjoint=True '
162 'whole_source_slice_contained=False endpoint_spatial_face_split=True')
163
164 # Direct enumeration of the finite general formula, including odd sides,
165 # adjacent endpoints, unequal arc lengths, and the periodic seam.
166 for side, separation, radius in ((4, 1, 0), (5, 2, 0), (6, 3, 1), (8, 4, 2)):
167 test = Lattice(side, 'SU2')
168 pins = _tree_pins(test, side)
169 packing, free_counts = _packing(test, pins, side, separation)
170 time = test.sites % side
171 slab = np.tile(np.minimum(time, side-time) <= radius, 4) & ~pins.ravel()
172 boundary = _boundary(test, pins, slab)
173 assert boundary.sum() == len(packing)
174 for links, face_ids in packing:
175 assert slab[links[0]] and not slab[links[-1]]
176 assert boundary[face_ids].sum() == 1
177 print(f'general: side={side} separation={separation} radius={radius} '
178 f'free_spatial_per_direction={free_counts} sharp_faces={int(boundary.sum())}')
179 print('PASS: geometry only; no configuration generation or field measurement')
180
181
182if __name__ == '__main__':
183 _controls()