Compare commits

...

2 Commits

Author SHA1 Message Date
c8e26d13fe Fix computation and add trident example notebook 2024-08-05 13:52:31 +02:00
7de7aa2353 Only use Ref of psp in propagator input 2024-07-19 08:50:59 +02:00
5 changed files with 3828 additions and 102 deletions

View File

@ -9,9 +9,9 @@
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"WARNING: Method definition (::Type{QEDcore.ParticleStateful{DIR, SPECIES, ELEMENT} where ELEMENT<:QEDbase.AbstractFourMomentum})(QEDbase.AbstractFourMomentum) where {DIR<:QEDbase.ParticleDirection, SPECIES<:QEDbase.AbstractParticleType} in module QEDcore at /home/antonr/.julia/packages/QEDcore/uVldP/src/phase_spaces/create.jl:7 overwritten in module MetagraphOptimization at /home/antonr/.julia/packages/MetagraphOptimization/0iydf/src/QEDprocesses_patch.jl:15.\n", "WARNING: Method definition (::Type{QEDcore.ParticleStateful{DIR, SPECIES, ELEMENT} where ELEMENT<:QEDbase.AbstractFourMomentum})(QEDbase.AbstractFourMomentum) where {DIR<:QEDbase.ParticleDirection, SPECIES<:QEDbase.AbstractParticleType} in module QEDcore at /home/antonr/.julia/packages/QEDcore/uVldP/src/phase_spaces/create.jl:7 overwritten in module MetagraphOptimization at /home/antonr/.julia/packages/MetagraphOptimization/kQaEJ/src/QEDprocesses_patch.jl:15.\n",
"ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.\n", "ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.\n",
"WARNING: Method definition (::Type{QEDcore.ParticleStateful{DIR, SPECIES, ELEMENT} where ELEMENT<:QEDbase.AbstractFourMomentum})(QEDbase.AbstractFourMomentum) where {DIR<:QEDbase.ParticleDirection, SPECIES<:QEDbase.AbstractParticleType} in module QEDcore at /home/antonr/.julia/packages/QEDcore/uVldP/src/phase_spaces/create.jl:7 overwritten in module MetagraphOptimization at /home/antonr/.julia/packages/MetagraphOptimization/0iydf/src/QEDprocesses_patch.jl:15.\n", "WARNING: Method definition (::Type{QEDcore.ParticleStateful{DIR, SPECIES, ELEMENT} where ELEMENT<:QEDbase.AbstractFourMomentum})(QEDbase.AbstractFourMomentum) where {DIR<:QEDbase.ParticleDirection, SPECIES<:QEDbase.AbstractParticleType} in module QEDcore at /home/antonr/.julia/packages/QEDcore/uVldP/src/phase_spaces/create.jl:7 overwritten in module MetagraphOptimization at /home/antonr/.julia/packages/MetagraphOptimization/kQaEJ/src/QEDprocesses_patch.jl:15.\n",
"ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.\n" "ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.\n"
] ]
} }
@ -29,13 +29,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"6-element Vector{VirtualParticle{QEDProcess{Tuple{Photon, Photon, Electron}, Tuple{Photon, Electron}, Tuple{AllPolarization, AllPolarization, AllSpin}, Tuple{AllPolarization, AllSpin}}, PT, 3, 2} where PT<:AbstractParticleType}:\n", "8-element Vector{VirtualParticle{QEDProcess{Tuple{Photon, Electron}, Tuple{Electron, Electron, Positron}, Tuple{AllPolarization, AllSpin}, Tuple{AllSpin, AllSpin, AllSpin}}, PT, 2, 3} where PT<:AbstractParticleType}:\n",
" positron: \t000 | 11\n", " photon: \t00 | 011\n",
" electron: \t001 | 10\n", " photon: \t00 | 101\n",
" positron: \t010 | 01\n", " photon: \t01 | 010\n",
" electron: \t011 | 00\n", " photon: \t01 | 100\n",
" positron: \t100 | 01\n", " electron: \t10 | 001\n",
" electron: \t101 | 00" " positron: \t10 | 010\n",
" positron: \t10 | 100\n",
" electron: \t11 | 000"
] ]
}, },
"metadata": {}, "metadata": {},
@ -50,7 +52,7 @@
} }
], ],
"source": [ "source": [
"proc = QEDProcess(2, 1, 1, 1, 0, 0)\n", "proc = QEDProcess(1, 0, 1, 2, 0, 1)\n",
"all_particles = Set()\n", "all_particles = Set()\n",
"for fd in feynman_diagrams(proc)\n", "for fd in feynman_diagrams(proc)\n",
" push!(all_particles, virtual_particles(proc, fd)...)\n", " push!(all_particles, virtual_particles(proc, fd)...)\n",
@ -67,13 +69,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"OrderedCollections.OrderedDict{VirtualParticle, Vector{Tuple{VirtualParticle, VirtualParticle}}} with 6 entries:\n", "OrderedCollections.OrderedDict{VirtualParticle, Vector{Tuple{VirtualParticle, VirtualParticle}}} with 8 entries:\n",
" positron: \t000 | 11 => [(positron: \t000 | 01, photon: \t000 | 10)]\n", " photon: \t00 | 011 => [(electron: \t00 | 001, positron: \t00 | 010)]\n",
" electron: \t001 | 10 => [(photon: \t000 | 10, electron: \t001 | 00)]\n", " photon: \t00 | 101 => [(electron: \t00 | 001, positron: \t00 | 100)]\n",
" positron: \t010 | 01 => [(positron: \t000 | 01, photon: \t010 | 00)]\n", " photon: \t01 | 010 => [(positron: \t00 | 010, electron: \t01 | 000)]\n",
" electron: \t011 | 00 => [(electron: \t001 | 00, photon: \t010 | 00)]\n", " photon: \t01 | 100 => [(positron: \t00 | 100, electron: \t01 | 000)]\n",
" positron: \t100 | 01 => [(positron: \t000 | 01, photon: \t100 | 00)]\n", " electron: \t10 | 001 => [(electron: \t00 | 001, photon: \t10 | 000)]\n",
" electron: \t101 | 00 => [(electron: \t001 | 00, photon: \t100 | 00)]" " positron: \t10 | 010 => [(positron: \t00 | 010, photon: \t10 | 000)]\n",
" positron: \t10 | 100 => [(positron: \t00 | 100, photon: \t10 | 000)]\n",
" electron: \t11 | 000 => [(electron: \t01 | 000, photon: \t10 | 000)]"
] ]
}, },
"metadata": {}, "metadata": {},
@ -92,13 +96,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"6-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n", "8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t000 | 10, electron: \t011 | 00, positron: \t100 | 01)\n", " (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t000 | 10, electron: \t101 | 00, positron: \t010 | 01)\n", " (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t010 | 00, electron: \t101 | 00, positron: \t000 | 11)\n", " (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t010 | 00, electron: \t001 | 10, positron: \t100 | 01)\n", " (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t100 | 00, electron: \t011 | 00, positron: \t000 | 11)\n", " (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (photon: \t100 | 00, electron: \t001 | 10, positron: \t010 | 01)" " (photon: \t01 | 010, electron: \t10 | 001, positron: \t00 | 100)\n",
" (photon: \t01 | 100, electron: \t00 | 001, positron: \t10 | 010)\n",
" (photon: \t01 | 100, electron: \t10 | 001, positron: \t00 | 010)"
] ]
}, },
"metadata": {}, "metadata": {},
@ -118,20 +124,22 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"s: 6, should be: 6\n", "s: 8, should be: 8\n",
"number of triples: 6\n" "number of triples: 8\n"
] ]
}, },
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"6-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n", "8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t000 | 10, electron: \t011 | 00, positron: \t100 | 01)\n", " (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t000 | 10, electron: \t101 | 00, positron: \t010 | 01)\n", " (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t010 | 00, electron: \t001 | 10, positron: \t100 | 01)\n", " (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t010 | 00, electron: \t101 | 00, positron: \t000 | 11)\n", " (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t100 | 00, electron: \t001 | 10, positron: \t010 | 01)\n", " (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (photon: \t100 | 00, electron: \t011 | 00, positron: \t000 | 11)" " (photon: \t01 | 010, electron: \t10 | 001, positron: \t00 | 100)\n",
" (photon: \t01 | 100, electron: \t00 | 001, positron: \t10 | 010)\n",
" (photon: \t01 | 100, electron: \t10 | 001, positron: \t00 | 010)"
] ]
}, },
"metadata": {}, "metadata": {},
@ -170,11 +178,11 @@
"data": { "data": {
"text/plain": [ "text/plain": [
"Graph:\n", "Graph:\n",
" Nodes: Total: 642, FeynmanDiagramGenerator.ComputeTask_PropagatePairs: 24, FeynmanDiagramGenerator.ComputeTask_CollectPairs: 24, \n", " Nodes: Total: 824, FeynmanDiagramGenerator.ComputeTask_CollectPairs: 32, FeynmanDiagramGenerator.ComputeTask_Triple: 256, \n",
" FeynmanDiagramGenerator.ComputeTask_Triple: 192, FeynmanDiagramGenerator.ComputeTask_SpinPolCumulation: 1, MetagraphOptimization.DataTask: 329, \n", " MetagraphOptimization.DataTask: 421, FeynmanDiagramGenerator.ComputeTask_BaseState: 10, FeynmanDiagramGenerator.ComputeTask_SpinPolCumulation: 1, \n",
" FeynmanDiagramGenerator.ComputeTask_BaseState: 10, FeynmanDiagramGenerator.ComputeTask_Pair: 24, FeynmanDiagramGenerator.ComputeTask_Propagator: 6, \n", " FeynmanDiagramGenerator.ComputeTask_Pair: 32, FeynmanDiagramGenerator.ComputeTask_CollectTriples: 32, FeynmanDiagramGenerator.ComputeTask_Propagator: 8, \n",
" FeynmanDiagramGenerator.ComputeTask_CollectTriples: 32\n", " FeynmanDiagramGenerator.ComputeTask_PropagatePairs: 32\n",
" Edges: 1249\n", " Edges: 1637\n",
" Total Compute Effort: 0.0\n", " Total Compute Effort: 0.0\n",
" Total Data Transfer: 0.0\n", " Total Data Transfer: 0.0\n",
" Total Compute Intensity: 0.0\n" " Total Compute Intensity: 0.0\n"
@ -231,7 +239,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"PhaseSpacePoint{QEDProcess{Tuple{Photon, Photon, Electron}, Tuple{Photon, Electron}, Tuple{AllPolarization, AllPolarization, AllSpin}, Tuple{AllPolarization, AllSpin}}, PerturbativeQED, PhasespaceDefinition{SphericalCoordinateSystem, ElectronRestFrame}, Tuple{ParticleStateful{Incoming, Photon, SFourMomentum}, ParticleStateful{Incoming, Photon, SFourMomentum}, ParticleStateful{Incoming, Electron, SFourMomentum}}, Tuple{ParticleStateful{Outgoing, Photon, SFourMomentum}, ParticleStateful{Outgoing, Electron, SFourMomentum}}, SFourMomentum}" "PhaseSpacePoint{QEDProcess{Tuple{Photon, Electron}, Tuple{Electron, Electron, Positron}, Tuple{AllPolarization, AllSpin}, Tuple{AllSpin, AllSpin, AllSpin}}, PerturbativeQED, PhasespaceDefinition{SphericalCoordinateSystem, ElectronRestFrame}, Tuple{ParticleStateful{Incoming, Photon, SFourMomentum}, ParticleStateful{Incoming, Electron, SFourMomentum}}, Tuple{ParticleStateful{Outgoing, Electron, SFourMomentum}, ParticleStateful{Outgoing, Electron, SFourMomentum}, ParticleStateful{Outgoing, Positron, SFourMomentum}}, SFourMomentum}"
] ]
}, },
"metadata": {}, "metadata": {},
@ -240,9 +248,9 @@
], ],
"source": [ "source": [
"psp = PhaseSpacePoint(\n", "psp = PhaseSpacePoint(\n",
" proc, \n", " proc,\n",
" PerturbativeQED(), \n", " PerturbativeQED(),\n",
" PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()), \n", " PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()),\n",
" tuple((rand(SFourMomentum) for _ in 1:number_incoming_particles(proc))...),\n", " tuple((rand(SFourMomentum) for _ in 1:number_incoming_particles(proc))...),\n",
" tuple((rand(SFourMomentum) for _ in 1:number_outgoing_particles(proc))...)\n", " tuple((rand(SFourMomentum) for _ in 1:number_outgoing_particles(proc))...)\n",
")\n", ")\n",
@ -251,23 +259,56 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "Base.Meta.ParseError", "data": {
"evalue": "Error trying to display an error.", "text/plain": [
"output_type": "error", "32.69810945002751"
"traceback": [ ]
"Error trying to display an error." },
] "metadata": {},
"output_type": "display_data"
} }
], ],
"source": [ "source": [
"using MetagraphOptimization: unpack_identity\n",
"\n",
"func = eval(get_compute_function(graph, proc, mock_machine()))\n", "func = eval(get_compute_function(graph, proc, mock_machine()))\n",
"\n", "\n",
"func(psp)" "func(psp)"
] ]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"BenchmarkTools.Trial: 10000 samples with 1 evaluation.\n",
" Range \u001b[90m(\u001b[39m\u001b[36m\u001b[1mmin\u001b[22m\u001b[39m … \u001b[35mmax\u001b[39m\u001b[90m): \u001b[39m\u001b[36m\u001b[1m35.405 μs\u001b[22m\u001b[39m … \u001b[35m627.297 μs\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmin … max\u001b[90m): \u001b[39m0.00% … 0.00%\n",
" Time \u001b[90m(\u001b[39m\u001b[34m\u001b[1mmedian\u001b[22m\u001b[39m\u001b[90m): \u001b[39m\u001b[34m\u001b[1m41.790 μs \u001b[22m\u001b[39m\u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmedian\u001b[90m): \u001b[39m0.00%\n",
" Time \u001b[90m(\u001b[39m\u001b[32m\u001b[1mmean\u001b[22m\u001b[39m ± \u001b[32mσ\u001b[39m\u001b[90m): \u001b[39m\u001b[32m\u001b[1m54.989 μs\u001b[22m\u001b[39m ± \u001b[32m 33.980 μs\u001b[39m \u001b[90m┊\u001b[39m GC \u001b[90m(\u001b[39mmean ± σ\u001b[90m): \u001b[39m0.00% ± 0.00%\n",
"\n",
" \u001b[39m█\u001b[39m▇\u001b[34m▆\u001b[39m\u001b[39m▅\u001b[39m▄\u001b[39m▄\u001b[39m▄\u001b[32m▃\u001b[39m\u001b[39m▃\u001b[39m▃\u001b[39m▃\u001b[39m▂\u001b[39m▂\u001b[39m▁\u001b[39m▂\u001b[39m▂\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m▁\u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m \u001b[39m▂\n",
" \u001b[39m█\u001b[39m█\u001b[34m█\u001b[39m\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[32m█\u001b[39m\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m▇\u001b[39m█\u001b[39m█\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▇\u001b[39m▆\u001b[39m▇\u001b[39m▆\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m▅\u001b[39m▆\u001b[39m▄\u001b[39m▄\u001b[39m▄\u001b[39m▅\u001b[39m▅\u001b[39m▅\u001b[39m▆\u001b[39m \u001b[39m█\n",
" 35.4 μs\u001b[90m \u001b[39m\u001b[90mHistogram: \u001b[39m\u001b[90m\u001b[1mlog(\u001b[22m\u001b[39m\u001b[90mfrequency\u001b[39m\u001b[90m\u001b[1m)\u001b[22m\u001b[39m\u001b[90m by time\u001b[39m 197 μs \u001b[0m\u001b[1m<\u001b[22m\n",
"\n",
" Memory estimate\u001b[90m: \u001b[39m\u001b[33m3.66 KiB\u001b[39m, allocs estimate\u001b[90m: \u001b[39m\u001b[33m50\u001b[39m."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"using BenchmarkTools\n",
"\n",
"@benchmark func($psp)"
]
} }
], ],
"metadata": { "metadata": {

3584
notebooks/trident.ipynb Normal file

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,28 @@ mutable struct QEDProcess{INT,OUTT,INSP,OUTSP} <: AbstractProcessDefinition wher
end end
end end
function QEDProcessSingleSpinPol(
in_ph::Int, out_ph::Int, in_el::Int, out_el::Int, in_po::Int, out_po::Int
)
in_p = ntuple(i -> if i <= in_ph
Photon()
elseif i <= in_ph + in_el
Electron()
else
Positron()
end, in_ph + in_el + in_po)
out_p = ntuple(i -> if i <= out_ph
Photon()
elseif i <= out_ph + out_el
Electron()
else
Positron()
end, out_ph + out_el + out_po)
in_sp = tuple([i <= in_ph ? PolX() : SpinUp() for i in 1:length(in_p)]...)
out_sp = tuple([i <= out_ph ? PolX() : SpinUp() for i in 1:length(out_p)]...)
return QEDProcess(in_p, out_p, in_sp, out_sp)
end
function spin_or_pol( function spin_or_pol(
process::QEDProcess, dir::ParticleDirection, species::AbstractParticleType, n::Int process::QEDProcess, dir::ParticleDirection, species::AbstractParticleType, n::Int
) )

View File

@ -42,8 +42,9 @@ struct BaseStateInput{PS_T<:AbstractParticleStateful,SPIN_POL_T<:AbstractSpinOrP
spin_pol::SPIN_POL_T spin_pol::SPIN_POL_T
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_BaseState, input::BaseStateInput{PS,SPIN_POL} ::ComputeTask_BaseState,
input::BaseStateInput{PS,SPIN_POL},
) where {PS,SPIN_POL} ) where {PS,SPIN_POL}
species = particle_species(input.particle) species = particle_species(input.particle)
if is_outgoing(input.particle) if is_outgoing(input.particle)
@ -63,21 +64,22 @@ end
struct PropagatorInput{VP_T<:VirtualParticle,PSP_T<:AbstractPhaseSpacePoint} struct PropagatorInput{VP_T<:VirtualParticle,PSP_T<:AbstractPhaseSpacePoint}
vp::VP_T vp::VP_T
psp::PSP_T psp::Ref{PSP_T}
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_Propagator, input::PropagatorInput{VP_T,PSP_T} ::ComputeTask_Propagator,
input::PropagatorInput{VP_T,PSP_T},
) where {VP_T,PSP_T} ) where {VP_T,PSP_T}
vp_mom = zero(typeof(momentum(input.psp, Incoming(), 1))) vp_mom = zero(typeof(momentum(input.psp[], Incoming(), 1)))
for i in eachindex(in_contributions(input.vp)) for i in eachindex(in_contributions(input.vp))
if in_contributions(input.vp)[i] if in_contributions(input.vp)[i]
vp_mom += momentum(input.psp, Incoming(), i) vp_mom += momentum(input.psp[], Incoming(), i)
end end
end end
for o in eachindex(out_contributions(input.vp)) for o in eachindex(out_contributions(input.vp))
if (out_contributions(input.vp))[o] if (out_contributions(input.vp))[o]
vp_mom -= momentum(input.psp, Outgoing(), o) vp_mom -= momentum(input.psp[], Outgoing(), o)
end end
end end
@ -102,39 +104,51 @@ struct Propagated{PARTICLE_T<:AbstractParticleType,VALUE_T}
end end
# maybe add the γ matrix term here too? # maybe add the γ matrix term here too?
@inline function compute( function compute( #=@inline=#
::ComputeTask_Pair, electron::Propagated{Electron,V1}, positron::Propagated{Positron,V2} ::ComputeTask_Pair,
electron::Propagated{Electron,V1},
positron::Propagated{Positron,V2},
) where {V1,V2} ) where {V1,V2}
return Unpropagated(Photon(), positron.value * _vertex() * electron.value) # fermion - antifermion -> photon return Unpropagated(Photon(), positron.value * _vertex() * electron.value) # fermion - antifermion -> photon
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_Pair, positron::Propagated{Positron,V1}, electron::Propagated{Electron,V2} ::ComputeTask_Pair,
positron::Propagated{Positron,V1},
electron::Propagated{Electron,V2},
) where {V1,V2} ) where {V1,V2}
return Unpropagated(Photon(), positron.value * _vertex() * electron.value) # antifermion - fermion -> photon return Unpropagated(Photon(), positron.value * _vertex() * electron.value) # antifermion - fermion -> photon
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_Pair, photon::Propagated{Photon,V1}, fermion::Propagated{F,V2} ::ComputeTask_Pair,
photon::Propagated{Photon,V1},
fermion::Propagated{F,V2},
) where {F<:FermionLike,V1,V2} ) where {F<:FermionLike,V1,V2}
return Unpropagated(fermion.particle, photon.value * _vertex() * fermion.value) # (anti-)fermion - photon -> (anti-)fermion return Unpropagated(fermion.particle, photon.value * _vertex() * fermion.value) # (anti-)fermion - photon -> (anti-)fermion
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_Pair, fermion::Propagated{F,V2}, photon::Propagated{Photon,V1} ::ComputeTask_Pair,
fermion::Propagated{F,V2},
photon::Propagated{Photon,V1},
) where {F<:FermionLike,V1,V2} ) where {F<:FermionLike,V1,V2}
return Unpropagated(fermion.particle, photon.value * _vertex() * fermion.value) # photon - (anti-)fermion -> (anti-)fermion return Unpropagated(fermion.particle, photon.value * _vertex() * fermion.value) # photon - (anti-)fermion -> (anti-)fermion
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_PropagatePairs, left::PROP_V, right::Unpropagated{P,VAL} ::ComputeTask_PropagatePairs,
left::PROP_V,
right::Unpropagated{P,VAL},
) where {PROP_V,P<:AbstractParticleType,VAL} ) where {PROP_V,P<:AbstractParticleType,VAL}
return Propagated(right.particle, left * right.value) return Propagated(right.particle, left * right.value)
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_PropagatePairs, left::Unpropagated{P,VAL}, right::PROP_V ::ComputeTask_PropagatePairs,
left::Unpropagated{P,VAL},
right::PROP_V,
) where {PROP_V,P<:AbstractParticleType,VAL} ) where {PROP_V,P<:AbstractParticleType,VAL}
return Propagated(left.particle, right * left.value) return Propagated(left.particle, right * left.value)
end end
@inline function compute( function compute( #=@inline=#
::ComputeTask_Triple, ::ComputeTask_Triple,
photon::Propagated{Photon,V1}, photon::Propagated{Photon,V1},
electron::Propagated{Electron,V2}, electron::Propagated{Electron,V2},
@ -142,7 +156,7 @@ end
) where {V1,V2,V3} ) where {V1,V2,V3}
return positron.value * _vertex() * photon.value * electron.value return positron.value * _vertex() * photon.value * electron.value
end end
@inline function compute( function compute( #=@inline=#
c::ComputeTask_Triple, c::ComputeTask_Triple,
photon::Propagated{Photon,V1}, photon::Propagated{Photon,V1},
positron::Propagated{Positron,V2}, positron::Propagated{Positron,V2},
@ -150,7 +164,7 @@ end
) where {V1,V2,V3} ) where {V1,V2,V3}
return compute(c, photon, electron, positron) return compute(c, photon, electron, positron)
end end
@inline function compute( function compute( #=@inline=#
c::ComputeTask_Triple, c::ComputeTask_Triple,
f1::Propagated{F1,V1}, f1::Propagated{F1,V1},
f2::Propagated{F2,V2}, f2::Propagated{F2,V2},
@ -158,7 +172,7 @@ end
) where {V1,V2,V3,F1<:FermionLike,F2<:FermionLike} ) where {V1,V2,V3,F1<:FermionLike,F2<:FermionLike}
return compute(c, photon, f1, f2) return compute(c, photon, f1, f2)
end end
@inline function compute( function compute( #=@inline=#
c::ComputeTask_Triple, c::ComputeTask_Triple,
f1::Propagated{F1,V1}, f1::Propagated{F1,V1},
photon::Propagated{Photon,V2}, photon::Propagated{Photon,V2},
@ -169,9 +183,9 @@ end
# this compiles in a reasonable amount of time for up to about 1e4 parameters # this compiles in a reasonable amount of time for up to about 1e4 parameters
# use a summation algorithm with more accuracy and/or parallelization # use a summation algorithm with more accuracy and/or parallelization
@inline compute(::ComputeTask_CollectPairs, args::Vararg{N,T}) where {N,T} = sum(args) compute(::ComputeTask_CollectPairs, args::Vararg{N,T}) where {N,T} = sum(args) #=@inline=#
@inline compute(::ComputeTask_CollectTriples, args::Vararg{N,T}) where {N,T} = sum(args) compute(::ComputeTask_CollectTriples, args::Vararg{N,T}) where {N,T} = sum(args) #=@inline=#
@inline function compute(::ComputeTask_SpinPolCumulation, args::Vararg{N,T}) where {N,T} function compute(::ComputeTask_SpinPolCumulation, args::Vararg{N,T}) where {N,T} #=@inline=#
sum = 0.0 sum = 0.0
for arg in args for arg in args
sum += abs2(arg) sum += abs2(arg)

View File

@ -87,7 +87,7 @@ function MetagraphOptimization.input_expr(
$(vp.in_particle_contributions), $(vp.in_particle_contributions),
$(vp.out_particle_contributions) $(vp.out_particle_contributions)
), ),
$psp_symbol Ref($psp_symbol)
)") )")
else else
throw(InvalidInputError("failed to parse node name \"$name\"")) throw(InvalidInputError("failed to parse node name \"$name\""))
@ -216,7 +216,7 @@ function _base_state_name(p::VirtualParticle)
) )
end end
# from two or three node names like "1_su-2-px"... return a single tuple of the indices and spin/pols in sorted # from two or three node names like "1_su-2_px"... return a single tuple of the indices and spin/pols in sorted
function _parse_node_names(name1::String, name2::String) function _parse_node_names(name1::String, name2::String)
split_strings_1 = split.(split(name1, "-"), "_") split_strings_1 = split.(split(name1, "-"), "_")
split_strings_2 = split.(split(name2, "-"), "_") split_strings_2 = split.(split(name2, "-"), "_")
@ -259,9 +259,8 @@ function _parse_node_names(name1::String, name2::String, name3::String)
) )
end end
function _make_node_name( function _make_node_name(spin_pols::Vector)
spin_pols::NTuple{N,Tuple{Int,AbstractSpinOrPolarization}} # spin_pols is a vector of tuples Tuple{Int, AbstractSpinOrPolarization}
) where {N}
node_name = "" node_name = ""
first = true first = true
for spin_pol_tuple in spin_pols for spin_pol_tuple in spin_pols
@ -318,8 +317,20 @@ function generate_DAG(proc::QEDProcess)
invalidate_cache=false, invalidate_cache=false,
) )
insert_edge!(graph, data_in, compute_base_state) insert_edge!(
insert_edge!(graph, compute_base_state, data_out) graph,
data_in,
compute_base_state;
track=false,
invalidate_cache=false,
)
insert_edge!(
graph,
compute_base_state,
data_out;
track=false,
invalidate_cache=false,
)
base_state_task_outputs[data_node_name] = data_out base_state_task_outputs[data_node_name] = data_out
end end
@ -348,8 +359,12 @@ function generate_DAG(proc::QEDProcess)
graph, make_node(DataTask(0)); track=false, invalidate_cache=false graph, make_node(DataTask(0)); track=false, invalidate_cache=false
) )
insert_edge!(graph, data_in, compute_vp_propagator) insert_edge!(
insert_edge!(graph, compute_vp_propagator, data_out) graph, data_in, compute_vp_propagator; track=false, invalidate_cache=false
)
insert_edge!(
graph, compute_vp_propagator, data_out; track=false, invalidate_cache=false
)
propagator_task_outputs[vp] = data_out propagator_task_outputs[vp] = data_out
end end
@ -394,9 +409,15 @@ function generate_DAG(proc::QEDProcess)
graph, make_node(DataTask(0)); track=false, invalidate_cache=false graph, make_node(DataTask(0)); track=false, invalidate_cache=false
) )
insert_edge!(graph, in_nodes[1], compute_pair) insert_edge!(
insert_edge!(graph, in_nodes[2], compute_pair) graph, in_nodes[1], compute_pair; track=false, invalidate_cache=false
insert_edge!(graph, compute_pair, pair_data_out) )
insert_edge!(
graph, in_nodes[2], compute_pair; track=false, invalidate_cache=false
)
insert_edge!(
graph, compute_pair, pair_data_out; track=false, invalidate_cache=false
)
# get the spin/pol config of the input particles from the data_out names # get the spin/pol config of the input particles from the data_out names
index = _parse_node_names(in_nodes[1].name, in_nodes[2].name) index = _parse_node_names(in_nodes[1].name, in_nodes[2].name)
@ -429,21 +450,47 @@ function generate_DAG(proc::QEDProcess)
# give this out node the correct name # give this out node the correct name
data_out_propagated = insert_node!( data_out_propagated = insert_node!(
graph, graph,
make_node(DataTask(0), _make_node_name(index)); make_node(DataTask(0), _make_node_name([index...]));
track=false, track=false,
invalidate_cache=false, invalidate_cache=false,
) )
for node in nodes_to_sum for node in nodes_to_sum
insert_edge!(graph, node, compute_pairs_sum) insert_edge!(
graph, node, compute_pairs_sum; track=false, invalidate_cache=false
)
end end
insert_edge!(graph, compute_pairs_sum, data_pairs_sum) insert_edge!(
graph,
compute_pairs_sum,
data_pairs_sum;
track=false,
invalidate_cache=false,
)
insert_edge!(graph, propagator_node, compute_propagated) insert_edge!(
insert_edge!(graph, data_pairs_sum, compute_propagated) graph,
propagator_node,
compute_propagated;
track=false,
invalidate_cache=false,
)
insert_edge!(
graph,
data_pairs_sum,
compute_propagated;
track=false,
invalidate_cache=false,
)
insert_edge!(graph, compute_propagated, data_out_propagated) insert_edge!(
graph,
compute_propagated,
data_out_propagated;
track=false,
invalidate_cache=false,
)
push!(pair_task_outputs[product_particle], data_out_propagated) push!(pair_task_outputs[product_particle], data_out_propagated)
end end
@ -475,11 +522,13 @@ function generate_DAG(proc::QEDProcess)
graph, make_node(DataTask(0)); track=false, invalidate_cache=false graph, make_node(DataTask(0)); track=false, invalidate_cache=false
) )
insert_edge!(graph, a, compute_triples) insert_edge!(graph, a, compute_triples; track=false, invalidate_cache=false)
insert_edge!(graph, b, compute_triples) insert_edge!(graph, b, compute_triples; track=false, invalidate_cache=false)
insert_edge!(graph, c, compute_triples) insert_edge!(graph, c, compute_triples; track=false, invalidate_cache=false)
insert_edge!(graph, compute_triples, data_triples) insert_edge!(
graph, compute_triples, data_triples; track=false, invalidate_cache=false
)
index = _parse_node_names(a.name, b.name, c.name) index = _parse_node_names(a.name, b.name, c.name)
if !haskey(triples_results, index) if !haskey(triples_results, index)
@ -503,9 +552,17 @@ function generate_DAG(proc::QEDProcess)
) )
for triple in results for triple in results
insert_edge!(graph, triple, compute_collect_triples) insert_edge!(
graph, triple, compute_collect_triples; track=false, invalidate_cache=false
)
end end
insert_edge!(graph, compute_collect_triples, data_collect_triples) insert_edge!(
graph,
compute_collect_triples,
data_collect_triples;
track=false,
invalidate_cache=false,
)
push!(collected_triples, data_collect_triples) push!(collected_triples, data_collect_triples)
end end
@ -518,12 +575,20 @@ function generate_DAG(proc::QEDProcess)
invalidate_cache=false, invalidate_cache=false,
) )
for finished_triple in collected_triples for finished_triple in collected_triples
insert_edge!(graph, finished_triple, compute_total_result) insert_edge!(
graph,
finished_triple,
compute_total_result;
track=false,
invalidate_cache=false,
)
end end
final_data_out = insert_node!( final_data_out = insert_node!(
graph, make_node(DataTask(0)); track=false, invalidate_cache=false graph, make_node(DataTask(0)); track=false, invalidate_cache=false
) )
insert_edge!(graph, compute_total_result, final_data_out) insert_edge!(
graph, compute_total_result, final_data_out; track=false, invalidate_cache=false
)
return graph return graph
end end