def test_reweighting(): my_obs = pe.Obs([np.random.rand(1000)], ['t']) assert not my_obs.reweighted r_obs = pe.reweight(my_obs, [my_obs]) assert r_obs[0].reweighted 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 my_covobs = pe.cov_Obs(1.0, 0.003, 'cov') with pytest.raises(Exception): pe.reweight(my_obs, [my_covobs]) my_obs2 = pe.Obs([np.random.rand(1000)], ['t2']) with pytest.raises(Exception): pe.reweight(my_obs, [my_obs + my_obs2]) with pytest.raises(Exception): pe.reweight(my_irregular_obs, [my_obs])
def test_rwms(): path = './tests//data/openqcd_test/' prefix = 'sfqcd' postfix = '.rwms' # sfqcd-1.6: Trajectories instead of confignumbers are printed to file. rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix) repname = list(rwfo[0].idl.keys())[0] assert(rwfo[0].idl[repname] == range(1, 13)) rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12]) assert(rwfo[0].idl[repname] == range(1, 13)) rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[3], r_stop=[8]) assert(rwfo[0].idl[repname] == range(3, 9)) rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[6]) assert(rwfo[0].idl[repname] == range(2, 7)) rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[1], r_stop=[12], r_step=2) assert(rwfs[0].idl[repname] == range(1, 12, 2)) rwfs = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix, r_start=[2], r_stop=[12], r_step=2) assert(rwfs[0].idl[repname] == range(2, 13, 2)) rwfo = pe.input.openQCD.read_rwms(path, prefix, version='1.6', postfix=postfix) assert((rwfo[0].r_values[repname] + rwfo[0].deltas[repname][1]) == (rwfs[0].r_values[repname] + rwfs[0].deltas[repname][0])) o = pe.pseudo_Obs(1., .01, repname, samples=12) pe.reweight(rwfo[0], [o]) o = pe.pseudo_Obs(1., .01, repname, samples=6) pe.reweight(rwfo[0], [o]) o.idl[repname] = range(2, 13, 2) pe.reweight(rwfo[0], [o]) pe.reweight(rwfs[0], [o]) files = ['openqcd2r1.ms1.dat'] names = ['openqcd2|r1'] # TM with 2 Hasenbusch factors and 2 sources each + RHMC with one source, openQCD 2.0 rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names) assert(len(rwfo) == 2) assert(rwfo[0].value == 0.9999974970236312) assert(rwfo[1].value == 1.184681251089919) repname = list(rwfo[0].idl.keys())[0] assert(rwfo[0].idl[repname] == range(1, 10)) rwfo = pe.input.openQCD.read_rwms(path, prefix, version='2.0', files=files, names=names, r_start=[1], r_stop=[8], print_err=True) assert(rwfo[0].idl[repname] == range(1, 9)) # t0 prefix = 'openqcd' t0 = pe.input.openQCD.extract_t0(path, prefix, dtr_read=3, xmin=0, spatial_extent=4) files = ['openqcd2r1.ms.dat'] names = ['openqcd2|r1'] t0 = pe.input.openQCD.extract_t0(path, '', dtr_read=3, xmin=0, spatial_extent=4, files=files, names=names, fit_range=2) t0 = pe.input.openQCD.extract_t0(path, prefix, dtr_read=3, xmin=0, spatial_extent=4, r_start=[1]) repname = list(rwfo[0].idl.keys())[0] assert(t0.idl[repname] == range(1, 10)) t0 = pe.input.openQCD.extract_t0(path, prefix, dtr_read=3, xmin=0, spatial_extent=4, r_start=[2], r_stop=[8]) repname = list(rwfo[0].idl.keys())[0] assert(t0.idl[repname] == range(2, 9)) t0 = pe.input.openQCD.extract_t0(path, prefix, dtr_read=3, xmin=0, spatial_extent=4, fit_range=2, plaquette=True, assume_thermalization=True) pe.input.openQCD.extract_t0(path, '', dtr_read=3, xmin=0, spatial_extent=4, files=files, names=names, fit_range=2, plot_fit=True)
def test_correlate(): my_obs1 = pe.Obs([np.random.rand(100)], ['t']) my_obs2 = pe.Obs([np.random.rand(100)], ['t']) corr1 = pe.correlate(my_obs1, my_obs2) corr2 = pe.correlate(my_obs2, my_obs1) assert corr1 == corr2 my_obs3 = pe.Obs([np.random.rand(100)], ['t'], idl=[range(2, 102)]) with pytest.raises(Exception): pe.correlate(my_obs1, my_obs3) my_obs4 = pe.Obs([np.random.rand(99)], ['t']) with pytest.raises(Exception): pe.correlate(my_obs1, my_obs4) my_obs5 = pe.Obs([np.random.rand(100)], ['t'], idl=[range(5, 505, 5)]) my_obs6 = pe.Obs([np.random.rand(100)], ['t'], idl=[range(5, 505, 5)]) corr3 = pe.correlate(my_obs5, my_obs6) assert my_obs5.idl == corr3.idl my_new_obs = pe.Obs([np.random.rand(100)], ['q3']) with pytest.raises(Exception): pe.correlate(my_obs1, my_new_obs) my_covobs = pe.cov_Obs(1.0, 0.003, 'cov') with pytest.raises(Exception): pe.correlate(my_covobs, my_covobs) r_obs = pe.reweight(my_obs1, [my_obs1])[0] with pytest.warns(RuntimeWarning): pe.correlate(r_obs, r_obs)
def test_json_corr_io(): my_list = [ pe.Obs([np.random.normal(1.0, 0.1, 100)], ['ens1']) for o in range(8) ] rw_list = pe.reweight(pe.Obs([np.random.normal(1.0, 0.1, 100)], ['ens1']), my_list) for obs_list in [my_list, rw_list]: for tag in [None, "test"]: obs_list[3].tag = tag for pad in [0, 2]: for corr_tag in [None, 'my_Corr_tag']: for prange in [None, [3, 6]]: for gap in [False, True]: my_corr = pe.Corr(obs_list, padding=[pad, pad], prange=prange) my_corr.tag = corr_tag if gap: my_corr.content[4] = None pe.input.json.dump_to_json(my_corr, 'corr') recover = pe.input.json.load_json('corr') os.remove('corr.json.gz') assert np.all([ o.is_zero() for o in [ x for x in (my_corr - recover) if x is not None ] ]) for index, entry in enumerate(my_corr): if entry is None: assert recover[index] is None assert my_corr.tag == recover.tag assert my_corr.prange == recover.prange assert my_corr.reweighted == recover.reweighted