Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TaylorAD() in Utility and update README #178

Merged
merged 22 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ __pycache__
*.vscode

# Temporarily unignore vscode settings
!.vscode/
.vscode/

*.DS_Store
*.pb.gz
Expand Down
7 changes: 0 additions & 7 deletions .vscode/settings.json

This file was deleted.

134 changes: 108 additions & 26 deletions README.md

Large diffs are not rendered by default.

557 changes: 554 additions & 3 deletions assets/diagram_compiler.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,363 changes: 3,363 additions & 0 deletions assets/sigmaDyn_ete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,489 changes: 1,489 additions & 0 deletions assets/sigmaIns_ete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
430 changes: 430 additions & 0 deletions assets/sigma_o2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/ver4tree.png
Binary file not shown.
1 change: 0 additions & 1 deletion example/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function main()
MaxLoopNum = 7
Random.seed!(randseed)

# FeynGraphs = diagdict_parquet(:vertex4, partition)
ver4df = Parquet.vertex4(para)
diags = ver4df.diagram
IR.optimize!(diags)
Expand Down
4 changes: 1 addition & 3 deletions example/benchmark_GV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ function main()
MaxLoopNum = 7
Random.seed!(randseed)

# FeynGraphs = diagdict_parquet(:vertex4, partition)
# ver4df = Parquet.vertex4(para)
diags, extT, responses = GV.eachorder_ver4diag(4)
diags = GV.diagsGV_ver4(4)

# diags = ver4df.diagram
IR.optimize!(diags)
Expand Down
17 changes: 9 additions & 8 deletions src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export labelreset, parity

export AbstractGraph, AbstractOperator
export Graph, FeynmanGraph, FeynmanProperties
export plot_tree

export isequiv, drop_topology, is_external, is_internal, diagram_type, orders, vertices, topology
export external_legs, external_indices, external_operators, external_labels
Expand All @@ -39,20 +40,20 @@ include("TaylorSeries/TaylorSeries.jl")
using .Taylor
export Taylor

include("utility.jl")
using .Utility
export Utility
export taylorexpansion!

include("frontend/frontends.jl")
using .FrontEnds
export FrontEnds
export LabelProduct
export LabelProduct, leafstates
export Filter, Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly
using .GV
export GV, diagdictGV, diagdictGV_ver4, leafstates
export GV
using .Parquet
export Parquet, diagdict_parquet, diagdict_parquet_extraAD
export Parquet

include("utility.jl")
using .Utility
export Utility
export taylorAD

include("backend/compiler.jl")
using .Compilers
Expand Down
18 changes: 9 additions & 9 deletions src/backend/compiler_python.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
function to_pystatic(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` in python.
Returns the static representation of a computational graph node `g` with operator `operator`, subgraphs `subgraphs`, and subgraph factors `subgraph_factors` in python.
"""
function to_pystatic(operator::Type, subgraphs::AbstractVector{<:AbstractGraph}, subgraph_factors::AbstractVector)
error(
Expand Down Expand Up @@ -65,11 +65,12 @@ end

"""
function to_python_str(graphs::AbstractVector{<:AbstractGraph})

Compile a list of graphs into a string for a python static function and output a python script which support the mindspore and jax framework.

# Arguments:
- `graphs` vector of computational graphs
- `framework` the type of the python frameworks, including `:jax` and `mindspore`.
# Arguments:
- `graphs` vector of computational graphs
- `framework` the type of the python frameworks, including `:jax` and `mindspore`.
"""
function to_python_str(graphs::AbstractVector{<:AbstractGraph}, framework::Symbol=:jax)
if framework == :jax
Expand Down Expand Up @@ -121,13 +122,12 @@ function to_python_str(graphs::AbstractVector{<:AbstractGraph}, framework::Symbo
end
expr = head * body * tail

return expr, leafidx, gid_to_leafid
return expr, gid_to_leafid
end
function compile_python(graphs::AbstractVector{<:AbstractGraph}, framework::Symbol=:jax, filename::String="GraphFunc.py")
py_string, leafnum, leafmap = to_python_str(graphs, framework)
println("The number of leaves: $leafnum")
function compile_Python(graphs::AbstractVector{<:AbstractGraph}, framework::Symbol=:jax, filename::String="GraphFunc.py")
py_string, leafmap = to_python_str(graphs, framework)
open(filename, "w") do f
write(f, py_string)
end
return leafnum, leafmap
return leafmap
end
2 changes: 1 addition & 1 deletion src/computational_graph/ComputationalGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export haschildren, onechild, isleaf, isbranch, ischain, has_zero_subfactors, el

include("operation.jl")
include("io.jl")
# plot_tree
export plot_tree

include("eval.jl")
export eval!
Expand Down
11 changes: 5 additions & 6 deletions src/computational_graph/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ end

function _stringrep(graph::AbstractGraph, color=true)
idstr = _idstring(graph)
# fstr = short(factor(graph), one(factor(graph)))
properties = graph.properties
wstr = short(weight(graph))
ostr = short_orders(orders(graph))
# =$(node.weight*(2π)^(3*node.id.para.innerLoopNum))

if length(subgraphs(graph)) == 0
# return isempty(fstr) ? "$(idstr)$(ostr)=$wstr" : "$(idstr)⋅$(fstr)=$wstr"
return "$(idstr)$(ostr)=$wstr"
if isleaf(graph)
return isnothing(properties) ? "$(idstr)$(ostr)=$wstr" : "$(idstr)$(properties)$(ostr)=$wstr"
else
return "$(idstr)$(ostr)=$wstr=$(operator(graph)) "
return isnothing(properties) ? "$(idstr)$(ostr)=$wstr=$(operator(graph)) " : "$(idstr)$(properties)$(ostr)=$wstr=$(operator(graph)) "
end
end

Expand All @@ -59,7 +58,7 @@ end
Write a text representation of an AbstractGraph `graph` to the output stream `io`.
"""
function Base.show(io::IO, graph::AbstractGraph; kwargs...)
if length(subgraphs(graph)) == 0
if isleaf(graph) == 0
typestr = ""
else
typestr = join(["$(id(g))" for g in subgraphs(graph)], ",")
Expand Down
Loading
Loading