diff --git a/src/FeynmanDiagram.jl b/src/FeynmanDiagram.jl index 8f1d9e14..87edae54 100644 --- a/src/FeynmanDiagram.jl +++ b/src/FeynmanDiagram.jl @@ -34,11 +34,11 @@ export multi_product, linear_combination, feynman_diagram, propagator, interacti # export reducibility, connectivity # export 𝐺ᶠ, 𝐺ᵇ, 𝐺ᵠ, 𝑊, Green2, Interaction # export Coupling_yukawa, Coupling_phi3, Coupling_phi4, Coupling_phi6 -export haschildren, onechild, isleaf, isbranch, ischain, has_zero_subfactors, eldest -export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_multi_product!, merge_chains! -export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_multi_product, merge_chains -export open_parenthesis, open_parenthesis!, flatten_prod!, flatten_prod, flatten_sum!, flatten_sum -export optimize!, optimize, merge_all_chains!, merge_all_linear_combinations!, remove_duplicated_leaves! +export haschildren, onechild, isleaf, isbranch, ischain, has_zero_subfactors, eldest, count_operation +export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_multi_product!, remove_zero_valued_subgraphs! +export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_multi_product, remove_zero_valued_subgraphs +export open_parenthesis, open_parenthesis!, flatten_prod!, flatten_prod, flatten_sum!, flatten_sum, flatten_chains!, flatten_chains +export optimize!, optimize, flatten_all_chains!, merge_all_linear_combinations!, merge_all_multi_products!, remove_all_zero_valued_subgraphs!, remove_duplicated_leaves!, remove_duplicated_nodes! include("TaylorSeries/TaylorSeries.jl") using .Taylor @@ -53,30 +53,18 @@ include("frontend/frontends.jl") using .FrontEnds export FrontEnds export LabelProduct +export Filter, Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly include("frontend/parquet/parquet.jl") using .Parquet export Parquet -export ParquetBlocks -export DiagramType, VacuumDiag, SigmaDiag, GreenDiag, PolarDiag, Ver3Diag, Ver4Diag -export Filter, Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly -export Response, Composite, ChargeCharge, SpinSpin, ProperChargeCharge, ProperSpinSpin, UpUp, UpDown -export AnalyticProperty, Instant, Dynamic, D_Instant, D_Dynamic - -export DiagPara -export Interaction, interactionTauNum, innerTauNum -export TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan -export Permutation, Di, Ex, DiEx -export DiagramId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId -export PropagatorId, BareGreenId, BareInteractionId -export mergeby include("frontend/GV.jl") using .GV export GV export diagdictGV, diagdict_parquet, leafstates, leafstates_diagtree -# include("frontend/strong_coupling_expansion_builder/strong_coupling_expansion.jl") +# include("strong_coupling_expansion_builder/strong_coupling_expansion.jl") # using .SCE # export SCE # export Gn diff --git a/src/backend/compiler.jl b/src/backend/compiler.jl index f2566a85..9b01a0a0 100644 --- a/src/backend/compiler.jl +++ b/src/backend/compiler.jl @@ -3,8 +3,7 @@ using PyCall using ..ComputationalGraphs import ..ComputationalGraphs: id, name, set_name!, operator, subgraphs, subgraph_factors, FeynmanProperties -using ..Parquet -using ..Parquet: PropagatorId, BareGreenId, BareInteractionId +using ..FrontEnds: PropagatorId, BareGreenId, BareInteractionId using ..QuantumOperators import ..QuantumOperators: isfermionic diff --git a/src/computational_graph/ComputationalGraph.jl b/src/computational_graph/ComputationalGraph.jl index 94d59dbd..350e4ec3 100644 --- a/src/computational_graph/ComputationalGraph.jl +++ b/src/computational_graph/ComputationalGraph.jl @@ -48,10 +48,11 @@ include("eval.jl") export eval! include("transform.jl") -export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_multi_product!, merge_chains!, flatten_chains! -export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_multi_product, merge_chains, flatten_chains -export open_parenthesis!, open_parenthesis, flatten_prod!, flatten_prod, flatten_sum!, flatten_sum +export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_multi_product!, remove_zero_valued_subgraphs! +export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_multi_product, remove_zero_valued_subgraphs +export open_parenthesis, open_parenthesis!, flatten_prod!, flatten_prod, flatten_sum!, flatten_sum, flatten_chains!, flatten_chains include("optimize.jl") -export optimize!, optimize +export optimize!, optimize, flatten_all_chains!, merge_all_linear_combinations!, merge_all_multi_products!, remove_all_zero_valued_subgraphs!, remove_duplicated_leaves!, remove_duplicated_nodes! + end diff --git a/src/computational_graph/optimize.jl b/src/computational_graph/optimize.jl index 67ccfa26..5ff34aa5 100644 --- a/src/computational_graph/optimize.jl +++ b/src/computational_graph/optimize.jl @@ -249,7 +249,7 @@ end """ function unique_nodes!(graphs::AbstractVector{<:AbstractGraph}) - Identifies and retrieves unique leaf nodes from a set of graphs. + Identifies and retrieves unique nodes from a set of graphs. # Arguments: - `graphs`: A collection of graphs to be processed. diff --git a/src/frontend/GV.jl b/src/frontend/GV.jl index cd16f951..aeec21f6 100644 --- a/src/frontend/GV.jl +++ b/src/frontend/GV.jl @@ -6,32 +6,24 @@ import ..ComputationalGraphs: FeynmanGraph import ..ComputationalGraphs: Graph import ..ComputationalGraphs: _dtype import ..Parquet -import ..Parquet: Filter, NoBubble, NoHartree, NoFock, DirectOnly -import ..Parquet: Wirreducible #remove all polarization subdiagrams -import ..Parquet: Girreducible #remove all self-energy inseration -import ..Parquet: NoBubble # true to remove all bubble subdiagram -import ..Parquet: Proper #ver4, ver3, and polarization diagrams may require to be irreducible along the transfer momentum/frequency -import ..Parquet: Response, Composite, ChargeCharge, SpinSpin, UpUp, UpDown -import ..Parquet: AnalyticProperty, Instant, Dynamic, D_Instant, D_Dynamic import ..Parquet: DiagramType, VacuumDiag, SigmaDiag, GreenDiag, PolarDiag, Ver3Diag, Ver4Diag +import ..Parquet: Interaction, DiagPara import ..Taylor using ..FrontEnds +import ..FrontEnds: Filter, NoHartree, NoFock, DirectOnly +import ..FrontEnds: Wirreducible #remove all polarization subdiagrams +import ..FrontEnds: Girreducible #remove all self-energy inseration +import ..FrontEnds: NoBubble # true to remove all bubble subdiagram +import ..FrontEnds: Proper #ver4, ver3, and polarization diagrams may require to be irreducible along the transfer momentum/frequency +import ..FrontEnds: Response, Composite, ChargeCharge, SpinSpin, UpUp, UpDown +import ..FrontEnds: AnalyticProperty, Instant, Dynamic +import ..FrontEnds: DiagramId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId, BareGreenId, BareInteractionId + + using AbstractTrees import ..Utility: taylorexpansion! -import ..Interaction -import ..DiagPara - -import ..DiagramId -import ..Ver4Id -import ..Ver3Id -import ..GreenId -import ..SigmaId -import ..PolarId -import ..BareInteractionId -import ..BareGreenId - export eachorder_diag, diagdictGV, diagdict_parquet, leafstates, leafstates_diagtree include("GV_diagrams/readfile.jl") diff --git a/src/frontend/diagram_id.jl b/src/frontend/diagram_id.jl new file mode 100644 index 00000000..b6d49000 --- /dev/null +++ b/src/frontend/diagram_id.jl @@ -0,0 +1,274 @@ +""" + abstract type DiagramId end + + The abstract type of all diagrams/subdiagrams/bare propagators +""" +abstract type DiagramId end + +""" + abstract type PropagatorId <: DiagramId end + + The abstract type of all bare propagators +""" +abstract type PropagatorId <: DiagramId end + +# Base.Dict(x::DiagramId) = Dict{Symbol,Any}([fn => getfield(x, fn) for fn ∈ fieldnames(typeof(x))]) +# Base.show(io::IO, d::DiagramId) = error("Base.show not implemented!") +# Base.isequal(a::DiagramId, b::DiagramId) = error("Base.isequal not implemented!") +Base.:(==)(a::DiagramId, b::DiagramId) = Base.isequal(a, b) + +struct BareGreenId <: PropagatorId + type::AnalyticProperty #Instant, Dynamic + 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 + end +end +Base.show(io::IO, v::BareGreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)") + +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(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 + end +end +Base.show(io::IO, v::BareInteractionId) = print(io, "$(short(v.response))$(short(v.type)), k$(v.extK), t$(v.extT)") + +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)") + +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 + end +end +Base.show(io::IO, v::GreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)") + +struct SigmaId{P} <: DiagramId + para::P + type::AnalyticProperty #Instant, Dynamic + 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 + end +end +Base.show(io::IO, v::SigmaId) = print(io, "$(short(v.type))#$(v.order), t$(v.extT)") + +struct PolarId{P} <: DiagramId + para::P + response::Response #UpUp, UpDown, ... + extK::Vector{Float64} + 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 + end +end +Base.show(io::IO, v::PolarId) = print(io, "$(short(v.response)), k$(v.extK), t$(v.extT)") + +struct Ver3Id{P} <: DiagramId + para::P + response::Response #UpUp, UpDown, ... + extK::Vector{Vector{Float64}} + extT::Tuple{Int,Int,Int} #all possible extT from different interactionType + function Ver3Id(para::P, response::Response; k, t=(0, 0, 0)) where {P} + return new{P}(para, response, k, Tuple(t)) + end +end +Base.show(io::IO, v::Ver3Id) = print(io, "$(short(v.response)),t$(v.extT)") + +struct Ver4Id{P} <: DiagramId + para::P + response::Response #UpUp, UpDown, ... + type::AnalyticProperty #Instant, Dynamic + channel::TwoBodyChannel # particle-hole, particle-hole exchange, particle-particle, irreducible + extK::Vector{Vector{Float64}} + extT::Tuple{Int,Int,Int,Int} #all possible extT from different interactionType + function Ver4Id(para::P, response::Response, type::AnalyticProperty=Dynamic; + k, t=(0, 0, 0, 0), chan::TwoBodyChannel=AnyChan) where {P} + return new{P}(para, response, type, chan, k, Tuple(t)) + end +end +Base.show(io::IO, v::Ver4Id) = print(io, (v.channel == AnyChan ? "" : "$(v.channel) ") * "$(short(v.response))$(short(v.type)),t$(v.extT)") + +function vstr(r, c) + N = length(r) + # cstr(x) = x ? "⁺" : "⁻" + s = "" + for i = 1:N-1 + s *= "$(r[i])$c" + end + s *= "$(r[end])$c" + return s +end + +function vcstr(r, creation) + N = length(r) + # cstr(x) = x ? "⁺" : "⁻" + s = "" + for i = 1:N-1 + if creation[i] + s *= "$(r[i])⁺" + else + s *= "$(r[i])⁻" + end + end + if creation[end] + s *= "$(r[end])⁺" + else + s *= "$(r[end])⁻" + end + return s +end + + +""" +hopping function c⁺c⁻ +""" +struct BareHoppingId{P} <: PropagatorId + para::P + site::Tuple{Int,Int} + orbital::Tuple{Int,Int} + extT::Tuple{Int,Int} + function BareHoppingId(para::P, orbital, t, r) where {P} + return new{P}(para, r, orbital, t) + end +end +Base.show(io::IO, v::BareHoppingId) = print(io, "($(vstr(v.site, "ᵣ"))|$(vstr(v.orbital, "ₒ"))|$(vcstr(v.extT, [true, false])))") + +""" +time-ordered N-point Bare Green's function +""" +struct BareGreenNId{P} <: PropagatorId + para::P + site::Int + creation::Vector{Bool} + orbital::Vector{Int} + extT::Vector{Int} + N::Int + function BareGreenNId(para::P; orbital=[], t=[], creation=[], r=0) where {P} + @assert length(orbital) == length(t) == length(creation) + return new{P}(para, r, creation, orbital, t, length(orbital)) + end +end +Base.show(io::IO, v::BareGreenNId) = print(io, "($(v.site)ᵣ|$(vstr(v.orbital, "ₒ"))|$(vcstr(v.extT, v.creation)))") + +""" +time-ordered N-point Composite Green's function +""" +struct GreenNId{P} <: DiagramId + para::P + site::Vector{Int} + creation::Vector{Bool} + orbital::Vector{Int} + extT::Vector{Int} + N::Int + function GreenNId(para::P; orbital=[], t=[], creation=[], r=[]) where {P} + @assert length(orbital) == length(t) == length(r) == length(creation) + return new{P}(para, r, creation, orbital, t, length(orbital)) + end +end +Base.show(io::IO, v::GreenNId) = print(io, "($(vstr(v.site, "ᵣ"))|$(vstr(v.orbital, "ₒ"))|$(vcstr(v.extT, v.creation)))") + +""" +time-ordered N-point Composite Green's function +""" +struct ConnectedGreenNId{P} <: DiagramId + para::P + site::Vector{Int} + creation::Vector{Bool} + orbital::Vector{Int} + extT::Vector{Int} + N::Int + function ConnectedGreenNId(para::P; orbital=[], t=[], creation=[], r=[]) where {P} + @assert length(orbital) == length(t) == length(r) == length(creation) + return new{P}(para, r, creation, orbital, t, length(orbital)) + end +end +Base.show(io::IO, v::ConnectedGreenNId) = print(io, "($(vstr(v.site, "ᵣ"))|$(vstr(v.orbital, "ₒ"))|$(vcstr(v.extT, v.creation)))") + + +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 + end + return true +end + +function index(type) + if type == BareGreenId + return 1 + elseif type == BareInteractionId + return 2 + elseif type == BareGreenNId + return 3 + elseif type == BareHoppingId + return 4 + else + error("Not Implemented!") + end +end + + diff --git a/src/frontend/frontends.jl b/src/frontend/frontends.jl index 96cb22e3..ce8580f3 100644 --- a/src/frontend/frontends.jl +++ b/src/frontend/frontends.jl @@ -8,14 +8,86 @@ import ..ComputationalGraphs: FeynmanGraph import ..ComputationalGraphs: Graph import ..ComputationalGraphs: _dtype +@enum TwoBodyChannel Alli = 1 PHr PHEr PPr AnyChan + +@enum Filter begin + Wirreducible #remove all polarization subdiagrams + Girreducible #remove all self-energy inseration + NoHartree + NoFock + NoBubble # true to remove all bubble subdiagram + Proper #ver4, ver3, and polarization diagrams may require to be irreducible along the transfer momentum/frequency + DirectOnly # only direct interaction, this can be useful for debug purpose +end + +Base.length(r::Filter) = 1 +Base.iterate(r::Filter) = (r, nothing) +function Base.iterate(r::Filter, ::Nothing) end + +@enum Response begin + Composite + ChargeCharge + SpinSpin + ProperChargeCharge + ProperSpinSpin + UpUp + UpDown +end + +Base.length(r::Response) = 1 +Base.iterate(r::Response) = (r, nothing) +function Base.iterate(r::Response, ::Nothing) end + +@enum AnalyticProperty begin + Instant + Dynamic +end + +Base.length(r::AnalyticProperty) = 1 +Base.iterate(r::AnalyticProperty) = (r, nothing) +function Base.iterate(r::AnalyticProperty, ::Nothing) end + +function short(name::Response) + if name == ChargeCharge + return "cc" + elseif name == SpinSpin + return "σσ" + elseif name == UpUp + return "↑↑" + elseif name == UpDown + return "↑↓" + else + @error("$name is not implemented!") + end +end + +function short(type::AnalyticProperty) + if type == Instant + return "Ins" + elseif type == Dynamic + return "Dyn" + else + @error("$type is not implemented!") + end +end + +function symbol(name::Response, type::AnalyticProperty, addition=nothing) + if isnothing(addition) + return Symbol("$(short(name))$(short(type))") + else + return Symbol("$(short(name))$(short(type))$(addition)") + end + +end + +include("diagram_id.jl") +export DiagramId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId, GreenNId, ConnectedGreenNId +export PropagatorId, BareGreenId, BareInteractionId, BareHoppingId, BareGreenNId + include("pool.jl") export LoopPool include("LabelProduct.jl") export LabelProduct -# include("parquet/parquet.jl") -# using .Parquet -# export Parquet - end \ No newline at end of file diff --git a/src/frontend/parquet/common.jl b/src/frontend/parquet/common.jl index b194c0ce..a7b0ae1d 100644 --- a/src/frontend/parquet/common.jl +++ b/src/frontend/parquet/common.jl @@ -74,7 +74,7 @@ function interactionTauNum(hasTau::Bool, interactionSet) return 0 end for interaction in interactionSet - if Dynamic in interaction.type || D_Dynamic in interaction.type + if Dynamic in interaction.type return 2 end end diff --git a/src/frontend/parquet/diagram_id.jl b/src/frontend/parquet/diagram_id.jl deleted file mode 100644 index ffa57973..00000000 --- a/src/frontend/parquet/diagram_id.jl +++ /dev/null @@ -1,167 +0,0 @@ -""" - abstract type DiagramId end - - The abstract type of all diagrams/subdiagrams/bare propagators -""" -abstract type DiagramId end - -""" - abstract type PropagatorId <: DiagramId end - - The abstract type of all bare propagators -""" -abstract type PropagatorId <: DiagramId end - -# Base.Dict(x::DiagramId) = Dict{Symbol,Any}([fn => getfield(x, fn) for fn ∈ fieldnames(typeof(x))]) -# Base.show(io::IO, d::DiagramId) = error("Base.show not implemented!") -# Base.isequal(a::DiagramId, b::DiagramId) = error("Base.isequal not implemented!") -Base.:(==)(a::DiagramId, b::DiagramId) = Base.isequal(a, b) - -struct BareGreenId <: PropagatorId - para::DiagPara - type::AnalyticProperty #Instant, Dynamic, D_Instant, D_Dynamic - extK::Vector{Float64} - extT::Tuple{Int,Int} #all possible extT from different interactionType - function BareGreenId(para::DiagPara, type::AnalyticProperty=Dynamic; k, t) - return new(para, type, k, Tuple(t)) - end -end -Base.show(io::IO, v::BareGreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)") - -struct BareInteractionId <: PropagatorId # bare W-type interaction, with only one extK - para::DiagPara - response::Response #UpUp, UpDown, ... - type::AnalyticProperty #Instant, Dynamic, D_Instant, D_Dynamic - extK::Vector{Float64} - extT::Tuple{Int,Int} #all possible extT from different interactionType - function BareInteractionId(para::DiagPara, response::Response, type::AnalyticProperty=Instant; k, t=(0, 0)) - return new(para, response, type, 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)") - -struct GenericId <: DiagramId - para::DiagPara - extra::Any - GenericId(para::DiagPara, extra=Nothing) = new(para, extra) -end -Base.show(io::IO, v::GenericId) = print(io, v.extra == Nothing ? "" : "$(v.extra)") - -struct GreenId <: DiagramId - para::DiagPara - type::AnalyticProperty #Instant, Dynamic, D_Instant, D_Dynamic - extK::Vector{Float64} - extT::Tuple{Int,Int} #all possible extT from different interactionType - function GreenId(para::DiagPara, type::AnalyticProperty=Dynamic; k, t) - return new(para, type, k, Tuple(t)) - end -end -Base.show(io::IO, v::GreenId) = print(io, "$(short(v.type)), k$(v.extK), t$(v.extT)") - -struct SigmaId <: DiagramId - para::DiagPara - type::AnalyticProperty #Instant, Dynamic, D_Instant, D_Dynamic - extK::Vector{Float64} - extT::Tuple{Int,Int} #all possible extT from different interactionType - function SigmaId(para::DiagPara, type::AnalyticProperty; k, t=(0, 0)) - return new(para, type, k, t) - end -end -Base.show(io::IO, v::SigmaId) = print(io, "$(short(v.type))#$(v.order), t$(v.extT)") - -struct PolarId <: DiagramId - para::DiagPara - response::Response #UpUp, UpDown, ... - extK::Vector{Float64} - extT::Tuple{Int,Int} #all possible extT from different interactionType - order::Vector{Int} - function PolarId(para::DiagPara, response::Response; k, t=(0, 0)) - return new(para, response, k, t) - end -end -Base.show(io::IO, v::PolarId) = print(io, "$(short(v.response)), k$(v.extK), t$(v.extT)") - -struct Ver3Id <: DiagramId - para::DiagPara - response::Response #UpUp, UpDown, ... - extK::Vector{Vector{Float64}} - extT::Tuple{Int,Int,Int} #all possible extT from different interactionType - function Ver3Id(para::DiagPara, response::Response; k, t=(0, 0, 0)) - return new(para, response, k, Tuple(t)) - end -end -Base.show(io::IO, v::Ver3Id) = print(io, "$(short(v.response)),t$(v.extT)") - -struct Ver4Id <: DiagramId - para::DiagPara - response::Response #UpUp, UpDown, ... - type::AnalyticProperty #Instant, Dynamic, D_Instant, D_Dynamic - channel::TwoBodyChannel # particle-hole, particle-hole exchange, particle-particle, irreducible - extK::Vector{Vector{Float64}} - extT::Tuple{Int,Int,Int,Int} #all possible extT from different interactionType - function Ver4Id(para::DiagPara, response::Response, type::AnalyticProperty=Dynamic; k, t=(0, 0, 0, 0), chan::TwoBodyChannel=AnyChan) - return new(para, response, type, chan, k, Tuple(t)) - end -end -Base.show(io::IO, v::Ver4Id) = print(io, (v.channel == AnyChan ? "" : "$(v.channel) ") * "$(short(v.response))$(short(v.type)),t$(v.extT)") - -function vstr(r, c) - N = length(r) - # cstr(x) = x ? "⁺" : "⁻" - s = "" - for i = 1:N-1 - s *= "$(r[i])$c" - end - s *= "$(r[end])$c" - return s -end - -function vcstr(r, creation) - N = length(r) - # cstr(x) = x ? "⁺" : "⁻" - s = "" - for i = 1:N-1 - if creation[i] - s *= "$(r[i])⁺" - else - s *= "$(r[i])⁻" - end - end - if creation[end] - s *= "$(r[end])⁺" - else - s *= "$(r[end])⁻" - end - return s -end - -function Base.isequal(a::DiagramId, b::DiagramId) - if typeof(a) != typeof(b) - return false - end - for field in fieldnames(typeof(a)) - # field in [:para, :permutation] && continue #both parameter and permutation needs to be compared - # if field == :extK - # if !(getproperty(a, :extK) ≈ getproperty(b, :extK)) && !(getproperty(a, :extK) ≈ -getproperty(b, :extK)) - # return false - # end - # continue - # end - if getproperty(a, field) != getproperty(b, field) - return false - end - end - return true -end - -function index(type) - if type == BareGreenId - return 1 - elseif type == BareInteractionId - return 2 - else - error("Not Implemented!") - end -end - - diff --git a/src/frontend/parquet/green.jl b/src/frontend/parquet/green.jl index 0bab8c62..cec6e786 100644 --- a/src/frontend/parquet/green.jl +++ b/src/frontend/parquet/green.jl @@ -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! ################## @@ -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 diff --git a/src/frontend/parquet/parquet.jl b/src/frontend/parquet/parquet.jl index 88e06060..5a724bfb 100644 --- a/src/frontend/parquet/parquet.jl +++ b/src/frontend/parquet/parquet.jl @@ -3,11 +3,16 @@ module Parquet import ..ComputationalGraphs import ..ComputationalGraphs: Graph import ..ComputationalGraphs: _dtype -import ..ComputationalGraphs: Sum -import ..ComputationalGraphs: Prod +import ..ComputationalGraphs: Sum, Prod # import ..ComputationalGraphs: Power Ftype, Wtype = ComputationalGraphs._dtype.factor, ComputationalGraphs._dtype.weight +import ..FrontEnds: TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan +import ..FrontEnds: Filter, NoBubble, NoHartree, NoFock, DirectOnly, Wirreducible, Girreducible, Proper +import ..FrontEnds: Response, Composite, ChargeCharge, SpinSpin, ProperChargeCharge, ProperSpinSpin, UpUp, UpDown +import ..FrontEnds: AnalyticProperty, Instant, Dynamic +import ..FrontEnds: DiagramId, PropagatorId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId, BareGreenId, BareInteractionId + using StaticArrays, PyCall using AbstractTrees using Parameters, Combinatorics @@ -17,14 +22,12 @@ using DataFrames # @eval Base.Experimental.@optlevel 1 # end - const DI, EX, BOTH = 1, 2, 3 const INL, OUTL, INR, OUTR = 1, 2, 3, 4 # orginal diagrams T, U, S; particle-hole counterterm Ts, Us; and their counterterm Tc, Uc, Sc, Tsc, Usc # symmetry factor for Alli, PHr, PHEr, PPr, PHrc, PHErc const SymFactor = [1.0, -1.0, 1.0, -0.5, +1.0, -1.0] -@enum TwoBodyChannel Alli = 1 PHr PHEr PPr AnyChan @enum Permutation Di = 1 Ex DiEx Base.length(r::TwoBodyChannel) = 1 @@ -47,46 +50,6 @@ Base.length(r::DiagramType) = 1 Base.iterate(r::DiagramType) = (r, nothing) function Base.iterate(r::DiagramType, ::Nothing) end -@enum Filter begin - Wirreducible #remove all polarization subdiagrams - Girreducible #remove all self-energy inseration - NoHartree - NoFock - NoBubble # true to remove all bubble subdiagram - Proper #ver4, ver3, and polarization diagrams may require to be irreducible along the transfer momentum/frequency - DirectOnly # only direct interaction, this can be useful for debug purpose -end - -Base.length(r::Filter) = 1 -Base.iterate(r::Filter) = (r, nothing) -function Base.iterate(r::Filter, ::Nothing) end - -@enum Response begin - Composite - ChargeCharge - SpinSpin - ProperChargeCharge - ProperSpinSpin - UpUp - UpDown -end - -Base.length(r::Response) = 1 -Base.iterate(r::Response) = (r, nothing) -function Base.iterate(r::Response, ::Nothing) end - -@enum AnalyticProperty begin - Instant - Dynamic - D_Instant #derivative of instant interaction - D_Dynamic #derivative of the dynamic interaction -end - -Base.length(r::AnalyticProperty) = 1 -Base.iterate(r::AnalyticProperty) = (r, nothing) -function Base.iterate(r::AnalyticProperty, ::Nothing) end - - struct Interaction response::Response type::Set{AnalyticProperty} @@ -105,43 +68,6 @@ function short(inter::Interaction) return "$(short(inter.response))_$(reduce(*, [short(t) for t in inter.type]))" end -function short(name::Response) - if name == ChargeCharge - return "cc" - elseif name == SpinSpin - return "σσ" - elseif name == UpUp - return "↑↑" - elseif name == UpDown - return "↑↓" - else - @error("$name is not implemented!") - end -end - -function short(type::AnalyticProperty) - if type == Instant - return "Ins" - elseif type == Dynamic - return "Dyn" - elseif type == D_Instant - return "dIns" - elseif type == D_Dynamic - return "dDyn" - else - @error("$type is not implemented!") - end -end - -function symbol(name::Response, type::AnalyticProperty, addition=nothing) - if isnothing(addition) - return Symbol("$(short(name))$(short(type))") - else - return Symbol("$(short(name))$(short(type))$(addition)") - end - -end - """ struct ParquetBlocks @@ -277,7 +203,6 @@ Base.:(==)(a::DiagPara, b::DiagPara) = Base.isequal(a, b) include("common.jl") -include("diagram_id.jl") include("operation.jl") include("filter.jl") @@ -292,17 +217,4 @@ include("ep_coupling.jl") include("benchmark/benchmark.jl") -export DiagPara, ParquetBlocks -export Interaction, interactionTauNum, innerTauNum -export DiagramType, VacuumDiag, SigmaDiag, GreenDiag, PolarDiag, Ver3Diag, Ver4Diag -export Filter, Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly -export Response, Composite, ChargeCharge, SpinSpin, ProperChargeCharge, ProperSpinSpin, UpUp, UpDown -export AnalyticProperty, Instant, Dynamic, D_Instant, D_Dynamic -export TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan -export Permutation, Di, Ex, DiEx -export DiagramId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId -export PropagatorId, BareGreenId, BareInteractionId -# export BareGreenNId, BareHoppingId, GreenNId, ConnectedGreenNId -export mergeby - end \ No newline at end of file diff --git a/src/frontend/parquet/vertex4.jl b/src/frontend/parquet/vertex4.jl index 95a3b8a4..4330144a 100644 --- a/src/frontend/parquet/vertex4.jl +++ b/src/frontend/parquet/vertex4.jl @@ -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 diff --git a/src/frontend/strong_coupling_expansion_builder/common.jl b/src/frontend/strong_coupling_expansion_builder/common.jl index 1581fbda..f31a0a72 100644 --- a/src/frontend/strong_coupling_expansion_builder/common.jl +++ b/src/frontend/strong_coupling_expansion_builder/common.jl @@ -24,8 +24,6 @@ import ..Response import ..Instant import ..Dynamic -import ..D_Instant -import ..D_Dynamic import ..AnalyticProperty import ..symbol diff --git a/test/front_end.jl b/test/front_end.jl index c5dad0d3..a9271852 100644 --- a/test/front_end.jl +++ b/test/front_end.jl @@ -1,3 +1,9 @@ +import FeynmanDiagram.FrontEnds: DiagramId, PropagatorId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId, BareGreenId, BareInteractionId +import FeynmanDiagram.FrontEnds: Response, Composite, ChargeCharge, SpinSpin, UpUp, UpDown +import FeynmanDiagram.FrontEnds: AnalyticProperty, Instant, Dynamic +import FeynmanDiagram.FrontEnds: Filter, NoHartree, NoFock, DirectOnly, Wirreducible, Girreducible, Proper +import FeynmanDiagram.FrontEnds: TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan + @testset "LoopPool" begin loopbasis = [[1.0, 1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0], [1.0, 0.0, -1.0, 0.0]] @@ -64,6 +70,8 @@ end @testset "Parquet" begin using FeynmanDiagram: ComputationalGraphs as Graphs Ftype, Wtype = Graphs._dtype.factor, Graphs._dtype.weight + import FeynmanDiagram.Parquet: DiagramType, VacuumDiag, SigmaDiag, GreenDiag, PolarDiag, Ver3Diag, Ver4Diag + import FeynmanDiagram.Parquet: DiagPara, Interaction, ParquetBlocks, mergeby @testset "Parameter" begin p = DiagPara(type=Ver4Diag, innerLoopNum=1) @@ -186,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 @@ -246,9 +254,9 @@ end t, taylormap = Utility.taylorexpansion!(root, propagator_var) taylorleafmap, taylorleafvec = assign_leaves(root, taylormap) - @test eval!(t.coeffs[[0, 0]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * factor - @test eval!(t.coeffs[[0, 1]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * 2 * factor / Taylor.taylor_factorial([0, 1]) - @test eval!(t.coeffs[[1, 0]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * 2 * factor / Taylor.taylor_factorial([1, 0]) + @test Graphs.eval!(t.coeffs[[0, 0]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * factor + @test Graphs.eval!(t.coeffs[[0, 1]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * 2 * factor / Taylor.taylor_factorial([0, 1]) + @test Graphs.eval!(t.coeffs[[1, 0]], taylorleafmap, taylorleafvec) ≈ (-2 + spin) * 2 * factor / Taylor.taylor_factorial([1, 0]) # #more sophisticated test of the weight evaluation varK = rand(D, Nk) diff --git a/test/runtests.jl b/test/runtests.jl index 22914595..6c1149df 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,7 +40,6 @@ end if isempty(ARGS) include("quantum_operator.jl") include("computational_graph.jl") - # include("diagram_tree.jl") # include("graph_deriv.jl") include("compiler.jl") include("front_end.jl") diff --git a/test/taylor.jl b/test/taylor.jl index d3fc6f13..b7092f25 100644 --- a/test/taylor.jl +++ b/test/taylor.jl @@ -1,6 +1,8 @@ using FeynmanDiagram using FeynmanDiagram: Taylor as Taylor using FeynmanDiagram: ComputationalGraphs as Graphs +import FeynmanDiagram.Parquet: DiagPara +import FeynmanDiagram.FrontEnds: DiagramId, PropagatorId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId, BareGreenId, BareInteractionId function assign_random_numbers(g, taylormap1, taylormap2) #Benchmark taylor expansion generated by two different methods leafmap1 = Dict{Int,Int}() @@ -139,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