Feat/files idl xsf (#185)

* added kwrg idl to ms5_xsf_read

* change output, warn user if expected idl not found
This commit is contained in:
Justus Kuhlmann 2023-05-26 14:01:52 +02:00 committed by GitHub
parent e97cc519a9
commit 1a811b04f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 19 deletions

View file

@ -1163,6 +1163,8 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
Additional keyword arguments. The following keyword arguments are recognized: Additional keyword arguments. The following keyword arguments are recognized:
- names (List[str]): A list of names to use for the replicas. - names (List[str]): A list of names to use for the replicas.
- files (List[str]): A list of files to read data from.
- idl (List[List[int]]): A list of idls per replicum, resticting data to the idls given.
Returns Returns
------- -------
@ -1211,7 +1213,8 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
names.append(se.split(sep)[0] + "|r" + se.split(sep)[1]) names.append(se.split(sep)[0] + "|r" + se.split(sep)[1])
else: else:
names.append(prefix) names.append(prefix)
if 'idl' in kwargs:
expected_idl = kwargs.get('idl')
names = sorted(names) names = sorted(names)
files = sorted(files) files = sorted(files)
@ -1254,13 +1257,19 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
for t in range(tmax): for t in range(tmax):
realsamples[repnum].append([]) realsamples[repnum].append([])
imagsamples[repnum].append([]) imagsamples[repnum].append([])
if 'idl' in kwargs:
left_idl = set(expected_idl[repnum])
while True: while True:
cnfgt = fp.read(chunksize) cnfgt = fp.read(chunksize)
if not cnfgt: if not cnfgt:
break break
asascii = struct.unpack(packstr, cnfgt) asascii = struct.unpack(packstr, cnfgt)
cnfg = asascii[0] cnfg = asascii[0]
idl_wanted = True
if 'idl' in kwargs:
idl_wanted = (cnfg in expected_idl[repnum])
left_idl = left_idl - set([cnfg])
if idl_wanted:
cnfgs[repnum].append(cnfg) cnfgs[repnum].append(cnfg)
if corr not in placesBB: if corr not in placesBB:
@ -1275,12 +1284,14 @@ def read_ms5_xsf(path, prefix, qc, corr, sep="r", **kwargs):
realsamples[repnum][t].append(corrres[0][t]) realsamples[repnum][t].append(corrres[0][t])
for t in range(int(len(tmpcorr) / 2)): for t in range(int(len(tmpcorr) / 2)):
imagsamples[repnum][t].append(corrres[1][t]) imagsamples[repnum][t].append(corrres[1][t])
if 'idl' in kwargs:
left_idl = list(left_idl)
if len(left_idl) > 0:
warnings.warn('Could not find idls ' + str(left_idl) + ' in replikum of file ' + file, UserWarning)
repnum += 1 repnum += 1
s = "Read correlator " + corr + " from " + str(repnum) + " replika with idls" + str(realsamples[0][t])
s = "Read correlator " + corr + " from " + str(repnum) + " replika with " + str(len(realsamples[0][t]))
for rep in range(1, repnum): for rep in range(1, repnum):
s += ", " + str(len(realsamples[rep][t])) s += ", " + str(realsamples[rep][t])
s += " samples"
print(s) print(s)
print("Asserted run parameters:\n T:", tmax, "kappa:", kappa, "csw:", csw, "dF:", dF, "zF:", zF, "bnd:", bnd) print("Asserted run parameters:\n T:", tmax, "kappa:", kappa, "csw:", csw, "dF:", dF, "zF:", zF, "bnd:", bnd)

View file

@ -121,7 +121,7 @@ def test_gf_coupling():
def test_read_ms5_xsf(): def test_read_ms5_xsf():
path = './tests//data/openqcd_test/' path = './tests/data/openqcd_test/'
prefix = "ms5_xsf_T24L16" prefix = "ms5_xsf_T24L16"
corr = "gA" corr = "gA"
qc = 'dd' qc = 'dd'
@ -145,6 +145,37 @@ def test_read_ms5_xsf():
pe.input.openQCD.read_ms5_xsf(path, prefix, qc, fcorr) pe.input.openQCD.read_ms5_xsf(path, prefix, qc, fcorr)
def test_read_ms5_xsf_idl():
path = './tests/data/openqcd_test/'
prefix = "ms5_xsf_T24L16"
corr = "gA"
qc = 'dd'
c = pe.input.openQCD.read_ms5_xsf(path, prefix, qc, corr, idl=[range(1, 6), range(1, 7), range(1, 8)])
assert c.real[12].names == ['ms5_xsf_T24L16|r1', 'ms5_xsf_T24L16|r2', 'ms5_xsf_T24L16|r3']
assert (c.real[12].shape['ms5_xsf_T24L16|r1'] == 5)
assert (c.real[12].shape['ms5_xsf_T24L16|r2'] == 6)
assert (c.real[12].shape['ms5_xsf_T24L16|r3'] == 7)
assert (c.real[12].idl['ms5_xsf_T24L16|r1'] == range(1, 6))
assert (c.real[12].idl['ms5_xsf_T24L16|r2'] == range(1, 7))
assert (c.real[12].idl['ms5_xsf_T24L16|r3'] == range(1, 8))
c = pe.input.openQCD.read_ms5_xsf(path, prefix, qc, corr, idl=[range(1, 11, 2), range(1, 11, 2), range(1, 11, 2)])
assert c.real[12].names == ['ms5_xsf_T24L16|r1', 'ms5_xsf_T24L16|r2', 'ms5_xsf_T24L16|r3']
assert (c.real[12].shape['ms5_xsf_T24L16|r1'] == 5)
assert (c.real[12].shape['ms5_xsf_T24L16|r2'] == 5)
assert (c.real[12].shape['ms5_xsf_T24L16|r3'] == 5)
assert (c.real[12].idl['ms5_xsf_T24L16|r1'] == range(1, 11, 2))
assert (c.real[12].idl['ms5_xsf_T24L16|r2'] == range(1, 11, 2))
assert (c.real[12].idl['ms5_xsf_T24L16|r3'] == range(1, 11, 2))
def test_find_files(): def test_find_files():
path = './tests/data/openqcd_test/' path = './tests/data/openqcd_test/'
prefix = "ms5_xsf_T24L16" prefix = "ms5_xsf_T24L16"