From 634a8af1997ce4d3baaa1fb5fa21a16f44393b1a Mon Sep 17 00:00:00 2001 From: SaltyChiang Date: Thu, 12 Dec 2024 15:40:43 +0800 Subject: [PATCH] Fix a bug in GPT interface. Add a package called `pyquda_io`. --- .gitignore | 1 + pyproject.toml | 2 +- pyquda_io/__init__.py | 46 +++++++++++++ .../_field_utils.py | 68 ++++++++++++------- .../io/mpi_file.py => pyquda_io/_mpi_file.py | 0 {pyquda_utils/io => pyquda_io}/chroma.py | 2 +- {pyquda_utils/io => pyquda_io}/io_general.py | 0 {pyquda_utils/io => pyquda_io}/kyu.py | 5 +- {pyquda_utils/io => pyquda_io}/lime.py | 0 {pyquda_utils/io => pyquda_io}/milc.py | 2 +- {pyquda_utils/io => pyquda_io}/nersc.py | 4 +- {pyquda_utils/io => pyquda_io}/npy.py | 2 +- {pyquda_utils/io => pyquda_io}/openqcd.py | 4 +- {pyquda_utils/io => pyquda_io}/xqcd.py | 5 +- pyquda_utils/gpt.py | 2 +- pyquda_utils/io/__init__.py | 64 +++++++---------- setup.py | 2 + 17 files changed, 135 insertions(+), 74 deletions(-) create mode 100644 pyquda_io/__init__.py rename pyquda_utils/io/gauge_utils.py => pyquda_io/_field_utils.py (82%) rename pyquda_utils/io/mpi_file.py => pyquda_io/_mpi_file.py (100%) rename {pyquda_utils/io => pyquda_io}/chroma.py (98%) rename {pyquda_utils/io => pyquda_io}/io_general.py (100%) rename {pyquda_utils/io => pyquda_io}/kyu.py (88%) rename {pyquda_utils/io => pyquda_io}/lime.py (100%) rename {pyquda_utils/io => pyquda_io}/milc.py (98%) rename {pyquda_utils/io => pyquda_io}/nersc.py (97%) rename {pyquda_utils/io => pyquda_io}/npy.py (97%) rename {pyquda_utils/io => pyquda_io}/openqcd.py (94%) rename {pyquda_utils/io => pyquda_io}/xqcd.py (89%) diff --git a/.gitignore b/.gitignore index 825fc2f..c49ff08 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ pyquda_core/pyquda/enum_quda.py pyquda_core/pyquda/src/*.c pyquda_core/pyquda/src/*.cpp pyquda_utils/_version.py +pyquda_io/_version.py # symbolic link /pyquda diff --git a/pyproject.toml b/pyproject.toml index 074daf0..f2e2296 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ requires = ["setuptools", "wheel"] [tool.setuptools.packages.find] -include = ["pyquda_utils*"] +include = ["pyquda_utils*", "pyquda_io*"] [tool.setuptools.dynamic] version = { attr = "pyquda_utils._version.__version__" } diff --git a/pyquda_io/__init__.py b/pyquda_io/__init__.py new file mode 100644 index 0000000..b501efa --- /dev/null +++ b/pyquda_io/__init__.py @@ -0,0 +1,46 @@ +# flake8: noqa + +from .io_general import ( + IOGeneral, + read as readIOGeneral, + write as writeIOGeneral, +) +from .lime import ( + Lime, +) +from .npy import ( + readGauge as readNPYGauge, + writeGauge as writeNPYGauge, + readPropagator as readNPYPropagator, + writePropagator as writeNPYPropagator, +) +from .chroma import ( + readQIOGauge as readChromaQIOGauge, + readQIOPropagator as readChromaQIOPropagator, + readILDGBinGauge, +) +from .milc import ( + readGauge as readMILCGauge, + writeGauge as writeMILCGauge, + readQIOPropagator as readMILCQIOPropagator, +) +from .kyu import ( + readGauge as readKYUGauge, + writeGauge as writeKYUGauge, + readPropagator as readKYUPropagator, + writePropagator as writeKYUPropagator, +) +from .xqcd import ( + readPropagator as readXQCDPropagator, + writePropagator as writeXQCDPropagator, + readPropagatorFast as readXQCDPropagatorFast, + writePropagatorFast as writeXQCDPropagatorFast, +) +from .nersc import ( + readGauge as readNERSCGauge, + writeGauge as writeNERSCGauge, +) +from .openqcd import ( + readGauge as readOpenQCDGauge, + writeGauge as writeOpenQCDGauge, +) diff --git a/pyquda_utils/io/gauge_utils.py b/pyquda_io/_field_utils.py similarity index 82% rename from pyquda_utils/io/gauge_utils.py rename to pyquda_io/_field_utils.py index 3b91587..4ff5a58 100644 --- a/pyquda_utils/io/gauge_utils.py +++ b/pyquda_io/_field_utils.py @@ -3,7 +3,7 @@ from mpi4py import MPI import numpy -from .mpi_file import getSublatticeSize, getNeighbourRank +from ._mpi_file import getSublatticeSize, getNeighbourRank Nd, Nc = 4, 3 @@ -72,30 +72,12 @@ def gaugeLexicoPlaquette(latt_size: List[int], grid_size: List[int], gauge: nump extended[:, -1, :-1, :-1, :-1] = buf plaq = numpy.zeros((6)) - plaq[0] = numpy.vdot( - numpy.linalg.matmul(gauge[0], extended[1, :-1, :-1, :-1, 1:]), - numpy.linalg.matmul(gauge[1], extended[0, :-1, :-1, 1:, :-1]), - ).real - plaq[1] = numpy.vdot( - numpy.linalg.matmul(gauge[0], extended[2, :-1, :-1, :-1, 1:]), - numpy.linalg.matmul(gauge[2], extended[0, :-1, 1:, :-1, :-1]), - ).real - plaq[2] = numpy.vdot( - numpy.linalg.matmul(gauge[1], extended[2, :-1, :-1, 1:, :-1]), - numpy.linalg.matmul(gauge[2], extended[1, :-1, 1:, :-1, :-1]), - ).real - plaq[3] = numpy.vdot( - numpy.linalg.matmul(gauge[0], extended[3, :-1, :-1, :-1, 1:]), - numpy.linalg.matmul(gauge[3], extended[0, 1:, :-1, :-1, :-1]), - ).real - plaq[4] = numpy.vdot( - numpy.linalg.matmul(gauge[1], extended[3, :-1, :-1, 1:, :-1]), - numpy.linalg.matmul(gauge[3], extended[1, 1:, :-1, :-1, :-1]), - ).real - plaq[5] = numpy.vdot( - numpy.linalg.matmul(gauge[2], extended[3, :-1, 1:, :-1, :-1]), - numpy.linalg.matmul(gauge[3], extended[2, 1:, :-1, :-1, :-1]), - ).real + plaq[0] = numpy.vdot(gauge[0] @ extended[1, :-1, :-1, :-1, 1:], gauge[1] @ extended[0, :-1, :-1, 1:, :-1]).real + plaq[1] = numpy.vdot(gauge[0] @ extended[2, :-1, :-1, :-1, 1:], gauge[2] @ extended[0, :-1, 1:, :-1, :-1]).real + plaq[2] = numpy.vdot(gauge[1] @ extended[2, :-1, :-1, 1:, :-1], gauge[2] @ extended[1, :-1, 1:, :-1, :-1]).real + plaq[3] = numpy.vdot(gauge[0] @ extended[3, :-1, :-1, :-1, 1:], gauge[3] @ extended[0, 1:, :-1, :-1, :-1]).real + plaq[4] = numpy.vdot(gauge[1] @ extended[3, :-1, :-1, 1:, :-1], gauge[3] @ extended[1, 1:, :-1, :-1, :-1]).real + plaq[5] = numpy.vdot(gauge[2] @ extended[3, :-1, 1:, :-1, :-1], gauge[3] @ extended[2, 1:, :-1, :-1, :-1]).real plaq /= int(numpy.prod(latt_size)) * Nc plaq = MPI.COMM_WORLD.allreduce(plaq, MPI.SUM) @@ -186,3 +168,39 @@ def gaugeEvenShiftBackward(latt_size: List[int], grid_size: List[int], gauge: nu MPI.COMM_WORLD.Sendrecv_replace(buf, dest=neighbour_rank[3], source=neighbour_rank[7]) gauge_shift[3, 1, 0, :, :, :] = buf return gauge_shift + + +# matrices to convert gamma basis bewteen DeGrand-Rossi and Dirac-Pauli +# DP for Dirac-Pauli, DR for DeGrand-Rossi +# \psi(DP) = _DR_TO_DP \psi(DR) +# \psi(DR) = _DP_TO_DR \psi(DP) +_DP_TO_DR = numpy.array( + [ + [0, 1, 0, -1], + [-1, 0, 1, 0], + [0, 1, 0, 1], + [-1, 0, -1, 0], + ] +) +_DR_TO_DP = numpy.array( + [ + [0, -1, 0, -1], + [1, 0, 1, 0], + [0, 1, 0, -1], + [-1, 0, 1, 0], + ] +) + + +def propagatorDeGrandRossiToDiracPauli(propagator: numpy.ndarray): + P = _DR_TO_DP + Pinv = _DP_TO_DR / 2 + + return numpy.ascontiguousarray(numpy.einsum("ij,tzyxjkab,kl->tzyxilab", P, propagator.data, Pinv, optimize=True)) + + +def propagatorDiracPauliToDeGrandRossi(propagator: numpy.ndarray): + P = _DP_TO_DR + Pinv = _DR_TO_DP / 2 + + return numpy.ascontiguousarray(numpy.einsum("ij,tzyxjkab,kl->tzyxilab", P, propagator.data, Pinv, optimize=True)) diff --git a/pyquda_utils/io/mpi_file.py b/pyquda_io/_mpi_file.py similarity index 100% rename from pyquda_utils/io/mpi_file.py rename to pyquda_io/_mpi_file.py diff --git a/pyquda_utils/io/chroma.py b/pyquda_io/chroma.py similarity index 98% rename from pyquda_utils/io/chroma.py rename to pyquda_io/chroma.py index 4ea1872..49eca91 100644 --- a/pyquda_utils/io/chroma.py +++ b/pyquda_io/chroma.py @@ -4,7 +4,7 @@ from mpi4py import MPI -from .mpi_file import getSublatticeSize, getGridCoord, readMPIFile +from ._mpi_file import getSublatticeSize, getGridCoord, readMPIFile Nd, Ns, Nc = 4, 4, 3 _precision_map = {"D": 8, "F": 4, "S": 4} diff --git a/pyquda_utils/io/io_general.py b/pyquda_io/io_general.py similarity index 100% rename from pyquda_utils/io/io_general.py rename to pyquda_io/io_general.py diff --git a/pyquda_utils/io/kyu.py b/pyquda_io/kyu.py similarity index 88% rename from pyquda_utils/io/kyu.py rename to pyquda_io/kyu.py index 19baede..4412e4c 100644 --- a/pyquda_utils/io/kyu.py +++ b/pyquda_io/kyu.py @@ -3,7 +3,8 @@ import numpy -from .mpi_file import getSublatticeSize, readMPIFile, writeMPIFile +from ._mpi_file import getSublatticeSize, readMPIFile, writeMPIFile +from ._field_utils import propagatorDiracPauliToDeGrandRossi, propagatorDeGrandRossiToDiracPauli Nd, Ns, Nc = 4, 4, 3 @@ -48,6 +49,7 @@ def readPropagator(filename: str, latt_size: List[int], grid_size: List[int]): .reshape(Lt, Lz, Ly, Lx, Ns, Ns, Nc, Nc * 2) .view("