Skip to content

Commit

Permalink
merge from computgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
houpc committed Oct 24, 2023
2 parents 145b150 + 9a1cb5f commit 651b735
Show file tree
Hide file tree
Showing 16 changed files with 1,176 additions and 32 deletions.
53 changes: 53 additions & 0 deletions example/taylor_expansion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using FeynmanDiagram
using FeynmanDiagram.Taylor
using FeynmanDiagram.ComputationalGraphs:
eval!, forwardAD, node_derivative, backAD, build_all_leaf_derivative, count_operation
using FeynmanDiagram.Utility:
taylorexpansion!, build_derivative_backAD!
g1 = Graph([])
g2 = Graph([])
g3 = Graph([]) #, factor=2.0)
g4 = Graph([])
g5 = Graph([])
g6 = Graph([])
G3 = g1
G4 = 1.0 * g1 * g1
G5 = 1.0 * (3.0 * G3 + 0.5 * G4)
#G6 = (0.5 * g1 * g2 + 0.5 * g2 * g3)
#G6 = (g1 + g2) * (0.5 * g1 + g3) * g1 # (0.5 * g1 + g3)
#G6 = g1 * g2 * g3 * g4 * g5 * g6
G6 = (1.0 * g1 + 2.0 * g2) * (g1 + g3)
#G6 = 1.5 * g1*g1 + 0.5 * g2 * 1.5 * g1 + 0.5*g2*g3
using FeynmanDiagram.Taylor:
TaylorSeries, getcoeff, set_variables


# set_variables("x y", order=3)
# @time T5 = taylorexpansion!(G5)
# print(T5)
set_variables("x y z a", order=7)
@time T5 = taylorexpansion!(G6)
#order = [0, 0, 0, 0, 0, 0]
#@time print(T5.coeffs[order])
print("$(count_operation(T5.coeffs))\n")
# for (order, coeff) in (T5.coeffs)
# #gs = Compilers.to_julia_str([coeff,], name="eval_graph!")
# #println("$(order) ", gs, "\n")
# print("$(order) $(eval!(coeff)) $(eval!(getcoeff(T5,order))) $(coeff.id) $(count_operation(coeff))\n")
# end

print("TaylorSeries $(T5)\n")

@time T5_compare = build_derivative_backAD!(G6)
print("$(count_operation(T5_compare.coeffs))\n")
for (order, coeff) in (T5_compare.coeffs)
@assert (eval!(coeff)) == (eval!(Taylor.taylor_factorial(order) * T5.coeffs[order]))
# gs = Compilers.to_julia_str([coeff,], name="eval_graph!")
# println("$(order) ", gs, "\n")
# print("$(order) $(eval!(coeff)) $(eval!(getderivative(T5,order))) $(count_operation(coeff))\n")
end





16 changes: 15 additions & 1 deletion 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 @@ -122,6 +125,12 @@ export relabel, standardize_labels, replace_subgraph, merge_linear_combination,

export optimize!, optimize, merge_all_chains!, merge_all_linear_combinations!, remove_duplicated_leaves!

include("TaylorSeries/TaylorSeries.jl")
using .Taylor
export Taylor
export TaylorSeries, set_variables, taylor_factorial, getcoeff


include("backend/compiler.jl")
using .Compilers
export Compilers
Expand Down Expand Up @@ -169,6 +178,10 @@ export addpropagator!, addnode!
export setroot!, addroot!
export evalNaive, showTree

include("utility.jl")
using .Utility
export Utility
export taylorexpansion!
##################### 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 +213,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_order, 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 651b735

Please sign in to comment.