Reenable tests and fix a lot
Some checks failed
MetagraphOptimization_CI / test (push) Failing after 6m58s
MetagraphOptimization_CI / docs (push) Failing after 7m6s

This commit is contained in:
Anton Reinhard 2024-08-19 17:45:40 +02:00
parent d553fe8ffc
commit 0ce98e29ef
No known key found for this signature in database
GPG Key ID: D65083A1729C9270
7 changed files with 47 additions and 156 deletions

View File

@ -11,57 +11,35 @@ function parse_process(
outphpol::AbstractDefinitePolarization = PolX(),
outelspin::AbstractDefiniteSpin = SpinUp(),
)
inParticles = Dict(
ParticleStateful{Incoming, Photon, SFourMomentum} => 0,
ParticleStateful{Incoming, Electron, SFourMomentum} => 0,
ParticleStateful{Incoming, Positron, SFourMomentum} => 0,
)
outParticles = Dict(
ParticleStateful{Outgoing, Photon, SFourMomentum} => 0,
ParticleStateful{Outgoing, Electron, SFourMomentum} => 0,
ParticleStateful{Outgoing, Positron, SFourMomentum} => 0,
)
if !(contains(str, "->"))
throw("Did not find -> while parsing process \"$str\"")
end
(inStr, outStr) = split(str, "->")
(in_str, out_str) = split(str, "->")
if (isempty(inStr) || isempty(outStr))
if (isempty(in_str) || isempty(out_str))
throw("Process (\"$str\") input or output part is empty!")
end
for t in types(model)
if (is_incoming(t))
inCount = count(x -> x == String(t)[1], inStr)
in_particles = Vector{AbstractParticleType}()
out_particles = Vector{AbstractParticleType}()
if inCount != 0
inParticles[t] = inCount
end
end
if (is_outgoing(t))
outCount = count(x -> x == String(t)[1], outStr)
if outCount != 0
outParticles[t] = outCount
for (particle_vector, s) in ((in_particles, in_str), (out_particles, out_str))
for c in s
if c == 'e'
push!(particle_vector, Electron())
elseif c == 'p'
push!(particle_vector, Positron())
elseif c == 'k'
push!(particle_vector, Photon())
else
throw("Encountered unknown characters in the process \"$str\"")
end
end
end
if length(inStr) != sum(values(inParticles))
throw("Encountered unknown characters in the input part of process \"$str\"")
elseif length(outStr) != sum(values(outParticles))
throw("Encountered unknown characters in the output part of process \"$str\"")
end
in_spin_pols = tuple([is_boson(in_particles[i]) ? inphpol : inelspin for i in eachindex(in_particles)]...)
out_spin_pols = tuple([is_boson(out_particles[i]) ? outphpol : outelspin for i in eachindex(out_particles)]...)
in_ph = inParticles[ParticleStateful{Incoming, Photon, SFourMomentum}]
in_el = inParticles[ParticleStateful{Incoming, Electron, SFourMomentum}]
in_pos = inParticles[ParticleStateful{Incoming, Positron, SFourMomentum}]
out_ph = outParticles[ParticleStateful{Outgoing, Photon, SFourMomentum}]
out_el = outParticles[ParticleStateful{Outgoing, Electron, SFourMomentum}]
out_pos = outParticles[ParticleStateful{Outgoing, Positron, SFourMomentum}]
in_spin_pols = tuple([i <= in_ph ? inphpol : inelspin for i in 1:(in_ph + in_el)]...)
out_spin_pols = tuple([i <= out_ph ? outphpol : outelspin for i in 1:(out_ph + out_el)]...)
return GenericQEDProcess(in_ph, out_ph, in_el, out_el, in_pos, out_pos, in_spin_pols, out_spin_pols)
return GenericQEDProcess(tuple(in_particles...), tuple(out_particles...), in_spin_pols, out_spin_pols)
end

View File

