tests: Tests for matrix Corr methods added. docstrings updated

This commit is contained in:
Fabian Joswig 2022-01-31 11:21:16 +00:00
parent fbb98e05f6
commit fb1f2074ca
2 changed files with 50 additions and 5 deletions

View file

@ -250,9 +250,6 @@ class Corr:
if self.N == 1: if self.N == 1:
raise Exception("Trying to symmetrize a smearing matrix, that already has N=1.") raise Exception("Trying to symmetrize a smearing matrix, that already has N=1.")
# There are two ways, the GEVP metod can be called.
# 1. return_list=False will return a single eigenvector, normalized according to V*C(t_0)*V=1
# 2. return_list=True will return a new eigenvector for every timeslice. The time t_s is used to order the vectors according to. arXiv:2004.10472 [hep-lat]
def GEVP(self, t0, ts=None, state=0, sorted_list=None): def GEVP(self, t0, ts=None, state=0, sorted_list=None):
"""Solve the general eigenvalue problem on the current correlator """Solve the general eigenvalue problem on the current correlator
@ -265,7 +262,7 @@ class Corr:
If return_list=True and sorting=Eigenvector it gives a reference point for the sorting method. If return_list=True and sorting=Eigenvector it gives a reference point for the sorting method.
state : int state : int
The state one is interested in ordered by energy. The lowest state is zero. The state one is interested in ordered by energy. The lowest state is zero.
sorted list : string sorted_list : string
if this argument is set, a list of vectors (len=self.T) is returned. If it is left as None, only one vector is returned. if this argument is set, a list of vectors (len=self.T) is returned. If it is left as None, only one vector is returned.
"Eigenvalue" - The eigenvector is chosen according to which einvenvalue it belongs individually on every timeslice. "Eigenvalue" - The eigenvector is chosen according to which einvenvalue it belongs individually on every timeslice.
"Eigenvector" - Use the method described in arXiv:2004.10472 [hep-lat] to find the set of v(t) belonging to the state. "Eigenvector" - Use the method described in arXiv:2004.10472 [hep-lat] to find the set of v(t) belonging to the state.
@ -273,7 +270,7 @@ class Corr:
""" """
if sorted_list is None: if sorted_list is None:
if (ts is None): if (ts is None):
raise Exception("ts is required if return_list=False") raise Exception("ts is required if sorted_list=None")
if (self.content[t0] is None) or (self.content[ts] is None): if (self.content[t0] is None) or (self.content[ts] is None):
raise Exception("Corr not defined at t0/ts") raise Exception("Corr not defined at t0/ts")
G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double") G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double")

View file

@ -167,3 +167,51 @@ def test_utility():
assert np.isclose(o_a[0].value, o_b[0].value) assert np.isclose(o_a[0].value, o_b[0].value)
assert np.isclose(o_a[0].dvalue, o_b[0].dvalue) assert np.isclose(o_a[0].dvalue, o_b[0].dvalue)
assert np.allclose(o_a[0].deltas['t'], o_b[0].deltas['t']) assert np.allclose(o_a[0].deltas['t'], o_b[0].deltas['t'])
def test_matrix_corr():
def _gen_corr(val):
corr_content = []
for t in range(16):
corr_content.append(pe.pseudo_Obs(val, 0.1, 't', 2000))
return pe.correlators.Corr(corr_content)
corr_aa = _gen_corr(1)
corr_ab = _gen_corr(0.5)
corr_mat = pe.Corr(np.array([[corr_aa, corr_ab], [corr_ab, corr_aa]]))
corr_mat.smearing(0, 0)
vec_0 = corr_mat.GEVP(0, 0)
vec_1 = corr_mat.GEVP(0, 0, state=1)
corr_0 = corr_mat.projected(vec_0)
corr_1 = corr_mat.projected(vec_1)
assert np.all([o == 0 for o in corr_0 - corr_aa])
assert np.all([o == 0 for o in corr_1 - corr_aa])
corr_mat.GEVP(0, 0, sorted_list="Eigenvalue")
corr_mat.GEVP(0, 0, sorted_list="Eigenvector")
with pytest.raises(Exception):
corr_mat.plottable()
with pytest.raises(Exception):
corr_mat.show()
with pytest.raises(Exception):
corr_mat.m_eff()
with pytest.raises(Exception):
corr_mat.Hankel()
with pytest.raises(Exception):
corr_mat.plateau()
with pytest.raises(Exception):
corr_mat.plateau([2, 4])
with pytest.raises(Exception):
corr_o.smearing(0, 0)