Skip to content

Commit

Permalink
remove para field and add isequal for PropagatorId
Browse files Browse the repository at this point in the history
  • Loading branch information
houpc committed Jan 11, 2024
1 parent 4ee9047 commit 9ec2358
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
30 changes: 19 additions & 11 deletions src/frontend/diagram_id.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,32 @@ abstract type PropagatorId <: DiagramId end
# Base.isequal(a::DiagramId, b::DiagramId) = error("Base.isequal not implemented!")
Base.:(==)(a::DiagramId, b::DiagramId) = Base.isequal(a, b)

struct BareGreenId{P} <: PropagatorId
para::P
struct BareGreenId <: PropagatorId
type::AnalyticProperty #Instant, Dynamic
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function BareGreenId(para::P, type::AnalyticProperty=Dynamic; k, t) where {P}
function BareGreenId(type::AnalyticProperty=Dynamic; k, t)
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new{P}(para, type, k, Tuple(t))
return new(type, k, Tuple(t))
else
return new{P}(para, type, -k, Tuple(t))
return new(type, -k, Tuple(t))
end
end
end
Base.show(io::IO, v::BareGreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)")

struct BareInteractionId{P} <: PropagatorId # bare W-type interaction, with only one extK
para::P
struct BareInteractionId <: PropagatorId # bare W-type interaction, with only one extK
response::Response #UpUp, UpDown, ...
type::AnalyticProperty #Instant, Dynamic
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function BareInteractionId(para::P, response::Response, type::AnalyticProperty=Instant; k, t=(0, 0)) where {P}
function BareInteractionId(response::Response, type::AnalyticProperty=Instant; k, t=(0, 0))
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new{P}(para, response, type, k, Tuple(t))
return new(response, type, k, Tuple(t))
else
return new{P}(para, response, type, -k, Tuple(t))
return new(response, type, -k, Tuple(t))
end
end
end
Expand Down Expand Up @@ -232,14 +230,24 @@ function Base.isequal(a::DiagramId, b::DiagramId)
if typeof(a) != typeof(b)
return false
end
bothIns = false
for field in fieldnames(typeof(a))
if getproperty(a, field) != getproperty(b, field)
return false
end
end
return true
end

