Compare commits
3 commits
5ea8326757
...
9498c1dd73
| Author | SHA1 | Date | |
|---|---|---|---|
|
9498c1dd73 |
|||
|
e654d7c1bb |
|||
|
71332264cf |
5 changed files with 140 additions and 66 deletions
|
|
@ -4,7 +4,9 @@ import os
|
|||
import fnmatch
|
||||
from typing import Any, Optional
|
||||
from pathlib import Path
|
||||
import struct
|
||||
from ..pars.openQCD import ms1
|
||||
from ..pars.openQCD import qcd2
|
||||
|
||||
|
||||
|
||||
def read_ms1_param(path: Path, project: str, file_in_project: str) -> dict[str, Any]:
|
||||
|
|
@ -307,79 +309,6 @@ def extract_t1(path: Path, project: str, dir_in_project: str, param: dict[str, A
|
|||
return t1_dict
|
||||
|
||||
|
||||
def read_qcd2_par_file(fname: Path) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
The subroutines written here have names according to the openQCD programs and functions that write out the data.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname: Path
|
||||
Location of the parameter file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
par_dict: dict
|
||||
Dictionary holding the parameters specified in the given file.
|
||||
"""
|
||||
def _qcd2_write_lat_parms() -> dict[str, Any]:
|
||||
"""
|
||||
Unpack the lattice parameters written by write_lat_parms.
|
||||
"""
|
||||
lat_pars = {}
|
||||
t = fp.read(16)
|
||||
lat_pars["N"] = list(struct.unpack('iiii', t)) # lattice extends
|
||||
t = fp.read(8)
|
||||
nk, isw = struct.unpack('ii', t) # number of kappas and isw parameter
|
||||
lat_pars["nk"] = nk
|
||||
lat_pars["isw"] = isw
|
||||
t = fp.read(8)
|
||||
lat_pars["beta"] = struct.unpack('d', t)[0] # beta
|
||||
t = fp.read(8)
|
||||
lat_pars["c0"] = struct.unpack('d', t)[0]
|
||||
t = fp.read(8)
|
||||
lat_pars["c1"] = struct.unpack('d', t)[0]
|
||||
t = fp.read(8)
|
||||
lat_pars["csw"] = struct.unpack('d', t)[0] # csw factor
|
||||
kappas = []
|
||||
m0s = []
|
||||
# read kappas
|
||||
for ik in range(nk):
|
||||
t = fp.read(8)
|
||||
kappas.append(struct.unpack('d', t)[0])
|
||||
t = fp.read(8)
|
||||
m0s.append(struct.unpack('d', t)[0])
|
||||
lat_pars["kappas"] = kappas
|
||||
lat_pars["m0s"] = m0s
|
||||
return lat_pars
|
||||
|
||||
def _qcd2_write_bc_parms() -> dict[str, Any]:
|
||||
"""
|
||||
Unpack the boundary parameters written by write_bc_parms.
|
||||
"""
|
||||
bc_pars: dict[str, Any] = {}
|
||||
t = fp.read(4)
|
||||
bc_pars["type"] = struct.unpack('i', t)[0] # type of hte boundaries
|
||||
t = fp.read(104)
|
||||
bc_parms = struct.unpack('d'*13, t)
|
||||
bc_pars["cG"] = list(bc_parms[:2]) # boundary gauge field improvement
|
||||
bc_pars["cF"] = list(bc_parms[2:4]) # boundary fermion field improvement
|
||||
phi: list[list[float]] = [[], []]
|
||||
phi[0] = list(bc_parms[4:7])
|
||||
phi[1] = list(bc_parms[7:10])
|
||||
bc_pars["phi"] = phi
|
||||
bc_pars["theta"] = list(bc_parms[10:])
|
||||
return bc_pars
|
||||
|
||||
with open(fname, "rb") as fp:
|
||||
lat_par_dict = _qcd2_write_lat_parms()
|
||||
bc_par_dict = _qcd2_write_bc_parms()
|
||||
fp.close()
|
||||
par_dict = {}
|
||||
par_dict["lat"] = lat_par_dict
|
||||
par_dict["bc"] = bc_par_dict
|
||||
return par_dict
|
||||
|
||||
|
||||
def load_qcd2_pars(path: Path, project: str, file_in_project: str) -> dict[str, Any]:
|
||||
"""
|
||||
Thin wrapper around read_qcd2_par_file, getting the file before reading.
|
||||
|
|
@ -401,4 +330,28 @@ def load_qcd2_pars(path: Path, project: str, file_in_project: str) -> dict[str,
|
|||
fname = path / "projects" / project / file_in_project
|
||||
ds = os.path.join(path, "projects", project)
|
||||
dl.get(fname, dataset=ds)
|
||||
return read_qcd2_par_file(fname)
|
||||
return qcd2.read_qcd2_par_file(fname)
|
||||
|
||||
|
||||
def load_ms1_pars(path: Path, project: str, file_in_project: str) -> dict[str, Any]:
|
||||
"""
|
||||
Thin wrapper around read_qcd2_ms1_par_file, getting the file before reading.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path: Path
|
||||
Path of the corrlib repository.
|
||||
project: str
|
||||
UUID of the project of the parameter-file.
|
||||
file_in_project: str
|
||||
The loaction of the file in the project directory.
|
||||
|
||||
Returns
|
||||
-------
|
||||
par_dict: dict
|
||||
The dict with the parameters read from the .par-file.
|
||||
"""
|
||||
fname = path / "projects" / project / file_in_project
|
||||
ds = os.path.join(path, "projects", project)
|
||||
dl.get(fname, dataset=ds)
|
||||
return ms1.read_qcd2_ms1_par_file(fname)
|
||||
|
|
|
|||
3
corrlib/pars/openQCD/__init__.py
Normal file
3
corrlib/pars/openQCD/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
from . import ms1 as ms1
|
||||
from . import qcd2 as qcd2
|
||||
59
corrlib/pars/openQCD/flags.py
Normal file
59
corrlib/pars/openQCD/flags.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
"""
|
||||
Reconstruct the outputs of flags.
|
||||
"""
|
||||
|
||||
import struct
|
||||
from typing import Any, BinaryIO
|
||||
|
||||
# lat_parms.c
|
||||
def lat_parms_write_lat_parms(fp: BinaryIO) -> dict[str, Any]:
|
||||
"""
|
||||
NOTE: This is a duplcation from qcd2.
|
||||
Unpack the lattice parameters written by write_lat_parms.
|
||||
"""
|
||||
lat_pars = {}
|
||||
t = fp.read(16)
|
||||
lat_pars["N"] = list(struct.unpack('iiii', t)) # lattice extends
|
||||
t = fp.read(8)
|
||||
nk, isw = struct.unpack('ii', t) # number of kappas and isw parameter
|
||||
lat_pars["nk"] = nk
|
||||
lat_pars["isw"] = isw
|
||||
t = fp.read(8)
|
||||
lat_pars["beta"] = struct.unpack('d', t)[0] # beta
|
||||
t = fp.read(8)
|
||||
lat_pars["c0"] = struct.unpack('d', t)[0]
|
||||
t = fp.read(8)
|
||||
lat_pars["c1"] = struct.unpack('d', t)[0]
|
||||
t = fp.read(8)
|
||||
lat_pars["csw"] = struct.unpack('d', t)[0] # csw factor
|
||||
kappas = []
|
||||
m0s = []
|
||||
# read kappas
|
||||
for ik in range(nk):
|
||||
t = fp.read(8)
|
||||
kappas.append(struct.unpack('d', t)[0])
|
||||
t = fp.read(8)
|
||||
m0s.append(struct.unpack('d', t)[0])
|
||||
lat_pars["kappas"] = kappas
|
||||
lat_pars["m0s"] = m0s
|
||||
return lat_pars
|
||||
|
||||
|
||||
def lat_parms_write_bc_parms(fp: BinaryIO) -> dict[str, Any]:
|
||||
"""
|
||||
NOTE: This is a duplcation from qcd2.
|
||||
Unpack the boundary parameters written by write_bc_parms.
|
||||
"""
|
||||
bc_pars: dict[str, Any] = {}
|
||||
t = fp.read(4)
|
||||
bc_pars["type"] = struct.unpack('i', t)[0] # type of hte boundaries
|
||||
t = fp.read(104)
|
||||
bc_parms = struct.unpack('d'*13, t)
|
||||
bc_pars["cG"] = list(bc_parms[:2]) # boundary gauge field improvement
|
||||
bc_pars["cF"] = list(bc_parms[2:4]) # boundary fermion field improvement
|
||||
phi: list[list[float]] = [[], []]
|
||||
phi[0] = list(bc_parms[4:7])
|
||||
phi[1] = list(bc_parms[7:10])
|
||||
bc_pars["phi"] = phi
|
||||
bc_pars["theta"] = list(bc_parms[10:])
|
||||
return bc_pars
|
||||
30
corrlib/pars/openQCD/ms1.py
Normal file
30
corrlib/pars/openQCD/ms1.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from . import flags
|
||||
|
||||
from typing import Any
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def read_qcd2_ms1_par_file(fname: Path) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
The subroutines written here have names according to the openQCD programs and functions that write out the data.
|
||||
Parameters
|
||||
----------
|
||||
fname: Path
|
||||
Location of the parameter file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
par_dict: dict
|
||||
Dictionary holding the parameters specified in the given file.
|
||||
"""
|
||||
|
||||
with open(fname, "rb") as fp:
|
||||
lat_par_dict = flags.lat_parms_write_lat_parms(fp)
|
||||
bc_par_dict = flags.lat_parms_write_bc_parms(fp)
|
||||
fp.close()
|
||||
par_dict = {}
|
||||
par_dict["lat"] = lat_par_dict
|
||||
par_dict["bc"] = bc_par_dict
|
||||
return par_dict
|
||||
|
||||
|
||||
29
corrlib/pars/openQCD/qcd2.py
Normal file
29
corrlib/pars/openQCD/qcd2.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from . import flags
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
def read_qcd2_par_file(fname: Path) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
The subroutines written here have names according to the openQCD programs and functions that write out the data.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fname: Path
|
||||
Location of the parameter file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
par_dict: dict
|
||||
Dictionary holding the parameters specified in the given file.
|
||||
"""
|
||||
|
||||
with open(fname, "rb") as fp:
|
||||
lat_par_dict = flags.lat_parms_write_lat_parms(fp)
|
||||
bc_par_dict = flags.lat_parms_write_bc_parms(fp)
|
||||
fp.close()
|
||||
par_dict = {}
|
||||
par_dict["lat"] = lat_par_dict
|
||||
par_dict["bc"] = bc_par_dict
|
||||
return par_dict
|
||||
Loading…
Add table
Add a link
Reference in a new issue