Skip to content

Commit

Permalink
Merge branch 'computgraph' into computgraph_pchou
Browse files Browse the repository at this point in the history
  • Loading branch information
houpc committed Jan 14, 2024
2 parents 29280ff + d9d591d commit d03b858
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 49 deletions.
93 changes: 44 additions & 49 deletions src/frontend/diagram_id.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ struct BareGreenId <: PropagatorId
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function BareGreenId(type::AnalyticProperty=Dynamic; k, t)
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new(type, k, Tuple(t))
else
return new(type, -k, Tuple(t))
end
return new(type, mirror_symmetrize(k), Tuple(t))
end
end
Base.show(io::IO, v::BareGreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)")
Expand All @@ -38,35 +33,64 @@ struct BareInteractionId <: PropagatorId # bare W-type interaction, with only on
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function BareInteractionId(response::Response, type::AnalyticProperty=Instant; k, t=(0, 0))
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new(response, type, k, Tuple(t))
else
return new(response, type, -k, Tuple(t))
end
return new(response, type, mirror_symmetrize(k), Tuple(t))
end
end
Base.show(io::IO, v::BareInteractionId) = print(io, "$(short(v.response))$(short(v.type)), k$(v.extK), t$(v.extT)")

function Base.isequal(a::BareInteractionId, b::BareInteractionId)
# Check if response, type, and extK are not equal
if (a.response != b.response) || (a.type != b.type) || ((a.extK b.extK) == false)
return false
end

# Check the conditions for Instant and Dynamic types
# both Instant or Dynamic can have extT = [1, 1] or [1, 2]
# This is because that Instant interaction may need an auxiliary time index to increase the number of the internal time variables to two.

# if extT[1] == extT[2], that means the interaction is not time-dependent, then the specific time is not important

# For example, if a.extT = [1, 1] and b.extT = [2, 2], then return true
# Or, if a.extT = [1, 2] and b.extT = [1, 2], then return true
# otherwise, return false

return ((a.extT[1] == a.extT[2]) && (b.extT[1] == b.extT[2])) || (a.extT == b.extT)

# If none of the conditions are met, return false
return false
end

struct GenericId{P} <: DiagramId
para::P
extra::Any
GenericId(para::P, extra=Nothing) where {P} = new{P}(para, extra)
end
Base.show(io::IO, v::GenericId) = print(io, v.extra == Nothing ? "" : "$(v.extra)")

function mirror_symmetrize(k::Vector{T}) where {T<:Number}
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return k
else
mk = -k
if T <: Real
for i in 1:length(mk)
if mk[i] == -T(0)
mk[i] = T(0)
end
end
end
return mk
end
end

struct GreenId{P} <: DiagramId
para::P
type::AnalyticProperty #Instant, Dynamic
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function GreenId(para::P, type::AnalyticProperty=Dynamic; k, t) where {P}
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new{P}(para, type, k, Tuple(t))
else
return new{P}(para, type, -k, Tuple(t))
end
return new{P}(para, type, mirror_symmetrize(k), Tuple(t))
end
end
Base.show(io::IO, v::GreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)")
Expand All @@ -77,12 +101,7 @@ struct SigmaId{P} <: DiagramId
extK::Vector{Float64}
extT::Tuple{Int,Int} #all possible extT from different interactionType
function SigmaId(para::P, type::AnalyticProperty; k, t=(0, 0)) where {P}
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new{P}(para, type, k, Tuple(t))
else
return new{P}(para, type, -k, Tuple(t))
end
return new{P}(para, type, mirror_symmetrize(k), Tuple(t))
end
end
Base.show(io::IO, v::SigmaId) = print(io, "$(short(v.type))#$(v.order), t$(v.extT)")
Expand All @@ -94,12 +113,7 @@ struct PolarId{P} <: DiagramId
extT::Tuple{Int,Int} #all possible extT from different interactionType
order::Vector{Int}
function PolarId(para::P, response::Response; k, t=(0, 0)) where {P}
idx = findfirst(!iszero, k)
if isnothing(idx) || k[idx] > 0
return new{P}(para, response, k, Tuple(t))
else
return new{P}(para, response, -k, Tuple(t))
end
return new{P}(para, response, mirror_symmetrize(k), Tuple(t))
end
end
Base.show(io::IO, v::PolarId) = print(io, "$(short(v.response)), k$(v.extK), t$(v.extT)")
Expand Down Expand Up @@ -230,26 +244,7 @@ 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
end
continue
end
bothIns && field == :extT && continue
if getproperty(a, field) != getproperty(b, field)
return false
end
Expand Down
35 changes: 35 additions & 0 deletions test/front_end.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ end
@test FrontEnds._find_label(typeof(labelProd.labels), typeof(loopbasis)) == 3
end

@testset "DiagramId" begin

# Test cases for type = Instant
@testset "Instant" begin
a = BareInteractionId(UpUp, Instant, k=[1.0, 1.0], t=(1, 1))
b = BareInteractionId(UpUp, Instant, k=[1.0, 1.0], t=(1, 1)) # same as a
c = BareInteractionId(UpUp, Instant, k=[2.0, 2.0], t=(2, 2)) # different k and t
d = BareInteractionId(UpUp, Instant, k=[1.0, 1.0], t=(2, 2)) # same k, different t
e = BareInteractionId(UpUp, Instant, k=[1.0, 1.0], t=(1, 2)) # same k, different t
f = BareInteractionId(UpUp, Instant, k=[1.0, 1.0], t=(1, 2))

@test isequal(a, b) == true
@test isequal(a, c) == false
@test isequal(a, d) == true
@test isequal(a, e) == false
@test isequal(e, f) == true
end

# Test cases for type = Dynamic
@testset "Dynamic" begin
a = BareInteractionId(UpUp, Dynamic, k=[1.0, 1.0], t=(1, 1))
b = BareInteractionId(UpUp, Dynamic, k=[1.0, 1.0], t=(1, 1)) # same as a
c = BareInteractionId(UpUp, Dynamic, k=[2.0, 2.0], t=(2, 2)) # different k and t
d = BareInteractionId(UpUp, Dynamic, k=[1.0, 1.0], t=(2, 2)) # same k, different t
e = BareInteractionId(UpUp, Dynamic, k=[1.0, 1.0], t=(1, 2)) # same k, different t
f = BareInteractionId(UpUp, Dynamic, k=[1.0, 1.0], t=(1, 2))

@test isequal(a, b) == true
@test isequal(a, c) == false
@test isequal(a, d) == true
@test isequal(a, e) == false
@test isequal(e, f) == true
end
end

@testset "Parquet" begin
using FeynmanDiagram: ComputationalGraphs as Graphs
Ftype, Wtype = Graphs._dtype.factor, Graphs._dtype.weight
Expand Down

0 comments on commit d03b858

Please sign in to comment.