Add QED Model (#25)
Reviewed-on: Rubydragon/MetagraphOptimization.jl#25 Co-authored-by: Anton Reinhard <anton.reinhard@proton.me> Co-committed-by: Anton Reinhard <anton.reinhard@proton.me>
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
[deps]
|
||||
AccurateArithmetic = "22286c92-06ac-501d-9306-4abd417d9753"
|
||||
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"
|
||||
QEDprocesses = "46de9c38-1bb3-4547-a1ec-da24d767fdad"
|
||||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
||||
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
|
||||
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
@ -8,23 +8,23 @@ graph = MetagraphOptimization.DAG()
|
||||
|
||||
d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskABC_S2()), track = false)
|
||||
|
||||
ED = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
FD = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
|
||||
EC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
FC = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
EC = insert_node!(graph, make_node(ComputeTaskABC_V()), track = false)
|
||||
FC = insert_node!(graph, make_node(ComputeTaskABC_V()), track = false)
|
||||
|
||||
A1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_1 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
B1D_2 = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
C1D = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
|
||||
A1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_1 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
B1C_2 = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
C1C = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
A1C = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
B1C_1 = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
B1C_2 = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
C1C = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
|
||||
AD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
BD = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
|
@ -1,35 +1,41 @@
|
||||
using SafeTestsets
|
||||
|
||||
@safetestset "Utility Unit Tests" begin
|
||||
@safetestset "Utility Unit Tests " begin
|
||||
include("unit_tests_utility.jl")
|
||||
end
|
||||
@safetestset "Task Unit Tests" begin
|
||||
@safetestset "Task Unit Tests " begin
|
||||
include("unit_tests_tasks.jl")
|
||||
end
|
||||
@safetestset "Node Unit Tests" begin
|
||||
@safetestset "Node Unit Tests " begin
|
||||
include("unit_tests_nodes.jl")
|
||||
end
|
||||
@safetestset "Properties Unit Tests" begin
|
||||
@safetestset "Properties Unit Tests " begin
|
||||
include("unit_tests_properties.jl")
|
||||
end
|
||||
@safetestset "Estimation Unit Tests" begin
|
||||
@safetestset "Estimation Unit Tests " begin
|
||||
include("unit_tests_estimator.jl")
|
||||
end
|
||||
@safetestset "ABC-Model Unit Tests" begin
|
||||
@safetestset "ABC-Model Unit Tests " begin
|
||||
include("unit_tests_abcmodel.jl")
|
||||
end
|
||||
@safetestset "Node Reduction Unit Tests" begin
|
||||
@safetestset "QED Feynman Diagram Generation Tests" begin
|
||||
include("unit_tests_qed_diagrams.jl")
|
||||
end
|
||||
@safetestset "QED-Model Unit Tests " begin
|
||||
include("unit_tests_qedmodel.jl")
|
||||
end
|
||||
@safetestset "Node Reduction Unit Tests " begin
|
||||
include("node_reduction.jl")
|
||||
end
|
||||
@safetestset "Graph Unit Tests" begin
|
||||
@safetestset "Graph Unit Tests " begin
|
||||
include("unit_tests_graph.jl")
|
||||
end
|
||||
@safetestset "Execution Unit Tests" begin
|
||||
@safetestset "Execution Unit Tests " begin
|
||||
include("unit_tests_execution.jl")
|
||||
end
|
||||
@safetestset "Optimization Unit Tests" begin
|
||||
@safetestset "Optimization Unit Tests " begin
|
||||
include("unit_tests_optimization.jl")
|
||||
end
|
||||
@safetestset "Known Graph Tests" begin
|
||||
@safetestset "Known Graph Tests " begin
|
||||
include("known_graphs.jl")
|
||||
end
|
||||
|
@ -19,5 +19,5 @@ testparticles = [ParticleA(def_momentum), ParticleB(def_momentum), ParticleC(def
|
||||
end
|
||||
|
||||
@testset "Vertex" begin
|
||||
@test isapprox(MetagraphOptimization.vertex(), 1 / 137.0)
|
||||
@test isapprox(MetagraphOptimization.ABC_vertex(), 1 / 137.0)
|
||||
end
|
||||
|
@ -38,8 +38,8 @@ function ground_truth_graph_result(input::ABCProcessInput)
|
||||
@test isapprox(getMass2(diagram1_C.momentum), getMass2(diagram1_Cp.momentum))
|
||||
@test isapprox(getMass2(diagram2_C.momentum), getMass2(diagram2_Cp.momentum))
|
||||
|
||||
inner1 = MetagraphOptimization.inner_edge(diagram1_C)
|
||||
inner2 = MetagraphOptimization.inner_edge(diagram2_C)
|
||||
inner1 = MetagraphOptimization.ABC_inner_edge(diagram1_C)
|
||||
inner2 = MetagraphOptimization.ABC_inner_edge(diagram2_C)
|
||||
|
||||
diagram1_result = inner1 * constant
|
||||
diagram2_result = inner2 * constant
|
||||
@ -122,95 +122,101 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
@testset "AB->AB large sum fusion" begin
|
||||
for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
if isa(fusion.input[3].task, ComputeTaskABC_Sum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@testset "AB->AB large sum fusion" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
@testset "AB->AB large sum fusion" begin
|
||||
for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, ComputeTaskSum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
# push a fusion with the sum node
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
if isa(fusion.input[3].task, ComputeTaskABC_Sum)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
# push two more fusions with the fused node
|
||||
for _ in 1:15
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[3].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
||||
@testset "AB->AB fusion edge case" for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
@testset "AB->AB fusion edge case" begin
|
||||
for _ in 1:20
|
||||
graph = parse_dag(joinpath(@__DIR__, "..", "input", "AB->AB.txt"), ABCModel())
|
||||
|
||||
# push two fusions with ComputeTaskV
|
||||
for _ in 1:2
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, ComputeTaskV)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
# push two fusions with ComputeTaskABC_V
|
||||
for _ in 1:2
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, ComputeTaskABC_V)
|
||||
push_operation!(graph, fusion)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# push fusions until the end
|
||||
cont = true
|
||||
while cont
|
||||
cont = false
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
cont = true
|
||||
break
|
||||
# push fusions until the end
|
||||
cont = true
|
||||
while cont
|
||||
cont = false
|
||||
ops = get_operations(graph)
|
||||
for fusion in ops.nodeFusions
|
||||
if isa(fusion.input[1].task, FusedComputeTask)
|
||||
push_operation!(graph, fusion)
|
||||
cont = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
# try execute
|
||||
@test is_valid(graph)
|
||||
expected_result = ground_truth_graph_result(particles_2_2)
|
||||
@test isapprox(execute(graph, process_2_2, machine, particles_2_2), expected_result; rtol = RTOL)
|
||||
end
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ d_exit = insert_node!(graph, make_node(DataTask(10)), track = false)
|
||||
@test length(graph.dirtyNodes) == 1
|
||||
|
||||
# final s compute
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskS2()), track = false)
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskABC_S2()), track = false)
|
||||
|
||||
@test length(graph.nodes) == 2
|
||||
@test length(graph.dirtyNodes) == 2
|
||||
@ -32,8 +32,8 @@ d_v0_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
d_v1_s0 = insert_node!(graph, make_node(DataTask(5)), track = false)
|
||||
|
||||
# v0 and v1 compute
|
||||
v0 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
v1 = insert_node!(graph, make_node(ComputeTaskV()), track = false)
|
||||
v0 = insert_node!(graph, make_node(ComputeTaskABC_V()), track = false)
|
||||
v1 = insert_node!(graph, make_node(ComputeTaskABC_V()), track = false)
|
||||
|
||||
# data from uB, uA, uBp and uAp to v0 and v1
|
||||
d_uB_v0 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
@ -42,10 +42,10 @@ d_uBp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
d_uAp_v1 = insert_node!(graph, make_node(DataTask(3)), track = false)
|
||||
|
||||
# uB, uA, uBp and uAp computes
|
||||
uB = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uA = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uBp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uAp = insert_node!(graph, make_node(ComputeTaskU()), track = false)
|
||||
uB = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
uA = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
uBp = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
uAp = insert_node!(graph, make_node(ComputeTaskABC_U()), track = false)
|
||||
|
||||
# data from PB, PA, PBp and PAp to uB, uA, uBp and uAp
|
||||
d_PB_uB = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
@ -54,10 +54,10 @@ d_PBp_uBp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
d_PAp_uAp = insert_node!(graph, make_node(DataTask(6)), track = false)
|
||||
|
||||
# P computes PB, PA, PBp and PAp
|
||||
PB = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PA = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PBp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PAp = insert_node!(graph, make_node(ComputeTaskP()), track = false)
|
||||
PB = insert_node!(graph, make_node(ComputeTaskABC_P()), track = false)
|
||||
PA = insert_node!(graph, make_node(ComputeTaskABC_P()), track = false)
|
||||
PBp = insert_node!(graph, make_node(ComputeTaskABC_P()), track = false)
|
||||
PAp = insert_node!(graph, make_node(ComputeTaskABC_P()), track = false)
|
||||
|
||||
# entry nodes getting data for P computes
|
||||
d_PB = insert_node!(graph, make_node(DataTask(4)), track = false)
|
||||
|
@ -1,9 +1,9 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
nC1 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskU())
|
||||
nC2 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskV())
|
||||
nC3 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskP())
|
||||
nC4 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskSum())
|
||||
nC1 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskABC_U())
|
||||
nC2 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskABC_V())
|
||||
nC3 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskABC_P())
|
||||
nC4 = MetagraphOptimization.make_node(MetagraphOptimization.ComputeTaskABC_Sum())
|
||||
|
||||
nD1 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(10))
|
||||
nD2 = MetagraphOptimization.make_node(MetagraphOptimization.DataTask(20))
|
||||
|
47
test/unit_tests_qed_diagrams.jl
Normal file
47
test/unit_tests_qed_diagrams.jl
Normal file
@ -0,0 +1,47 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
import MetagraphOptimization.gen_diagrams
|
||||
import MetagraphOptimization.isincoming
|
||||
import MetagraphOptimization.types
|
||||
|
||||
|
||||
model = QEDModel()
|
||||
compton = ("Compton Scattering", parse_process("ke->ke", model), 2)
|
||||
compton_3 = ("3-Photon Compton Scattering", parse_process("kkke->ke", QEDModel()), 24)
|
||||
compton_4 = ("4-Photon Compton Scattering", parse_process("kkkke->ke", QEDModel()), 120)
|
||||
bhabha = ("Bhabha Scattering", parse_process("ep->ep", model), 2)
|
||||
moller = ("Møller Scattering", parse_process("ee->ee", model), 2)
|
||||
pair_production = ("Pair production", parse_process("kk->ep", model), 2)
|
||||
pair_annihilation = ("Pair annihilation", parse_process("ep->kk", model), 2)
|
||||
trident = ("Trident", parse_process("ke->epe", model), 8)
|
||||
|
||||
@testset "Known Processes" begin
|
||||
@testset "$name" for (name, process, n) in
|
||||
[compton, bhabha, moller, pair_production, pair_annihilation, trident, compton_3, compton_4]
|
||||
initial_diagram = FeynmanDiagram(process)
|
||||
|
||||
n_particles = 0
|
||||
for type in types(model)
|
||||
if (isincoming(type))
|
||||
n_particles += get(process.inParticles, type, 0)
|
||||
else
|
||||
n_particles += get(process.outParticles, type, 0)
|
||||
end
|
||||
end
|
||||
@test n_particles == length(initial_diagram.particles)
|
||||
@test ismissing(initial_diagram.tie[])
|
||||
@test isempty(initial_diagram.vertices)
|
||||
|
||||
result_diagrams = gen_diagrams(initial_diagram)
|
||||
@test length(result_diagrams) == n
|
||||
|
||||
for d in result_diagrams
|
||||
n_vertices = 0
|
||||
for vs in d.vertices
|
||||
n_vertices += length(vs)
|
||||
end
|
||||
@test n_vertices == n_particles - 2
|
||||
@test !ismissing(d.tie[])
|
||||
end
|
||||
end
|
||||
end
|
291
test/unit_tests_qedmodel.jl
Normal file
291
test/unit_tests_qedmodel.jl
Normal file
@ -0,0 +1,291 @@
|
||||
using MetagraphOptimization
|
||||
using QEDbase
|
||||
using QEDprocesses
|
||||
using StatsBase # for countmap
|
||||
using Random
|
||||
|
||||
import MetagraphOptimization.caninteract
|
||||
import MetagraphOptimization.issame
|
||||
import MetagraphOptimization.interaction_result
|
||||
import MetagraphOptimization.propagation_result
|
||||
import MetagraphOptimization.direction
|
||||
import MetagraphOptimization.spin_or_pol
|
||||
import MetagraphOptimization.QED_vertex
|
||||
|
||||
def_momentum = SFourMomentum(1.0, 0.0, 0.0, 0.0)
|
||||
|
||||
RNG = Random.default_rng()
|
||||
|
||||
testparticleTypes = [
|
||||
PhotonStateful{Incoming},
|
||||
PhotonStateful{Outgoing},
|
||||
FermionStateful{Incoming},
|
||||
FermionStateful{Outgoing},
|
||||
AntiFermionStateful{Incoming},
|
||||
AntiFermionStateful{Outgoing},
|
||||
]
|
||||
|
||||
testparticleTypesPropagated = [
|
||||
PhotonStateful{Outgoing},
|
||||
PhotonStateful{Incoming},
|
||||
FermionStateful{Outgoing},
|
||||
FermionStateful{Incoming},
|
||||
AntiFermionStateful{Outgoing},
|
||||
AntiFermionStateful{Incoming},
|
||||
]
|
||||
|
||||
function compton_groundtruth(input::QEDProcessInput)
|
||||
# p1k1 -> p2k2
|
||||
# formula: −(ie)^2 (u(p2) slashed(ε1) S(p2 − k1) slashed(ε2) u(p1) + u(p2) slashed(ε2) S(p1 + k1) slashed(ε1) u(p1))
|
||||
|
||||
p1 = input.inParticles[findfirst(x -> typeof(x) <: FermionStateful, input.inParticles)]
|
||||
p2 = input.outParticles[findfirst(x -> typeof(x) <: FermionStateful, input.outParticles)]
|
||||
|
||||
k1 = input.inParticles[findfirst(x -> typeof(x) <: PhotonStateful, input.inParticles)]
|
||||
k2 = input.outParticles[findfirst(x -> typeof(x) <: PhotonStateful, input.outParticles)]
|
||||
|
||||
u_p1 = base_state(Electron(), Incoming(), p1.momentum, spin_or_pol(p1))
|
||||
u_p2 = base_state(Electron(), Outgoing(), p2.momentum, spin_or_pol(p2))
|
||||
|
||||
eps_1 = base_state(Photon(), Incoming(), k1.momentum, spin_or_pol(k1))
|
||||
eps_2 = base_state(Photon(), Outgoing(), k2.momentum, spin_or_pol(k2))
|
||||
|
||||
virt1_mom = p2.momentum - k1.momentum
|
||||
@test isapprox(p1.momentum - k2.momentum, virt1_mom)
|
||||
|
||||
virt2_mom = p1.momentum + k1.momentum
|
||||
@test isapprox(p2.momentum + k2.momentum, virt2_mom)
|
||||
|
||||
s_p2_k1 = propagator(Electron(), virt1_mom)
|
||||
s_p1_k1 = propagator(Electron(), virt2_mom)
|
||||
|
||||
diagram1 = u_p2 * (eps_1 * QED_vertex()) * s_p2_k1 * (eps_2 * QED_vertex()) * u_p1
|
||||
diagram2 = u_p2 * (eps_2 * QED_vertex()) * s_p1_k1 * (eps_1 * QED_vertex()) * u_p1
|
||||
|
||||
return diagram1 + diagram2
|
||||
end
|
||||
|
||||
|
||||
@testset "Interaction Result" begin
|
||||
import MetagraphOptimization.QED_conserve_momentum
|
||||
|
||||
for p1 in testparticleTypes, p2 in testparticleTypes
|
||||
if !caninteract(p1, p2)
|
||||
@test_throws AssertionError interaction_result(p1, p2)
|
||||
continue
|
||||
end
|
||||
|
||||
@test interaction_result(p1, p2) in setdiff(testparticleTypes, [p1, p2])
|
||||
@test issame(interaction_result(p1, p2), interaction_result(p2, p1))
|
||||
|
||||
testParticle1 = p1(rand(RNG, SFourMomentum))
|
||||
testParticle2 = p2(rand(RNG, SFourMomentum))
|
||||
p3 = interaction_result(p1, p2)
|
||||
|
||||
resultParticle = QED_conserve_momentum(testParticle1, testParticle2)
|
||||
|
||||
@test issame(typeof(resultParticle), interaction_result(p1, p2))
|
||||
|
||||
totalMom = zero(SFourMomentum)
|
||||
for (p, mom) in [(p1, testParticle1.momentum), (p2, testParticle2.momentum), (p3, resultParticle.momentum)]
|
||||
if (typeof(direction(p)) <: Incoming)
|
||||
totalMom += mom
|
||||
else
|
||||
totalMom -= mom
|
||||
end
|
||||
end
|
||||
|
||||
@test isapprox(totalMom, zero(SFourMomentum); atol = sqrt(eps()))
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Propagation Result" begin
|
||||
for (p, propResult) in zip(testparticleTypes, testparticleTypesPropagated)
|
||||
@test issame(propagation_result(p), propResult)
|
||||
@test direction(propagation_result(p)(def_momentum)) != direction(p(def_momentum))
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Parse Process" begin
|
||||
@testset "Order invariance" begin
|
||||
@test parse_process("ke->ke", QEDModel()) == parse_process("ek->ke", QEDModel())
|
||||
@test parse_process("ke->ke", QEDModel()) == parse_process("ek->ek", QEDModel())
|
||||
@test parse_process("ke->ke", QEDModel()) == parse_process("ke->ek", QEDModel())
|
||||
|
||||
@test parse_process("kkke->eep", QEDModel()) == parse_process("kkek->epe", QEDModel())
|
||||
end
|
||||
|
||||
@testset "Known processes" begin
|
||||
compton_process = QEDProcessDescription(
|
||||
Dict{Type, Int}(PhotonStateful{Incoming} => 1, FermionStateful{Incoming} => 1),
|
||||
Dict{Type, Int}(PhotonStateful{Outgoing} => 1, FermionStateful{Outgoing} => 1),
|
||||
)
|
||||
|
||||
@test parse_process("ke->ke", QEDModel()) == compton_process
|
||||
|
||||
positron_compton_process = QEDProcessDescription(
|
||||
Dict{Type, Int}(PhotonStateful{Incoming} => 1, AntiFermionStateful{Incoming} => 1),
|
||||
Dict{Type, Int}(PhotonStateful{Outgoing} => 1, AntiFermionStateful{Outgoing} => 1),
|
||||
)
|
||||
|
||||
@test parse_process("kp->kp", QEDModel()) == positron_compton_process
|
||||
|
||||
trident_process = QEDProcessDescription(
|
||||
Dict{Type, Int}(PhotonStateful{Incoming} => 1, FermionStateful{Incoming} => 1),
|
||||
Dict{Type, Int}(FermionStateful{Outgoing} => 2, AntiFermionStateful{Outgoing} => 1),
|
||||
)
|
||||
|
||||
@test parse_process("ke->eep", QEDModel()) == trident_process
|
||||
|
||||
pair_production_process = QEDProcessDescription(
|
||||
Dict{Type, Int}(PhotonStateful{Incoming} => 2),
|
||||
Dict{Type, Int}(FermionStateful{Outgoing} => 1, AntiFermionStateful{Outgoing} => 1),
|
||||
)
|
||||
|
||||
@test parse_process("kk->pe", QEDModel()) == pair_production_process
|
||||
|
||||
pair_annihilation_process = QEDProcessDescription(
|
||||
Dict{Type, Int}(FermionStateful{Incoming} => 1, AntiFermionStateful{Incoming} => 1),
|
||||
Dict{Type, Int}(PhotonStateful{Outgoing} => 2),
|
||||
)
|
||||
|
||||
@test parse_process("pe->kk", QEDModel()) == pair_annihilation_process
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Generate Process Inputs" begin
|
||||
@testset "Process $proc_str" for proc_str in ["ke->ke", "kp->kp", "kk->ep", "ep->kk"]
|
||||
# currently can only generate for 2->2 processes
|
||||
process = parse_process(proc_str, QEDModel())
|
||||
|
||||
for i in 1:100
|
||||
input = gen_process_input(process)
|
||||
@test countmap(typeof.(input.inParticles)) == process.inParticles
|
||||
@test countmap(typeof.(input.outParticles)) == process.outParticles
|
||||
|
||||
@test isapprox(
|
||||
sum(getfield.(input.inParticles, :momentum)),
|
||||
sum(getfield.(input.outParticles, :momentum));
|
||||
atol = sqrt(eps()),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Compton" begin
|
||||
import MetagraphOptimization.insert_node!
|
||||
import MetagraphOptimization.insert_edge!
|
||||
import MetagraphOptimization.make_node
|
||||
|
||||
model = QEDModel()
|
||||
process = parse_process("ke->ke", model)
|
||||
machine = get_machine_info()
|
||||
|
||||
graph = MetagraphOptimization.DAG()
|
||||
|
||||
# manually build a graph for compton
|
||||
graph = DAG()
|
||||
|
||||
# s to output (exit node)
|
||||
d_exit = insert_node!(graph, make_node(DataTask(16)), track = false)
|
||||
|
||||
sum_node = insert_node!(graph, make_node(ComputeTaskQED_Sum(2)), track = false)
|
||||
|
||||
d_s0_sum = insert_node!(graph, make_node(DataTask(16)), track = false)
|
||||
d_s1_sum = insert_node!(graph, make_node(DataTask(16)), track = false)
|
||||
|
||||
# final s compute
|
||||
s0 = insert_node!(graph, make_node(ComputeTaskQED_S2()), track = false)
|
||||
s1 = insert_node!(graph, make_node(ComputeTaskQED_S2()), track = false)
|
||||
|
||||
# data from v0 and v1 to s0
|
||||
d_v0_s0 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_v1_s0 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_v2_s1 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_v3_s1 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
|
||||
# v0 and v1 compute
|
||||
v0 = insert_node!(graph, make_node(ComputeTaskQED_V()), track = false)
|
||||
v1 = insert_node!(graph, make_node(ComputeTaskQED_V()), track = false)
|
||||
v2 = insert_node!(graph, make_node(ComputeTaskQED_V()), track = false)
|
||||
v3 = insert_node!(graph, make_node(ComputeTaskQED_V()), track = false)
|
||||
|
||||
# data from uPhIn, uPhOut, uElIn, uElOut to v0 and v1
|
||||
d_uPhIn_v0 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uElIn_v0 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uPhOut_v1 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uElOut_v1 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
|
||||
# data from uPhIn, uPhOut, uElIn, uElOut to v2 and v3
|
||||
d_uPhOut_v2 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uElIn_v2 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uPhIn_v3 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
d_uElOut_v3 = insert_node!(graph, make_node(DataTask(96)), track = false)
|
||||
|
||||
# uPhIn, uPhOut, uElIn and uElOut computes
|
||||
uPhIn = insert_node!(graph, make_node(ComputeTaskQED_U()), track = false)
|
||||
uPhOut = insert_node!(graph, make_node(ComputeTaskQED_U()), track = false)
|
||||
uElIn = insert_node!(graph, make_node(ComputeTaskQED_U()), track = false)
|
||||
uElOut = insert_node!(graph, make_node(ComputeTaskQED_U()), track = false)
|
||||
|
||||
# data into U
|
||||
d_uPhIn = insert_node!(graph, make_node(DataTask(16), "ki1"), track = false)
|
||||
d_uPhOut = insert_node!(graph, make_node(DataTask(16), "ko1"), track = false)
|
||||
d_uElIn = insert_node!(graph, make_node(DataTask(16), "ei1"), track = false)
|
||||
d_uElOut = insert_node!(graph, make_node(DataTask(16), "eo1"), track = false)
|
||||
|
||||
# now for all the edges
|
||||
insert_edge!(graph, d_uPhIn, uPhIn, track = false)
|
||||
insert_edge!(graph, d_uPhOut, uPhOut, track = false)
|
||||
insert_edge!(graph, d_uElIn, uElIn, track = false)
|
||||
insert_edge!(graph, d_uElOut, uElOut, track = false)
|
||||
|
||||
insert_edge!(graph, uPhIn, d_uPhIn_v0, track = false)
|
||||
insert_edge!(graph, uPhOut, d_uPhOut_v1, track = false)
|
||||
insert_edge!(graph, uElIn, d_uElIn_v0, track = false)
|
||||
insert_edge!(graph, uElOut, d_uElOut_v1, track = false)
|
||||
|
||||
insert_edge!(graph, uPhIn, d_uPhIn_v3, track = false)
|
||||
insert_edge!(graph, uPhOut, d_uPhOut_v2, track = false)
|
||||
insert_edge!(graph, uElIn, d_uElIn_v2, track = false)
|
||||
insert_edge!(graph, uElOut, d_uElOut_v3, track = false)
|
||||
|
||||
insert_edge!(graph, d_uPhIn_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uPhOut_v1, v1, track = false)
|
||||
insert_edge!(graph, d_uElIn_v0, v0, track = false)
|
||||
insert_edge!(graph, d_uElOut_v1, v1, track = false)
|
||||
|
||||
insert_edge!(graph, d_uPhIn_v3, v3, track = false)
|
||||
insert_edge!(graph, d_uPhOut_v2, v2, track = false)
|
||||
insert_edge!(graph, d_uElIn_v2, v2, track = false)
|
||||
insert_edge!(graph, d_uElOut_v3, v3, track = false)
|
||||
|
||||
insert_edge!(graph, v0, d_v0_s0, track = false)
|
||||
insert_edge!(graph, v1, d_v1_s0, track = false)
|
||||
insert_edge!(graph, v2, d_v2_s1, track = false)
|
||||
insert_edge!(graph, v3, d_v3_s1, track = false)
|
||||
|
||||
insert_edge!(graph, d_v0_s0, s0, track = false)
|
||||
insert_edge!(graph, d_v1_s0, s0, track = false)
|
||||
|
||||
insert_edge!(graph, d_v2_s1, s1, track = false)
|
||||
insert_edge!(graph, d_v3_s1, s1, track = false)
|
||||
|
||||
insert_edge!(graph, s0, d_s0_sum, track = false)
|
||||
insert_edge!(graph, s1, d_s1_sum, track = false)
|
||||
|
||||
insert_edge!(graph, d_s0_sum, sum_node, track = false)
|
||||
insert_edge!(graph, d_s1_sum, sum_node, track = false)
|
||||
|
||||
insert_edge!(graph, sum_node, d_exit, track = false)
|
||||
|
||||
input = [gen_process_input(process) for _ in 1:1000]
|
||||
|
||||
compton_function = get_compute_function(graph, process, machine)
|
||||
@test isapprox(compton_function.(input), compton_groundtruth.(input))
|
||||
|
||||
graph_generated = gen_graph(process)
|
||||
|
||||
compton_function = get_compute_function(graph_generated, process, machine)
|
||||
@test isapprox(compton_function.(input), compton_groundtruth.(input))
|
||||
end
|
@ -1,11 +1,11 @@
|
||||
using MetagraphOptimization
|
||||
|
||||
S1 = MetagraphOptimization.ComputeTaskS1()
|
||||
S2 = MetagraphOptimization.ComputeTaskS2()
|
||||
U = MetagraphOptimization.ComputeTaskU()
|
||||
V = MetagraphOptimization.ComputeTaskV()
|
||||
P = MetagraphOptimization.ComputeTaskP()
|
||||
Sum = MetagraphOptimization.ComputeTaskSum()
|
||||
S1 = MetagraphOptimization.ComputeTaskABC_S1()
|
||||
S2 = MetagraphOptimization.ComputeTaskABC_S2()
|
||||
U = MetagraphOptimization.ComputeTaskABC_U()
|
||||
V = MetagraphOptimization.ComputeTaskABC_V()
|
||||
P = MetagraphOptimization.ComputeTaskABC_P()
|
||||
Sum = MetagraphOptimization.ComputeTaskABC_Sum()
|
||||
|
||||
Data10 = MetagraphOptimization.DataTask(10)
|
||||
Data20 = MetagraphOptimization.DataTask(20)
|
||||
@ -46,4 +46,4 @@ Data10_3 = copy(Data10)
|
||||
S1_2 = copy(S1)
|
||||
|
||||
@test S1_2 == S1
|
||||
@test S1 == MetagraphOptimization.ComputeTaskS1()
|
||||
@test S1 == MetagraphOptimization.ComputeTaskABC_S1()
|
||||
|
Reference in New Issue
Block a user