Fix computation and add trident example notebook

This commit is contained in:
Rubydragon 2024-08-05 13:52:31 +02:00
parent 7de7aa2353
commit c8e26d13fe
5 changed files with 3814 additions and 148 deletions

View File

@ -29,27 +29,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"42-element Vector{VirtualParticle{QEDProcess{Tuple{Photon, Electron}, Tuple{Electron, Electron, Electron, Positron, Positron}, Tuple{AllPolarization, AllSpin}, NTuple{5, AllSpin}}, PT, 2, 5} 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",
" photon: \t00 | 00101\n", " photon: \t00 | 011\n",
" photon: \t00 | 00110\n", " photon: \t00 | 101\n",
" photon: \t00 | 01001\n", " photon: \t01 | 010\n",
" photon: \t00 | 01010\n", " photon: \t01 | 100\n",
" photon: \t00 | 10001\n", " electron: \t10 | 001\n",
" photon: \t00 | 10010\n", " positron: \t10 | 010\n",
" photon: \t01 | 00100\n", " positron: \t10 | 100\n",
" photon: \t01 | 01000\n", " electron: \t11 | 000"
" photon: \t01 | 10000\n",
" electron: \t10 | 00001\n",
" ⋮\n",
" photon: \t10 | 00101\n",
" photon: \t10 | 00110\n",
" photon: \t10 | 01001\n",
" photon: \t10 | 01010\n",
" photon: \t10 | 10001\n",
" photon: \t10 | 10010\n",
" photon: \t11 | 00100\n",
" photon: \t11 | 01000\n",
" photon: \t11 | 10000"
] ]
}, },
"metadata": {}, "metadata": {},
@ -64,7 +52,7 @@
} }
], ],
"source": [ "source": [
"proc = QEDProcess(1, 0, 1, 3, 0, 2)\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",
@ -81,27 +69,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"OrderedCollections.OrderedDict{VirtualParticle, Vector{Tuple{VirtualParticle, VirtualParticle}}} with 42 entries:\n", "OrderedCollections.OrderedDict{VirtualParticle, Vector{Tuple{VirtualParticle, VirtualParticle}}} with 8 entries:\n",
" photon: \t00 | 00101 => [(electron: \t00 | 00001, positron: \t00 | 00100)]\n", " photon: \t00 | 011 => [(electron: \t00 | 001, positron: \t00 | 010)]\n",
" photon: \t00 | 00110 => [(electron: \t00 | 00010, positron: \t00 | 00100)]\n", " photon: \t00 | 101 => [(electron: \t00 | 001, positron: \t00 | 100)]\n",
" photon: \t00 | 01001 => [(electron: \t00 | 00001, positron: \t00 | 01000)]\n", " photon: \t01 | 010 => [(positron: \t00 | 010, electron: \t01 | 000)]\n",
" photon: \t00 | 01010 => [(electron: \t00 | 00010, positron: \t00 | 01000)]\n", " photon: \t01 | 100 => [(positron: \t00 | 100, electron: \t01 | 000)]\n",
" photon: \t00 | 10001 => [(electron: \t00 | 00001, positron: \t00 | 10000)]\n", " electron: \t10 | 001 => [(electron: \t00 | 001, photon: \t10 | 000)]\n",
" photon: \t00 | 10010 => [(electron: \t00 | 00010, positron: \t00 | 10000)]\n", " positron: \t10 | 010 => [(positron: \t00 | 010, photon: \t10 | 000)]\n",
" photon: \t01 | 00100 => [(positron: \t00 | 00100, electron: \t01 | 00000)]\n", " positron: \t10 | 100 => [(positron: \t00 | 100, photon: \t10 | 000)]\n",
" photon: \t01 | 01000 => [(positron: \t00 | 01000, electron: \t01 | 00000)]\n", " electron: \t11 | 000 => [(electron: \t01 | 000, photon: \t10 | 000)]"
" photon: \t01 | 10000 => [(positron: \t00 | 10000, electron: \t01 | 00000)]\n",
" electron: \t10 | 00001 => [(electron: \t00 | 00001, photon: \t10 | 00000)]\n",
" electron: \t10 | 00010 => [(electron: \t00 | 00010, photon: \t10 | 00000)]\n",
" positron: \t10 | 00100 => [(positron: \t00 | 00100, photon: \t10 | 00000)]\n",
" positron: \t10 | 01000 => [(positron: \t00 | 01000, photon: \t10 | 00000)]\n",
" positron: \t10 | 10000 => [(positron: \t00 | 10000, photon: \t10 | 00000)]\n",
" electron: \t11 | 00000 => [(electron: \t01 | 00000, photon: \t10 | 00000)]\n",
" electron: \t00 | 00111 => [(electron: \t00 | 00001, photon: \t00 | 00110), (electro…\n",
" electron: \t00 | 01011 => [(electron: \t00 | 00001, photon: \t00 | 01010), (electro…\n",
" positron: \t00 | 01101 => [(positron: \t00 | 00100, photon: \t00 | 01001), (positro…\n",
" positron: \t00 | 01110 => [(positron: \t00 | 00100, photon: \t00 | 01010), (positro…\n",
" ⋮ => ⋮"
] ]
}, },
"metadata": {}, "metadata": {},
@ -120,27 +96,15 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"81-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n", "8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t00 | 00101, electron: \t01 | 10010, positron: \t10 | 01000)\n", " (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t00 | 00101, electron: \t11 | 00000, positron: \t00 | 11010)\n", " (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t00 | 00101, electron: \t10 | 00010, positron: \t01 | 11000)\n", " (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t00 | 00101, electron: \t01 | 01010, positron: \t10 | 10000)\n", " (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t00 | 00110, electron: \t11 | 00000, positron: \t00 | 11001)\n", " (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (photon: \t00 | 00110, electron: \t10 | 00001, positron: \t01 | 11000)\n", " (photon: \t01 | 010, electron: \t10 | 001, positron: \t00 | 100)\n",
" (photon: \t00 | 00110, electron: \t01 | 10001, positron: \t10 | 01000)\n", " (photon: \t01 | 100, electron: \t00 | 001, positron: \t10 | 010)\n",
" (photon: \t00 | 00110, electron: \t01 | 01001, positron: \t10 | 10000)\n", " (photon: \t01 | 100, electron: \t10 | 001, positron: \t00 | 010)"
" (photon: \t00 | 01001, electron: \t01 | 10010, positron: \t10 | 00100)\n",
" (photon: \t00 | 01001, electron: \t11 | 00000, positron: \t00 | 10110)\n",
" ⋮\n",
" (photon: \t10 | 00000, electron: \t01 | 10010, positron: \t00 | 01101)\n",
" (photon: \t10 | 00000, electron: \t01 | 00110, positron: \t00 | 11001)\n",
" (photon: \t10 | 00000, electron: \t00 | 00111, positron: \t01 | 11000)\n",
" (photon: \t10 | 00000, electron: \t00 | 01011, positron: \t01 | 10100)\n",
" (photon: \t10 | 00000, electron: \t01 | 10001, positron: \t00 | 01110)\n",
" (photon: \t10 | 00000, electron: \t00 | 10011, positron: \t01 | 01100)\n",
" (photon: \t10 | 00000, electron: \t01 | 01001, positron: \t00 | 10110)\n",
" (photon: \t10 | 00000, electron: \t01 | 00101, positron: \t00 | 11010)\n",
" (photon: \t10 | 00000, electron: \t01 | 01010, positron: \t00 | 10101)"
] ]
}, },
"metadata": {}, "metadata": {},
@ -160,34 +124,22 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"s: 252, should be: 252\n", "s: 8, should be: 8\n",
"number of triples: 81\n" "number of triples: 8\n"
] ]
}, },
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"81-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n", "8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t10 | 00000, electron: \t00 | 00111, positron: \t01 | 11000)\n", " (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t10 | 00000, electron: \t00 | 01011, positron: \t01 | 10100)\n", " (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t10 | 00000, electron: \t00 | 10011, positron: \t01 | 01100)\n", " (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t10 | 00000, electron: \t01 | 00101, positron: \t00 | 11010)\n", " (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t10 | 00000, electron: \t01 | 00110, positron: \t00 | 11001)\n", " (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (photon: \t10 | 00000, electron: \t01 | 01001, positron: \t00 | 10110)\n", " (photon: \t01 | 010, electron: \t10 | 001, positron: \t00 | 100)\n",
" (photon: \t10 | 00000, electron: \t01 | 01010, positron: \t00 | 10101)\n", " (photon: \t01 | 100, electron: \t00 | 001, positron: \t10 | 010)\n",
" (photon: \t10 | 00000, electron: \t01 | 10001, positron: \t00 | 01110)\n", " (photon: \t01 | 100, electron: \t10 | 001, positron: \t00 | 010)"
" (photon: \t10 | 00000, electron: \t01 | 10010, positron: \t00 | 01101)\n",
" (photon: \t00 | 00101, electron: \t10 | 00010, positron: \t01 | 11000)\n",
" ⋮\n",
" (photon: \t11 | 00100, electron: \t00 | 10011, positron: \t00 | 01000)\n",
" (photon: \t11 | 01000, electron: \t00 | 00001, positron: \t00 | 10110)\n",
" (photon: \t11 | 01000, electron: \t00 | 00010, positron: \t00 | 10101)\n",
" (photon: \t11 | 01000, electron: \t00 | 00111, positron: \t00 | 10000)\n",
" (photon: \t11 | 01000, electron: \t00 | 10011, positron: \t00 | 00100)\n",
" (photon: \t11 | 10000, electron: \t00 | 00001, positron: \t00 | 01110)\n",
" (photon: \t11 | 10000, electron: \t00 | 00010, positron: \t00 | 01101)\n",
" (photon: \t11 | 10000, electron: \t00 | 00111, positron: \t00 | 01000)\n",
" (photon: \t11 | 10000, electron: \t00 | 01011, positron: \t00 | 00100)"
] ]
}, },
"metadata": {}, "metadata": {},
@ -226,11 +178,11 @@
"data": { "data": {
"text/plain": [ "text/plain": [
"Graph:\n", "Graph:\n",
" Nodes: Total: 23250, FeynmanDiagramGenerator.ComputeTask_CollectTriples: 128, FeynmanDiagramGenerator.ComputeTask_Pair: 492, \n", " Nodes: Total: 824, FeynmanDiagramGenerator.ComputeTask_CollectPairs: 32, FeynmanDiagramGenerator.ComputeTask_Triple: 256, \n",
" FeynmanDiagramGenerator.ComputeTask_BaseState: 14, MetagraphOptimization.DataTask: 11653, FeynmanDiagramGenerator.ComputeTask_Triple: 10368, \n", " MetagraphOptimization.DataTask: 421, FeynmanDiagramGenerator.ComputeTask_BaseState: 10, FeynmanDiagramGenerator.ComputeTask_SpinPolCumulation: 1, \n",
" FeynmanDiagramGenerator.ComputeTask_PropagatePairs: 276, FeynmanDiagramGenerator.ComputeTask_CollectPairs: 276, FeynmanDiagramGenerator.ComputeTask_Propagator: 42, \n", " FeynmanDiagramGenerator.ComputeTask_Pair: 32, FeynmanDiagramGenerator.ComputeTask_CollectTriples: 32, FeynmanDiagramGenerator.ComputeTask_Propagator: 8, \n",
" FeynmanDiagramGenerator.ComputeTask_SpinPolCumulation: 1\n", " FeynmanDiagramGenerator.ComputeTask_PropagatePairs: 32\n",
" Edges: 55281\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"
@ -287,7 +239,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"PhaseSpacePoint{QEDProcess{Tuple{Photon, Electron}, Tuple{Electron, Electron, Electron, Positron, Positron}, Tuple{AllPolarization, AllSpin}, NTuple{5, 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, Electron, SFourMomentum}, ParticleStateful{Outgoing, Positron, SFourMomentum}, ParticleStateful{Outgoing, Positron, 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": {},
@ -296,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",
@ -307,9 +259,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"32.69810945002751"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"using MetagraphOptimization: unpack_identity\n", "using MetagraphOptimization: unpack_identity\n",
"\n", "\n",
@ -320,9 +282,28 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "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": [ "source": [
"using BenchmarkTools\n", "using BenchmarkTools\n",
"\n", "\n",

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)
@ -66,8 +67,9 @@ struct PropagatorInput{VP_T<:VirtualParticle,PSP_T<:AbstractPhaseSpacePoint}
psp::Ref{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))
@ -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

@ -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