Added i/o for configurations in native BDIO format

This commit is contained in:
Alberto Ramos 2022-06-04 23:20:09 +02:00
parent afd837e80d
commit 2e71d6c0e1
4 changed files with 171 additions and 6 deletions

View file

@ -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{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.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::SU2alg{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::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{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))) Random.rand(rng::AbstractRNG, ::Random.SamplerType{SU2{T}}) where T <: AbstractFloat = exp(SU2alg{T}(randn(rng,T),randn(rng,T),randn(rng,T)))

View file

@ -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 FlowIntr, wfl_euler, zfl_euler, wfl_rk2, zfl_rk2, wfl_rk3, zfl_rk3
export flw, flw_adapt export flw, flw_adapt
export sfcoupling, bndfield, setbndfield 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") include("Spinors/Spinors.jl")

View file

@ -147,6 +147,6 @@ include("YMsf.jl")
export sfcoupling, bndfield, setbndfield export sfcoupling, bndfield, setbndfield
include("YMio.jl") include("YMio.jl")
export import_lex64, import_cern64, import_bsfqcd export import_lex64, import_cern64, import_bsfqcd, save_cnfg, read_cnfg
end end

View file

@ -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) function import_bsfqcd(fname, lp::SpaceParm)