better openQCD input
This commit is contained in:
parent
77ee4993f0
commit
2312b5972d
2 changed files with 60 additions and 39 deletions
|
@ -15,37 +15,43 @@ def read_param(path: str, project: str, file_in_project: str) -> dict[str, Any]:
|
|||
param['rw_fcts'] = []
|
||||
param['rand'] = {}
|
||||
|
||||
for line in lines:
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
if line.startswith('\n'):
|
||||
continue
|
||||
|
||||
if line.startswith("nrw"):
|
||||
l = line.strip()
|
||||
num_rw = l.split('#').split()[1]
|
||||
stline = line.strip()
|
||||
num_rw = int(stline.split('#')[0].split()[1].strip())
|
||||
param["rw_fcts"] = [{}]*num_rw
|
||||
for i, line in enumerate(lines):
|
||||
for nrw in range(num_rw):
|
||||
param["rw_fcts"][nrw] = {}
|
||||
if line == "[Reweighting factor " + str(nrw) + "]\n":
|
||||
j=0
|
||||
while not (lines[i+j] == "\n" or lines[i+j].startswith("[")):
|
||||
j+=1
|
||||
chunk = lines[i:j+i]
|
||||
for cline in chunk:
|
||||
cline = cline.strip()
|
||||
for rwp in ["rwfact", "nsrc", "irp", "mu", "np"]:
|
||||
if cline.startswith(rwp):
|
||||
param["rw_fcts"][nrw][rwp] = cline.split()[1]
|
||||
print(param)
|
||||
for nrw in range(num_rw):
|
||||
if "nsrc" not in param["rw_fcts"][nrw]:
|
||||
param["rw_fcts"][nrw]["nsrc"] = 1
|
||||
if "mu" not in param["rw_fcts"][nrw]:
|
||||
param["rw_fcts"][nrw]["mu"] = "None"
|
||||
if "np" not in param["rw_fcts"][nrw]:
|
||||
param["rw_fcts"][nrw]["np"] = "None"
|
||||
if "irp" not in param["rw_fcts"][nrw]:
|
||||
param["rw_fcts"][nrw]["irp"] = "None"
|
||||
|
||||
return param
|
||||
|
||||
# reweighting factors (len nrw)
|
||||
|
||||
# void read_rw_parms(int irw)
|
||||
# On process 0, this program scans stdin for a line starting with the
|
||||
# string "[Reweighting factor <int>]" (after any number of blanks), where
|
||||
# <int> is the integer value passed through the argument. An error occurs
|
||||
# if no such line or more than one is found. The lines
|
||||
#
|
||||
# rwfact <rwfact_t>
|
||||
# im0 <int>
|
||||
# nsrc <int>
|
||||
# irp <int>
|
||||
# mu <double> [<double>]
|
||||
# np <int> [<int>]
|
||||
# isp <int> [<int>]
|
||||
|
||||
|
||||
def read_rwms(path: str, project: str, dir_in_project: str, prefix, postfix="ms1", version='2.0', names=None, files=None):
|
||||
|
||||
def read_rwms(path: str, project: str, dir_in_project: str, param: dict[str, Any], prefix: str, postfix: str="ms1", version: str='2.0', names: list[str]=None, files: list[str]=None):
|
||||
directory = path + "/projects/" + project + '/' + dir_in_project
|
||||
if files is None:
|
||||
files = []
|
||||
|
@ -60,7 +66,12 @@ def read_rwms(path: str, project: str, dir_in_project: str, prefix, postfix="ms1
|
|||
if files is not None:
|
||||
kwargs['files'] = files
|
||||
rwms = input.read_rwms(directory, prefix, version, **kwargs)
|
||||
print(rwms)
|
||||
rw_dict: dict[str, Any] = {}
|
||||
rw_dict[''] =
|
||||
rw_dict: dict[str, dict[str, Any]] = {}
|
||||
rw_dict[param["type"]] = {}
|
||||
for i in range(len(param["rw_fcts"])):
|
||||
par_list= []
|
||||
for k in param["rw_fcts"][i].keys():
|
||||
par_list.append(str(param["rw_fcts"][i][k]))
|
||||
pars = "/".join(par_list)
|
||||
rw_dict[param["type"]][pars] = rwms[i]
|
||||
return rw_dict
|
|
@ -2,7 +2,8 @@ from pyerrors.input import json as pj
|
|||
import os
|
||||
import datalad.api as dl
|
||||
import sqlite3
|
||||
from .input.sfcf import get_specs, read_param
|
||||
from .input import sfcf,openQCD
|
||||
import json
|
||||
|
||||
|
||||
def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
|
||||
|
@ -21,7 +22,11 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
|
|||
uuid: str
|
||||
The uuid of the project.
|
||||
"""
|
||||
parameters = read_param(path, uuid, parameter_file)
|
||||
if code == "sfcf":
|
||||
parameters = sfcf.read_param(path, uuid, parameter_file)
|
||||
elif code == "openQCD":
|
||||
parameters = openQCD.read_param(path, uuid, parameter_file)
|
||||
|
||||
dl.unlock(path + '/backlogger.db', dataset=path)
|
||||
conn = sqlite3.connect(path + '/backlogger.db')
|
||||
c = conn.cursor()
|
||||
|
@ -36,7 +41,7 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
|
|||
if os.path.exists(file):
|
||||
dl.unlock(file, dataset=path)
|
||||
known_meas = pj.load_json_dict(file)
|
||||
|
||||
if code == "sfcf":
|
||||
for subkey in measurement[corr].keys():
|
||||
meas_path = file + "::" + subkey
|
||||
if known_meas is not None:
|
||||
|
@ -48,7 +53,12 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file):
|
|||
if c.execute("SELECT * FROM backlogs WHERE path = ?", (meas_path,)).fetchone() is not None:
|
||||
c.execute("UPDATE backlogs SET updated_at = datetime('now') WHERE path = ?", (meas_path, ))
|
||||
else:
|
||||
c.execute("INSERT INTO backlogs (name, ensemble, code, path, project, parameters, parameter_file, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))", (corr, ensemble, code, meas_path, uuid, get_specs(corr + "/" + subkey, parameters), parameter_file))
|
||||
c.execute("INSERT INTO backlogs (name, ensemble, code, path, project, parameters, parameter_file, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))", (corr, ensemble, code, meas_path, uuid, sfcf.get_specs(corr + "/" + subkey, parameters), parameter_file))
|
||||
elif code == "openQCD":
|
||||
for i in range(len(parameters["rw_fcts"])):
|
||||
subkey = "/".join(parameters["rw_fcts"][i])
|
||||
meas_path = file + "::" + subkey
|
||||
c.execute("INSERT INTO backlogs (name, ensemble, code, path, project, parameters, parameter_file, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))", ("ms1", ensemble, code, meas_path, uuid, json.dumps(parameters["rw_fcts"][i]), parameter_file))
|
||||
conn.commit()
|
||||
pj.dump_dict_to_json(measurement[corr], file)
|
||||
files.append(path + '/backlogger.db')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue