Skip to content

Commit

Permalink
Update docstrings & tests, remove parameters from Graph, remove Stabl…
Browse files Browse the repository at this point in the history
…eGraph.
  • Loading branch information
dcerkoney committed Sep 24, 2023
1 parent 764e478 commit 369b56e
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 385 deletions.
6 changes: 3 additions & 3 deletions src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export ComputationalGraphs
export labelreset, parity
# export AbstractOperator, Prod, Sum

export AbstractGraph, AbstractOperator, BuiltinGraphType
export Graph, StableGraph, FeynmanGraph, FeynmanProperties
export AbstractGraph, AbstractOperator
export Graph, FeynmanGraph, FeynmanProperties, BuiltinGraphType

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

Expand Down
56 changes: 16 additions & 40 deletions src/backend/static.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function _to_static(::Type{ComputationalGraphs.Sum}, subgraphs::Vector{Graph{F,W}}, subgraph_factors::Vector{F}) where {F,W}
if length(subgraphs) == 1
return "(g$(subgraphs[1].id) * $(subgraph_factors[1]))"
else
return "(" * join(["g$(g.id) * $gfactor" for (g, gfactor) in zip(subgraphs, subgraph_factors)], " + ") * ")"
end
end

function _to_static(::Type{ComputationalGraphs.Prod}, subgraphs::Vector{Graph{F,W}}, subgraph_factors::Vector{F}) where {F,W}
if length(subgraphs) == 1
return "(g$(subgraphs[1].id))"
else
return "(" * join(["g$(g.id)" for g in subgraphs], " * ") * ")"
end
end

function _to_static(::Type{ComputationalGraphs.Sum}, subgraphs::Vector{FeynmanGraph{F,W}}, subgraph_factors::Vector{F}) where {F,W}
if length(subgraphs) == 1
return "(g$(subgraphs[1].id) * $(subgraph_factors[1]))"
Expand Down Expand Up @@ -80,46 +96,6 @@ function to_julia_str(graphs::AbstractVector{G}, leafMap::Dict{Int,Int}; root::A
return head * body * tail
end

"""
function to_julia_str(graphs::AbstractVector{FeynmanGraph}, leafMap::Dict{Int,Int}; root::AbstractVector{Int}=[g.id for g in graphs],
leaftypes=[ComputationalGraphs.Propagator, ComputationalGraphs.Interaction], name::String="eval_graph!")
Compile a list of Feynman graphs into a string for a julia static function. The complied function takes two arguments: `root` and `leafVal`.
`root` is a vector of the root node ids of the graphs, and `leafVal` is a vector of the leaf nodes' weights of the graphs.
# Arguments:
- `graphs` (AbstractVector{FeynmanGraph}): The vector object representing the Feynman graphs,
- `leafMap (Dict{Int,Int})`: The mapping dictionary from the id of each leaf to the index of the leaf weight's table `leafVal`.
- `root` (AbstractVector{Int}, optional): The vector of the root node ids of the graphs (defaults to `[g.id for g in graphs]`).
- `leaftypes (optional)`: The set of `DiagramType` for all the relevant leaves to the weight table. It defaults to `[Propagator, Interaction]`.
- `name` (String,optional): The name of the complied function (defaults to `"eval_graph!"`).
"""
function to_julia_str(graphs::AbstractVector{FeynmanGraph}, leafMap::Dict{Int,Int}; root::AbstractVector{Int}=[g.id for g in graphs],
leaftypes=[ComputationalGraphs.Propagator, ComputationalGraphs.Interaction], name::String="eval_graph!")
head = "function $name(root::AbstractVector, leafVal::AbstractVector)\n "
body = ""
for graph in graphs
for g in PostOrderDFS(graph) #leaf first search
if g.id in root
target = "root[$(findfirst(x -> x == g.id, root))]"
else
target = "g$(g.id)"
end
if isempty(g.subgraphs) #leaf
g.name == "compiled" && continue
if g.type in leaftypes
body *= " $target = leafVal[$(leafMap[g.id])]\n "
end
g.name = "compiled"
else
body *= " $target = $(_to_static(g.operator, g.subgraphs, g.subgraph_factors))*$(g.factor)\n "
end
end
end
tail = "end"
return head * body * tail
end

"""
function compile(graphs::AbstractVector{G}; root::AbstractVector{Int}=[g.id for g in graphs]) where {G<:AbstractGraph}
Expand Down
9 changes: 4 additions & 5 deletions src/computational_graph/ComputationalGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ export _dtype
export set_datatype

include("abstractgraph.jl")
export AbstractGraph, AbstractOperator, BuiltinGraphType
export AbstractGraph, AbstractOperator
export unary_istrivial, isassociative, isequiv

include("graph.jl")
include("stablegraph.jl")
include("feynmangraph.jl")
const BuiltinGraphType = Union{Graph,StableGraph,FeynmanGraph}

export Graph, StableGraph, FeynmanGraph, FeynmanProperties
const BuiltinGraphType = Union{Graph,FeynmanGraph}
export Graph, FeynmanGraph, FeynmanProperties, BuiltinGraphType
# export DiagramType

export isequiv, drop_topology, is_external, is_internal, diagram_type, orders, vertices, topology
export hasLeg, external_indices, external_operators, external_labels
export external_legs, external_indices, external_operators, external_labels
export linear_combination, feynman_diagram, propagator, interaction, external_vertex

# export Prod, Sum
Expand Down
Loading

0 comments on commit 369b56e

Please sign in to comment.