Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_taylorcoeff_map #157

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions example/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ function assign_leaves(g::FeynmanGraph, taylormap)
return leafmap, leafvec
end

dict_g, fl, bl, leafmap = diagdictGV(:sigma, [(2, 0, 0), (2, 0, 1), (2, 0, 2), (2, 1, 0), (2, 1, 1), (2, 2, 0), (2, 1, 2), (2, 2, 2)], 3)
#dict_g, fl, bl, leafmap = diagdictGV(:sigma, [(2, 0, 0), (2, 0, 1), (2, 0, 2), (2, 1, 0), (2, 1, 1), (2, 2, 0), (2, 1, 2), (2, 2, 2)], 3)
dict_g, lp, leafmap = diagdictGV(:sigma, [(3, 0, 0), (3, 0, 3), (3, 0, 2), (3, 0, 1)])
g = dict_g[(3, 0, 0)]

g = dict_g[(2, 0, 0)]

set_variables("x y", orders=[2, 2])
set_variables("x y", orders=[1, 3])
propagator_var = ([true, false], [false, true]) # Specify variable dependence of fermi (first element) and bose (second element) particles.
t, taylormap = taylorexpansion!(g[1][1], propagator_var, (fl, bl))
t, taylormap, from_coeff_map = taylorexpansion!(g[1][1], propagator_var)

for (order, graph) in dict_g
if graph[2][1] == g[2][1]
idx = 1
else
idx = 2
end
print("$(count_operation(t.coeffs[[order[2],order[3]]]))\n")
print("$(count_operation(graph[1][idx]))\n")
print("$(order) $(eval!(graph[1][idx])) $(eval!(t.coeffs[[order[2],order[3]]]))\n")
end

10 changes: 7 additions & 3 deletions example/taylor_expansion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ using FeynmanDiagram.Utility:
taylorexpansion!, build_derivative_backAD!, count_operation

function benchmark_AD(glist::Vector{T}) where {T<:Graph}
taylormap = Dict{Int,TaylorSeries{T}}()
#taylormap = Dict{Int,TaylorSeries{T}}()
totaloperation = [0, 0]
taylorlist = Vector{TaylorSeries{T}}()
for g in glist
@time t, taylormap = taylorexpansion!(g; taylormap=taylormap)
var_dependence = Dict{Int,Vector{Bool}}()
for leaf in FeynmanDiagram.Leaves(g)
var_dependence[leaf.id] = [true for _ in 1:get_numvars()]
end
@time t, taylormap, from_coeff_map = taylorexpansion!(g, var_dependence)


operation = count_operation(t)
totaloperation = totaloperation + operation
push!(taylorlist, t)
print("operation number: $(operation)\n")
t_compare = build_derivative_backAD!(g)
t_compare, leaftaylor = build_derivative_backAD!(g)
for (order, coeff) in (t_compare.coeffs)
@assert (eval!(coeff)) == (eval!(Taylor.taylor_factorial(order) * t.coeffs[order]))
end
Expand Down
6 changes: 3 additions & 3 deletions src/computational_graph/tree_properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ end
# Arguments:
- `g::Graph`: graph for which to find the total number of operations.
"""
function count_operation(g::Graph)
function count_operation(g::G) where {G<:AbstractGraph}
totalsum = 0
totalprod = 0
for node in PreOrderDFS(g)
Expand All @@ -134,7 +134,7 @@ function count_operation(g::Graph)
return [totalsum, totalprod]
end

function count_operation(g::Array{G}) where {G<:Graph}
function count_operation(g::Vector{G}) where {G<:AbstractGraph}
visited = Set{Int}()
totalsum = 0
totalprod = 0
Expand All @@ -156,7 +156,7 @@ function count_operation(g::Array{G}) where {G<:Graph}
end


function count_operation(g::Dict{Vector{Int},G}) where {G<:Graph}
function count_operation(g::Dict{Vector{Int},G}) where {G<:AbstractGraph}
visited = Set{Int}()
totalsum = 0
totalprod = 0
Expand Down
37 changes: 37 additions & 0 deletions src/diagram_tree/tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,40 @@ AbstractTrees.nodetype(::Diagram{W}) where {W} = Diagram{W}
# (They are not sufficient to solve all internal inference issues, however.)
Base.eltype(::Type{<:TreeIterator{Diagram{W}}}) where {W} = Diagram{W}
Base.IteratorEltype(::Type{<:TreeIterator{Diagram{W}}}) where {W} = Base.HasEltype()

function count_operation(g::T) where {T<:Diagram}
totalsum = 0
totalprod = 0
for node in PreOrderDFS(g)
#print(node.hash)
if length(node.subdiagram) > 0
if node.operator isa Prod
totalprod += length(node.subdiagram) - 1
elseif node.operator isa Sum
totalsum += length(node.subdiagram) - 1
end
end
end
return [totalsum, totalprod]
end

function count_operation(g::Vector{T}) where {T<:Diagram}
visited = Set{Int}()
totalsum = 0
totalprod = 0
for graph in g
for node in PreOrderDFS(graph)
if !(node.hash in visited)
push!(visited, node.hash)
if length(node.subdiagram) > 0
if node.operator isa Prod
totalprod += length(node.subdiagram) - 1
elseif node.operator isa Sum
totalsum += length(node.subdiagram) - 1
end
end
end
end
end
return [totalsum, totalprod]
end
Loading
Loading