mirror of
				https://github.com/fjosw/pyerrors.git
				synced 2025-10-30 23:35:45 +01:00 
			
		
		
		
	Merge pull request #60 from s-kuberski/feature/rwf
Yet another small change to openQCD. Added explicit tests for reweighting
This commit is contained in:
		
				commit
				
					
						f16ba109fc
					
				
			
		
					 4 changed files with 62 additions and 15 deletions
				
			
		|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								tests/data/openqcd_test/openqcd2r1.ms1.dat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/data/openqcd_test/openqcd2r1.ms1.dat
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								tests/data/openqcd_test/sfqcdr1.rwms.dat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tests/data/openqcd_test/sfqcdr1.rwms.dat
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -242,3 +242,48 @@ 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) | ||||
|     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)) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue