Merge branch 'develop' into feat/meas_class

This commit is contained in:
Fabian Joswig 2025-01-06 11:13:55 +01:00 committed by GitHub
commit 8c7cd5a74b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 218 additions and 165 deletions

View file

@ -129,7 +129,7 @@ def test_m_eff():
with pytest.warns(RuntimeWarning):
my_corr.m_eff('sinh')
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_corr.m_eff('unkown_variant')
@ -140,7 +140,7 @@ def test_m_eff_negative_values():
assert m_eff_log[padding + 1] is None
m_eff_cosh = my_corr.m_eff('cosh')
assert m_eff_cosh[padding + 1] is None
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_corr.m_eff('logsym')
@ -155,7 +155,7 @@ def test_correlate():
my_corr = pe.correlators.Corr([pe.pseudo_Obs(10, 0.1, 't'), pe.pseudo_Obs(0, 0.05, 't')])
corr1 = my_corr.correlate(my_corr)
corr2 = my_corr.correlate(my_corr[0])
with pytest.raises(Exception):
with pytest.raises(TypeError):
corr3 = my_corr.correlate(7.3)
@ -176,9 +176,9 @@ def test_fit_correlator():
assert fit_res[0] == my_corr[0]
assert fit_res[1] == my_corr[1] - my_corr[0]
with pytest.raises(Exception):
with pytest.raises(TypeError):
my_corr.fit(f, "from 0 to 3")
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_corr.fit(f, [0, 2, 3])
@ -256,11 +256,11 @@ def test_prange():
corr = pe.correlators.Corr(corr_content)
corr.set_prange([2, 4])
with pytest.raises(Exception):
with pytest.raises(ValueError):
corr.set_prange([2])
with pytest.raises(Exception):
with pytest.raises(TypeError):
corr.set_prange([2, 2.3])
with pytest.raises(Exception):
with pytest.raises(ValueError):
corr.set_prange([4, 1])

View file

@ -30,7 +30,7 @@ def test_grid_dirac():
'SigmaYZ',
'SigmaZT']:
pe.dirac.Grid_gamma(gamma)
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.dirac.Grid_gamma('Not a gamma matrix')
@ -44,7 +44,7 @@ def test_epsilon_tensor():
(1, 1, 3) : 0.0}
for key, value in check.items():
assert pe.dirac.epsilon_tensor(*key) == value
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.dirac.epsilon_tensor(0, 1, 3)
@ -59,5 +59,5 @@ def test_epsilon_tensor_rank4():
(1, 2, 3, 1) : 0.0}
for key, value in check.items():
assert pe.dirac.epsilon_tensor_rank4(*key) == value
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.dirac.epsilon_tensor_rank4(0, 1, 3, 4)

View file

