PyQUDA-Utils 0.9.9.dev8__tar.gz → 0.9.10.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PKG-INFO +1 -1
  2. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PyQUDA_Utils.egg-info/PKG-INFO +1 -1
  3. pyquda_utils-0.9.10.dev0/pyquda_utils/_version.py +1 -0
  4. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/__init__.py +3 -11
  5. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/milc.py +1 -1
  6. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/mpi_file.py +15 -0
  7. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/nersc.py +5 -3
  8. pyquda_utils-0.9.10.dev0/pyquda_utils/io/openqcd.py +189 -0
  9. pyquda_utils-0.9.9.dev8/pyquda_utils/_version.py +0 -1
  10. pyquda_utils-0.9.9.dev8/pyquda_utils/io/openqcd.py +0 -59
  11. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/LICENSE +0 -0
  12. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/MANIFEST.in +0 -0
  13. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PyQUDA_Utils.egg-info/SOURCES.txt +0 -0
  14. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PyQUDA_Utils.egg-info/dependency_links.txt +0 -0
  15. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PyQUDA_Utils.egg-info/requires.txt +0 -0
  16. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/PyQUDA_Utils.egg-info/top_level.txt +0 -0
  17. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/README.md +0 -0
  18. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyproject.toml +0 -0
  19. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/__init__.py +0 -0
  20. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/convert.py +0 -0
  21. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/core.py +0 -0
  22. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/deprecated.py +0 -0
  23. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/gamma.py +0 -0
  24. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/gpt.py +0 -0
  25. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/hmc_param.py +0 -0
  26. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/chroma.py +0 -0
  27. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/io_general.py +0 -0
  28. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/kyu.py +0 -0
  29. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/lime.py +0 -0
  30. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/npy.py +0 -0
  31. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/io/xqcd.py +0 -0
  32. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/milc_rhmc_param.py +0 -0
  33. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/phase.py +0 -0
  34. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/quasi_axial_gauge_fixing.py +0 -0
  35. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/pyquda_utils/source.py +0 -0
  36. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/setup.cfg +0 -0
  37. {pyquda_utils-0.9.9.dev8 → pyquda_utils-0.9.10.dev0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyQUDA-Utils
3
- Version: 0.9.9.dev8
3
+ Version: 0.9.10.dev0
4
4
  Summary: Utility scripts based on PyQUDA
5
5
  Author-email: SaltyChiang <SaltyChiang@users.noreply.github.com>
6
6
  Maintainer-email: SaltyChiang <SaltyChiang@users.noreply.github.com>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyQUDA-Utils
3
- Version: 0.9.9.dev8
3
+ Version: 0.9.10.dev0
4
4
  Summary: Utility scripts based on PyQUDA
5
5
  Author-email: SaltyChiang <SaltyChiang@users.noreply.github.com>
6
6
  Maintainer-email: SaltyChiang <SaltyChiang@users.noreply.github.com>
@@ -0,0 +1 @@
1
+ __version__ = "0.9.10.dev0"
@@ -236,27 +236,19 @@ def writeNPYPropagator(filename: str, propagator: LatticePropagator):
236
236
 
237
237
  def readOpenQCDGauge(filename: str):
238
238
  from pyquda import getGridSize
239
- from pyquda.field import X, Y, Z, T
240
239
  from .openqcd import readGauge as read
241
240
 
242
- latt_size, plaquette, gauge_ = read(filename, getGridSize())
243
- gauge_ = LatticeGauge(LatticeInfo(latt_size), gauge_)
244
- gauge_.toDevice()
245
- gauge = gauge_.shift([X, Y, Z, T])
246
- gauge.data[:, 1] = gauge_.data[:, 0]
241
+ latt_size, plaquette, gauge = read(filename, getGridSize(), False)
242
+ gauge = LatticeGauge(LatticeInfo(latt_size), gauge)
247
243
  assert numpy.isclose(gauge.plaquette()[0], plaquette)
248
244
  return gauge
249
245
 
250
246
 
251
247
  def writeOpenQCDGauge(filename: str, gauge: LatticeGauge):
252
- from pyquda.field import X, Y, Z, T
253
248
  from .openqcd import writeGauge as write
254
249
 
255
- gauge.toDevice()
256
250
  plaquette = gauge.plaquette()[0]
257
- gauge_ = gauge.shift([-X, -Y, -Z, -T])
258
- gauge_.data[:, 0] = gauge.data[:, 1]
259
- write(filename, gauge.latt_info.global_size, gauge.latt_info.grid_size, plaquette, gauge_.getHost())
251
+ write(filename, gauge.latt_info.global_size, gauge.latt_info.grid_size, plaquette, gauge.getHost(), False)
260
252
 
261
253
 
262
254
  def readNERSCGauge(filename: str, link_trace: bool = True, checksum: bool = True):
@@ -64,7 +64,7 @@ def readGauge(filename: str, grid_size: List[int], checksum: bool = True):
64
64
  else:
65
65
  raise ValueError(f"Broken magic {magic} in MILC gauge")
66
66
  latt_size = struct.unpack(f"{endian}iiii", f.read(16))
67
- time_stamp = f.read(64).decode() # noqa: F841
67
+ timestamp = f.read(64).decode() # noqa: F841
68
68
  assert struct.unpack(f"{endian}i", f.read(4))[0] == 0 # order
69
69
  sum29, sum31 = struct.unpack(f"{endian}II", f.read(8))
70
70
  offset = f.tell()
@@ -19,6 +19,21 @@ def getGridCoord(grid_size: Sequence[int]):
19
19
  return [gx, gy, gz, gt]
20
20
 
21
21
 
22
+ def getNeighbourRank(grid_size: Sequence[int]):
23
+ Gx, Gy, Gz, Gt = grid_size
24
+ gx, gy, gz, gt = getGridCoord(grid_size)
25
+ return [
26
+ (((gx + 1) % Gx * Gy + gy) * Gz + gz) * Gt + gt,
27
+ ((gx * Gy + (gy + 1) % Gy) * Gz + gz) * Gt + gt,
28
+ ((gx * Gy + gy) * Gz + (gz + 1) % Gz) * Gt + gt,
29
+ ((gx * Gy + gy) * Gz + gz) * Gt + (gt + 1) % Gt,
30
+ (((gx - 1) % Gx * Gy + gy) * Gz + gz) * Gt + gt,
31
+ ((gx * Gy + (gy - 1) % Gy) * Gz + gz) * Gt + gt,
32
+ ((gx * Gy + gy) * Gz + (gz - 1) % Gz) * Gt + gt,
33
+ ((gx * Gy + gy) * Gz + gz) * Gt + (gt - 1) % Gt,
34
+ ]
35
+
36
+
22
37
  def getSubarray(shape: Sequence[int], axes: Sequence[int], grid: Sequence[int]):
23
38
  sizes = [d for d in shape]
24
39
  subsizes = [d for d in shape]
@@ -77,13 +77,15 @@ def writeGauge(
77
77
  grid_size: List[int],
78
78
  plaquette: float,
79
79
  gauge: numpy.ndarray,
80
- float_nbytes: int = 8,
80
+ use_fp32: bool = False,
81
81
  ):
82
82
  filename = path.expanduser(path.expandvars(filename))
83
+ float_nbytes = 4 if use_fp32 else 8
83
84
  dtype, offset = f"<c{2 * float_nbytes}", None
84
85
  gauge = numpy.ascontiguousarray(gauge.transpose(1, 2, 3, 4, 0, 5, 6).astype(dtype))
85
86
  link_trace = link_trace_nersc(gauge)
86
87
  checksum = checksum_nersc(gauge.reshape(-1))
88
+ timestamp = datetime.now().astimezone().strftime(R"%a %b %d %H:%M:%S %Y %Z")
87
89
  Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
88
90
  header: Dict[str, str] = {
89
91
  "HDR_VERSION": "1.0",
@@ -107,8 +109,8 @@ def writeGauge(
107
109
  "SEQUENCE_NUMBER": "1",
108
110
  "CREATOR": "pyquda",
109
111
  "CREATOR_HARDWARE": f"{uname().nodename}-{uname().machine}-{uname().sysname}-{uname().release}",
110
- "CREATION_DATE": datetime.now().strftime(R"%a %b %d %H:%M:%S %Y %z"),
111
- "ARCHIVE_DATE": datetime.now().strftime(R"%a %b %d %H:%M:%S %Y %z"),
112
+ "CREATION_DATE": timestamp,
113
+ "ARCHIVE_DATE": timestamp,
112
114
  "FLOATING_POINT": f"IEEE{float_nbytes * 8}LITTLE",
113
115
  }
114
116
  if MPI.COMM_WORLD.Get_rank() == 0:
@@ -0,0 +1,189 @@
1
+ from os import path
2
+ import struct
3
+ from typing import List
4
+
5
+ import numpy
6
+ from mpi4py import MPI
7
+
8
+ from .mpi_file import getSublatticeSize, getNeighbourRank, readMPIFile, writeMPIFile
9
+
10
+ Nd, Ns, Nc = 4, 4, 3
11
+
12
+
13
+ def cb2Gauge(latt_size: List[int], gauge: numpy.ndarray):
14
+ Lx, Ly, Lz, Lt = latt_size
15
+ gauge_cb2 = numpy.zeros_like(gauge).reshape(Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc)
16
+ for t in range(Lt):
17
+ for z in range(Lz):
18
+ for y in range(Ly):
19
+ eo = (t + z + y) % 2
20
+ if eo == 0:
21
+ gauge_cb2[:, 0, t, z, y, :] = gauge[:, t, z, y, 0::2]
22
+ gauge_cb2[:, 1, t, z, y, :] = gauge[:, t, z, y, 1::2]
23
+ else:
24
+ gauge_cb2[:, 0, t, z, y, :] = gauge[:, t, z, y, 1::2]
25
+ gauge_cb2[:, 1, t, z, y, :] = gauge[:, t, z, y, 0::2]
26
+ return gauge_cb2
27
+
28
+
29
+ def lexicoGauge(latt_size: List[int], gauge: numpy.ndarray):
30
+ Lx, Ly, Lz, Lt = latt_size
31
+ gauge_lexico = numpy.empty_like(gauge).reshape(Nd, Lt, Lz, Ly, Lx, Nc, Nc)
32
+ for t in range(Lt):
33
+ for z in range(Lz):
34
+ for y in range(Ly):
35
+ eo = (t + z + y) % 2
36
+ if eo == 0:
37
+ gauge_lexico[:, t, z, y, 0::2] = gauge[:, 0, t, z, y, :]
38
+ gauge_lexico[:, t, z, y, 1::2] = gauge[:, 1, t, z, y, :]
39
+ else:
40
+ gauge_lexico[:, t, z, y, 1::2] = gauge[:, 0, t, z, y, :]
41
+ gauge_lexico[:, t, z, y, 0::2] = gauge[:, 1, t, z, y, :]
42
+ return gauge_lexico
43
+
44
+
45
+ def shiftGaugeOddForward(latt_size: List[int], grid_size: List[int], gauge: numpy.ndarray):
46
+ Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
47
+ gauge_shift = numpy.empty_like(gauge)
48
+ gauge_shift[:, 1] = gauge[:, 0]
49
+ rank = MPI.COMM_WORLD.Get_rank()
50
+ neighbour_rank = getNeighbourRank(grid_size)
51
+ for t in range(Lt):
52
+ for z in range(Lz):
53
+ for y in range(Ly):
54
+ if (t + z + y) % 2 == 0:
55
+ gauge_shift[0, 0, t, z, y, :] = gauge[0, 1, t, z, y, :]
56
+ else:
57
+ gauge_shift[0, 0, t, z, y, :-1] = gauge[0, 1, t, z, y, 1:]
58
+ if rank == neighbour_rank[0] and rank == neighbour_rank[4]:
59
+ gauge_shift[0, 0, t, z, y, -1] = gauge[0, 1, t, z, y, 0]
60
+ else:
61
+ buf = gauge[0, 1, t, z, y, 0].copy()
62
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[4], source=neighbour_rank[0])
63
+ gauge_shift[0, 0, t, z, y, -1] = buf
64
+ gauge_shift[1, 0, :, :, :-1, :] = gauge[1, 1, :, :, 1:, :]
65
+ if rank == neighbour_rank[1] and rank == neighbour_rank[5]:
66
+ gauge_shift[1, 0, :, :, -1, :] = gauge[1, 1, :, :, 0, :]
67
+ else:
68
+ buf = gauge[1, 1, :, :, 0, :].copy()
69
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[5], source=neighbour_rank[1])
70
+ gauge_shift[1, 0, :, :, -1, :] = buf
71
+ gauge_shift[2, 0, :, :-1, :, :] = gauge[2, 1, :, 1:, :, :]
72
+ if rank == neighbour_rank[2] and rank == neighbour_rank[6]:
73
+ gauge_shift[2, 0, :, -1, :, :] = gauge[2, 1, :, 0, :, :]
74
+ else:
75
+ buf = gauge[2, 1, :, 0, :, :].copy()
76
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[6], source=neighbour_rank[2])
77
+ gauge_shift[2, 0, :, -1, :, :] = buf
78
+ gauge_shift[3, 0, :-1, :, :, :] = gauge[3, 1, 1:, :, :, :]
79
+ if rank == neighbour_rank[3] and rank == neighbour_rank[7]:
80
+ gauge_shift[3, 0, -1, :, :, :] = gauge[3, 1, 0, :, :, :]
81
+ else:
82
+ buf = gauge[3, 1, 0, :, :, :].copy()
83
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[7], source=neighbour_rank[3])
84
+ gauge_shift[3, 0, -1, :, :, :] = buf
85
+ return gauge_shift
86
+
87
+
88
+ def shiftGaugeEvenBackward(latt_size: List[int], grid_size: List[int], gauge: numpy.ndarray):
89
+ Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
90
+ gauge_shift = numpy.empty_like(gauge)
91
+ gauge_shift[:, 0] = gauge[:, 1]
92
+ rank = MPI.COMM_WORLD.Get_rank()
93
+ neighbour_rank = getNeighbourRank(grid_size)
94
+ for t in range(Lt):
95
+ for z in range(Lz):
96
+ for y in range(Ly):
97
+ if (t + z + y) % 2 == 0:
98
+ gauge_shift[0, 1, t, z, y, :] = gauge[0, 0, t, z, y, :]
99
+ else:
100
+ gauge_shift[0, 1, t, z, y, 1:] = gauge[0, 0, t, z, y, :-1]
101
+ if rank == neighbour_rank[0] and rank == neighbour_rank[4]:
102
+ gauge_shift[0, 1, t, z, y, 0] = gauge[0, 0, t, z, y, -1]
103
+ else:
104
+ buf = gauge[0, 0, t, z, y, -1].copy()
105
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[0], source=neighbour_rank[4])
106
+ gauge_shift[0, 1, t, z, y, 0] = buf
107
+ gauge_shift[1, 1, :, :, 1:, :] = gauge[1, 0, :, :, :-1, :]
108
+ if rank == neighbour_rank[1] and rank == neighbour_rank[5]:
109
+ gauge_shift[1, 1, :, :, 0, :] = gauge[1, 0, :, :, -1, :]
110
+ else:
111
+ buf = gauge[1, 0, :, :, -1, :].copy()
112
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[1], source=neighbour_rank[5])
113
+ gauge_shift[1, 1, :, :, 0, :] = buf
114
+ gauge_shift[2, 1, :, 1:, :, :] = gauge[2, 0, :, :-1, :, :]
115
+ if rank == neighbour_rank[2] and rank == neighbour_rank[6]:
116
+ gauge_shift[2, 1, :, 0, :, :] = gauge[2, 0, :, -1, :, :]
117
+ else:
118
+ buf = gauge[2, 0, :, -1, :, :].copy()
119
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[2], source=neighbour_rank[6])
120
+ gauge_shift[2, 1, :, 0, :, :] = buf
121
+ gauge_shift[3, 1, 1:, :, :, :] = gauge[3, 0, :-1, :, :, :]
122
+ if rank == neighbour_rank[3] and rank == neighbour_rank[7]:
123
+ gauge_shift[3, 1, 0, :, :, :] = gauge[3, 0, -1, :, :, :]
124
+ else:
125
+ buf = gauge[3, 0, -1, :, :, :].copy()
126
+ MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[3], source=neighbour_rank[7])
127
+ gauge_shift[3, 1, 0, :, :, :] = buf
128
+ return gauge_shift
129
+
130
+
131
+ def readGauge(filename: str, grid_size: List[int], lexico: bool = True):
132
+ filename = path.expanduser(path.expandvars(filename))
133
+ with open(filename, "rb") as f:
134
+ latt_size = struct.unpack("<iiii", f.read(16))[::-1]
135
+ plaquette = struct.unpack("<d", f.read(8))[0] / Nc
136
+ offset = f.tell()
137
+ Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
138
+ dtype = "<c16"
139
+
140
+ gauge_reorder = readMPIFile(filename, dtype, offset, (Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), (1, 2, 3, 0), grid_size)
141
+
142
+ gauge = numpy.zeros((Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc), dtype)
143
+ for t in range(Lt):
144
+ for y in range(Ly):
145
+ for z in range(Lz):
146
+ for x in range(Lx // 2):
147
+ x_ = 2 * x + (1 - (t + z + y) % 2)
148
+ z_ = z // 2
149
+ gauge[[3, 0, 1, 2], :, t, z, y, x, :, :] = gauge_reorder[t, x_, y, z_]
150
+
151
+ gauge = shiftGaugeOddForward(latt_size, grid_size, gauge)
152
+ if lexico:
153
+ gauge = lexicoGauge([Lx, Ly, Lz, Lt], gauge).astype("<c16")
154
+ return latt_size, plaquette, gauge
155
+
156
+
157
+ def writeGauge(
158
+ filename: str,
159
+ latt_size: List[int],
160
+ grid_size: List[int],
161
+ plaquette: float,
162
+ gauge: numpy.ndarray,
163
+ lexico: bool = True,
164
+ ):
165
+ filename = path.expanduser(path.expandvars(filename))
166
+ Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
167
+ dtype, offset = "<c16", None
168
+
169
+ if lexico:
170
+ gauge = cb2Gauge([Lx, Ly, Lz, Lt], gauge.astype(dtype))
171
+ gauge = shiftGaugeEvenBackward(latt_size, grid_size, gauge)
172
+ gauge_reorder = numpy.zeros((Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), dtype)
173
+ for t in range(Lt):
174
+ for y in range(Ly):
175
+ for z in range(Lz):
176
+ for x in range(Lx // 2):
177
+ x_ = 2 * x + (1 - (t + z + y) % 2)
178
+ z_ = z // 2
179
+ gauge_reorder[t, x_, y, z_] = gauge[[3, 0, 1, 2], :, t, z, y, x, :, :]
180
+
181
+ gauge = gauge_reorder.astype(dtype)
182
+ if MPI.COMM_WORLD.Get_rank() == 0:
183
+ with open(filename, "wb") as f:
184
+ f.write(struct.pack("<iiii", *latt_size[::-1]))
185
+ f.write(struct.pack("<d", plaquette * Nc))
186
+ offset = f.tell()
187
+ offset = MPI.COMM_WORLD.bcast(offset)
188
+
189
+ writeMPIFile(filename, dtype, offset, (Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), (1, 2, 3, 0), grid_size, gauge)
@@ -1 +0,0 @@
1
- __version__ = "0.9.9.dev8"
@@ -1,59 +0,0 @@
1
- from os import path
2
- import struct
3
- from typing import List
4
-
5
- import numpy
6
- from mpi4py import MPI
7
-
8
- from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
9
-
10
- Nd, Ns, Nc = 4, 4, 3
11
-
12
-
13
- def readGauge(filename: str, grid_size: List[int]):
14
- filename = path.expanduser(path.expandvars(filename))
15
- with open(filename, "rb") as f:
16
- latt_size = struct.unpack("<iiii", f.read(16))[::-1]
17
- plaquette = struct.unpack("<d", f.read(8))[0] / Nc
18
- offset = f.tell()
19
- Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
20
- dtype = "<c16"
21
-
22
- gauge_reorder = readMPIFile(filename, dtype, offset, (Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), (1, 2, 3, 0), grid_size)
23
-
24
- gauge = numpy.zeros((Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc), dtype="<c16")
25
- for t in range(Lt):
26
- for y in range(Ly):
27
- for z in range(Lz):
28
- for x in range(Lx // 2):
29
- x_ = 2 * x + (1 - (t + z + y) % 2)
30
- z_ = z // 2
31
- gauge[[3, 0, 1, 2], :, t, z, y, x, :, :] = gauge_reorder[t, x_, y, z_]
32
-
33
- gauge = gauge.astype("<c16")
34
- return latt_size, plaquette, gauge
35
-
36
-
37
- def writeGauge(filename: str, latt_size: List[int], grid_size: List[int], plaquette: float, gauge: numpy.ndarray):
38
- filename = path.expanduser(path.expandvars(filename))
39
- Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
40
- dtype, offset = "<c16", None
41
-
42
- gauge_reorder = numpy.zeros((Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), dtype="<c16")
43
- for t in range(Lt):
44
- for y in range(Ly):
45
- for z in range(Lz):
46
- for x in range(Lx // 2):
47
- x_ = 2 * x + (1 - (t + z + y) % 2)
48
- z_ = z // 2
49
- gauge_reorder[t, x_, y, z_] = gauge[[3, 0, 1, 2], :, t, z, y, x, :, :]
50
-
51
- gauge = gauge_reorder.astype(dtype)
52
- if MPI.COMM_WORLD.Get_rank() == 0:
53
- with open(filename, "wb") as f:
54
- f.write(struct.pack("<iiii", *latt_size[::-1]))
55
- f.write(struct.pack("<d", plaquette * Nc))
56
- offset = f.tell()
57
- offset = MPI.COMM_WORLD.bcast(offset)
58
-
59
- writeMPIFile(filename, dtype, offset, (Lt, Lx, Ly, Lz // 2, Nd, 2, Nc, Nc), (1, 2, 3, 0), grid_size, gauge)