PyQUDA-Utils 0.10.8.dev5__tar.gz → 0.10.9.dev1__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 (46) hide show
  1. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PKG-INFO +1 -1
  2. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/PKG-INFO +1 -1
  3. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/SOURCES.txt +1 -0
  4. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_plugins/plugin_pyx.py +56 -3
  5. pyquda_utils-0.10.9.dev1/pyquda_plugins/pycontract/__init__.py +41 -0
  6. pyquda_utils-0.10.9.dev1/pyquda_utils/_version.py +1 -0
  7. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/convert.py +1 -1
  8. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/gamma.py +76 -4
  9. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/hmc_param.py +1 -1
  10. pyquda_utils-0.10.8.dev5/pyquda_utils/_version.py +0 -1
  11. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/LICENSE +0 -0
  12. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/MANIFEST.in +0 -0
  13. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/dependency_links.txt +0 -0
  14. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/entry_points.txt +0 -0
  15. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/requires.txt +0 -0
  16. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/PyQUDA_Utils.egg-info/top_level.txt +0 -0
  17. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/README.md +0 -0
  18. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyproject.toml +0 -0
  19. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/__init__.py +0 -0
  20. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/_field_utils.py +0 -0
  21. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/_mpi_file.py +0 -0
  22. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/chroma.py +0 -0
  23. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/io_general.py +0 -0
  24. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/kyu.py +0 -0
  25. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/lime.py +0 -0
  26. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/milc.py +0 -0
  27. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/nersc.py +0 -0
  28. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/npy.py +0 -0
  29. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/openqcd.py +0 -0
  30. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_io/xqcd.py +0 -0
  31. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_plugins/__main__.py +0 -0
  32. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_plugins/pygwu/__init__.py +0 -0
  33. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/__init__.py +0 -0
  34. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/alg_remez.py +0 -0
  35. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/core.py +0 -0
  36. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/deprecated.py +0 -0
  37. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/eigensolve.py +0 -0
  38. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/gauge_nd_sun.py +0 -0
  39. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/gpt.py +0 -0
  40. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/io/__init__.py +0 -0
  41. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/milc_rhmc_param.py +0 -0
  42. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/phase.py +0 -0
  43. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/quasi_axial_gauge_fixing.py +0 -0
  44. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/pyquda_utils/source.py +0 -0
  45. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/setup.cfg +0 -0
  46. {pyquda_utils-0.10.8.dev5 → pyquda_utils-0.10.9.dev1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyQUDA-Utils
3
- Version: 0.10.8.dev5
3
+ Version: 0.10.9.dev1
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.10.8.dev5
3
+ Version: 0.10.9.dev1
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>
@@ -23,6 +23,7 @@ pyquda_io/openqcd.py
23
23
  pyquda_io/xqcd.py
24
24
  pyquda_plugins/__main__.py
25
25
  pyquda_plugins/plugin_pyx.py
26
+ pyquda_plugins/pycontract/__init__.py
26
27
  pyquda_plugins/pygwu/__init__.py
27
28
  pyquda_utils/__init__.py
28
29
  pyquda_utils/_version.py
@@ -5,8 +5,13 @@ _C_TO_PYTHON: Dict[str, str] = {
5
5
  "void *": "Pointer",
6
6
  "void": "None",
7
7
  "short": "int",
8
+ "unsigned short": "int",
8
9
  "int": "int",
10
+ "unsigned int": "int",
9
11
  "long": "int",
12
+ "unsigned long": "int",
13
+ "long long": "int",
14
+ "unsigned long long": "int",
10
15
  "float": "float",
11
16
  "double": "float",
12
17
  "long double": "float",
@@ -125,10 +130,29 @@ def parseHeader(header, include_path):
125
130
  except ImportError or ModuleNotFoundError:
126
131
  from pyquda_core.pycparser.pycparser import parse_file, c_ast # This is for the language server
127
132
 
133
+ def evaluate(node):
134
+ if node is None:
135
+ return
136
+ elif type(node) is c_ast.UnaryOp:
137
+ if node.op == "+":
138
+ return evaluate(node.expr)
139
+ elif node.op == "-":
140
+ return -evaluate(node.expr)
141
+ elif type(node) is c_ast.BinaryOp:
142
+ if node.op == "+":
143
+ return evaluate(node.left) + evaluate(node.right)
144
+ elif node.op == "-":
145
+ return evaluate(node.left) - evaluate(node.right)
146
+ elif type(node) is c_ast.Constant:
147
+ return int(node.value, 0)
148
+ else:
149
+ raise ValueError(f"Unknown node {node}")
150
+
128
151
  ast = parse_file(
129
152
  os.path.join(include_path, header), use_cpp=True, cpp_path="cc", cpp_args=["-E", Rf"-I{include_path}"]
130
153
  )
131
154
  funcs: List[FunctionMeta] = []
155
+ enums: Dict[str, List[Tuple[str, int]]] = {}
132
156
  for node in ast:
133
157
  if isinstance(node.type, c_ast.FuncDecl):
134
158
  a = []
@@ -179,24 +203,53 @@ def parseHeader(header, include_path):
179
203
  funcs.append(FunctionMeta((" ".join(nttt.type.names), "*"), node.name, a))
180
204
  else:
181
205
  raise ValueError(f"Unexpected node {node}")
182
- return funcs
206
+ elif type(node.type.type) is c_ast.Enum:
207
+ print(node.name)
208
+ current_value = -1
209
+ enums[node.name] = []
210
+ for item in node.type.type.values:
211
+ item_value = evaluate(item.value)
212
+ if item_value is not None:
213
+ current_value = item_value
214
+ else:
215
+ current_value += 1
216
+ enums[node.name].append((item.name, current_value))
217
+ return funcs, enums
183
218
 
184
219
 
185
220
  def build_plugin_pyx(plugins_root, lib: str, header: str, include_path: str):
186
221
  lib_pxd = f'cdef extern from "{header}":\n'
187
222
  pylib_pyx = (
223
+ "from enum import IntEnum\n"
188
224
  "from libcpp cimport bool\n"
189
225
  "from numpy cimport ndarray\n"
190
226
  "from pyquda_comm.pointer cimport Pointer, _NDArray\n"
191
227
  f"cimport {lib}\n"
192
228
  "\n"
193
229
  )
194
- pylib_pyi = "from numpy import int32, float64, complex128\n" "from numpy.typing import NDArray\n" "\n"
195
- c_funcs = parseHeader(header, include_path)
230
+ pylib_pyi = (
231
+ "from enum import IntEnum\n"
232
+ "from numpy import int32, float64, complex128\n"
233
+ "from numpy.typing import NDArray\n"
234
+ "\n"
235
+ )
236
+ c_funcs, c_enums = parseHeader(header, include_path)
237
+ for c_enum in c_enums.keys():
238
+ lib_pxd += f" ctypedef enum {c_enum}:\n pass\n\n"
239
+ pylib_pyx += f"class {c_enum}(IntEnum):\n"
240
+ pylib_pyi += f"class {c_enum}(IntEnum):\n"
241
+ for key, value in c_enums[c_enum]:
242
+ pylib_pyx += f" {key} = {value}\n"
243
+ pylib_pyi += f" {key} = {value}\n"
244
+ pylib_pyx += "\n"
245
+ pylib_pyi += "\n"
246
+ _C_TO_PYTHON.update({c_enum: c_enum})
196
247
  for c_func in c_funcs:
197
248
  lib_pxd += f" {c_func}\n"
198
249
  pylib_pyx += "\n" + c_func.pyx(lib)
199
250
  pylib_pyi += c_func.pyi()
251
+ for c_enum in c_enums.keys():
252
+ pylib_pyx = pylib_pyx.replace(f"{c_enum} ", f"{lib}.{c_enum} ")
200
253
 
201
254
  os.makedirs(os.path.join(plugins_root, f"py{lib}", "src"), exist_ok=True)
202
255
  with open(os.path.join(plugins_root, f"py{lib}", "src", f"{lib}.pxd"), "w") as f:
@@ -0,0 +1,41 @@
1
+ from typing import Union
2
+
3
+ from pyquda_comm import getLogger
4
+ from pyquda_comm.field import LatticeComplex, LatticePropagator
5
+ from pyquda_utils.gamma import Gamma, Polarize
6
+
7
+ from . import _pycontract as contract
8
+ from ._pycontract import BaryonContractType
9
+
10
+
11
+ def baryonTwoPoint(
12
+ propag_i: LatticePropagator,
13
+ propag_j: LatticePropagator,
14
+ propag_m: LatticePropagator,
15
+ contract_type: BaryonContractType,
16
+ gamma_ij: Gamma,
17
+ gamma_kl: Gamma,
18
+ gamma_mn: Union[Gamma, Polarize],
19
+ ):
20
+ latt_info = propag_i.latt_info
21
+ if isinstance(gamma_mn, Gamma):
22
+ correl = LatticeComplex(latt_info)
23
+ contract.baryon_two_point(
24
+ correl.data_ptr,
25
+ propag_i.data_ptr,
26
+ propag_j.data_ptr,
27
+ propag_m.data_ptr,
28
+ contract_type,
29
+ latt_info.volume,
30
+ gamma_ij.index,
31
+ gamma_kl.index,
32
+ gamma_mn.index,
33
+ )
34
+ correl.data *= gamma_ij.sign * gamma_kl.sign * gamma_mn.sign
35
+ return correl
36
+ elif isinstance(gamma_mn, Polarize):
37
+ correl_left = baryonTwoPoint(propag_i, propag_j, propag_m, contract_type, gamma_ij, gamma_kl, gamma_mn.left)
38
+ correl_right = baryonTwoPoint(propag_i, propag_j, propag_m, contract_type, gamma_ij, gamma_kl, gamma_mn.right)
39
+ return correl_left + correl_right
40
+ else:
41
+ raise getLogger().critical("gamma_mn should be Gamma or Polarize", ValueError)
@@ -0,0 +1 @@
1
+ __version__ = "0.10.9.dev1"
@@ -12,7 +12,7 @@ from pyquda.field import (
12
12
 
13
13
 
14
14
  def linkToFermion(link: LatticeLink):
15
- fermion = LatticeLink(link.latt_info)
15
+ fermion = LatticeFermion(link.latt_info)
16
16
  for color in range(link.latt_info.Nc):
17
17
  fermion.data[:, :, :, :, :, color, :] = link.data[:, :, :, :, :, :, color]
18
18
  return fermion
@@ -54,7 +54,7 @@ class GammaMatrix:
54
54
  )
55
55
 
56
56
  @classmethod
57
- def matrix(cls, index) -> numpy.ndarray:
57
+ def matrix(cls, index):
58
58
  return (
59
59
  (cls.gamma_1 if index & 0b0001 else cls.gamma_0)
60
60
  @ (cls.gamma_2 if index & 0b0010 else cls.gamma_0)
@@ -115,14 +115,14 @@ class Gamma:
115
115
  popcnt = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]
116
116
  popsign = [1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1]
117
117
 
118
- def __init__(self, index: int, sign: Literal[1, -1]) -> None:
118
+ def __init__(self, index: int, sign: Literal[1, -1] = 1) -> None:
119
119
  assert isinstance(index, int) and 0b0000 <= index <= 0b1111, "index should be int from 0 to 15"
120
120
  self.index = index
121
121
  self.sign = sign
122
122
 
123
123
  def __repr__(self) -> str:
124
124
  return (
125
- f"{'-' if self.sign == -1 else ''}"
125
+ f"{'-' if self.sign == -1 else '' if self.sign == 1 else self.sign}"
126
126
  f"{'γ₀' if not self.index else ''}"
127
127
  f"{'γ₁' if self.index & 0b0001 else ''}"
128
128
  f"{'γ₂' if self.index & 0b0010 else ''}"
@@ -130,6 +130,35 @@ class Gamma:
130
130
  f"{'γ₄' if self.index & 0b1000 else ''}"
131
131
  )
132
132
 
133
+ def __neg__(self) -> "Gamma":
134
+ return Gamma(self.index, -self.sign)
135
+
136
+ def __mul__(self, rhs: Union[int, float, complex]) -> "Gamma":
137
+ assert isinstance(rhs, (int, float, complex)), "rhs should be int, float or complex"
138
+ return Gamma(self.index, self.sign * rhs)
139
+
140
+ def __rmul__(self, lhs: Union[int, float, complex]) -> "Gamma":
141
+ assert isinstance(lhs, (int, float, complex)), "lhs should be int, float or complex"
142
+ return Gamma(self.index, lhs * self.sign)
143
+
144
+ def __truediv__(self, rhs: Union[int, float, complex]) -> "Gamma":
145
+ assert isinstance(rhs, (int, float, complex)), "rhs should be int, float or complex"
146
+ return Gamma(self.index, self.sign / rhs)
147
+
148
+ def __add__(self, rhs: "Gamma") -> Union["Gamma", "Polarize"]:
149
+ assert isinstance(rhs, Gamma), "rhs should be Gamma"
150
+ if self.index == rhs.index:
151
+ return Gamma(self.index, self.sign + rhs.sign)
152
+ else:
153
+ return Polarize(self, rhs)
154
+
155
+ def __sub__(self, rhs: "Gamma") -> Union["Gamma", "Polarize"]:
156
+ assert isinstance(rhs, Gamma), "rhs should be Gamma"
157
+ if self.index == rhs.index:
158
+ return Gamma(self.index, self.sign - rhs.sign)
159
+ else:
160
+ return Polarize(self, -rhs)
161
+
133
162
  def __matmul__(self, rhs: "Gamma") -> "Gamma":
134
163
  index = self.index ^ rhs.index
135
164
  sign = self.sign * rhs.sign
@@ -150,7 +179,7 @@ class Gamma:
150
179
  return Gamma(index, sign)
151
180
 
152
181
  @property
153
- def matrix(self) -> numpy.ndarray:
182
+ def matrix(self):
154
183
  return self.sign * GammaMatrix.matrix(self.index)
155
184
 
156
185
  @property
@@ -158,6 +187,49 @@ class Gamma:
158
187
  return GammaSparse.csr_matrix(self.index)
159
188
 
160
189
 
190
+ class Polarize:
191
+ def __init__(self, left: Gamma, right: Gamma) -> None:
192
+ assert isinstance(left, Gamma), "left should be Gamma"
193
+ assert isinstance(right, Gamma), "right should be Gamma"
194
+ assert left.index != right.index, "left and right should be different"
195
+ self.left = left
196
+ self.right = right
197
+
198
+ def __repr__(self) -> str:
199
+ return (
200
+ f"{self.left} + {self.right}"
201
+ if self.right.sign > 0
202
+ else f"{self.left} - {Gamma(self.right.index, -self.right.sign)}"
203
+ )
204
+
205
+ def __neg__(self) -> "Polarize":
206
+ return Polarize(-self.left, -self.right)
207
+
208
+ def __mul__(self, rhs: Union[int, float, complex]) -> "Gamma":
209
+ assert isinstance(rhs, (int, float, complex)), "rhs should be int, float or complex"
210
+ return Polarize(self.left * rhs, self.right * rhs)
211
+
212
+ def __rmul__(self, lhs: Union[int, float, complex]) -> "Gamma":
213
+ assert isinstance(lhs, (int, float, complex)), "lhs should be int, float or complex"
214
+ return Polarize(lhs * self.left, lhs * self.right)
215
+
216
+ def __truediv__(self, rhs: Union[int, float, complex]) -> "Gamma":
217
+ assert isinstance(rhs, (int, float, complex)), "rhs should be int, float or complex"
218
+ return Polarize(self.left / rhs, self.right / rhs)
219
+
220
+ def __matmul__(self, rhs: Gamma) -> "Polarize":
221
+ assert isinstance(rhs, Gamma), "rhs should be Gamma"
222
+ return Polarize(self.left @ rhs, self.right @ rhs)
223
+
224
+ def __rmatmul__(self, lhs: Gamma) -> "Polarize":
225
+ assert isinstance(lhs, Gamma), "rhs should be Gamma"
226
+ return Polarize(lhs @ self.left, lhs @ self.right)
227
+
228
+ @property
229
+ def matrix(self):
230
+ return self.left.matrix + self.right.matrix
231
+
232
+
161
233
  def gamma(n: int):
162
234
  assert isinstance(n, int) and 0 <= n <= 15, "n should be int from 0 to 15"
163
235
  backend = getCUDABackend()
@@ -307,7 +307,7 @@ def staggeredFermionRationalParam(
307
307
  fermion_action = remez.getIPFE()
308
308
  rational_param = RationalParam(*molecular_dynamics, *pseudo_fermion, *fermion_action)
309
309
  cache[key] = rational_param
310
- _dumpCache(cache)
310
+ _dumpCache(cache)
311
311
  else:
312
312
  rational_param = None
313
313
  return getMPIComm().bcast(rational_param)
@@ -1 +0,0 @@
1
- __version__ = "0.10.8.dev5"