Skip to content

Commit

Permalink
Don't aquire QUDA_PATH for pip download.
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyChiang committed Nov 8, 2024
1 parent ec57c4d commit f5f015c
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 15 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp
- Multi-GPU supported
- with [MPI for Python](https://mpi4py.readthedocs.io/en/stable/) package
- File I/O
- Read gauge and propagator in Chroma format
- Read gauge and propagator in MILC format
- Read gauge and propagator in Chroma format (with checksum)
- Read gauge and propagator in MILC format (with checksum)
- Read/write gauge and propagator in KYU format
- Read/write gauge and propagator in XQCD format
- Read/write gauge and propagator in NPY format (numpy)
Expand All @@ -21,10 +21,10 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp
- Isotropic/anisotropic Clover fermion action with multigrid support
- Isotropic HISQ fermion action
- HMC
- Isotropic Wilson gauge action
- Isotropic Symanzik gauge action
- Isotropic gauge action
- 1-flavor isotropic clover fermion action
- 2-flavor isotropic clover fermion action
- N-flavor isotropic HISQ fermion action
- Gauge fixing
- Rotation field with over-relaxation method (waiting for QUDA merge)
- Gauge smearing
Expand All @@ -39,6 +39,17 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp

## Installation

### Install from PyPI

Assuming the QUDA installation path is `/path/to/quda/build/usqcd`

```bash
export QUDA_PATH=/path/to/quda/build/usqcd
python3 -m pip install pyquda pyquda-utils
```

### Install from source

Refer to https://github.com/CLQCD/PyQUDA/wiki/Installation for detailed instructions to install PyQUDA from the source.

## Benchmark
Expand All @@ -54,7 +65,7 @@ https://github.com/CLQCD/PyQUDA/wiki/Documentation
We recommend building PyQUDA using in-place mode instead of installing PyQUDA for development.

```bash
git clone https://github.com/CLQCD/PyQUDA.git
git clone --recursive https://github.com/CLQCD/PyQUDA.git
cd PyQUDA
ln -s pyquda_core/pyquda pyquda
cd pyquda_core
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "wheel"]

[tool.setuptools.packages.find]
include = ["pyquda_utils*"]
Expand Down
21 changes: 16 additions & 5 deletions pyquda_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp
- Multi-GPU supported
- with [MPI for Python](https://mpi4py.readthedocs.io/en/stable/) package
- File I/O
- Read gauge and propagator in Chroma format
- Read gauge and propagator in MILC format
- Read gauge and propagator in Chroma format (with checksum)
- Read gauge and propagator in MILC format (with checksum)
- Read/write gauge and propagator in KYU format
- Read/write gauge and propagator in XQCD format
- Read/write gauge and propagator in NPY format (numpy)
Expand All @@ -21,10 +21,10 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp
- Isotropic/anisotropic Clover fermion action with multigrid support
- Isotropic HISQ fermion action
- HMC
- Isotropic Wilson gauge action
- Isotropic Symanzik gauge action
- Isotropic gauge action
- 1-flavor isotropic clover fermion action
- 2-flavor isotropic clover fermion action
- N-flavor isotropic HISQ fermion action
- Gauge fixing
- Rotation field with over-relaxation method (waiting for QUDA merge)
- Gauge smearing
Expand All @@ -39,6 +39,17 @@ This project is based on the latest QUDA `develop` branch. PyQUDA should be comp

## Installation

### Install from PyPI

Assuming the QUDA installation path is `/path/to/quda/build/usqcd`

```bash
export QUDA_PATH=/path/to/quda/build/usqcd
python3 -m pip install pyquda pyquda-utils
```

### Install from source

Refer to https://github.com/CLQCD/PyQUDA/wiki/Installation for detailed instructions to install PyQUDA from the source.

## Benchmark
Expand All @@ -54,7 +65,7 @@ https://github.com/CLQCD/PyQUDA/wiki/Documentation
We recommend building PyQUDA using in-place mode instead of installing PyQUDA for development.

```bash
git clone https://github.com/CLQCD/PyQUDA.git
git clone --recursive https://github.com/CLQCD/PyQUDA.git
cd PyQUDA
ln -s pyquda_core/pyquda pyquda
cd pyquda_core
Expand Down
2 changes: 1 addition & 1 deletion pyquda_core/pyquda/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.4"
__version__ = "0.9.5"
2 changes: 1 addition & 1 deletion pyquda_core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import Extension, setup
from pyquda_pyx import build_pyquda_pyx

if "egg_info" in sys.argv or "sdist" in sys.argv:
if "egg_info" in sys.argv or "dist_info" in sys.argv or "sdist" in sys.argv:
setup()
elif "QUDA_PATH" in os.environ:
quda_path = os.path.realpath(os.environ["QUDA_PATH"])
Expand Down
207 changes: 207 additions & 0 deletions pyquda_utils/io/io_general.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
from ctypes import Union, Structure, c_char, c_int, sizeof
from enum import IntEnum
import io
from os import path
from typing import Sequence

import numpy
from numpy.typing import NDArray


class _DimensionType(IntEnum):
dim_other = 0
dim_x = 1
dim_y = 2
dim_z = 3
dim_t = 4
dim_d = 5
dim_c = 6
dim_d2 = 7
dim_c2 = 8
dim_complex = 9
dim_mass = 10
dim_smear = 11
dim_displacement = 12

dim_s_01 = 13
dim_s_02 = 14
dim_s_03 = 15
dim_s_11 = 16
dim_s_12 = 17
dim_s_13 = 18
dim_d_01 = 19
dim_d_02 = 20
dim_d_03 = 21
dim_d_11 = 22
dim_d_12 = 23
dim_d_13 = 24

dim_conf = 25
dim_operator = 26
dim_momentum = 27
dim_direction = 28
dim_t2 = 29
dim_mass2 = 30

dim_column = 31
dim_row = 32
dim_temporary = 33
dim_temporary2 = 34
dim_temporary3 = 35
dim_temporary4 = 36

dim_errorbar = 37
"""0 means average, 1 means errorbar, ..."""

dim_operator2 = 38

dim_param = 39
dim_fitleft = 40
dim_fitright = 41

dim_jackknife = 42
dim_jackknife2 = 43
dim_jackknife3 = 44
dim_jackknife4 = 45

dim_summary = 46
"""
0 means average, 1 means standard deviation, 2 means minimal value, 3 means maximum value, 4 means standard error,
5 means median, ...
"""

dim_channel = 47
dim_channel2 = 48

dim_eigen = 49

dim_d_row = 50
"""on matrix multiplication, row is contracted with the left operand, col is contracted with the right operand."""
dim_d_col = 51
dim_c_row = 52
dim_c_col = 53

dim_parity = 54
"""dimension for different parities. we use 1/-1 for +/- parities for baryons."""

dim_noise = 55
dim_evenodd = 56

dim_disp_x = 57
dim_disp_y = 58
dim_disp_z = 59
dim_disp_t = 60

dim_t3 = 61
dim_t4 = 62
dim_t_source = 63
dim_t_current = 64
dim_t_sink = 65

dim_nothing = 66
"""do not use this unless for unused data."""

dim_bootstrap = 67

# add new dimensions here and add a string name in xqcd_type_dim_desc[] in io_general.c
# ...

dim_last = 68


class _OneDim(Structure):
# _pack_ = 1
_fields_ = [("type", c_int), ("n_indices", c_int), ("indices", c_int * 1024)]

type: int
n_indices: int
indices: Sequence[int]


class _Head(Structure):
# _pack_ = 1
_fields_ = [("n_dimensions", c_int), ("dimensions", _OneDim * 16)]

n_dimensions: int
dimensions: Sequence[_OneDim]

@property
def dimensions_type(self):
return tuple([_DimensionType(self.dimensions[i].type)._name_[4:] for i in range(self.n_dimensions)])

@property
def dimensions_n_indices(self):
return tuple([self.dimensions[i].n_indices for i in range(self.n_dimensions)])


class _FileType(Union):
_fields_ = [("head", _Head), ("blank", c_char * 102400)]

head: _Head
blank: bytes

@property
def n_dimensions(self):
return self.head.n_dimensions

@n_dimensions.setter
def n_dimensions(self, value):
self.head.n_dimensions = value

@property
def dimensions(self):
return self.head.dimensions

@property
def dimensions_type(self):
return self.head.dimensions_type

@property
def dimensions_n_indices(self):
return self.head.dimensions_n_indices

def __repr__(self):
retval = ""
for i in range(self.n_dimensions):
retval += f"{_DimensionType(self.dimensions[i].type)._name_:18s}{self.dimensions[i].n_indices:<6d}( "
for j in range(self.dimensions[i].n_indices):
retval += f"{self.dimensions[i].indices[j]} "
retval += ")\n"
return retval


def read(filename: str):
filename = path.expanduser(path.expandvars(filename))
with open(filename, "rb") as f:
head = _FileType.from_buffer_copy(f.read(sizeof(_FileType)))
data = numpy.frombuffer(f.read(), "<f8").reshape(head.dimensions_n_indices)

return head, data


def write(filename: str, head: _FileType, data: NDArray[numpy.float64]):
assert head.dimensions_n_indices == data.shape
assert data.dtype == numpy.float64

filename = path.expanduser(path.expandvars(filename))
with open(filename, "wb") as f:
f.write(bytes(head))
f.write(data.tobytes())


class IOGeneral:
def __init__(self, filename: str):
self.filename = path.expanduser(path.expandvars(filename))
with open(self.filename, "rb") as f:
self.head = _FileType.from_buffer_copy(f.read(sizeof(_FileType)))
self.data = None

def read(self):
with open(self.filename, "rb") as f:
f.seek(sizeof(_FileType), io.SEEK_SET)
self.data = numpy.frombuffer(f.read(), "<f8").reshape(self.head.dimensions_n_indices)

def write(self):
with open(self.filename, "wb") as f:
f.write(bytes(self.head))
f.write(self.data.reshape(self.head.dimensions_n_indices).tobytes())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from setuptools import setup

if "egg_info" in sys.argv or "sdist" in sys.argv:
if "egg_info" in sys.argv or "dist_info" in sys.argv or "sdist" in sys.argv:
describe = os.popen("git describe --tags", "r").read().strip()
if describe != "":
if "-" in describe:
Expand Down
29 changes: 29 additions & 0 deletions tests/test.clover.mrhs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import cupy as cp

from check_pyquda import weak_field

from pyquda import init
from pyquda_utils import core, io, source

xi_0, nu = 2.464, 0.95
kappa = 0.115
mass = 1 / (2 * kappa) - 4
coeff = 1.17
coeff_r, coeff_t = 0.91, 1.07

init(None, [4, 4, 4, 8], -1, xi_0 / nu, resource_path=".cache")
latt_info = core.getDefaultLattice()

dslash = core.getDefaultDirac(mass, 1e-12, 1000, xi_0, coeff_t, coeff_r)
gauge = io.readQIOGauge(weak_field)

dslash.loadGauge(gauge)

point_source = source.multiFermion(latt_info, "point", [0, 0, 0, 0])
propagator = dslash.invertMultiSrc(point_source).toPropagator()

dslash.destroy()

propagator_chroma = io.readQIOPropagator("pt_prop_1")
propagator_chroma.toDevice()
print(cp.linalg.norm(propagator.data - propagator_chroma.data))

0 comments on commit f5f015c

Please sign in to comment.