function Base.isequal(a::BareInteractionId, b::BareInteractionId)
bothIns = false
for field in fieldnames(typeof(a))
if field == :type
a.type != b.type && return false
if a.type == Instant
bothIns = true
continue
end
continue
end
bothIns && field == :extT && continue
if getproperty(a, field) != getproperty(b, field)
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/parquet/green.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function green(para::DiagPara, extK=getK(para.totalLoopNum, 1), extT=para.hasTau
# end

if para.innerLoopNum == 0
return Graph([]; properties=BareGreenId(para, k=extK, t=extT), name=name)
return Graph([]; properties=BareGreenId(k=extK, t=extT), name=name)
end

# ################# after this step, the Green's function must be nontrivial! ##################
Expand All @@ -61,8 +61,8 @@ function green(para::DiagPara, extK=getK(para.totalLoopNum, 1), extT=para.hasTau
return Graph([group[:diagram], G]; properties=GenericId(para, pairT), operator=Prod(), name=:ΣG)
end

para0 = reconstruct(para, innerLoopNum=0) #parameter for g0
g0 = Graph([]; properties=BareGreenId(para0, k=extK, t=(tin, t0)), name=:g0)
# para0 = reconstruct(para, innerLoopNum=0) #parameter for g0
g0 = Graph([]; properties=BareGreenId(k=extK, t=(tin, t0)), name=:g0)
ΣGpairs = Vector{Graph{Ftype,Wtype}}()
for p in orderedPartition(para.innerLoopNum, 2, 0)
oΣ, oG = p
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/parquet/vertex4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function _bare(para::DiagPara, diex::Vector{Permutation}, response::Response, ty

if notProper(para, _q) == false && _diex in diex
#create new bare ver4 only if _diex is required in the diex table
vid = BareInteractionId(para, response, type, k=_q, t=_innerT)
vid = BareInteractionId(response, type, k=_q, t=_innerT)
return Graph([]; factor=sign * _factor, properties=vid)
else
return nothing
Expand Down
8 changes: 4 additions & 4 deletions test/front_end.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ end
# #construct the propagator table
gK = [[0.0, 0.0, 1.0, 1.0], [0.0, 0.0, 0.0, 1.0]]
gT = [(1, 2), (2, 1)]
g = [Graph([], properties=BareGreenId(paraG, k=gK[i], t=gT[i]), name=:G) for i in 1:2]
g = [Graph([], properties=BareGreenId(k=gK[i], t=gT[i]), name=:G) for i in 1:2]

vdK = [[0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 1.0, 0.0]]
# vdT = [[1, 1], [2, 2]]
vd = [Graph([], properties=BareInteractionId(paraV, ChargeCharge, k=vdK[i]), name=:Vd) for i in 1:2]
vd = [Graph([], properties=BareInteractionId(ChargeCharge, k=vdK[i]), name=:Vd) for i in 1:2]

veK = [[1, 0, -1, -1], [0, 1, 0, -1]]
# veT = [[1, 1], [2, 2]]
ve = [Graph([], properties=BareInteractionId(paraV, ChargeCharge, k=veK[i]), name=:Ve) for i in 1:2]
ve = [Graph([], properties=BareInteractionId(ChargeCharge, k=veK[i]), name=:Ve) for i in 1:2]

Id = GenericId(paraV)
# contruct the tree
Expand Down Expand Up @@ -250,7 +250,7 @@ end
# autodiff
factor = 1 / (2π)^D
Taylor.set_variables("x y"; orders=[1, 1])
propagator_var = Dict(BareGreenId{DiagPara} => [true, false], BareInteractionId{DiagPara} => [false, true]) # Specify variable dependence of fermi (first element) and bose (second element) particles.
propagator_var = Dict(BareGreenId => [true, false], BareInteractionId => [false, true]) # Specify variable dependence of fermi (first element) and bose (second element) particles.
t, taylormap = Utility.taylorexpansion!(root, propagator_var)

taylorleafmap, taylorleafvec = assign_leaves(root, taylormap)
Expand Down
8 changes: 4 additions & 4 deletions test/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ function getdiagram(spin=2.0, D=3, Nk=4, Nt=2)
# #construct the propagator table
gK = [[0.0, 0.0, 1.0, 1.0], [0.0, 0.0, 0.0, 1.0]]
gT = [(1, 2), (2, 1)]
g = [Graph([], properties=BareGreenId(paraG, k=gK[i], t=gT[i]), name=:G) for i in 1:2]
g = [Graph([], properties=BareGreenId(k=gK[i], t=gT[i]), name=:G) for i in 1:2]

vdK = [[0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 1.0, 0.0]]
# vdT = [[1, 1], [2, 2]]
vd = [Graph([], properties=BareInteractionId(paraV, ChargeCharge, k=vdK[i]), name=:Vd) for i in 1:2]
vd = [Graph([], properties=BareInteractionId(ChargeCharge, k=vdK[i]), name=:Vd) for i in 1:2]

veK = [[1, 0, -1, -1], [0, 1, 0, -1]]
# veT = [[1, 1], [2, 2]]
ve = [Graph([], properties=BareInteractionId(paraV, ChargeCharge, k=veK[i]), name=:Ve) for i in 1:2]
ve = [Graph([], properties=BareInteractionId(ChargeCharge, k=veK[i]), name=:Ve) for i in 1:2]

Id = GenericId(paraV)
# contruct the tree
Expand Down Expand Up @@ -198,7 +198,7 @@ end
# autodiff
factor = 1 / (2π)^D
set_variables("x y"; orders=[2, 2])
propagator_var = Dict(BareGreenId{DiagPara} => [true, false], BareInteractionId{DiagPara} => [false, true]) # Specify variable dependence of fermi (first element) and bose (second element) particles.
propagator_var = Dict(BareGreenId => [true, false], BareInteractionId => [false, true]) # Specify variable dependence of fermi (first element) and bose (second element) particles.
t, taylormap = taylorexpansion!(root, propagator_var)

taylorleafmap, taylorleafvec = assign_leaves(root, taylormap)
Expand Down

0 comments on commit 9ec2358

Please sign in to comment.