From fc25ec692910a0c838b7b47ba3e49655150fd961 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Wed, 8 Dec 2021 22:42:13 +0000 Subject: [PATCH 1/5] test: test for Corr.plateau added --- tests/correlators_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/correlators_test.py b/tests/correlators_test.py index f27bba54..6c3418f8 100644 --- a/tests/correlators_test.py +++ b/tests/correlators_test.py @@ -91,6 +91,14 @@ def test_fit_correlator(): assert fit_res[1] == my_corr[1] - my_corr[0] +def test_plateau(): + my_corr = pe.correlators.Corr([pe.pseudo_Obs(1.01324, 0.05, 't'), pe.pseudo_Obs(1.042345, 0.008, 't')]) + + my_corr.plateau([0, 1], method="fit") + my_corr.plateau([0, 1], method="mean") + with pytest.raises(Exception): + my_corr.plateau() + def test_utility(): corr_content = [] for t in range(8): From 53cea6267d75dd01f7e65431e640016c77eebaf2 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 9 Dec 2021 07:36:34 +0000 Subject: [PATCH 2/5] test: additional test cases for reweighting and pseudo_Obs added --- tests/obs_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/obs_test.py b/tests/obs_test.py index f5d04832..cedad117 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -346,6 +346,7 @@ def test_overloaded_functions(): def test_utils(): + zero_pseudo_obs = pe.pseudo_Obs(1.0, 0.0, 'null') my_obs = pe.pseudo_Obs(1.0, 0.5, 't|r01') my_obs += pe.pseudo_Obs(1.0, 0.5, 't|r02') str(my_obs) @@ -412,6 +413,15 @@ def test_reweighting(): r_obs2 = r_obs[0] * my_obs assert r_obs2.reweighted + my_irregular_obs = pe.Obs([np.random.rand(500)], ['t'], idl=[range(1, 1001, 2)]) + assert not my_irregular_obs.reweighted + r_obs = pe.reweight(my_obs, [my_irregular_obs], all_configs=True) + r_obs = pe.reweight(my_obs, [my_irregular_obs], all_configs=False) + r_obs = pe.reweight(my_obs, [my_obs]) + assert r_obs[0].reweighted + r_obs2 = r_obs[0] * my_obs + assert r_obs2.reweighted + def test_merge_obs(): my_obs1 = pe.Obs([np.random.rand(100)], ['t']) From f30fcbd4d9c6e791928900de7902cf72b7924ecb Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 9 Dec 2021 07:37:42 +0000 Subject: [PATCH 3/5] ci: pytest workflow scheduled to run once a month. --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index db0b8de1..b9d60c7a 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -7,7 +7,7 @@ on: - develop pull_request: schedule: - - cron: '0 4 * * *' + - cron: '0 4 1 * *' jobs: pytest: From 8879e6b3829bb4730bae609d0c5a949ac69a5472 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 9 Dec 2021 09:44:50 +0000 Subject: [PATCH 4/5] refactor: check in Obs.__init__ withe means!=None removed which could never be reached. --- pyerrors/obs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index c24da74a..168f7292 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -125,8 +125,6 @@ class Obs: for name, sample, mean in sorted(zip(names, samples, means)): self.shape[name] = len(self.idl[name]) self.N += self.shape[name] - if len(sample) != self.shape[name]: - raise Exception('Incompatible samples and idx for %s: %d vs. %d' % (name, len(sample), self.shape[name])) self.r_values[name] = mean self.deltas[name] = sample else: From b3a021985b3d477349324b9fc8300856b1ba1af6 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 9 Dec 2021 09:45:29 +0000 Subject: [PATCH 5/5] test: test for exceptions in Obs.__init__ extended --- tests/obs_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/obs_test.py b/tests/obs_test.py index cedad117..8fbfa43d 100644 --- a/tests/obs_test.py +++ b/tests/obs_test.py @@ -22,6 +22,12 @@ def test_Obs_exceptions(): pe.Obs([np.random.rand(10)], [1]) with pytest.raises(Exception): pe.Obs([np.random.rand(4)], ['name']) + with pytest.raises(Exception): + pe.Obs([np.random.rand(5)], ['1'], idl=[[5, 3, 2 ,4 ,1]]) + with pytest.raises(Exception): + pe.Obs([np.random.rand(5)], ['1'], idl=['t']) + with pytest.raises(Exception): + pe.Obs([np.random.rand(5)], ['1'], idl=[range(1, 8)]) my_obs = pe.Obs([np.random.rand(6)], ['name']) my_obs._value = 0.0