From 7efe9612bcb903473c415a130c70a7990df47577 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 21 Oct 2021 10:59:53 +0100 Subject: [PATCH] npr doc extended, CObs now have real and imag properties --- pyerrors/npr.py | 20 ++++++++++++++------ pyerrors/pyerrors.py | 14 +++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pyerrors/npr.py b/pyerrors/npr.py index ad7d7de8..96e35514 100644 --- a/pyerrors/npr.py +++ b/pyerrors/npr.py @@ -38,7 +38,7 @@ class Npr_matrix(np.ndarray): if s_mom is not None and o_mom is not None: if not np.allclose(s_mom, o_mom): raise Exception(name + ' does not match.') - return o_mom if o_mom else s_mom + return o_mom if o_mom is not None else s_mom def __matmul__(self, other): return self.__new__(Npr_matrix, @@ -65,13 +65,23 @@ def _check_geometry(): raise Exception("Temporal extent 'T' must be an integer.") -def _invert_propagator(prop): +def inv_propagator(prop): + """ Inverts a 12x12 quark propagator""" + if prop.shape != (12, 12): + raise Exception("Only 12x12 propagators can be inverted.") return Npr_matrix(mat_mat_op(anp.linalg.inv, prop), prop.mom_in) -def Zq(prop, fermion='Wilson'): +def Zq(inv_prop, fermion='Wilson'): + """ Calculates the quark field renormalization constant Zq + + Attributes: + inv_prop -- Inverted 12x12 quark propagator + fermion -- Fermion type for which the tree-level propagator is used + in the calculation of Zq. Default Wilson. + """ _check_geometry() - mom = np.copy(prop.mom_in) + mom = np.copy(inv_prop.mom_in) mom[3] /= T / L sin_mom = np.sin(2 * np.pi / L * mom) @@ -80,8 +90,6 @@ def Zq(prop, fermion='Wilson'): else: raise Exception("Fermion type '" + fermion + "' not implemented") - inv_prop = _invert_propagator(prop) - res = 1 / 12. * np.trace(inv_prop @ np.kron(np.eye(3, dtype=int), p_slash)) res.gamma_method() diff --git a/pyerrors/pyerrors.py b/pyerrors/pyerrors.py index acb704c2..853809c6 100644 --- a/pyerrors/pyerrors.py +++ b/pyerrors/pyerrors.py @@ -650,13 +650,21 @@ class Obs: class CObs: """Class for a complex valued observable.""" - __slots__ = ['real', 'imag', 'tag'] + __slots__ = ['_real', '_imag', 'tag'] def __init__(self, real, imag=0.0): - self.real = real - self.imag = imag + self._real = real + self._imag = imag self.tag = None + @property + def real(self): + return self._real + + @property + def imag(self): + return self._imag + def gamma_method(self, **kwargs): if isinstance(self.real, Obs): self.real.gamma_method(**kwargs)