Skip to content

Commit

Permalink
add a DiagTree to Graph transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyuan committed Oct 30, 2023
1 parent a7e6573 commit 7431767
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ include("backend/compiler.jl")
using .Compilers
export Compilers

include("frontend/frontends.jl")
using .FrontEnds
export FrontEnds
export LabelProduct

include("frontend/GV.jl")
using .GV
export GV
export diagdictGV, leafstates
# export read_onediagram, read_diagrams

include("diagram_tree/DiagTree.jl")
using .DiagTree
export DiagTree
Expand Down Expand Up @@ -181,6 +170,18 @@ include("utility.jl")
using .Utility
export Utility
export taylorexpansion!

include("frontend/frontends.jl")
using .FrontEnds
export FrontEnds
export LabelProduct

include("frontend/GV.jl")
using .GV
export GV
export diagdictGV, leafstates
# export read_onediagram, read_diagrams

##################### precompile #######################
# precompile as the final step of the module definition:
if ccall(:jl_generating_output, Cint, ()) == 1 # if we're precompiling the package
Expand Down
58 changes: 58 additions & 0 deletions src/frontend/diagtree.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
function Graph!(d::DiagTree.Diagram{W}; map=Dict{Int,DiagTree.DiagramId}()) where {W}
Converts a DiagTree `d` into a Graph, storing the diagram information (which is a DiagramId object) in a Graph.id to DiagramId dictionary ``map".
# Arguments:
- `d`: DiagTree.Diagram object.
- `map`: map between the Graph.id and DiagramId. It will be updated with the new nodes and leaves contained in the DiagTree.Diagram `d`.
# Example:
```julia-repl
julia> para = DiagParaF64(type = Ver4Diag, innerLoopNum=2);
julia> ver4=Parquet.build(para)
2×5 DataFrame
Row │ diagram extT hash response type
│ Diagram… Tuple… Int64 Response Analytic…
─────┼─────────────────────────────────────────────────────────────────────────────
1 │ 5978:↑↑Dyn#[0, 0, 0, 0],t(1, 1, … (1, 1, 1, 1) 5978 UpUp Dynamic
2 │ 5979:↑↓Dyn#[0, 0, 0, 0],t(1, 1, … (1, 1, 1, 1) 5979 UpDown Dynamic
julia> d = ver4.diagram[1] # take the first diagram
5978:↑↑Dyn#[0, 0, 0, 0],t(1, 1, 1, 1)=0.0=⨁ (5026, 5071, 5137, 5146, 5175, 5220, 5312, 5321, 5350, 5396, 5463, 5473, 5503, 5549, 5642, 5652, 5682, 5793, 5831, 5968)
julia> root = FrontEnds.Graph!(d)
```
"""
function Graph!(d::DiagTree.Diagram{W}; map=Dict{Int,DiagTree.DiagramId}()) where {W}

function op(o)
if o isa DiagTree.Sum
return ComputationalGraphs.Sum()
elseif o isa DiagTree.Prod
return ComputationalGraphs.Prod()
else
error("Unknown operator: $o")
end
end

subgraph = ComputationalGraphs.Graph{W,W}[]
for g in d.subdiagram
res, map = Graph!(g; map=map)
push!(subgraph, res)
end

tree = ComputationalGraphs.Graph(subgraph; subgraph_factors=ones(W, length(d.subdiagram)), name=String(d.name), operator=op(d.operator), orders=d.id.order, ftype=W, wtype=W, weight=d.weight)

root = ComputationalGraphs.Graph([tree,]; subgraph_factors=[d.factor,], name=tree.name, orders=tree.orders, ftype=W, wtype=W, weight=d.weight * d.factor)

@assert haskey(map, root.id) == false "DiagramId already exists in map: $(root.id)"
@assert haskey(map, tree.id) == false "DiagramId already exists in map: $(tree.id)"
map[root.id] = d.id
map[tree.id] = d.id

return root, map
end
7 changes: 7 additions & 0 deletions src/frontend/frontends.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module FrontEnds

import ..ComputationalGraphs
using LinearAlgebra
import ..QuantumOperators as Op
import ..ComputationalGraphs as IR
import ..ComputationalGraphs: FeynmanGraph
# import ..ComputationalGraphs: Graph
import ..ComputationalGraphs: _dtype

using ..DiagTree


include("pool.jl")
export LoopPool

Expand All @@ -16,4 +21,6 @@ include("parquet.jl")
using .Parquet
# export Parquet

include("diagtree.jl")

end

0 comments on commit 7431767

Please sign in to comment.