Skip to content

Commit

Permalink
Add Base.:* conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dcerkoney committed Oct 25, 2023
1 parent 91e447f commit f39bf22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/computational_graph/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ linear_combination(graphs::Vector{Union{Graph{F,W},FeynmanGraph{F,W}}}, constant
multi_product(g1::Graph{F,W}, g2::FeynmanGraph{F,W}, c1=F(1), c2=F(1)) where {F,W} = multi_product(Base.promote(g1, g2)..., c1, c2)
multi_product(g1::FeynmanGraph{F,W}, g2::Graph{F,W}, c1=F(1), c2=F(1)) where {F,W} = multi_product(Base.promote(g1, g2)..., c1, c2)
multi_product(graphs::Vector{Union{Graph{F,W},FeynmanGraph{F,W}}}, constants::AbstractVector=ones(F, length(graphs))) where {F,W} = multi_product(Base.promote(graphs)..., constants)
Base.:*(g1::Graph, g2::FeynmanGraph) = error("Multiplication of Feynman graphs is not well defined!")
Base.:*(g1::FeynmanGraph, g2::Graph) = error("Multiplication of Feynman graphs is not well defined!")
Base.:*(g1::Graph{F,W}, g2::FeynmanGraph{F,W}) where {F,W} = Base.:*(Base.promote(g1, g2)...)
Base.:*(g1::FeynmanGraph{F,W}, g2::Graph{F,W}) where {F,W} = Base.:*(Base.promote(g1, g2)...)
Base.:+(g1::Graph{F,W}, g2::FeynmanGraph{F,W}) where {F,W} = Base.:+(Base.promote(g1, g2)...)
Base.:+(g1::FeynmanGraph{F,W}, g2::Graph{F,W}) where {F,W} = Base.:+(Base.promote(g1, g2)...)
Base.:-(g1::Graph{F,W}, g2::FeynmanGraph{F,W}) where {F,W} = Base.:-(Base.promote(g1, g2)...)
Expand Down
9 changes: 5 additions & 4 deletions test/computational_graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -877,23 +877,24 @@ end
l5 = linear_combination([g_feyn, g, g1, g2], [2, 5, 3, 9])
l6 = multi_product(g_feyn, g1, 2, 3)
l7 = multi_product(g_feyn, g, 2, 3)
r7 = multi_product(g_feyn, g, 2, 3)
l8 = multi_product([g_feyn, g, g1, g2], [2, 5, 3, 9])
r7 = multi_product(g, g, 2, 3)
r8 = multi_product([g, g, g1, g2], [2, 5, 3, 9])
catch
conversion_successful = false
end
@test conversion_successful
Graphs.optimize!([l1, l2, l3, l4, l5, l6, l7, r7, l8, r8]) # cache unique leaves

Graphs.optimize!([l1, l2, l3, l4, l5, l6, l7, r7, l8, r8]) # cache unique leaves
@test isequiv(l1, g + g1, :id)
@test isequiv(l2, g - g1, :id)
@test isequiv(l3, 2 * g + 3 * g1, :id)
@test isequiv(l4, linear_combination([g], [5]), :id)
@test isequiv(l5, linear_combination([g, g1, g2], [7, 3, 9]), :id)
@test isequiv(l6, multi_product(g, g1, 2, 3), :id)

# TODO: Refine multiple Prod -> Power conversion

# NOTE: convert(Graphs.Graph, g_feyn) and g have different IDs, so they aren't merged by multi_product.
# We need to add an in-place Power optimization to optimize! to fix this.
@test_broken isequiv(l7, r7, :id)
@test_broken isequiv(l8, r8, :id)

Expand Down

0 comments on commit f39bf22

Please sign in to comment.