From 570c6abf2a4ca2ea67824c627bde4d15b61dda0c Mon Sep 17 00:00:00 2001 From: Simon Kuberski Date: Wed, 9 Feb 2022 14:08:05 +0100 Subject: [PATCH 1/2] Yet another small change to openQCD. Added explicit tests for reweighting. --- pyerrors/input/openQCD.py | 32 ++++++++-------- tests/data/openqcd_test/openqcd2r1.ms1.dat | Bin 0 -> 2076 bytes tests/data/openqcd_test/sfqcdr1.rwms.dat | Bin 0 -> 252 bytes tests/io_test.py | 41 +++++++++++++++++++++ 4 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 tests/data/openqcd_test/openqcd2r1.ms1.dat create mode 100644 tests/data/openqcd_test/sfqcdr1.rwms.dat diff --git a/pyerrors/input/openQCD.py b/pyerrors/input/openQCD.py index 5ded025a..acbf60f0 100644 --- a/pyerrors/input/openQCD.py +++ b/pyerrors/input/openQCD.py @@ -182,6 +182,13 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs): print('Partial factor:', tmp_nfct) tmp_array[i].append(tmp_nfct) + diffmeas = configlist[-1][-1] - configlist[-1][-2] + configlist[-1] = [item // diffmeas for item in configlist[-1]] + if configlist[-1][0] > 1 and diffmeas > 1: + warnings.warn('Assume thermalization and that the first measurement belongs to the first config.') + offset = configlist[-1][0] - 1 + configlist[-1] = [item - offset for item in configlist[-1]] + if r_start[rep] is None: r_start_index.append(0) else: @@ -195,15 +202,13 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs): r_stop_index.append(len(configlist[-1]) - 1) else: try: - r_stop_index.append(configlist[-1].index(r_stop[rep]) + 1) - if r_stop_index[-1] == len(configlist[-1]): - r_stop_index[-1] -= 1 + r_stop_index.append(configlist[-1].index(r_stop[rep])) except ValueError: raise Exception('Config %d not in file with range [%d, %d]' % ( r_stop[rep], configlist[-1][0], configlist[-1][-1])) from None for k in range(nrw): - deltas[k].append(tmp_array[k][r_start_index[rep]:r_stop_index[rep]][::r_step]) + deltas[k].append(tmp_array[k][r_start_index[rep]:r_stop_index[rep] + 1][::r_step]) if np.any([len(np.unique(np.diff(cl))) != 1 for cl in configlist]): raise Exception('Irregular spaced data in input file!', [len(np.unique(np.diff(cl))) for cl in configlist]) @@ -213,7 +218,8 @@ def read_rwms(path, prefix, version='2.0', names=None, **kwargs): print(',', nrw, 'reweighting factors with', nsrc, 'sources') result = [] - idl = [range(configlist[rep][r_start_index[rep]], configlist[rep][r_stop_index[rep]], r_step) for rep in range(replica)] + idl = [range(configlist[rep][r_start_index[rep]], configlist[rep][r_stop_index[rep]] + 1, r_step) for rep in range(replica)] + for t in range(nrw): result.append(Obs(deltas[t], rep_names, idl=idl)) return result @@ -395,9 +401,7 @@ def extract_t0(path, prefix, dtr_read, xmin, spatial_extent, fit_range=5, **kwar r_stop_index.append(len(configlist[-1]) - 1) else: try: - r_stop_index.append(configlist[-1].index(r_stop[rep]) + 1) - if r_stop_index[-1] == len(configlist[-1]): - r_stop_index[-1] -= 1 + r_stop_index.append(configlist[-1].index(r_stop[rep])) except ValueError: raise Exception('Config %d not in file with range [%d, %d]' % ( r_stop[rep], configlist[-1][0], configlist[-1][-1])) from None @@ -408,7 +412,7 @@ def extract_t0(path, prefix, dtr_read, xmin, spatial_extent, fit_range=5, **kwar if np.any([step != 1 for step in stepsizes]): warnings.warn('Stepsize between configurations is greater than one!' + str(stepsizes), RuntimeWarning) - idl = [range(configlist[rep][r_start_index[rep]], configlist[rep][r_stop_index[rep]], r_step) for rep in range(replica)] + idl = [range(configlist[rep][r_start_index[rep]], configlist[rep][r_stop_index[rep]] + 1, r_step) for rep in range(replica)] t2E_dict = {} for n in range(nn + 1): samples = [] @@ -416,7 +420,7 @@ def extract_t0(path, prefix, dtr_read, xmin, spatial_extent, fit_range=5, **kwar samples.append([]) for cnfg in rep: samples[-1].append(cnfg[n]) - samples[-1] = samples[-1][r_start_index[nrep]:r_stop_index[nrep]][::r_step] + samples[-1] = samples[-1][r_start_index[nrep]:r_stop_index[nrep] + 1][::r_step] new_obs = Obs(samples, rep_names, idl=idl) t2E_dict[n * dn * eps] = (n * dn * eps) ** 2 * new_obs / (spatial_extent ** 3) - 0.3 @@ -720,9 +724,7 @@ def read_qtop(path, prefix, c, dtr_cnfg=1, version="openQCD", **kwargs): r_stop_index.append(len(configlist[-1]) - 1) else: try: - r_stop_index.append(configlist[-1].index(r_stop[rep]) + 1) - if r_stop_index[-1] == len(configlist[-1]): - r_stop_index[-1] -= 1 + r_stop_index.append(configlist[-1].index(r_stop[rep])) except ValueError: raise Exception('Config %d not in file with range [%d, %d]' % ( r_stop[rep], configlist[-1][0], configlist[-1][-1])) from None @@ -766,8 +768,8 @@ def read_qtop(path, prefix, c, dtr_cnfg=1, version="openQCD", **kwargs): rep_names = names deltas.append(Q_top) - idl = [range(int(configlist[rep][r_start_index[rep]]), int(configlist[rep][r_stop_index[rep]]), 1) for rep in range(len(deltas))] - deltas = [deltas[nrep][r_start_index[nrep]:r_stop_index[nrep]] for nrep in range(len(deltas))] + idl = [range(int(configlist[rep][r_start_index[rep]]), int(configlist[rep][r_stop_index[rep]]) + 1, 1) for rep in range(len(deltas))] + deltas = [deltas[nrep][r_start_index[nrep]:r_stop_index[nrep] + 1] for nrep in range(len(deltas))] result = Obs(deltas, rep_names, idl=idl) return result diff --git a/tests/data/openqcd_test/openqcd2r1.ms1.dat b/tests/data/openqcd_test/openqcd2r1.ms1.dat new file mode 100644 index 0000000000000000000000000000000000000000..cd5ee2c9b7db69e86147fe1926084560695556eb GIT binary patch literal 2076 zcmZvc2~bm46owxt5ono4JE&C)iWL!Df+QG|+-C|wu6`61WB^R?U zxKNn#`L@klcVvpuM`_Pa+dU7F8_unt&-`p}WypuZPxCAW#=7HxxPQgD)&>NTeyOeq zV!(L}XS&}m3gg^{Gc$m+HLmla26|FK#n8Q`eFab_fe5FPuj|)M?Erehow$jGs&}t|})l0%^Q6K&pu`=F;o}U<*tNQLYG+pH0 zf3TBEH)bd|PtpugVL#%;PGNTX9c=hKv)F2|MaS59WdD+I#*9xpH)Q-M8u=&46EZje zYuTeKC;m**EyzP^V7p)zI%vQ@GhcK`-d3)-rtU5@ai*3HI)> zcfir$HRBoO9yC(<+|_w;V)T+}V(;T0c=8P<_L5$EF=`&PB8JS~ipy~%$C@`&1N$*> zjPZ-QZQcdwbF^_CXYOX`cWu0PS=rH;N86_u_(YH3=MB)4h^0#_#(WM=>X>Y$Bz8ZsWYja^mudH|GUtY-#qO_oK(5To)j70_4{OcrJ($g-NQpS-i-GHO4|PR%k4 zk{{*dOWO*h=vQjViPH;6IL3}8!5thn?El}lVVI-yMi%`=!8IMD`m>az2!+`+jE&xw zqHi*x2MIWHy>ed7f;9ts_c5t(1{X3h0F!K{-hx7%h|95vBQEn=HVle4z6$KQ8bDk1 zEI(4~@e=f;6a?435Yj@Im&E?Lsu8UeTDK4~*mPUJ6V7J{a+I}@Ex7H&!!iC*n=s<& z2>UZ}Ij$HyFDdw0&nOxe*iaONX&5V?@#;r>p@#!Nm}~jwlerQ>Zc;*za1PWF#D0## zC7TUvGA>71p~&yGN&_yR3~Akc{unL!rz`WcaZdnC+xqR(u^d^)(ltJ0i%zub*X9e9 zsC9DMD7RgGsR^Ya+cK_3hT^`*9AWp4*=dvgCU$C=qn*G}*-p8kV+=TWi_^T+ddle5y8n_xYV(`vy}qzjFSV-+_R!xs$d=4drQBi~ z#jZGyV)TFzyi zt)-Q=XhydUzX7hu2Q`6|Dm!%3;$B1bLsS_e9z(aM)8jiv>#YLrqAbhEBKcA-E=NU( c$6voNVLuY?U5yy@Kh&qy=O_(*Hq)$ literal 0 HcmV?d00001 diff --git a/tests/data/openqcd_test/sfqcdr1.rwms.dat b/tests/data/openqcd_test/sfqcdr1.rwms.dat new file mode 100644 index 0000000000000000000000000000000000000000..53f0f2426f65a54d3cb659b8947caed88233f20b GIT binary patch literal 252 zcmZQ%U|?W`VkRIRJooS-OW{clT1ygqIG)DsX90?B+*&1La%rN&BGU!kpO%*HX9J4$ zZB@Ck&}ouGw#-85TVHGTa{$F2``5&^9-8EERO+LbXJ*}gE}+=$sP2>PlP5WB-|Hga z+E%-t2Pn4JOk(C{ddvY zi4H$3`gD-U9BnRiED%KS_jr&D_Vp*J0?qN?SIz*i>+;DSY!+tTK pm|OyP#H{&~9F+47B5S`j?Uw+G-C3FG%_cp`VM?G_v+;(;{Q#%rT!;Vw literal 0 HcmV?d00001 diff --git a/tests/io_test.py b/tests/io_test.py index f5546d9f..cb47c065 100644 --- a/tests/io_test.py +++ b/tests/io_test.py @@ -242,3 +242,44 @@ def test_json_dict_io(): jsonio.dump_dict_to_json(od, fname, description=desc) os.remove(fname + '.json.gz') + + +def test_openqcd(): + 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) From 25d00de5ceb47b1b64160a9fcd3e09d18599f427 Mon Sep 17 00:00:00 2001 From: Simon Kuberski Date: Wed, 9 Feb 2022 14:13:04 +0100 Subject: [PATCH 2/2] More tests for openQCD-2.0 --- tests/io_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/io_test.py b/tests/io_test.py index cb47c065..92e97902 100644 --- a/tests/io_test.py +++ b/tests/io_test.py @@ -283,3 +283,7 @@ def test_openqcd(): 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]) + assert(rwfo[0].idl[repname] == range(1, 9))