From 763c759ae0aeeb83331e0e24eb380e99fdfcad02 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 28 Jun 2022 14:40:49 +0100 Subject: [PATCH] fix: Corr.m_eff can now returns None entries if the correlator has a sign flip. Before that the logarithm of a negative number was computed and a warning was thrown. --- pyerrors/correlators.py | 4 ++++ tests/correlators_test.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index 0ebb6115..e0cccec8 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -604,6 +604,8 @@ class Corr: for t in range(self.T - 1): if ((self.content[t] is None) or (self.content[t + 1] is None)) or (self.content[t + 1][0].value == 0): newcontent.append(None) + elif self.content[t][0].value / self.content[t + 1][0].value < 0: + newcontent.append(None) else: newcontent.append(self.content[t] / self.content[t + 1]) if(all([x is None for x in newcontent])): @@ -627,6 +629,8 @@ class Corr: # Fill the two timeslices in the middle of the lattice with their predecessors elif variant == 'sinh' and t in [self.T / 2, self.T / 2 - 1]: newcontent.append(newcontent[-1]) + elif self.content[t][0].value / self.content[t + 1][0].value < 0: + newcontent.append(None) else: newcontent.append(np.abs(find_root(self.content[t][0] / self.content[t + 1][0], root_function, guess=guess))) if(all([x is None for x in newcontent])): diff --git a/tests/correlators_test.py b/tests/correlators_test.py index c1c79975..ee2c3eb7 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -105,6 +105,15 @@ def test_m_eff(): my_corr.m_eff('unkown_variant') +def test_m_eff_negative_values(): + for padding in [0, 4]: + my_corr = pe.correlators.Corr([1.0 * pe.pseudo_Obs(10, 0.1, 't'), 1.0 * pe.pseudo_Obs(9, 0.05, 't'), -pe.pseudo_Obs(9, 0.1, 't')], padding=[padding, padding]) + m_eff_log = my_corr.m_eff('log') + assert m_eff_log[padding + 1] is None + m_eff_cosh = my_corr.m_eff('cosh') + assert m_eff_cosh[padding + 1] is None + + def test_reweighting(): my_corr = pe.correlators.Corr([pe.pseudo_Obs(10, 0.1, 't'), pe.pseudo_Obs(0, 0.05, 't')]) assert my_corr.reweighted is False