Skip to content

Commit 634a8af

Browse files
committed
Fix a bug in GPT interface.
Add a package called `pyquda_io`.
1 parent a8fccc3 commit 634a8af

17 files changed

+135
-74
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pyquda_core/pyquda/enum_quda.py
2222
pyquda_core/pyquda/src/*.c
2323
pyquda_core/pyquda/src/*.cpp
2424
pyquda_utils/_version.py
25+
pyquda_io/_version.py
2526

2627
# symbolic link
2728
/pyquda

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
requires = ["setuptools", "wheel"]
33

44
[tool.setuptools.packages.find]
5-
include = ["pyquda_utils*"]
5+
include = ["pyquda_utils*", "pyquda_io*"]
66

77
[tool.setuptools.dynamic]
88
version = { attr = "pyquda_utils._version.__version__" }

pyquda_io/__init__.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# flake8: noqa
2+
3+
from .io_general import (
4+
IOGeneral,
5+
read as readIOGeneral,
6+
write as writeIOGeneral,
7+
)
8+
from .lime import (
9+
Lime,
10+
)
11+
from .npy import (
12+
readGauge as readNPYGauge,
13+
writeGauge as writeNPYGauge,
14+
readPropagator as readNPYPropagator,
15+
writePropagator as writeNPYPropagator,
16+
)
17+
from .chroma import (
18+
readQIOGauge as readChromaQIOGauge,
19+
readQIOPropagator as readChromaQIOPropagator,
20+
readILDGBinGauge,
21+
)
22+
from .milc import (
23+
readGauge as readMILCGauge,
24+
writeGauge as writeMILCGauge,
25+
readQIOPropagator as readMILCQIOPropagator,
26+
)
27+
from .kyu import (
28+
readGauge as readKYUGauge,
29+
writeGauge as writeKYUGauge,
30+
readPropagator as readKYUPropagator,
31+
writePropagator as writeKYUPropagator,
32+
)
33+
from .xqcd import (
34+
readPropagator as readXQCDPropagator,
35+
writePropagator as writeXQCDPropagator,
36+
readPropagatorFast as readXQCDPropagatorFast,
37+
writePropagatorFast as writeXQCDPropagatorFast,
38+
)
39+
from .nersc import (
40+
readGauge as readNERSCGauge,
41+
writeGauge as writeNERSCGauge,
42+
)
43+
from .openqcd import (
44+
readGauge as readOpenQCDGauge,
45+
writeGauge as writeOpenQCDGauge,
46+
)

pyquda_utils/io/gauge_utils.py renamed to pyquda_io/_field_utils.py

+43-25
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from mpi4py import MPI
44
import numpy
55

6-
from .mpi_file import getSublatticeSize, getNeighbourRank
6+
from ._mpi_file import getSublatticeSize, getNeighbourRank
77

88
Nd, Nc = 4, 3
99

@@ -72,30 +72,12 @@ def gaugeLexicoPlaquette(latt_size: List[int], grid_size: List[int], gauge: nump
7272
extended[:, -1, :-1, :-1, :-1] = buf
7373

7474
plaq = numpy.zeros((6))
75-
plaq[0] = numpy.vdot(
76-
numpy.linalg.matmul(gauge[0], extended[1, :-1, :-1, :-1, 1:]),
77-
numpy.linalg.matmul(gauge[1], extended[0, :-1, :-1, 1:, :-1]),
78-
).real
79-
plaq[1] = numpy.vdot(
80-
numpy.linalg.matmul(gauge[0], extended[2, :-1, :-1, :-1, 1:]),
81-
numpy.linalg.matmul(gauge[2], extended[0, :-1, 1:, :-1, :-1]),
82-
).real
83-
plaq[2] = numpy.vdot(
84-
numpy.linalg.matmul(gauge[1], extended[2, :-1, :-1, 1:, :-1]),
85-
numpy.linalg.matmul(gauge[2], extended[1, :-1, 1:, :-1, :-1]),
86-
).real
87-
plaq[3] = numpy.vdot(
88-
numpy.linalg.matmul(gauge[0], extended[3, :-1, :-1, :-1, 1:]),
89-
numpy.linalg.matmul(gauge[3], extended[0, 1:, :-1, :-1, :-1]),
90-
).real
91-
plaq[4] = numpy.vdot(
92-
numpy.linalg.matmul(gauge[1], extended[3, :-1, :-1, 1:, :-1]),
93-
numpy.linalg.matmul(gauge[3], extended[1, 1:, :-1, :-1, :-1]),
94-
).real
95-
plaq[5] = numpy.vdot(
96-
numpy.linalg.matmul(gauge[2], extended[3, :-1, 1:, :-1, :-1]),
97-
numpy.linalg.matmul(gauge[3], extended[2, 1:, :-1, :-1, :-1]),
98-
).real
75+
plaq[0] = numpy.vdot(gauge[0] @ extended[1, :-1, :-1, :-1, 1:], gauge[1] @ extended[0, :-1, :-1, 1:, :-1]).real
76+
plaq[1] = numpy.vdot(gauge[0] @ extended[2, :-1, :-1, :-1, 1:], gauge[2] @ extended[0, :-1, 1:, :-1, :-1]).real
77+
plaq[2] = numpy.vdot(gauge[1] @ extended[2, :-1, :-1, 1:, :-1], gauge[2] @ extended[1, :-1, 1:, :-1, :-1]).real
78+
plaq[3] = numpy.vdot(gauge[0] @ extended[3, :-1, :-1, :-1, 1:], gauge[3] @ extended[0, 1:, :-1, :-1, :-1]).real
79+
plaq[4] = numpy.vdot(gauge[1] @ extended[3, :-1, :-1, 1:, :-1], gauge[3] @ extended[1, 1:, :-1, :-1, :-1]).real
80+
plaq[5] = numpy.vdot(gauge[2] @ extended[3, :-1, 1:, :-1, :-1], gauge[3] @ extended[2, 1:, :-1, :-1, :-1]).real
9981

10082
plaq /= int(numpy.prod(latt_size)) * Nc
10183
plaq = MPI.COMM_WORLD.allreduce(plaq, MPI.SUM)
@@ -186,3 +168,39 @@ def gaugeEvenShiftBackward(latt_size: List[int], grid_size: List[int], gauge: nu
186168
MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[3], source=neighbour_rank[7])
187169
gauge_shift[3, 1, 0, :, :, :] = buf
188170
return gauge_shift
171+
172+
173+
# matrices to convert gamma basis bewteen DeGrand-Rossi and Dirac-Pauli
174+
# DP for Dirac-Pauli, DR for DeGrand-Rossi
175+
# \psi(DP) = _DR_TO_DP \psi(DR)
176+
# \psi(DR) = _DP_TO_DR \psi(DP)
177+
_DP_TO_DR = numpy.array(
178+
[
179+
[0, 1, 0, -1],
180+
[-1, 0, 1, 0],
181+
[0, 1, 0, 1],
182+
[-1, 0, -1, 0],
183+
]
184+
)
185+
_DR_TO_DP = numpy.array(
186+
[
187+
[0, -1, 0, -1],
188+
[1, 0, 1, 0],
189+
[0, 1, 0, -1],
190+
[-1, 0, 1, 0],
191+
]
192+
)
193+
194+
195+
def propagatorDeGrandRossiToDiracPauli(propagator: numpy.ndarray):
196+
P = _DR_TO_DP
197+
Pinv = _DP_TO_DR / 2
198+
199+
return numpy.ascontiguousarray(numpy.einsum("ij,tzyxjkab,kl->tzyxilab", P, propagator.data, Pinv, optimize=True))
200+
201+
202+
def propagatorDiracPauliToDeGrandRossi(propagator: numpy.ndarray):
203+
P = _DP_TO_DR
204+
Pinv = _DR_TO_DP / 2
205+
206+
return numpy.ascontiguousarray(numpy.einsum("ij,tzyxjkab,kl->tzyxilab", P, propagator.data, Pinv, optimize=True))
File renamed without changes.

pyquda_utils/io/chroma.py renamed to pyquda_io/chroma.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from mpi4py import MPI
66

7-
from .mpi_file import getSublatticeSize, getGridCoord, readMPIFile
7+
from ._mpi_file import getSublatticeSize, getGridCoord, readMPIFile
88

99
Nd, Ns, Nc = 4, 4, 3
1010
_precision_map = {"D": 8, "F": 4, "S": 4}
File renamed without changes.

pyquda_utils/io/kyu.py renamed to pyquda_io/kyu.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import numpy
55

6-
from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
6+
from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
7+
from ._field_utils import propagatorDiracPauliToDeGrandRossi, propagatorDeGrandRossiToDiracPauli
78

89
Nd, Ns, Nc = 4, 4, 3
910

@@ -48,6 +49,7 @@ def readPropagator(filename: str, latt_size: List[int], grid_size: List[int]):
4849
.reshape(Lt, Lz, Ly, Lx, Ns, Ns, Nc, Nc * 2)
4950
.view("<c16")
5051
)
52+
propagator = propagatorDiracPauliToDeGrandRossi(propagator)
5153
return propagator
5254

5355

@@ -56,6 +58,7 @@ def writePropagator(filename: str, latt_size: List[int], grid_size: List[int], p
5658
Lx, Ly, Lz, Lt = getSublatticeSize(latt_size, grid_size)
5759
dtype, offset = ">f8", 0
5860

61+
propagator = propagatorDeGrandRossiToDiracPauli(propagator)
5962
propagator = (
6063
propagator.view("<f8")
6164
.reshape(Lt, Lz, Ly, Lx, Ns, Ns, Nc, Nc, 2)
File renamed without changes.

pyquda_utils/io/milc.py renamed to pyquda_io/milc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy
88
from mpi4py import MPI
99

10-
from .mpi_file import getGridCoord, getSublatticeSize, readMPIFile, writeMPIFile
10+
from ._mpi_file import getGridCoord, getSublatticeSize, readMPIFile, writeMPIFile
1111

1212
Nd, Ns, Nc = 4, 4, 3
1313
_precision_map = {"D": 8, "F": 4, "S": 4}

pyquda_utils/io/nersc.py renamed to pyquda_io/nersc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import numpy
66
from mpi4py import MPI
77

8-
from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
9-
from .gauge_utils import gaugeLexicoPlaquette
8+
from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
9+
from ._field_utils import gaugeLexicoPlaquette
1010

1111
Nd, Ns, Nc = 4, 4, 3
1212

pyquda_utils/io/npy.py renamed to pyquda_io/npy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from numpy.lib.format import dtype_to_descr, read_magic, read_array_header_1_0, write_array_header_1_0
66
from mpi4py import MPI
77

8-
from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
8+
from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
99

1010
Nd, Ns, Nc = 4, 4, 3
1111

pyquda_utils/io/openqcd.py renamed to pyquda_io/openqcd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import numpy
66
from mpi4py import MPI
77

8-
from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
9-
from .gauge_utils import gaugeEvenOdd, gaugeLexico, gaugeLexicoPlaquette, gaugeOddShiftForward, gaugeEvenShiftBackward
8+
from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
9+
from ._field_utils import gaugeEvenOdd, gaugeLexico, gaugeLexicoPlaquette, gaugeOddShiftForward, gaugeEvenShiftBackward
1010

1111
Nd, Ns, Nc = 4, 4, 3
1212

pyquda_utils/io/xqcd.py renamed to pyquda_io/xqcd.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import numpy
55

6-
from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
6+
from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile
7+
from ._field_utils import propagatorDiracPauliToDeGrandRossi, propagatorDeGrandRossiToDiracPauli
78

89
Ns, Nc = 4, 3
910

@@ -16,6 +17,7 @@ def readPropagator(filename: str, latt_size: List[int], grid_size: List[int], st
1617
if not staggered:
1718
propagator = readMPIFile(filename, dtype, offset, (Ns, Nc, Lt, Lz, Ly, Lx, Ns, Nc), (5, 4, 3, 2), grid_size)
1819
propagator = propagator.transpose(2, 3, 4, 5, 6, 0, 7, 1).astype("<c16")
20+
propagator = propagatorDiracPauliToDeGrandRossi(propagator)
1921
else:
2022
# QDP_ALIGN16 makes the last Nc to be aligned with 16 Bytes.
2123
propagator_align16 = readMPIFile(filename, dtype, offset, (Nc, Lt, Lz, Ly, Lx, 4), (4, 3, 2, 1), grid_size)
@@ -32,6 +34,7 @@ def writePropagator(
3234
dtype, offset = "<c8", 0
3335

3436
if not staggered:
37+
propagator = propagatorDeGrandRossiToDiracPauli(propagator)
3538
propagator = propagator.astype(dtype).transpose(5, 7, 0, 1, 2, 3, 4, 6).copy()
3639
writeMPIFile(filename, dtype, offset, (Ns, Nc, Lt, Lz, Ly, Lx, Ns, Nc), (5, 4, 3, 2), grid_size, propagator)
3740
else:

pyquda_utils/gpt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def LatticeGaugeGPT(lattice: List[g.lattice], gen_simd_width: int, gauge: Lattic
4949
else:
5050
assert latt_info.size == gauge.latt_info.size
5151
for index in range(latt_info.Nd):
52-
gpt_shape = [i for sl in zip(gpt_simd, gpt_latt) for i in sl]
52+
gpt_shape = [i for sl in zip(gpt_simd[::-1], gpt_latt[::-1]) for i in sl]
5353
lattice[index].mview()[0][:] = (
5454
gauge[index]
5555
.lexico()

0 commit comments

Comments
 (0)