@ -61,9 +61,9 @@ def test_Obs_exceptions():
my_obs.plot_rep_dist()
with pytest.raises(Exception):
my_obs.plot_piechart()
with pytest.raises(Exception):
with pytest.raises(TypeError):
my_obs.gamma_method(S='2.3')
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_obs.gamma_method(tau_exp=2.3)
my_obs.gamma_method()
my_obs.details()
@ -199,7 +199,7 @@ def test_gamma_method_no_windowing():
assert np.isclose(np.sqrt(np.var(obs.deltas['ens'], ddof=1) / obs.shape['ens']), obs.dvalue)
obs.gamma_method(S=1.1)
assert obs.e_tauint['ens'] > 0.5
with pytest.raises(Exception):
with pytest.raises(ValueError):
obs.gamma_method(S=-0.2)
@ -461,6 +461,18 @@ def test_cobs_overloading():
obs / cobs
def test_pow():
data = [1, 2.341, pe.pseudo_Obs(4.8, 0.48, "test_obs"), pe.cov_Obs(1.1, 0.3 ** 2, "test_cov_obs")]
for d in data:
assert d * d == d ** 2
assert d * d * d == d ** 3
for d2 in data:
assert np.log(d ** d2) == d2 * np.log(d)
assert (d ** d2) ** (1 / d2) == d
def test_reweighting():
my_obs = pe.Obs([np.random.rand(1000)], ['t'])
assert not my_obs.reweighted
@ -478,12 +490,12 @@ def test_reweighting():
r_obs2 = r_obs[0] * my_obs
assert r_obs2.reweighted
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.reweight(my_obs, [my_covobs])
my_obs2 = pe.Obs([np.random.rand(1000)], ['t2'])
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.reweight(my_obs, [my_obs + my_obs2])
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.reweight(my_irregular_obs, [my_obs])
@ -493,10 +505,10 @@ def test_merge_obs():
merged = pe.merge_obs([my_obs1, my_obs2])
diff = merged - my_obs2 - my_obs1
assert diff == -(my_obs1.value + my_obs2.value) / 2
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.merge_obs([my_obs1, my_obs1])
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.merge_obs([my_obs1, my_covobs])
@ -519,11 +531,11 @@ def test_correlate():
assert corr1 == corr2
my_obs3 = pe.Obs([np.random.rand(100)], ['t'], idl=[range(2, 102)])
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.correlate(my_obs1, my_obs3)
my_obs4 = pe.Obs([np.random.rand(99)], ['t'])
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.correlate(my_obs1, my_obs4)
my_obs5 = pe.Obs([np.random.rand(100)], ['t'], idl=[range(5, 505, 5)])
@ -532,10 +544,10 @@ def test_correlate():
assert my_obs5.idl == corr3.idl
my_new_obs = pe.Obs([np.random.rand(100)], ['q3'])
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.correlate(my_obs1, my_new_obs)
my_covobs = pe.cov_Obs(1.0, 0.003, 'cov')
with pytest.raises(Exception):
with pytest.raises(ValueError):
pe.correlate(my_covobs, my_covobs)
r_obs = pe.reweight(my_obs1, [my_obs1])[0]
with pytest.warns(RuntimeWarning):
@ -762,7 +774,7 @@ def test_gamma_method_irregular():
my_obs.gm()
idl += [range(1, 400, 4)]
my_obs = pe.Obs([dat for i in range(len(idl))], ['%s|%d' % ('A', i) for i in range(len(idl))], idl=idl)
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_obs.gm()
# check cases where tau is large compared to the chain length
@ -1110,7 +1122,7 @@ def test_jackknife():
assert np.allclose(tmp_jacks, my_obs.export_jackknife())
my_new_obs = my_obs + pe.Obs([full_data], ['test2'])
with pytest.raises(Exception):
with pytest.raises(ValueError):
my_new_obs.export_jackknife()

View file

@ -387,3 +387,33 @@ def test_find_correlator():
found_start, found_T = sfin._find_correlator(file, "2.0", "name f_A\nquarks lquark lquark\noffset 0\nwf 0", False, False)
assert found_start == 21
assert found_T == 3
def test_get_rep_name():
names = ['data_r0', 'data_r1', 'data_r2']
new_names = sfin._get_rep_names(names)
assert len(new_names) == 3
assert new_names[0] == 'data_|r0'
assert new_names[1] == 'data_|r1'
assert new_names[2] == 'data_|r2'
names = ['data_q0', 'data_q1', 'data_q2']
new_names = sfin._get_rep_names(names, rep_sep='q')
assert len(new_names) == 3
assert new_names[0] == 'data_|q0'
assert new_names[1] == 'data_|q1'
assert new_names[2] == 'data_|q2'
def test_get_appended_rep_name():
names = ['data_r0.f_1', 'data_r1.f_1', 'data_r2.f_1']
new_names = sfin._get_appended_rep_names(names, 'data', 'f_1')
assert len(new_names) == 3
assert new_names[0] == 'data_|r0'
assert new_names[1] == 'data_|r1'
assert new_names[2] == 'data_|r2'
names = ['data_q0.f_1', 'data_q1.f_1', 'data_q2.f_1']
new_names = sfin._get_appended_rep_names(names, 'data', 'f_1', rep_sep='q')
assert len(new_names) == 3
assert new_names[0] == 'data_|q0'
assert new_names[1] == 'data_|q1'
assert new_names[2] == 'data_|q2'