add first openQCD functionality
This commit is contained in:
parent
dccce894b9
commit
0786d7decd
4 changed files with 95 additions and 12 deletions
|
@ -3,3 +3,5 @@ Import functions for different codes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from . import sfcf
|
from . import sfcf
|
||||||
|
from . import openQCD
|
||||||
|
from . import implementations
|
||||||
|
|
2
corrlib/input/implementations.py
Normal file
2
corrlib/input/implementations.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
codes = ['sfcf', 'openQCD']
|
66
corrlib/input/openQCD.py
Normal file
66
corrlib/input/openQCD.py
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import pyerrors.input.openQCD as input
|
||||||
|
import datalad.api as dl
|
||||||
|
import os
|
||||||
|
import fnmatch
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def read_param(path: str, project: str, file_in_project: str) -> dict[str, Any]:
|
||||||
|
file = path + "/projects/" + project + '/' + file_in_project
|
||||||
|
dl.get(file, dataset=path + "/projects/" + project)
|
||||||
|
with open(file, 'r') as fp:
|
||||||
|
lines = fp.readlines()
|
||||||
|
fp.close()
|
||||||
|
param = {}
|
||||||
|
param['rw_fcts'] = []
|
||||||
|
param['rand'] = {}
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
|
if line.startswith('\n'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith("nrw"):
|
||||||
|
l = line.strip()
|
||||||
|
num_rw = l.split('#').split()[1]
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
||||||
|
directory = path + "/projects/" + project + '/' + dir_in_project
|
||||||
|
if files is None:
|
||||||
|
files = []
|
||||||
|
for root, ds, fs in os.walk(directory):
|
||||||
|
for f in fs:
|
||||||
|
if fnmatch.fnmatch(f, prefix + "*" + postfix + ".dat"):
|
||||||
|
files.append(f)
|
||||||
|
dl.get([directory + "/" + f for f in files], dataset=path + "/projects/" + project)
|
||||||
|
kwargs = {}
|
||||||
|
if names is not None:
|
||||||
|
kwargs['names'] = names
|
||||||
|
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[''] =
|
||||||
|
return rw_dict
|
|
@ -10,11 +10,12 @@ the import of projects via TOML.
|
||||||
|
|
||||||
import tomllib as toml
|
import tomllib as toml
|
||||||
import shutil
|
import shutil
|
||||||
from .input import sfcf
|
from .input import sfcf, openQCD
|
||||||
from .main import import_project, update_aliases
|
from .main import import_project, update_aliases
|
||||||
from .meas_io import write_measurement
|
from .meas_io import write_measurement
|
||||||
import datalad.api as dl
|
import datalad.api as dl
|
||||||
import os
|
import os
|
||||||
|
from .input.implementations import codes as known_codes
|
||||||
|
|
||||||
|
|
||||||
def check_project_data(d: dict) -> None:
|
def check_project_data(d: dict) -> None:
|
||||||
|
@ -30,8 +31,12 @@ def check_project_data(d: dict) -> None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def check_measurement_data(measurements: dict) -> None:
|
def check_measurement_data(measurements: dict, code: str) -> None:
|
||||||
var_names: list[str] = ["path", "ensemble", "param_file", "version", "prefix", "cfg_seperator", "names"]
|
var_names: list[str] = []
|
||||||
|
if code == "sfcf":
|
||||||
|
var_names = ["path", "ensemble", "param_file", "version", "prefix", "cfg_seperator", "names"]
|
||||||
|
elif code == "openQCD":
|
||||||
|
var_names = ["path", "ensemble", "measurement", "prefix", "param_file"]
|
||||||
for mname, md in measurements.items():
|
for mname, md in measurements.items():
|
||||||
for var_name in var_names:
|
for var_name in var_names:
|
||||||
if var_name not in md.keys():
|
if var_name not in md.keys():
|
||||||
|
@ -56,8 +61,10 @@ def import_toml(path: str, file: str, copy_file: bool=True) -> None:
|
||||||
toml_dict = toml.load(fp)
|
toml_dict = toml.load(fp)
|
||||||
check_project_data(toml_dict)
|
check_project_data(toml_dict)
|
||||||
project: dict = toml_dict['project']
|
project: dict = toml_dict['project']
|
||||||
|
if project['code'] not in known_codes:
|
||||||
|
raise ValueError('Code' + project['code'] + 'has no import implementation!')
|
||||||
measurements: dict = toml_dict['measurements']
|
measurements: dict = toml_dict['measurements']
|
||||||
check_measurement_data(measurements)
|
check_measurement_data(measurements, project['code'])
|
||||||
aliases = project.get('aliases', None)
|
aliases = project.get('aliases', None)
|
||||||
uuid = project.get('uuid', None)
|
uuid = project.get('uuid', None)
|
||||||
if uuid is not None:
|
if uuid is not None:
|
||||||
|
@ -70,15 +77,21 @@ def import_toml(path: str, file: str, copy_file: bool=True) -> None:
|
||||||
for mname, md in measurements.items():
|
for mname, md in measurements.items():
|
||||||
print("Import measurement: " + mname)
|
print("Import measurement: " + mname)
|
||||||
ensemble = md['ensemble']
|
ensemble = md['ensemble']
|
||||||
param = sfcf.read_param(path, uuid, md['param_file'])
|
if project['code'] == 'sfcf':
|
||||||
if 'names' in md.keys():
|
param = sfcf.read_param(path, uuid, md['param_file'])
|
||||||
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
if 'names' in md.keys():
|
||||||
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/', names=md['names'])
|
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
||||||
else:
|
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/', names=md['names'])
|
||||||
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
else:
|
||||||
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/')
|
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
||||||
|
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/')
|
||||||
|
print(mname + " imported.")
|
||||||
|
elif project['code'] == 'openQCD':
|
||||||
|
param = openQCD.read_param(path, uuid, md['param_file'])
|
||||||
|
param['type'] = md['measurement']
|
||||||
|
measurement = openQCD.read_rwms(path, uuid, md['path'], md["prefix"], version=md["version"], names=md['names'], files=md['files'])
|
||||||
write_measurement(path, ensemble, measurement, uuid, project['code'], md['param_file'])
|
write_measurement(path, ensemble, measurement, uuid, project['code'], md['param_file'])
|
||||||
print(mname + " imported.")
|
|
||||||
if not os.path.exists(os.path.join(path, "toml_imports", uuid)):
|
if not os.path.exists(os.path.join(path, "toml_imports", uuid)):
|
||||||
os.makedirs(os.path.join(path, "toml_imports", uuid))
|
os.makedirs(os.path.join(path, "toml_imports", uuid))
|
||||||
if copy_file:
|
if copy_file:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue