Skip to content

Commit

Permalink
Ignore already installed pycparser.
Browse files Browse the repository at this point in the history
Update pycparser to upstream 2.22.
  • Loading branch information
SaltyChiang committed Apr 1, 2024
1 parent 8ee4ea6 commit fc52355
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pycparser
98 changes: 43 additions & 55 deletions pyquda/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,112 +96,100 @@ def cb2(data: numpy.ndarray, axes: List[int], dtype=None):
return data_cb2.reshape(*shape[: axes[0]], 2, Lt, Lz, Ly, Lx // 2, *shape[axes[-1] + 1 :])


def newLatticeFieldData(latt_info: LatticeInfo, dtype: str):
def newLatticeFieldData(latt_info: LatticeInfo, field: str):
from . import getCUDABackend

backend = getCUDABackend()
Lx, Ly, Lz, Lt = latt_info.size
if backend == "numpy":
if dtype == "Gauge":
if field == "Gauge":
ret = numpy.zeros((Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc), "<c16")
ret[:] = numpy.identity(Nc)
return ret
elif dtype == "Colorvector":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "Fermion":
elif field == "Fermion":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif dtype == "Propagator":
elif field == "Propagator":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Ns, Nc, Nc), "<c16")
elif dtype == "StaggeredFermion":
elif field == "StaggeredFermion":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "StaggeredPropagator":
elif field == "StaggeredPropagator":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc, Nc), "<c16")
elif dtype == "Clover":
elif field == "Clover":
return numpy.zeros((2, Lt, Lz, Ly, Lx // 2, 2, ((Ns // 2) * Nc) ** 2), "<f8")
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
elif backend == "cupy":
import cupy

if dtype == "Gauge":
if field == "Gauge":
ret = cupy.zeros((Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc), "<c16")
ret[:] = cupy.identity(Nc)
return ret
elif dtype == "Colorvector":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "Fermion":
elif field == "Fermion":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif dtype == "Propagator":
elif field == "Propagator":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Ns, Nc, Nc), "<c16")
elif dtype == "StaggeredFermion":
elif field == "StaggeredFermion":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "StaggeredPropagator":
elif field == "StaggeredPropagator":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, Nc, Nc), "<c16")
elif dtype == "Clover":
elif field == "Clover":
return cupy.zeros((2, Lt, Lz, Ly, Lx // 2, 2, ((Ns // 2) * Nc) ** 2), "<f8")
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
elif backend == "torch":
import torch

if dtype == "Gauge":
if field == "Gauge":
ret = torch.zeros((Nd, 2, Lt, Lz, Ly, Lx // 2, Nc, Nc), dtype=torch.complex128)
ret[:] = torch.eye(Nc)
return ret
elif dtype == "Colorvector":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), dtype=torch.complex128)
elif dtype == "Fermion":
elif field == "Fermion":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Nc), dtype=torch.complex128)
elif dtype == "Propagator":
elif field == "Propagator":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, Ns, Ns, Nc, Nc), dtype=torch.complex128)
elif dtype == "StaggeredFermion":
elif field == "StaggeredFermion":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, Nc), dtype=torch.complex128)
elif dtype == "StaggeredPropagator":
elif field == "StaggeredPropagator":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, Nc, Nc), dtype=torch.complex128)
elif dtype == "Clover":
elif field == "Clover":
return torch.zeros((2, Lt, Lz, Ly, Lx // 2, 2, ((Ns // 2) * Nc) ** 2), dtype=torch.float64)
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
else:
raise ValueError(f"Unsupported CUDA backend {backend}")


def newMultiLatticeFieldData(latt_info: LatticeInfo, num_field: int, dtype: str):
def newMultiLatticeFieldData(latt_info: LatticeInfo, L5: int, field: str):
from . import getCUDABackend

backend = getCUDABackend()
Lx, Ly, Lz, Lt = latt_info.size
if backend == "numpy":
if dtype == "Colorvector":
return numpy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "Fermion":
return numpy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif dtype == "StaggeredFermion":
return numpy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
if field == "Fermion":
return numpy.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif field == "StaggeredFermion":
return numpy.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
elif backend == "cupy":
import cupy

if dtype == "Colorvector":
return cupy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
elif dtype == "Fermion":
return cupy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif dtype == "StaggeredFermion":
return cupy.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
if field == "Fermion":
return cupy.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), "<c16")
elif field == "StaggeredFermion":
return cupy.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Nc), "<c16")
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
elif backend == "torch":
import torch

if dtype == "Colorvector":
return torch.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), dtype=torch.complex128)
elif dtype == "Fermion":
return torch.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), dtype=torch.complex128)
elif dtype == "StaggeredFermion":
return torch.zeros((num_field, 2, Lt, Lz, Ly, Lx // 2, Nc), dtype=torch.complex128)
if field == "Fermion":
return torch.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Ns, Nc), dtype=torch.complex128)
elif field == "StaggeredFermion":
return torch.zeros((L5, 2, Lt, Lz, Ly, Lx // 2, Nc), dtype=torch.complex128)
else:
raise ValueError(f"Unsupported lattice field type {dtype}")
raise ValueError(f"Unsupported lattice field type {field}")
else:
raise ValueError(f"Unsupported CUDA backend {backend}")

Expand Down Expand Up @@ -284,9 +272,9 @@ def getHost(self):


class MultiLatticeField(LatticeField):
def __init__(self, latt_info: LatticeInfo, num_field: int) -> None:
def __init__(self, latt_info: LatticeInfo, L5: int) -> None:
super().__init__(latt_info)
self.num_field = num_field
self.L5 = L5


class LatticeGauge(LatticeField):
Expand Down Expand Up @@ -528,15 +516,15 @@ def __init__(self, latt_info: LatticeInfo, L5: int, value=None) -> None:

@property
def data_ptrs(self) -> Pointers:
return ndarrayPointer(self.data.reshape(self.num_field, -1), True)
return ndarrayPointer(self.data.reshape(self.L5, -1), True)

@property
def even_ptrs(self) -> Pointers:
return ndarrayPointer(self.data.reshape(self.num_field, 2, -1)[:, 0], True)
return ndarrayPointer(self.data.reshape(self.L5, 2, -1)[:, 0], True)

@property
def odd_ptrs(self) -> Pointers:
return ndarrayPointer(self.data.reshape(self.num_field, 2, -1)[:, 1], True)
return ndarrayPointer(self.data.reshape(self.L5, 2, -1)[:, 1], True)


class LatticePropagator(LatticeField):
Expand Down
6 changes: 3 additions & 3 deletions pyquda/hmc_clover.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def updateGaugeField(self, dt: float):

def computeCloverForce(self, dt, x: LatticeFermion, kappa2, ck):
self.updateClover()
if self.offset_inv_square_root is None:
if self.num_flavor == 2:
invertQuda(x.even_ptr, x.odd_ptr, self.invert_param)
# Some conventions force the dagger to be YES here
self.invert_param.dagger = QudaDagType.QUDA_DAG_YES
Expand Down Expand Up @@ -193,7 +193,7 @@ def actionFermion(self, x: LatticeFermion) -> float:
self.updateClover()
self.invert_param.compute_clover_trlog = 0
self.invert_param.compute_action = 1
if self.offset_inv_square_root is None:
if self.num_flavor == 2:
invertQuda(x.even_ptr, x.odd_ptr, self.invert_param)
else:
num_offset = len(self.offset_inv_square_root)
Expand All @@ -220,7 +220,7 @@ def updateClover(self):

def initNoise(self, x: LatticeFermion, seed: int):
self.updateClover()
if self.offset_fourth_root is None:
if self.num_flavor == 2:
self.invert_param.dagger = QudaDagType.QUDA_DAG_YES
MatQuda(x.odd_ptr, x.even_ptr, self.invert_param)
self.invert_param.dagger = QudaDagType.QUDA_DAG_NO
Expand Down
2 changes: 1 addition & 1 deletion pyquda/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.13"
__version__ = "0.6.14"
5 changes: 4 additions & 1 deletion pyquda_pyx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from typing import Dict, List, NamedTuple, Union


Expand Down Expand Up @@ -143,10 +144,12 @@ def build_pyquda_pyx(pyquda_root, quda_path):
quda_include = os.path.join(quda_path, "include")
assert os.path.exists(fake_libc_include), f"{fake_libc_include} not found"
print(f"Building pyquda wrapper from {os.path.join(quda_include, 'quda.h')}")
sys.path.insert(1, os.path.join(pyquda_root, "pycparser"))
try:
from pycparser import parse_file, c_ast
except ImportError or ModuleNotFoundError:
from pycparser.pycparser import parse_file, c_ast
from pycparser.pycparser import parse_file, c_ast # This is for the language server
sys.path.remove(os.path.join(pyquda_root, "pycparser"))

def evaluate(node):
if node is None:
Expand Down

0 comments on commit fc52355

Please sign in to comment.