Compilers compile computational graphs to optimized source code for diverse platforms
API
FeynmanDiagram.Compilers.compile
— Methodfunction compile(graphs::AbstractVector{<:AbstractGraph}; root::AbstractVector{Int}=[id(g) for g in graphs])
Compile a list of graphs into a julia static function. The function takes two arguments: root
and leaf
. root
is a vector of the root node ids of the graphs, and leaf
is a vector of the leaf node ids of the graphs. This function calls tojuliastr and generate a defined function using RuntimeGeneratedFunctions. Comparing to eval(Meta.parse(tojuliastr(...))), this function does not leak out the function name into global scope.
Example:
factor = 1.5
V1 = [𝑓⁺(1)𝑓⁻(2), 𝑓⁺(3)𝑓⁻(4)]
subgraphs = [external_vertex(V1[1]), external_vertex(V1[2])]
g = FeynmanGraph(subgraphs; factor=factor)
# println(g)
eval_graph! = Compilers.compile([g,])
root = [0.0,]
leaf = [1.0, 2.0]
@assert eval_graph!(root, leaf) ≈ (leaf[1] + leaf[2]) * factor
FeynmanDiagram.Compilers.compile_C
— Methodfunction compile_C(graphs::AbstractVector{<:AbstractGraph}, filename::String;
datatype::DataType=_dtype.weight, root::AbstractVector{Int}=[id(g) for g in graphs], func_name="eval_graph")
Compiles a set of graphs into C language code and append the generated code to a specified file.
Arguments
datatype::DataType
: This type is used for variables types in the generated C code.graphs::AbstractVector{<:AbstractGraph}
: An array of graph objects. These graphs are processed to generate Julia code.filename::String
: The name of the file to which the generated code will be appended. The file is created if it does not exist.root::AbstractVector{Int}
(keyword): An array of integers representing root nodes for each graph ingraphs
. By default, it is an array of IDs obtained by callingid(g)
for each graphg
ingraphs
.func_name::String
(keyword): The base name for the function(s) to be generated. Defaults to"eval_graph"
.
Returns
- A dictionary (
leafmap
) that maps the index of the leaf weight's tableleafVal
to the leaf graph.
FeynmanDiagram.Compilers.compile_Julia
— Methodfunction compile_Julia(graphs::AbstractVector{<:AbstractGraph}, filename::String;
root::AbstractVector{Int}=[id(g) for g in graphs], func_name="eval_graph!")
Compiles a set of graphs into Julia code and append the generated code to a specified file.
Arguments
graphs::AbstractVector{<:AbstractGraph}
: An array of graph objects. These graphs are processed to generate Julia code.filename::String
: The name of the file to which the generated code will be appended. The file is created if it does not exist.root::AbstractVector{Int}
(keyword): An array of integers representing root nodes for each graph ingraphs
. By default, it is an array of IDs obtained by callingid(g)
for each graphg
ingraphs
.func_name::String
(keyword): The base name for the function(s) to be generated. Defaults to"eval_graph!"
.
Returns
- A dictionary (
leafmap
) that maps the index of the leaf weight's tableleafVal
to the leaf graph.
FeynmanDiagram.Compilers.to_dot_str
— Functionfunction to_dot_str(graphs::AbstractVector{<:AbstractGraph}, name::String="")
Compile a list of graphs into a string for dot language.
# Arguments:
- `graphs` vector of computational graphs
- `title` The name of the compiled function (defaults to nothing)
FeynmanDiagram.Compilers.to_julia_str
— Methodfunction to_julia_str(graphs::AbstractVector{<:AbstractGraph}, leafMap::Dict{Int,Int}; root::AbstractVector{Int}=[id(g) for g in graphs],
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{G}): The vector object representing the Feynman graphs,root
(AbstractVector{Int}, optional): The vector of the root node ids of the graphs (defaults to[id(g) for g in graphs]
).name
(String,optional): The name of the complied function (defaults to"eval_graph!"
).
Returns:
- A String representing the compiled Julia function.
leafMap (Dict{Int,G})
: A dictionary that maps the index of the leaf weight's tableleafVal
to the leaf graph.
FeynmanDiagram.Compilers.to_python_str
— Methodfunction to_python_str(graphs::AbstractVector{<:AbstractGraph})
Compile a list of graphs into a string for a python static function and output a python script.
Arguments:
graphs
vector of computational graphs
FeynmanDiagram.Compilers.to_static
— Methodfunction to_static(operator::Type, subgraphs::AbstractVector{<:AbstractGraph}, subgraph_factors::AbstractVector)
Returns the static representation of a computational graph node `g` with operator `operator`, subgraphs `subgraphs`, and subgraph factors `subgraph_factors`.