Skip to content

Commit

Permalink
merge computgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
fsxbhyy committed Oct 30, 2023
2 parents 61e29f4 + 12f821d commit 825edd6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export optimize!, optimize, merge_all_chains!, merge_all_linear_combinations!, r
include("TaylorSeries/TaylorSeries.jl")
using .Taylor
export Taylor
export TaylorSeries, set_variables, taylor_factorial, getcoeff


include("backend/compiler.jl")
Expand Down
10 changes: 5 additions & 5 deletions src/backend/static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function to_static(::Type{ComputationalGraphs.Prod}, subgraphs::Vector{Graph{F,W
end
end

function _to_static(::Type{ComputationalGraphs.Power{N}}, subgraphs::Vector{Graph{F,W}}, subgraph_factors::Vector{F}) where {N,F,W}
function to_static(::Type{ComputationalGraphs.Power{N}}, subgraphs::Vector{Graph{F,W}}, subgraph_factors::Vector{F}) where {N,F,W}
factor_str = subgraph_factors[1] == 1 ? "" : " * $(subgraph_factors[1])"
return "((g$(subgraphs[1].id))^$N$factor_str)"
end

function _to_static(::Type{ComputationalGraphs.Sum}, subgraphs::Vector{FeynmanGraph{F,W}}, subgraph_factors::Vector{F}) where {F,W}
function to_static(::Type{ComputationalGraphs.Sum}, subgraphs::Vector{FeynmanGraph{F,W}}, subgraph_factors::Vector{F}) where {F,W}
if length(subgraphs) == 1
factor_str = subgraph_factors[1] == 1 ? "" : " * $(subgraph_factors[1])"
return "(g$(subgraphs[1].id)$factor_str)"
Expand All @@ -56,7 +56,7 @@ function to_static(::Type{ComputationalGraphs.Prod}, subgraphs::Vector{FeynmanGr
end
end

function _to_static(::Type{ComputationalGraphs.Power{N}}, subgraphs::Vector{FeynmanGraph{F,W}}, subgraph_factors::Vector{F}) where {N,F,W}
function to_static(::Type{ComputationalGraphs.Power{N}}, subgraphs::Vector{FeynmanGraph{F,W}}, subgraph_factors::Vector{F}) where {N,F,W}
factor_str = subgraph_factors[1] == 1 ? "" : " * $(subgraph_factors[1])"
return "((g$(subgraphs[1].id))^$N$factor_str)"
end
Expand Down Expand Up @@ -91,7 +91,7 @@ function to_julia_str(graphs::AbstractVector{<:AbstractGraph}; root::AbstractVec
else
g_id in inds_visitednode && continue
factor_str = factor(g) == 1 ? "" : " * $(factor(g))"
body *= " $target = $(_to_static(operator(g), subgraphs(g), subgraph_factors(g)))$factor_str\n "
body *= " $target = $(to_static(operator(g), subgraphs(g), subgraph_factors(g)))$factor_str\n "
push!(inds_visitednode, g_id)
end
if isroot
Expand Down Expand Up @@ -139,7 +139,7 @@ function to_julia_str(graphs::AbstractVector{<:AbstractGraph}, leafMap::Dict{Int
else
g_id in inds_visitednode && continue
factor_str = factor(g) == 1 ? "" : " * $(factor(g))"
body *= " $target = $(_to_static(operator(g), subgraphs(g), subgraph_factors(g)))$factor_str\n "
body *= " $target = $(to_static(operator(g), subgraphs(g), subgraph_factors(g)))$factor_str\n "
push!(inds_visitednode, g_id)
end
if isroot
Expand Down
4 changes: 1 addition & 3 deletions test/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using FeynmanDiagram: Taylor as Taylor

@testset verbose = true "TaylorSeries" begin
using FeynmanDiagram.Taylor:
getcoeff
getcoeff, set_variables, taylor_factorial
a, b, c, d, e = set_variables("a b c d e", order=[3, 3, 3, 3, 3])
F1 = (a + b) * (a + b) * (a + b)
print("$(F1)")
Expand Down Expand Up @@ -31,8 +31,6 @@ using FeynmanDiagram: Taylor as Taylor
G4 = 1.0 * g1 * g1
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 z", order=[2, 3, 2])
for G in [G3, G4, G5, G6]
Expand Down

0 comments on commit 825edd6

Please sign in to comment.