Npr_matrix class added

This commit is contained in:
Fabian Joswig 2021-10-19 23:53:44 +01:00
parent 5e98c89411
commit 207678513c
2 changed files with 94 additions and 6 deletions

View file

@ -6,7 +6,7 @@ import h5py
import numpy as np import numpy as np
from ..pyerrors import Obs, CObs from ..pyerrors import Obs, CObs
from ..correlators import Corr from ..correlators import Corr
from ..npr import Propagator from ..npr import Npr_matrix
def _get_files(path, filestem): def _get_files(path, filestem):
@ -103,4 +103,4 @@ def read_ExternalLeg_hd5(path, filestem, ens_id, order='C'):
matrix[si, sj, ci, cj] = CObs(real, imag) matrix[si, sj, ci, cj] = CObs(real, imag)
matrix[si, sj, ci, cj].gamma_method() matrix[si, sj, ci, cj].gamma_method()
return Propagator(matrix.reshape((12,12), order=order), mom) return Npr_matrix(matrix.reshape((12,12), order=order), mom_in=mom)

View file

@ -1,13 +1,101 @@
import numpy as np import numpy as np
class Propagator(np.ndarray): _gamma = ['gammas', 0, 0, 0, 0, 0]
_gamma[1] = np.array(
[[0, 0, 0, 1j], [0, 0, 1j, 0], [0, -1j, 0, 0], [-1j, 0, 0, 0]],
dtype=complex)
_gamma[2] = np.array(
[[0, 0, 0, -1], [0, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 0, 0]],
dtype=complex)
_gamma[3] = np.array(
[[0, 0, 1j, 0], [0, 0, 0, -1j], [-1j, 0, 0, 0], [0, 1j, 0, 0]],
dtype=complex)
_gamma[4] = np.array(
[[0, 0, 1, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 1, 0, 0]],
dtype=complex)
_gamma[5] = np.array(
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, -1]],
dtype=complex)
_imat = np.array(
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
dtype=complex)
def __new__(cls, input_array, mom=None):
def gamma_matrix(gamma_tag):
"""Returns gamma matrix in Grid labeling."""
if gamma_tag == 'Identity':
g = _imat
elif gamma_tag == 'Gamma5':
g = _gamma[5]
elif gamma_tag == 'GammaX':
g = _gamma[1]
elif gamma_tag == 'GammaY':
g = _gamma[2]
elif gamma_tag == 'GammaZ':
g = _gamma[3]
elif gamma_tag == 'GammaT':
g = _gamma[4]
elif gamma_tag == 'GammaXGamma5':
g = _gamma[1] @ _gamma[5]
elif gamma_tag == 'GammaYGamma5':
g = _gamma[2] @ _gamma[5]
elif gamma_tag == 'GammaZGamma5':
g = _gamma[3] @ _gamma[5]
elif gamma_tag == 'GammaTGamma5':
g = _gamma[4] @ _gamma[5]
elif gamma_tag == 'SigmaXT':
g = 0.5 * (_gamma[1] @ _gamma[4] - _gamma[4] @ _gamma[1])
elif gamma_tag == 'SigmaXY':
g = 0.5 * (_gamma[1] @ _gamma[2] - _gamma[2] @ _gamma[1])
elif gamma_tag == 'SigmaXZ':
g = 0.5 * (_gamma[1] @ _gamma[3] - _gamma[3] @ _gamma[1])
elif gamma_tag == 'SigmaYT':
g = 0.5 * (_gamma[2] @ _gamma[4] - _gamma[4] @ _gamma[2])
elif gamma_tag == 'SigmaYZ':
g = 0.5 * (_gamma[2] @ _gamma[3] - _gamma[3] @ _gamma[2])
elif gamma_tag == 'SigmaZT':
g = 0.5 * (_gamma[3] @ _gamma[4] - _gamma[4] @ _gamma[3])
else:
raise Exception('Unkown gamma structure', gamma_tag)
return g
class Npr_matrix(np.ndarray):
g5 = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, -1]],
dtype=complex)
def __new__(cls, input_array, mom_in=None, mom_out=None):
obj = np.asarray(input_array).view(cls) obj = np.asarray(input_array).view(cls)
obj.mom = mom obj.mom_in = mom_in
obj.mom_out = mom_out
return obj return obj
@property
def g5H(self):
new_matrix = Npr_matrix.g5 @ self.conj().T @ Npr_matrix.g5
new_matrix.mom_in = self.mom_out
new_matrix.mom_out = self.mom_in
return new_matrix
def __matmul__(self, other):
if hasattr(other, 'mom_in'):
if self.mom_in != other.mom_in and self.mom_in and other.mom_in:
raise Exception('mom_in does not match.')
mom_in = self.mom_in if self.mom_in else other.mom_in
else:
mom_in = self.mom_in
if hasattr(other, 'mom_out'):
if self.mom_out != other.mom_out and self.mom_out and other.mom_out:
raise Exception('mom_out does not match.')
mom_out = self.mom_out if self.mom_out else other.mom_out
else:
mom_out = self.mom_out
return self.__new__(Npr_matrix, super().__matmul__(other), mom_in, mom_out)
def __array_finalize__(self, obj): def __array_finalize__(self, obj):
if obj is None: return if obj is None: return
self.mom = getattr(obj, 'mom', None) self.mom_in = getattr(obj, 'mom_in', None)
self.mom_out = getattr(obj, 'mom_out', None)