Skip to content

Commit

Permalink
remove diagram_orders in TaylorAD
Browse files Browse the repository at this point in the history
  • Loading branch information
houpc committed Feb 13, 2024
1 parent 2517e39 commit 77de7bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ The example code below demonstrates how to build the renormalized Feynman diagra
```julia
# Set the renormalization orders. The first element is the order of the Green's function counterterms, and the second element is the order of the interaction counterterms.
julia> renormalization_orders = [2, 3];
julia> perturbative_orders = [para.innerLoopNum, para.innerLoopNum]; # each corresponding to the Feynman diagram's perturbative order of graphs.

# Generate the Dict of Graph for the renormalized self-energy diagrams with the Green's function counterterms and the interaction counterterms.
julia> dict_sigma = taylorAD(sigmadf.diagram, perturbative_orders, renormalization_orders);
julia> dict_sigma = taylorAD(sigmadf.diagram, renormalization_orders);
```
### Example: Compile Feynman diagrams to different programming languages
Expand Down
25 changes: 11 additions & 14 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,39 @@ export taylorAD
@inline apply(::Type{ComputationalGraphs.Power{N}}, diags::Vector{T}, factors::Vector{F}) where {N,T<:TaylorSeries,F<:Number} = (diags[1])^N * factors[1]

"""
function taylorAD(graphs::Vector{G}, diagram_orders::Vector{Int}, deriv_orders::Vector{Int},
function taylorAD(graphs::Vector{G}, deriv_orders::Vector{Int},
leaf_dep_funcs::Vector{Function}=[pr -> pr isa BareGreenId, pr -> pr isa BareInteractionId];
dict_graphs::Dict{Vector{Int},Vector{Graph}}=Dict{Vector{Int},Vector{Graph}}()
) where {G<:Graph}
Performs Taylor-mode automatic differentiation (AD) on a vector of graphs, with the differentiation process tailored based on specified derivative orders,
and leaf dependency functions. It categorizes the differentiated graphs in a dictionary based on their diagram and derivative orders.
and leaf dependency functions. It categorizes the differentiated graphs in a dictionary based on their derivative orders.
# Parameters
- `graphs`: A vector of graphs to be differentiated.
- `diagram_orders`: A vector of integers, each corresponding to the diagram order of the graph at the same index in `graphs`.
- `deriv_orders`: A vector of integers specifying the orders of differentiation to apply to the graphs.
- `leaf_dep_funcs`: Optional. A vector of functions determining the dependency of differentiation variables on the properties of leaves in the graphs.
Defaults to functions identifying BareGreenId and BareInteractionId properties.
- `dict_graphs`: Optional. A dictionary for storing the output graphs, keyed by vectors of integers representing the diagram order followed by specific differentiation orders. Defaults to an empty dictionary.
- `dict_graphs`: Optional. A dictionary for storing the output graphs, keyed by vectors of integers representing the specific differentiation orders. Defaults to an empty dictionary.
# Returns
- `Dict{Vector{Int},Vector{Graph}}`: A dictionary containing the graphs processed through Taylor-mode AD, categorized by their diagram and differentiation orders.
- `Dict{Vector{Int},Vector{Graph}}`: A dictionary containing the graphs processed through Taylor-mode AD, categorized by their differentiation orders.
# Example Usage
```julia
# Define a vector of graphs and their corresponding diagram orders
graphs = [g1, g2]
diagram_orders = [1, 2]
deriv_orders = [2, 3, 3]
leaf_dep_funcs = [pr -> pr isa BareGreenId, pr -> pr isa BareInteractionId, pr -> pr.extK[1] != 0]
# Perform Taylor-mode AD and categorize the results
result_dict = taylorAD(graphs, diagram_orders, deriv_orders, leaf_dep_funcs)
result_dict = taylorAD(graphs, deriv_orders, leaf_dep_funcs)
```
"""
function taylorAD(graphs::Vector{G}, diagram_orders::Vector{Int}, deriv_orders::Vector{Int},
function taylorAD(graphs::Vector{G}, deriv_orders::Vector{Int},
leaf_dep_funcs::Vector{Function}=[pr -> pr isa BareGreenId, pr -> pr isa BareInteractionId];
dict_graphs::Dict{Vector{Int},Vector{Graph}}=Dict{Vector{Int},Vector{Graph}}()
) where {G<:Graph}
@assert length(graphs) == length(diagram_orders) "Lengths of graphs and diagram_orders must be equal."
@assert length(deriv_orders) == length(leaf_dep_funcs) "Lengths of deriv_orders and properties_deps must be equal."

charset = 'a':'z'
Expand Down Expand Up @@ -83,12 +80,12 @@ function taylorAD(graphs::Vector{G}, diagram_orders::Vector{Int}, deriv_orders::
taylor_series_vec, taylormap = taylorexpansion!(graphs, var_dependence)

for (idx, taylor_series) in enumerate(taylor_series_vec)
for (o, graph) in taylor_series.coeffs
key = [diagram_orders[idx]; o]
if haskey(dict_graphs, key)
push!(dict_graphs[key], graph)
for (orders, graph) in taylor_series.coeffs
# key = [diagram_orders[idx]; o]
if haskey(dict_graphs, orders)
push!(dict_graphs[orders], graph)
else
dict_graphs[key] = [graph,]
dict_graphs[orders] = [graph,]
end
end
end
Expand Down

0 comments on commit 77de7bb

Please sign in to comment.