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

Update Parquet and remove diagTree, ExprTree, and old parquet_builder #172

Merged
merged 9 commits into from
Jan 10, 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
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
"python.formatting.provider": "none",
"julia.environmentPath": "/home/pchou/Documents/DiagMC/Code/numericalEFT/FeynmanDiagram.jl"
}
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ makedocs(;
"API reference" => Any[
"lib/operator.md",
"lib/computgraph.md",
"lib/taylorseries.md",
"lib/frontend.md",
"lib/GV.md",
"lib/parquet.md",
"lib/diagtree.md",
"lib/exprtree.md",
"lib/backend.md",
]
]
)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Modules = [FeynmanDiagram]
Pages = [
"lib/operator.md",
"lib/computgraph.md",
"lib/taylorseries.md",
"lib/frontend.md",
"lib/GV.md",
"lib/parquet.md",
"lib/diagtree.md",
"lib/exprtree.md",
"lib/backend.md",
]
Depth = 2
```
7 changes: 7 additions & 0 deletions docs/src/lib/backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Compilers compile computational graphs to optimized source code for diverse platforms

## API

```@autodocs
Modules = [FeynmanDiagram.Compilers]
```
7 changes: 0 additions & 7 deletions docs/src/lib/diagtree.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/src/lib/exprtree.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/src/lib/frontend.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Front-end translates a source code into a computational graph
# Front-end generates Feynman diagrams and translates then into a computational graph

## API

Expand Down
7 changes: 7 additions & 0 deletions docs/src/lib/taylorseries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Taylor expansions in independent variables (support AbstractGraph)

## API

```@autodocs
Modules = [FeynmanDiagram.Taylor]
```
8 changes: 4 additions & 4 deletions example/to_dot_parquetV2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using FeynmanDiagram
function recursive_print(diag)
if typeof(diag) <: FeynmanDiagram.ComputationalGraphs.Graph
if !isempty(diag.subgraphs)
print("$(diag.id) $(diag.factor) $(diag.subgraph_factors)\n")
print("$(diag.id) $(diag.subgraph_factors)\n")
for subdiag in diag.subgraphs
recursive_print(subdiag)
end
Expand All @@ -24,7 +24,7 @@ function main()
KinL, KoutL, KinR = zeros(16), zeros(16), zeros(16)
KinL[1], KoutL[2], KinR[3] = 1.0, 1.0, 1.0
# para = GV.diagPara(SigmaDiag, false, spin, order, [NoHartree], KinL - KoutL)
para = DiagParaF64(type=SigmaDiag, innerLoopNum=order, interaction=[Interaction(UpUp, [Instant,])], hasTau=true)
para = DiagPara(type=SigmaDiag, innerLoopNum=order, interaction=[Interaction(UpUp, [Instant,])], hasTau=true)
# para = DiagParaF64(type=SigmaDiag, innerLoopNum=2, interaction=[Interaction(ChargeCharge, [Instant,])], hasTau=true)
parquet_builder = Parquet.build(para)
diag = parquet_builder.diagram
Expand All @@ -38,8 +38,8 @@ function main()
# print("new diag2\n")
# recursive_print(eachd)
# end
G = FrontEnds.Graph!(d[1])
G = [eldest(G)] # drop extraneous Add node at root
# G = FrontEnds.Graph!(d[1])
G = [eldest(d[1])] # drop extraneous Add node at root
# for d in G
# print("graph1\n")
# recursive_print(d)
Expand Down
202 changes: 53 additions & 149 deletions src/FeynmanDiagram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,6 @@ macro todo()
return :(error("Not yet implemented!"))
end

@enum DiagramType begin
VacuumDiag #vaccum diagram for the free energy
SigmaDiag #self-energy
GreenDiag #green's function
PolarDiag #polarization
Ver3Diag #3-point vertex function
Ver4Diag #4-point vertex function
GnDiag #n-point Green's function
GcDiag #n-point connected Green's function
end
Base.length(r::DiagramType) = 1
Base.iterate(r::DiagramType) = (r, nothing)
function Base.iterate(r::DiagramType, ::Nothing) end

abstract type DiagType end
abstract type Vacuum <: DiagType end
abstract type Tadpole <: DiagType end
abstract type FermiPropagator <: DiagType end
abstract type BosePropagator <: DiagType end
abstract type FermiSelfEnergy <: DiagType end
abstract type BoseSelfEnergy <: DiagType end
abstract type VertexDiag <: DiagType end
abstract type GncDiag <: DiagType end
abstract type GndDiag <: DiagType end

@enum Filter begin
Wirreducible #remove all polarization subdiagrams
Girreducible #remove all self-energy inseration
NoHartree
NoFock
NoBubble # true to remove all bubble subdiagram
Proper #ver4, ver3, and polarization diagrams may require to be irreducible along the transfer momentum/frequency
DirectOnly # only direct interaction, this can be useful for debug purpose
end

Base.length(r::Filter) = 1
Base.iterate(r::Filter) = (r, nothing)
function Base.iterate(r::Filter, ::Nothing) end

@enum Response begin
Composite
ChargeCharge
SpinSpin
ProperChargeCharge
ProperSpinSpin
UpUp
UpDown
end

Base.length(r::Response) = 1
Base.iterate(r::Response) = (r, nothing)
function Base.iterate(r::Response, ::Nothing) end

@enum AnalyticProperty begin
Instant
Dynamic
D_Instant #derivative of instant interaction
D_Dynamic #derivative of the dynamic interaction
end

Base.length(r::AnalyticProperty) = 1
Base.iterate(r::AnalyticProperty) = (r, nothing)
function Base.iterate(r::AnalyticProperty, ::Nothing) end

export SigmaDiag, PolarDiag, Ver3Diag, Ver4Diag, GreenDiag
export VacuumDiag, GnDiag, GcDiag
export Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly
export Response, ChargeCharge, SpinSpin, UpUp, UpDown
export AnalyticProperty, Instant, Dynamic, D_Instant, D_Dynamic

export DiagType
export FermiPropagator, BosePropagator, FermiSelfEnergy, BoseSelfEnergy, VertexDiag
export Vacuum, Tadpole, GncDiag, GndDiag

include("common.jl")
export DiagPara, DiagParaF64
export Interaction, interactionTauNum, innerTauNum

include("common_new.jl")
export DiagramPara, DiagramParaF64
# export Interaction, interactionTauNum, innerTauNum

include("quantum_operator/QuantumOperators.jl")

using .QuantumOperators
Expand All @@ -98,9 +16,6 @@ export fermionic_annihilation, fermionic_creation, majorana
export bosonic_annihilation, bosonic_creation, real_classic
export correlator_order, normal_order




include("computational_graph/ComputationalGraph.jl")
using .ComputationalGraphs
export ComputationalGraphs
Expand All @@ -119,7 +34,7 @@ export multi_product, linear_combination, feynman_diagram, propagator, interacti
# export reducibility, connectivity
# export 𝐺ᶠ, 𝐺ᵇ, 𝐺ᵠ, 𝑊, Green2, Interaction
# export Coupling_yukawa, Coupling_phi3, Coupling_phi4, Coupling_phi6
export haschildren, onechild, isleaf, isbranch, ischain, isfactorless, has_zero_subfactors, eldest
export haschildren, onechild, isleaf, isbranch, ischain, has_zero_subfactors, eldest
export relabel!, standardize_labels!, replace_subgraph!, merge_linear_combination!, merge_multi_product!, merge_chains!
export relabel, standardize_labels, replace_subgraph, merge_linear_combination, merge_multi_product, merge_chains
export open_parenthesis, open_parenthesis!, flatten_prod!, flatten_prod, flatten_sum!, flatten_sum
Expand All @@ -129,39 +44,6 @@ include("TaylorSeries/TaylorSeries.jl")
using .Taylor
export Taylor

include("diagram_tree/DiagTree.jl")
using .DiagTree
export DiagTree
export TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan
export Permutation, Di, Ex, DiEx
export Diagram, addSubDiagram!, toDataFrame
export evalDiagNode!, evalDiagTree!, evalDiagTreeKT!
export Operator, Sum, Prod
export DiagramId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId
export PropagatorId, BareGreenId, BareInteractionId
export BareGreenNId, BareHoppingId, GreenNId, ConnectedGreenNId
export uidreset, toDataFrame, mergeby, plot_tree


include("parquet_builder/parquet.jl")
using .Parquet
export Parquet
export ParquetBlocks

include("strong_coupling_expansion_builder/strong_coupling_expansion")
using .SCE
export SCE
export Gn

include("expression_tree/ExpressionTree.jl")
using .ExprTree
export ExprTree
export Component, ExpressionTree
# export Propagator
export addpropagator!, addnode!
export setroot!, addroot!
export evalNaive, showTree

include("utility.jl")
using .Utility
export Utility
Expand All @@ -172,46 +54,68 @@ using .FrontEnds
export FrontEnds
export LabelProduct

include("frontend/parquet/parquet.jl")
using .Parquet
export Parquet
export ParquetBlocks
export DiagramType, VacuumDiag, SigmaDiag, GreenDiag, PolarDiag, Ver3Diag, Ver4Diag
export Filter, Wirreducible, Girreducible, NoBubble, NoHartree, NoFock, Proper, DirectOnly
export Response, Composite, ChargeCharge, SpinSpin, ProperChargeCharge, ProperSpinSpin, UpUp, UpDown
export AnalyticProperty, Instant, Dynamic, D_Instant, D_Dynamic

export DiagPara
export Interaction, interactionTauNum, innerTauNum
export TwoBodyChannel, Alli, PHr, PHEr, PPr, AnyChan
export Permutation, Di, Ex, DiEx
export DiagramId, GenericId, Ver4Id, Ver3Id, GreenId, SigmaId, PolarId
export PropagatorId, BareGreenId, BareInteractionId
export mergeby

include("frontend/GV.jl")
using .GV
export GV
export diagdictGV, diagdict_parquet, leafstates, leafstates_diagtree

# include("frontend/strong_coupling_expansion_builder/strong_coupling_expansion.jl")
# using .SCE
# export SCE
# export Gn

include("backend/compiler.jl")
using .Compilers
export Compilers


##################### precompile #######################
# precompile as the final step of the module definition:
if ccall(:jl_generating_output, Cint, ()) == 1 # if we're precompiling the package
let
para = DiagParaF64(type=Ver4Diag, innerLoopNum=2, hasTau=true)
# ver4 = Parquet.vertex4(para) # this will force precompilation
ver4 = Parquet.build(para) # this will force precompilation

mergeby(ver4, [:response])
mergeby(ver4.diagram)
mergeby(ver4.diagram, [:response]; idkey=[:extT, :response])

para = DiagParaF64(type=SigmaDiag, innerLoopNum=2, hasTau=true)
Parquet.build(para) # this will force precompilation
para = DiagParaF64(type=GreenDiag, innerLoopNum=2, hasTau=true)
Parquet.green(para) # this will force precompilation
para = DiagParaF64(type=PolarDiag, innerLoopNum=2, hasTau=true)
# Parquet.polarization(para) # this will force precompilation
Parquet.build(para) # this will force precompilation
para = DiagParaF64(type=Ver3Diag, innerLoopNum=2, hasTau=true)
# Parquet.vertex3(para) # this will force precompilation
Parquet.build(para) # this will force precompilation

DiagTree.removeHartreeFock!(ver4.diagram)
DiagTree.derivative(ver4.diagram, BareGreenId)
DiagTree.derivative(ver4.diagram, BareInteractionId)
# DiagTree.removeHartreeFock!(ver4.diagram)
ExprTree.build(ver4.diagram, 3)
end
end
# ##################### precompile #######################
# # precompile as the final step of the module definition:
# if ccall(:jl_generating_output, Cint, ()) == 1 # if we're precompiling the package
# let
# para = DiagParaF64(type=Ver4Diag, innerLoopNum=2, hasTau=true)
# # ver4 = Parquet.vertex4(para) # this will force precompilation
# ver4 = Parquet.build(para) # this will force precompilation

# mergeby(ver4, [:response])
# mergeby(ver4.diagram)
# mergeby(ver4.diagram, [:response]; idkey=[:extT, :response])

# para = DiagParaF64(type=SigmaDiag, innerLoopNum=2, hasTau=true)
# Parquet.build(para) # this will force precompilation
# para = DiagParaF64(type=GreenDiag, innerLoopNum=2, hasTau=true)
# Parquet.green(para) # this will force precompilation
# para = DiagParaF64(type=PolarDiag, innerLoopNum=2, hasTau=true)
# # Parquet.polarization(para) # this will force precompilation
# Parquet.build(para) # this will force precompilation
# para = DiagParaF64(type=Ver3Diag, innerLoopNum=2, hasTau=true)
# # Parquet.vertex3(para) # this will force precompilation
# Parquet.build(para) # this will force precompilation

# DiagTree.removeHartreeFock!(ver4.diagram)
# DiagTree.derivative(ver4.diagram, BareGreenId)
# DiagTree.derivative(ver4.diagram, BareInteractionId)
# # DiagTree.removeHartreeFock!(ver4.diagram)
# ExprTree.build(ver4.diagram, 3)
# end
# end


end
6 changes: 3 additions & 3 deletions src/backend/compiler.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Compilers
using PyCall
using ..ComputationalGraphs
import ..ComputationalGraphs: id, name, set_name!, operator, subgraphs, subgraph_factors, factor, FeynmanProperties
import ..ComputationalGraphs: id, name, set_name!, operator, subgraphs, subgraph_factors, FeynmanProperties

using ..DiagTree
using ..DiagTree: Diagram, PropagatorId, BareGreenId, BareInteractionId
using ..Parquet
using ..Parquet: PropagatorId, BareGreenId, BareInteractionId

using ..QuantumOperators
import ..QuantumOperators: isfermionic
Expand Down
Loading
Loading