From 2e71d6c0e1079c2392cb60985faecaddcf748cfe Mon Sep 17 00:00:00 2001 From: Alberto Ramos Date: Sat, 4 Jun 2022 23:20:09 +0200 Subject: [PATCH] Added i/o for configurations in native BDIO format --- src/Groups/SU2Types.jl | 4 +- src/LatticeGPU.jl | 2 +- src/YM/YM.jl | 2 +- src/YM/YMio.jl | 169 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 171 insertions(+), 6 deletions(-) diff --git a/src/Groups/SU2Types.jl b/src/Groups/SU2Types.jl index 3ecd36b..a1adb14 100644 --- a/src/Groups/SU2Types.jl +++ b/src/Groups/SU2Types.jl @@ -32,8 +32,8 @@ Base.zero(::Type{M2x2{T}}) where T <: AbstractFloat = M2x2{T}(zero(T),zero(T), Base.one(::Type{SU2{T}}) where T <: AbstractFloat = SU2{T}(one(T),zero(T)) Base.one(::Type{M2x2{T}}) where T <: AbstractFloat = M2x2{T}(one(T),zero(T),zero(T),one(T)) -Base.convert(::Type{M2x2{T}}, a::SU3alg{T}) where T = alg2mat(a) -Base.convert(::Type{M2x2{T}}, a::SU3{T}) where T = M2x2{T}(a.t1,a.t2,-conj(a.t2), conj(a.t1)) +Base.convert(::Type{M2x2{T}}, a::SU2alg{T}) where T = alg2mat(a) +Base.convert(::Type{M2x2{T}}, a::SU2{T}) where T = M2x2{T}(a.t1,a.t2,-conj(a.t2), conj(a.t1)) Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2alg{T}}) where T <: AbstractFloat = SU2alg{T}(randn(rng,T),randn(rng,T),randn(rng,T)) Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2{T}}) where T <: AbstractFloat = exp(SU2alg{T}(randn(rng,T),randn(rng,T),randn(rng,T))) diff --git a/src/LatticeGPU.jl b/src/LatticeGPU.jl index 72886b6..96a8f57 100644 --- a/src/LatticeGPU.jl +++ b/src/LatticeGPU.jl @@ -45,7 +45,7 @@ export Eoft_clover, Eoft_plaq, Qtop export FlowIntr, wfl_euler, zfl_euler, wfl_rk2, zfl_rk2, wfl_rk3, zfl_rk3 export flw, flw_adapt export sfcoupling, bndfield, setbndfield -export import_lex64, import_cern64, import_bsfqcd +export import_lex64, import_cern64, import_bsfqcd, save_cnfg, read_cnfg include("Spinors/Spinors.jl") diff --git a/src/YM/YM.jl b/src/YM/YM.jl index 022beee..b325771 100644 --- a/src/YM/YM.jl +++ b/src/YM/YM.jl @@ -147,6 +147,6 @@ include("YMsf.jl") export sfcoupling, bndfield, setbndfield include("YMio.jl") -export import_lex64, import_cern64, import_bsfqcd +export import_lex64, import_cern64, import_bsfqcd, save_cnfg, read_cnfg end diff --git a/src/YM/YMio.jl b/src/YM/YMio.jl index f795914..aaca3d0 100644 --- a/src/YM/YMio.jl +++ b/src/YM/YMio.jl @@ -10,9 +10,174 @@ ### """ - function import_lex64(fname::String, lp::SpaceParm) + read_cnfg(U, lp::SpaceParm{4,M,B,D},) -import a double precision configuration in lexicographic format. SF boundary conditions are assummed. +Reads configuration from file `fname` using the native (BDIO) format. +""" +function read_cnfg(fname::String) + + UID_HDR = 14 + fb = BDIO_open(fname, "r") + while BDIO_get_uinfo(fb) != UID_HDR + BDIO_seek!(fb) + end + ihdr = Vector{Int32}(undef, 2) + BDIO_read(fb, ihdr) + if (ihdr[1] != convert(Int32, 1653996111)) && (ihdr[2] != convert(Int32, 2)) + error("Wrong file format [header]") + end + + run = BDIO.BDIO_read_str(fb) + + while BDIO_get_uinfo(fb) != 1 + BDIO_seek!(fb) + end + + ifoo = Vector{Int32}(undef, 4) + BDIO_read(fb, ifoo) + ndim = convert(Int64, ifoo[1]) + npls = convert(Int64, round(ndim*(ndim-1)/2)) + ibc = convert(Int64, ifoo[2]) + nf = ifoo[4] + + ifoo = Vector{Int32}(undef, ndim+convert(Int32, npls)) + BDIO_read(fb, ifoo) + iL = ntuple(i -> convert(Int64, ifoo[i]),ndim) + ntw = ntuple(i -> convert(Int64, ifoo[i+ndim]), npls) + + dfoo = Vector{Float64}(undef, 4) + BDIO_read(fb, dfoo) + + lp = SpaceParm{ndim}(iL, (4,4,4,4), ibc, ntw) + gp = GaugeParm{Float64}(SU3{Float64}, dfoo[1], dfoo[2]) + + dtr = (2,3,4,1) + assign(id, V, i3) = SU3{Float64}(V[1,dtr[id],i3],V[2,dtr[id],i3],V[3,dtr[id],i3], + V[4,dtr[id],i3],V[5,dtr[id],i3],V[6,dtr[id],i3]) + + while BDIO_get_uinfo(fb) != 8 + BDIO_seek!(fb) + end + Ucpu = Array{SU3{Float64}, 3}(undef, lp.bsz, lp.ndim, lp.rsz) + V = Array{ComplexF64, 3}(undef, 9, lp.ndim, lp.iL[3]) + for i4 in 1:lp.iL[4] + for i1 in 1:lp.iL[1] + for i2 in 1:lp.iL[2] + BDIO_read(fb, vec(V)) + for i3 in 1:lp.iL[3] + b, r = point_index(CartesianIndex(i1,i2,i3,i4), lp) + for id in 1:lp.ndim + Ucpu[b,id,r] = assign(id, V, i3) + end + end + end + end + end + + if ibc == BC_SF_AFWB || ibc == BC_SF_ORBI + BDIO_read(fb, V) + Ubnd = ntuple(i->assign(i, V, 1), 3) + BDIO_close!(fb) + + return CuArray(Ucpu), Ubnd + else + BDIO_close!(fb) + return CuArray(Ucpu) + end +end + + +""" + save_cnfg(fname, U, lp::SpaceParm, gp::GaugeParm; run::Union{Nothing,String}=nothing) + +Saves configuration `U` in the file `fname` using the native (BDIO) format. +""" +function save_cnfg(fname::String, U, lp::SpaceParm{4,M,B,D}, gp::GaugeParm; run::Union{Nothing,String}=nothing) where {M,B,D} + + ihdr = [convert(Int32, 1653996111),convert(Int32,2)] + UID_HDR = 14 + + if isfile(fname) + fb = BDIO_open(fname, "a") + else + fb = BDIO_open(fname, "w", "Configuration of LatticeGPU.jl") + BDIO_start_record!(fb, BDIO_BIN_GENERIC, UID_HDR) + BDIO_write!(fb, ihdr) + if run != nothing + BDIO_write!(fb, run*"\0") + end + BDIO_write_hash!(fb) + + dfoo = Vector{Float64}(undef, 16) + BDIO_start_record!(fb, BDIO_BIN_GENERIC, 1) + BDIO_write!(fb, [convert(Int32, 4)]) + BDIO_write!(fb, [convert(Int32, B)]) + BDIO_write!(fb, [convert(Int32, gp.ng)]) + BDIO_write!(fb, [convert(Int32, 0)]) + BDIO_write!(fb, [convert(Int32, lp.iL[i]) for i in 1:4]) + BDIO_write!(fb, [convert(Int32, lp.ntw[i]) for i in 1:M]) + BDIO_write!(fb, [gp.beta, gp.c0, gp.cG[1], gp.cG[2]]) + end + BDIO_write_hash!(fb) + + dtr = (2,3,4,1) + + function assign!(id, V, i3, M::M3x3{T}) where T + + V[1,dtr[id],i3] = M.u11 + V[2,dtr[id],i3] = M.u12 + V[3,dtr[id],i3] = M.u13 + V[4,dtr[id],i3] = M.u21 + V[5,dtr[id],i3] = M.u22 + V[6,dtr[id],i3] = M.u23 + V[7,dtr[id],i3] = M.u31 + V[8,dtr[id],i3] = M.u32 + V[9,dtr[id],i3] = M.u33 + return nothing + end + assign!(id, V, i3, g::SU3{T}) where T = assign!(id,V,i3,convert(M3x3{T}, g)) + + BDIO_start_record!(fb, BDIO_BIN_F64LE, 8, true) + Ucpu = Array(U) + V = Array{ComplexF64, 3}(undef, 9, lp.ndim, lp.iL[3]) + for i4 in 1:lp.iL[4] + for i1 in 1:lp.iL[1] + for i2 in 1:lp.iL[2] + for i3 in 1:lp.iL[3] + b, r = point_index(CartesianIndex(i1,i2,i3,i4), lp) + for id in 1:lp.ndim + assign!(id, V, i3, Ucpu[b,id,r]) + end + end + BDIO_write!(fb, V) + end + end + end + + if B == BC_SF_AFWB || B == BC_SF_ORBI + for i3 in 1:lp.iL[3] + for id in 1:lp.ndim-1 + assign!(id, V, i3, Ubnd[id]) + end + assign!(4, V, i3, zero(M3x3{Float64})) + end + for i1 in 1:lp.iL[1] + for i2 in 1:lp.iL[2] + BDIO_write!(fb, V) + end + end + end + BDIO_write_hash!(fb) + BDIO_close!(fb) + + return nothing +end + + +""" + function import_bsfqcd(fname::String, lp::SpaceParm) + +import a double precision configuration in bsfqcd format. SF boundary conditions are assummed. """ function import_bsfqcd(fname, lp::SpaceParm)