FeynmanDiagrams.jl/notebooks/diagram_generation.ipynb

330 lines
13 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"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/kQaEJ/src/QEDprocesses_patch.jl:15.\n",
2024-07-17 15:45:54 +02:00
"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/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"
]
}
],
"source": [
2024-07-16 18:51:09 +02:00
"using Revise\n",
"using FeynmanDiagramGenerator"
]
},
{
"cell_type": "code",
2024-07-17 15:45:54 +02:00
"execution_count": 2,
"metadata": {},
2024-07-17 15:45:54 +02:00
"outputs": [
{
"data": {
"text/plain": [
"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 | 011\n",
" photon: \t00 | 101\n",
" photon: \t01 | 010\n",
" photon: \t01 | 100\n",
" electron: \t10 | 001\n",
" positron: \t10 | 010\n",
" positron: \t10 | 100\n",
" electron: \t11 | 000"
2024-07-17 15:45:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: both QEDcore and QEDbase export \"mul\"; uses of it in module FeynmanDiagramGenerator must be qualified\n"
]
}
],
"source": [
"proc = QEDProcess(1, 0, 1, 2, 0, 1)\n",
"all_particles = Set()\n",
2024-07-16 18:51:09 +02:00
"for fd in feynman_diagrams(proc)\n",
" push!(all_particles, virtual_particles(proc, fd)...)\n",
"end\n",
"all_particles = sort([all_particles...])\n",
"display(all_particles)\n"
]
},
{
"cell_type": "code",
2024-07-17 15:45:54 +02:00
"execution_count": 3,
"metadata": {},
2024-07-17 15:45:54 +02:00
"outputs": [
{
"data": {
"text/plain": [
"OrderedCollections.OrderedDict{VirtualParticle, Vector{Tuple{VirtualParticle, VirtualParticle}}} with 8 entries:\n",
" photon: \t00 | 011 => [(electron: \t00 | 001, positron: \t00 | 010)]\n",
" photon: \t00 | 101 => [(electron: \t00 | 001, positron: \t00 | 100)]\n",
" photon: \t01 | 010 => [(positron: \t00 | 010, electron: \t01 | 000)]\n",
" photon: \t01 | 100 => [(positron: \t00 | 100, electron: \t01 | 000)]\n",
" electron: \t10 | 001 => [(electron: \t00 | 001, photon: \t10 | 000)]\n",
" 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)]"
2024-07-17 15:45:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-07-17 15:45:54 +02:00
"pairs = sort(FeynmanDiagramGenerator.particle_pairs(all_particles))"
]
},
{
"cell_type": "code",
2024-07-17 15:45:54 +02:00
"execution_count": 4,
"metadata": {},
2024-07-17 15:45:54 +02:00
"outputs": [
{
"data": {
"text/plain": [
"8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (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)"
2024-07-17 15:45:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"triples = FeynmanDiagramGenerator.total_particle_triples(all_particles)"
]
},
{
"cell_type": "code",
2024-07-17 15:45:54 +02:00
"execution_count": 5,
"metadata": {},
2024-07-17 15:45:54 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"s: 8, should be: 8\n",
"number of triples: 8\n"
2024-07-17 15:45:54 +02:00
]
},
{
"data": {
"text/plain": [
"8-element Vector{Tuple{VirtualParticle, VirtualParticle, VirtualParticle}}:\n",
" (photon: \t00 | 011, electron: \t01 | 000, positron: \t10 | 100)\n",
" (photon: \t00 | 011, electron: \t11 | 000, positron: \t00 | 100)\n",
" (photon: \t00 | 101, electron: \t01 | 000, positron: \t10 | 010)\n",
" (photon: \t00 | 101, electron: \t11 | 000, positron: \t00 | 010)\n",
" (photon: \t01 | 010, electron: \t00 | 001, positron: \t10 | 100)\n",
" (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)"
2024-07-17 15:45:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"function n(vp::VirtualParticle)\n",
" if !haskey(pairs, vp)\n",
" return 1\n",
" end\n",
" s = 0\n",
" for (l, r) in pairs[vp]\n",
" s += n(l) * n(r)\n",
" end\n",
" return s\n",
"end\n",
"\n",
"s = 0\n",
"for (ph, e, p) in triples\n",
" s += n(ph) * n(e) * n(p)\n",
"end\n",
"\n",
"println(\"s: $s, should be: $(length(feynman_diagrams(proc)))\")\n",
"println(\"number of triples: $(length(triples))\")\n",
"\n",
"sort(triples)"
]
2024-07-16 18:51:09 +02:00
},
2024-07-17 15:45:54 +02:00
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Graph:\n",
" Nodes: Total: 824, FeynmanDiagramGenerator.ComputeTask_CollectPairs: 32, FeynmanDiagramGenerator.ComputeTask_Triple: 256, \n",
" MetagraphOptimization.DataTask: 421, FeynmanDiagramGenerator.ComputeTask_BaseState: 10, FeynmanDiagramGenerator.ComputeTask_SpinPolCumulation: 1, \n",
" FeynmanDiagramGenerator.ComputeTask_Pair: 32, FeynmanDiagramGenerator.ComputeTask_CollectTriples: 32, FeynmanDiagramGenerator.ComputeTask_Propagator: 8, \n",
" FeynmanDiagramGenerator.ComputeTask_PropagatePairs: 32\n",
" Edges: 1637\n",
2024-07-17 15:45:54 +02:00
" Total Compute Effort: 0.0\n",
" Total Data Transfer: 0.0\n",
" Total Compute Intensity: 0.0\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"graph = generate_DAG(proc)"
]
},
{
"cell_type": "code",
2024-07-17 18:22:54 +02:00
"execution_count": 7,
2024-07-17 15:45:54 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2024-07-17 18:22:54 +02:00
"mock_machine (generic function with 1 method)"
2024-07-17 15:45:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"using MetagraphOptimization\n",
"using UUIDs\n",
"\n",
"function mock_machine()\n",
" return Machine(\n",
" [\n",
" MetagraphOptimization.NumaNode(\n",
" 0,\n",
" 1,\n",
" MetagraphOptimization.default_strategy(MetagraphOptimization.NumaNode),\n",
" -1.0,\n",
" UUIDs.uuid1(),\n",
" ),\n",
" ],\n",
" [-1.0;;],\n",
" )\n",
2024-07-17 18:22:54 +02:00
"end"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"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}"
2024-07-17 18:22:54 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"psp = PhaseSpacePoint(\n",
" proc,\n",
" PerturbativeQED(),\n",
" PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()),\n",
2024-07-17 18:22:54 +02:00
" tuple((rand(SFourMomentum) for _ in 1:number_incoming_particles(proc))...),\n",
" tuple((rand(SFourMomentum) for _ in 1:number_outgoing_particles(proc))...)\n",
")\n",
"typeof(psp)"
2024-07-17 15:45:54 +02:00
]
},
2024-07-16 18:51:09 +02:00
{
"cell_type": "code",
"execution_count": 11,
2024-07-16 18:51:09 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"32.69810945002751"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2024-07-16 18:51:09 +02:00
"source": [
"using MetagraphOptimization: unpack_identity\n",
"\n",
2024-07-17 18:22:54 +02:00
"func = eval(get_compute_function(graph, proc, mock_machine()))\n",
"\n",
"func(psp)"
2024-07-16 18:51:09 +02:00
]
},
{
"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": {
"kernelspec": {
"display_name": "Julia 1.10.4",
"language": "julia",
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}