@ -3,13 +3,6 @@ using StaticArrays
const e = sqrt(4π / 137)
"""
QEDModel <: AbstractPhysicsModel
Singleton definition for identification of the QED-Model.
"""
struct QEDModel <: AbstractPhysicsModel end
QEDbase.is_incoming(::Type{<:ParticleStateful{Incoming}}) = true
QEDbase.is_outgoing(::Type{<:ParticleStateful{Outgoing}}) = true
QEDbase.is_incoming(::Type{<:ParticleStateful{Outgoing}}) = false
@ -20,61 +13,6 @@ QEDbase.particle_species(
::Type{<:ParticleStateful{DIR, SPECIES}},
) where {DIR <: ParticleDirection, SPECIES <: AbstractParticleType} = SPECIES()
_assert_particle_type_tuple(::Tuple{}) = nothing
_assert_particle_type_tuple(t::Tuple{AbstractParticleType, Vararg}) = _assert_particle_type_tuple(t[2:end])
_assert_particle_type_tuple(t::Any) =
throw(InvalidInputError("invalid input, provide a tuple of AbstractParticleTypes to construct a GenericQEDProcess"))
struct GenericQEDProcess{INT, OUTT, INSP, OUTSP} <:
AbstractProcessDefinition where {INT <: Tuple, OUTT <: Tuple, INSP <: Tuple, OUTSP <: Tuple}
incoming_particles::INT
outgoing_particles::OUTT
incoming_spins_pols::INSP
outgoing_spins_pols::OUTSP
function GenericQEDProcess(
in_particles::INT,
out_particles::OUTT,
in_sp::INSP,
out_sp::OUTSP,
) where {INT <: Tuple, OUTT <: Tuple, INSP <: Tuple, OUTSP <: Tuple}
_assert_particle_type_tuple(in_particles)
_assert_particle_type_tuple(out_particles)
# TODO: check in_sp/out_sp fits to particles (spin->fermion, pol->photon)
return new{INT, OUTT, INSP, OUTSP}(in_particles, out_particles, in_sp, out_sp)
end
"""
GenericQEDProcess{INSP, OUTSP}(in_ph::Int, out_ph::Int, in_el::Int, out_el::Int, in_po::Int, out_po::Int, in_sp::INSP, out_sp::OUTSP)
Convenience constructor from numbers of input/output photons, electrons and positrons.
`in_sp` and `out_sp` are tuples of the spin and polarization configurations of the given particles. Their order is Photons, then Electrons, then Positrons for both incoming and outgoing particles.
# TODO: make default for in_sp and out_sp available for convenience
"""
function GenericQEDProcess(
in_ph::Int,
out_ph::Int,
in_el::Int,
out_el::Int,
in_po::Int,
out_po::Int,
in_sp::INSP,
out_sp::OUTSP,
) where {INSP <: Tuple, OUTSP <: Tuple}
in_p = ntuple(i -> i <= in_ph ? Photon() : i <= in_ph + in_el ? Electron() : Positron(), in_ph + in_el + in_po)
out_p = ntuple(
i -> i <= out_ph ? Photon() : i <= out_ph + out_el ? Electron() : Positron(),
out_ph + out_el + out_po,
)
return GenericQEDProcess(in_p, out_p, in_sp, out_sp)
end
end
function spin_or_pol(
process::GenericQEDProcess,
type::Type{ParticleStateful{DIR, SPECIES, EL}},
@ -105,16 +43,6 @@ function spin_or_pol(
end
end
QEDprocesses.incoming_particles(proc::GenericQEDProcess) = proc.incoming_particles
QEDprocesses.outgoing_particles(proc::GenericQEDProcess) = proc.outgoing_particles
function isphysical(proc::GenericQEDProcess)
return (
number_particles(proc, Incoming(), Electron()) + number_particles(proc, Outgoing(), Positron()) ==
number_particles(proc, Incoming(), Positron()) + number_particles(proc, Outgoing(), Electron())
) && number_particles(proc, Incoming()) + number_particles(proc, Outgoing()) >= 2
end
function input_type(p::GenericQEDProcess)
in_t = QEDcore._assemble_tuple_type(incoming_particles(p), Incoming(), SFourMomentum)
out_t = QEDcore._assemble_tuple_type(outgoing_particles(p), Outgoing(), SFourMomentum)

View File

@ -1,3 +1,10 @@
"""
QEDModel <: AbstractPhysicsModel
Singleton definition for identification of the QED-Model.
"""
struct QEDModel <: AbstractPhysicsModel end
"""
ComputeTaskQED_S1 <: AbstractComputeTask

View File

@ -1,5 +1,5 @@
using MetagraphOptimization
using QEDbase
using QEDcore
using AccurateArithmetic
using Random
using UUIDs

View File

@ -136,8 +136,6 @@ operations = get_operations(graph)
@test length(operations) == (nodeReductions = 0, nodeSplits = 0)
@test length(graph.dirtyNodes) == 0
@test sum(length(operations)) == 10
@test operations == get_operations(graph)
properties = get_properties(graph)
@ -153,13 +151,13 @@ operations = get_operations(graph)
@test length(operations) == (nodeReductions = 0, nodeSplits = 0)
@test isempty(operations)
@test length(graph.dirtyNodes) == 0
@test length(graph.nodes) == 6
@test length(graph.appliedOperations) == 10
@test length(graph.nodes) == 26
@test length(graph.appliedOperations) == 0
@test length(graph.operationsToApply) == 0
reset_graph!(graph)
@test length(graph.dirtyNodes) == 26
@test length(graph.dirtyNodes) == 0
@test length(graph.nodes) == 26
@test length(graph.appliedOperations) == 0
@test length(graph.operationsToApply) == 0

View File

@ -1,7 +1,8 @@
using MetagraphOptimization
using QEDcore
import MetagraphOptimization.gen_diagrams
import MetagraphOptimization.isincoming
import MetagraphOptimization.types
@ -9,25 +10,12 @@ 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]
@testset "$name" for (name, process, n) in [compton, compton_3, compton_4]
initial_diagram = FeynmanDiagram(process)
n_particles = number_incoming_particles(process) + number_outgoing_particles(process)
n_particles = 0
for type in types(model)
if (is_incoming(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)

View File

@ -106,34 +106,26 @@ 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 = GenericQEDProcess(1, 1, 1, 1, 0, 0)
proc = parse_process("ke->ke", QEDModel())
@test incoming_particles(proc) == (Photon(), Electron())
@test outgoing_particles(proc) == (Photon(), Electron())
@test parse_process("ke->ke", QEDModel()) == compton_process
proc = parse_process("kp->kp", QEDModel())
@test incoming_particles(proc) == (Photon(), Positron())
@test outgoing_particles(proc) == (Photon(), Positron())
positron_compton_process = GenericQEDProcess(1, 1, 0, 0, 1, 1)
proc = parse_process("ke->eep", QEDModel())
@test incoming_particles(proc) == (Photon(), Electron())
@test outgoing_particles(proc) == (Electron(), Electron(), Positron())
@test parse_process("kp->kp", QEDModel()) == positron_compton_process
proc = parse_process("kk->pe", QEDModel())
@test incoming_particles(proc) == (Photon(), Photon())
@test outgoing_particles(proc) == (Positron(), Electron())
trident_process = GenericQEDProcess(1, 0, 1, 2, 0, 1)
@test parse_process("ke->eep", QEDModel()) == trident_process
pair_production_process = GenericQEDProcess(2, 0, 0, 1, 0, 1)
@test parse_process("kk->pe", QEDModel()) == pair_production_process
pair_annihilation_process = GenericQEDProcess(0, 2, 1, 0, 1, 0)
@test parse_process("pe->kk", QEDModel()) == pair_annihilation_process
proc = parse_process("pe->kk", QEDModel())
@test incoming_particles(proc) == (Positron(), Electron())
@test outgoing_particles(proc) == (Photon(), Photon())
end
end