Skip to content

Commit

Permalink
Merge pull request #160 from numericalEFT/computgraph
Browse files Browse the repository at this point in the history
Computgraph
  • Loading branch information
houpc authored Nov 30, 2023
2 parents 418f8f5 + 27bdeee commit 0dfdc9d
Show file tree
Hide file tree
Showing 134 changed files with 325,585 additions and 14,785 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
version:
- "1.6"
# - "1.6"
# - "nightly"
- "1.9"
os:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ DataFrames = "1.6"
Lehmann = "0.2"
Parameters = "0.12"
PyCall = "1"
StaticArrays = "1"
RuntimeGeneratedFunctions = "0.5"
SnoopPrecompile = "1, 2"
StaticArrays = "1"
julia = "1.6"

[extras]
Expand Down
43 changes: 43 additions & 0 deletions example/benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using FeynmanDiagram
using FeynmanDiagram.Taylor
using FeynmanDiagram.ComputationalGraphs:
eval!, Leaves
using FeynmanDiagram.Utility:
taylorexpansion!, count_operation


function assign_leaves(g::FeynmanGraph, taylormap)
leafmap = Dict{Int,Int}()
leafvec = Vector{Float64}()
idx = 0
for leaf in Leaves(g)
taylor = taylormap[leaf.id]
for (order, coeff) in taylor.coeffs
idx += 1
push!(leafvec, 1.0 / taylor_factorial(order))
leafmap[coeff.id] = idx
print("assign $(order) $(coeff.id) $(taylor_factorial(order)) $(leafvec[idx])\n")
end
end
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, lp, leafmap = diagdictGV(:sigma, [(3, 0, 0), (3, 0, 3), (3, 0, 2), (3, 0, 1)])
g = dict_g[(3, 0, 0)]

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, 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

56 changes: 56 additions & 0 deletions example/taylor_expansion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using FeynmanDiagram
using FeynmanDiagram.Taylor
using FeynmanDiagram.ComputationalGraphs:
eval!, forwardAD, node_derivative, backAD, build_all_leaf_derivative
using FeynmanDiagram.Utility:
taylorexpansion!, build_derivative_backAD!, count_operation

function benchmark_AD(glist::Vector{T}) where {T<:Graph}
#taylormap = Dict{Int,TaylorSeries{T}}()
totaloperation = [0, 0]
taylorlist = Vector{TaylorSeries{T}}()
for g in glist
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, leaftaylor = build_derivative_backAD!(g)
for (order, coeff) in (t_compare.coeffs)
@assert (eval!(coeff)) == (eval!(Taylor.taylor_factorial(order) * t.coeffs[order]))
end
end

total_uniqueoperation = count_operation(taylorlist)
print(" total operation number: $(length(taylorlist)) $(totaloperation) $(total_uniqueoperation)\n")
return total_uniqueoperation
end
g1 = Graph([])
g2 = Graph([])
g3 = Graph([]) #, factor=2.0)
g4 = Graph([])
g5 = Graph([])
g6 = Graph([])
G3 = g1
G4 = 1.0 * g1 * g2
G5 = 1.0 * (3.0 * G3 + 0.5 * G4)
G6 = (1.0 * g1 + 2.0 * g2) * (g1 + g3)

using FeynmanDiagram.Taylor:
TaylorSeries, getcoeff, set_variables

set_variables("x y", orders=[3, 2])

benchmark_AD([G3, G4, G5, G6])






47 changes: 32 additions & 15 deletions src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export fermionic_annihilation, fermionic_creation, majorana
export bosonic_annihilation, bosonic_creation, real_classic
export correlator_order, normal_order




include("computational_graph/ComputationalGraph.jl")
using .ComputationalGraphs
export ComputationalGraphs
Expand All @@ -109,34 +112,28 @@ export Graph, FeynmanGraph, FeynmanProperties

export isequiv, drop_topology, is_external, is_internal, diagram_type, orders, vertices, topology
export external_legs, external_indices, external_operators, external_labels
export linear_combination, feynman_diagram, propagator, interaction, external_vertex
export multi_product, linear_combination, feynman_diagram, propagator, interaction, external_vertex
# export DiagramType, Interaction, ExternalVertex, Propagator, SelfEnergy, VertexDiag, GreenDiag, GenericDiag

# export standardize_order!
# export reducibility, connectivity
# export 𝐺ᶠ, 𝐺ᵇ, 𝐺ᵠ, 𝑊, Green2, Interaction
# export Coupling_yukawa, Coupling_phi3, Coupling_phi4, Coupling_phi6
export haschildren, onechild, isleaf, isbranch, ischain, isfactorless, eldest
export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_chains!
export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_chains
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 optimize!, optimize, merge_all_chains!, merge_all_linear_combinations!, remove_duplicated_leaves!

include("TaylorSeries/TaylorSeries.jl")
using .Taylor
export Taylor


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 All @@ -150,6 +147,7 @@ export PropagatorId, BareGreenId, BareInteractionId
export BareGreenNId, BareHoppingId, GreenNId, ConnectedGreenNId
export uidreset, toDataFrame, mergeby, plot_tree


include("parquet_builder/parquet.jl")
using .Parquet
export Parquet
Expand All @@ -169,6 +167,24 @@ export addpropagator!, addnode!
export setroot!, addroot!
export evalNaive, showTree



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

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

include("utility.jl")
using .Utility
export Utility
export taylorexpansion!
# 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 Expand Up @@ -200,4 +216,5 @@ if ccall(:jl_generating_output, Cint, ()) == 1 # if we're precompiling the pac
end
end

end

end
29 changes: 29 additions & 0 deletions src/TaylorSeries/TaylorSeries.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
TaylorSeries
A Julia package for Taylor expansions in one or more independent variables.
The basic constructors is [`TaylorSeries`](@ref).
"""
module Taylor

using ..ComputationalGraphs
#using Markdown


#export show_params_TaylorN, show_monomials, displayBigO, use_show_default,

include("parameter.jl")
include("constructors.jl")
include("print.jl")
include("arithmetic.jl")
export TaylorSeries

export get_orders, get_numvars,
set_variables, get_variables,
get_variable_names, get_variable_symbols,
displayBigO, use_show_default,
getcoeff, taylor_factorial

end # module
Loading

0 comments on commit 0dfdc9d

Please sign in to comment.