add first openQCD functionality
This commit is contained in:
parent
dccce894b9
commit
0786d7decd
4 changed files with 95 additions and 12 deletions
|
|
@ -10,11 +10,12 @@ the import of projects via TOML.
|
|||
|
||||
import tomllib as toml
|
||||
import shutil
|
||||
from .input import sfcf
|
||||
from .input import sfcf, openQCD
|
||||
from .main import import_project, update_aliases
|
||||
from .meas_io import write_measurement
|
||||
import datalad.api as dl
|
||||
import os
|
||||
from .input.implementations import codes as known_codes
|
||||
|
||||
|
||||
def check_project_data(d: dict) -> None:
|
||||
|
|
@ -30,8 +31,12 @@ def check_project_data(d: dict) -> None:
|
|||
return
|
||||
|
||||
|
||||
def check_measurement_data(measurements: dict) -> None:
|
||||
var_names: list[str] = ["path", "ensemble", "param_file", "version", "prefix", "cfg_seperator", "names"]
|
||||
def check_measurement_data(measurements: dict, code: str) -> None:
|
||||
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 var_name in var_names:
|
||||
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)
|
||||
check_project_data(toml_dict)
|
||||
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']
|
||||
check_measurement_data(measurements)
|
||||
check_measurement_data(measurements, project['code'])
|
||||
aliases = project.get('aliases', None)
|
||||
uuid = project.get('uuid', 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():
|
||||
print("Import measurement: " + mname)
|
||||
ensemble = md['ensemble']
|
||||
param = sfcf.read_param(path, uuid, md['param_file'])
|
||||
if 'names' in md.keys():
|
||||
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
||||
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/', names=md['names'])
|
||||
else:
|
||||
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
||||
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/')
|
||||
if project['code'] == 'sfcf':
|
||||
param = sfcf.read_param(path, uuid, md['param_file'])
|
||||
if 'names' in md.keys():
|
||||
measurement = sfcf.read_data(path, uuid, md['path'], md['prefix'], param,
|
||||
version=md['version'], cfg_seperator=md['cfg_seperator'], sep='/', names=md['names'])
|
||||
else:
|
||||
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'])
|
||||
print(mname + " imported.")
|
||||
|
||||
if not os.path.exists(os.path.join(path, "toml_imports", uuid)):
|
||||
os.makedirs(os.path.join(path, "toml_imports", uuid))
|
||||
if copy_file:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue