From d4e952e1de2a536ab293e7cf0f273b7577dbc026 Mon Sep 17 00:00:00 2001 From: houpc Date: Fri, 16 Feb 2024 12:54:43 +0800 Subject: [PATCH] improve docs and readme --- README.md | 19 +++++++++++++------ src/utility.jl | 10 +++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 86991a36..59655e10 100644 --- a/README.md +++ b/README.md @@ -76,14 +76,21 @@ julia> optimize!(sigmadf.diagram); The example code below demonstrates how to build the renormalized Feynman diagrams for the self-energy with the Green's function counterterms and the interaction counterterms using Taylor-mode AD. ```julia -# Set the renormalization orders. The first element is the order of the Green's function counterterms, and the second element is the order of the interaction counterterms. -julia> renormalization_orders = [2, 3]; +# Set the renormalization orders. The first element is the maximum order of the Green's function counterterms, and the second element is the maximum order of the interaction counterterms. +julia> renormalization_orders = [2, 1]; # Define functions that determine how the differentiation variables depend on the properties of the leaves in your graphs, identifying `BareGreenId` and `BareInteractionId` properties as the Green's function and interaction counterterms, respectively. julia> leaf_dep_funcs = [pr -> pr isa FrontEnds.BareGreenId, pr -> pr isa FrontEnds.BareInteractionId]; # Generate the Dict of Graph for the renormalized self-energy diagrams with the Green's function counterterms and the interaction counterterms. -julia> dict_sigma = taylorAD(sigmadf.diagram, renormalization_orders, leaf_dep_funcs); +julia> dict_sigma = taylorAD(sigmadf.diagram, renormalization_orders, leaf_dep_funcs) +Dict{Vector{Int64}, Vector{Graph}} with 6 entries: + [0, 0] => [18822Ins, k[1.0, 0.0, 0.0], t(1, 1)=0.0=Ⓧ , 19019Dyn, k[1.0, 0.0, 0.0], t(1, 2)=0.0=⨁ ] + [2, 1] => [18823Ins, k[1.0, 0.0, 0.0], t(1, 1)[2, 1]=0.0=Ⓧ , 19020Dyn, k[1.0, 0.0, 0.0], t(1, 2)[2, 1]=0.0=⨁ ] + [2, 0] => [18824Ins, k[1.0, 0.0, 0.0], t(1, 1)[2]=0.0=Ⓧ , 19021Dyn, k[1.0, 0.0, 0.0], t(1, 2)[2]=0.0=⨁ ] + [1, 1] => [18825Ins, k[1.0, 0.0, 0.0], t(1, 1)[1, 1]=0.0=Ⓧ , 19022Dyn, k[1.0, 0.0, 0.0], t(1, 2)[1, 1]=0.0=⨁ ] + [1, 0] => [18826Ins, k[1.0, 0.0, 0.0], t(1, 1)[1]=0.0=Ⓧ , 19023Dyn, k[1.0, 0.0, 0.0], t(1, 2)[1]=0.0=⨁ ] + [0, 1] => [18827Ins, k[1.0, 0.0, 0.0], t(1, 1)[0, 1]=0.0=Ⓧ , 19024Dyn, k[1.0, 0.0, 0.0], t(1, 2)[0, 1]=0.0=⨁ ] ``` ### Example: Compile Feynman diagrams to different programming languages @@ -108,14 +115,14 @@ julia> Compilers.compile_Python(g_o21, :jax, "func_o21.py"); ``` ### Computational Graph visualization -#### Tree-type visualization using ETE -To visualize tree-type structures of the self-energy in the Parquet example, install the [ete3](http://etetoolkit.org/) Python package, a powerful toolkit for tree visualizations. +#### Tree-type visualization using ETE3 +To visualize tree-type structures of the self-energy in the Parquet example, install the [ETE3](http://etetoolkit.org/) Python package, a powerful toolkit for tree visualizations. Execute the following command in Julia for tree-type visualization of the self-energy generated in the above `Parquet` example: ```julia julia> plot_tree(sigmadf.diagram, depth = 3) ``` -For installation instructions on using ete3 with [PyCall.jl](https://github.com/JuliaPy/PyCall.jl), please refer to the PyCall.jl documentation on how to configure and use external Python packages within Julia. +For installation instructions on using ETE3 with [PyCall.jl](https://github.com/JuliaPy/PyCall.jl), please refer to the PyCall.jl documentation on how to configure and use external Python packages within Julia. #### Graph visualization using DOT The Back-End's `Compilers` module includes functionality to translate computational graphs into .dot files, which can be visualized using the `dot` command from Graphviz software. Below is an example code snippet that illustrates how to visualize the computational graph of the self-energy from the previously mentioned `Parquet` example. diff --git a/src/utility.jl b/src/utility.jl index 6bb509e5..98811f45 100644 --- a/src/utility.jl +++ b/src/utility.jl @@ -1,6 +1,5 @@ module Utility using ..ComputationalGraphs -#using ..ComputationalGraphs: Sum, Prod, Power, decrement_power using ..ComputationalGraphs: decrement_power using ..ComputationalGraphs: build_all_leaf_derivative, eval!, isfermionic import ..ComputationalGraphs: count_operation, count_expanded_operation @@ -18,12 +17,12 @@ export taylorAD dict_graphs::Dict{Vector{Int},Vector{Graph}}=Dict{Vector{Int},Vector{Graph}}() ) where {G<:Graph} - Performs Taylor-mode automatic differentiation (AD) on a vector of graphs, with the differentiation process tailored based on specified derivative orders, + Performs Taylor-mode automatic differentiation (AD) on a vector of graphs, with the differentiation process tailored based on specified maximum orders of differentiation and leaf dependency functions. It categorizes the differentiated graphs in a dictionary based on their derivative orders. # Parameters - `graphs`: A vector of graphs to be differentiated. -- `deriv_orders`: A vector of integers specifying the orders of differentiation to apply to the graphs. +- `deriv_orders`: A vector of integers specifying the maximum orders of differentiation to apply to the graphs. - `leaf_dep_funcs`: A vector of functions determining the dependency of differentiation variables on the properties of leaves in the graphs. - `dict_graphs`: Optional. A dictionary for storing the output graphs, keyed by vectors of integers representing the specific differentiation orders. Defaults to an empty dictionary. @@ -32,8 +31,9 @@ export taylorAD # Example Usage ```julia -# Define a vector of graphs and their corresponding derivative orders +# Define a vector of graphs graphs = [g1, g2] +# Specify the maximum orders of differentiation deriv_orders = [2, 3, 3] # Define a vector of differentiation dependency functions for the properties of leaf. @@ -41,7 +41,7 @@ deriv_orders = [2, 3, 3] # The third function specifies the dependence of on the first external momentum of the leaf. leaf_dep_funcs = [pr -> pr isa FrontEnds.BareGreenId, pr -> pr isa FrontEnds.BareInteractionId, pr -> pr.extK[1] != 0] -# Perform Taylor-mode AD and categorize the results +# Perform Taylor-mode AD and categorize the results. `result_dict` holds the AD results, organized by differentiation orders `[0:2, 0:3, 0:3]`. result_dict = taylorAD(graphs, deriv_orders, leaf_dep_funcs) ``` """