Skip to content

Commit

Permalink
Fix tests for integration tests on QEDbase (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
szabo137 authored Jun 19, 2024
2 parents c29838a + 96d9384 commit a40938b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/QEDcore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ include("algebraic_objects/four_momentum.jl")
include("algebraic_objects/lorentz_vector.jl")
include("algebraic_objects/gamma_matrices.jl")

include("particles/spinors.jl")
include("particles/particle_types.jl")
include("particles/spinors.jl")

end
15 changes: 7 additions & 8 deletions src/particles/spinors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _build_particle_booster(
return (slashed(mom) + mass * one(DiracMatrix)) / (sqrt(abs(mom.t) + mass))
end

struct IncomingFermionSpinor <: QEDbase.AbstractParticleSpinor
struct IncomingFermionSpinor <: AbstractParticleSpinor
booster::DiracMatrix
end

Expand All @@ -59,7 +59,7 @@ end

const SpinorU = IncomingFermionSpinor

struct OutgoingFermionSpinor <: QEDbase.AbstractParticleSpinor
struct OutgoingFermionSpinor <: AbstractParticleSpinor
booster::DiracMatrix
end

Expand All @@ -86,7 +86,7 @@ function _build_antiparticle_booster(
return (mass * one(DiracMatrix) - slashed(mom)) / (sqrt(abs(mom.t) + mass))
end

struct OutgoingAntiFermionSpinor <: QEDbase.AbstractParticleSpinor
struct OutgoingAntiFermionSpinor <: AbstractParticleSpinor
booster::DiracMatrix
end

Expand All @@ -102,7 +102,7 @@ end

const SpinorV = OutgoingAntiFermionSpinor

struct IncomingAntiFermionSpinor <: QEDbase.AbstractParticleSpinor
struct IncomingAntiFermionSpinor <: AbstractParticleSpinor
booster::DiracMatrix
end

Expand All @@ -118,7 +118,6 @@ end

const SpinorVbar = IncomingAntiFermionSpinor

# TODO: reenable when it's no longer in QEDbase
# function getindex(SP::T, idx) where {T<:QEDbase.AbstractParticleSpinor}
# return idx in (1, 2) ? SP(idx) : throw(BoundsError())
# end
function getindex(SP::T, idx) where {T<:AbstractParticleSpinor}
return idx in (1, 2) ? SP(idx) : throw(BoundsError())
end
50 changes: 25 additions & 25 deletions test/particles/base_states.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using Random
include("../utils.jl")

FERMION_STATES_GROUNDTRUTH_FACTORY = Dict(
(QEDbase.Incoming, QEDbase.Electron) => IncomingFermionSpinor,
(QEDbase.Outgoing, QEDbase.Electron) => OutgoingFermionSpinor,
(QEDbase.Incoming, QEDbase.Positron) => IncomingAntiFermionSpinor,
(QEDbase.Outgoing, QEDbase.Positron) => OutgoingAntiFermionSpinor,
(QEDbase.Incoming, Electron) => IncomingFermionSpinor,
(QEDbase.Outgoing, Electron) => OutgoingFermionSpinor,
(QEDbase.Incoming, Positron) => IncomingAntiFermionSpinor,
(QEDbase.Outgoing, Positron) => OutgoingAntiFermionSpinor,
)

RNG = MersenneTwister(708583836976)
Expand Down Expand Up @@ -39,14 +39,14 @@ test_broadcast(x::QEDbase.ParticleDirection) = x
test_broadcast(x::QEDbase.AbstractSpinOrPolarization) = x

@testset "fermion" begin
struct TestFermion <: QEDbase.Fermion end
struct TestFermion <: Fermion end
@test QEDbase.is_fermion(TestFermion())
@test QEDbase.is_particle(TestFermion())
@test !QEDbase.is_anti_particle(TestFermion())
@test test_broadcast.(TestFermion()) == TestFermion()

@testset "$p $d" for (p, d) in Iterators.product(
(QEDbase.Electron, QEDbase.Positron), (QEDbase.Incoming, QEDbase.Outgoing)
(Electron, Positron), (QEDbase.Incoming, QEDbase.Outgoing)
)
mom = SFourMomentum(sqrt(QEDbase.mass(p()) + X^2 + Y^2 + Z^2), X, Y, Z)
particle_mass = QEDbase.mass(p())
Expand All @@ -73,13 +73,13 @@ test_broadcast(x::QEDbase.AbstractSpinOrPolarization) = x
end

@testset "photon" begin
@test !QEDbase.is_fermion(QEDbase.Photon())
@test QEDbase.is_boson(QEDbase.Photon())
@test QEDbase.is_particle(QEDbase.Photon())
@test QEDbase.is_anti_particle(QEDbase.Photon())
@test QEDbase.charge(QEDbase.Photon()) == 0.0
@test QEDbase.mass(QEDbase.Photon()) == 0.0
@test test_broadcast.(QEDbase.Photon()) == QEDbase.Photon()
@test !QEDbase.is_fermion(Photon())
@test QEDbase.is_boson(Photon())
@test QEDbase.is_particle(Photon())
@test QEDbase.is_anti_particle(Photon())
@test QEDbase.charge(Photon()) == 0.0
@test QEDbase.mass(Photon()) == 0.0
@test test_broadcast.(Photon()) == Photon()

@testset "$D" for D in [QEDbase.Incoming, QEDbase.Outgoing]
@testset "$om $cth $phi" for (om, cth, phi) in
Expand All @@ -88,7 +88,7 @@ end

mom = SFourMomentum(_cartesian_coordinates(om, om, cth, phi))
both_photon_states = QEDbase.base_state(
QEDbase.Photon(), D(), mom, QEDbase.AllPolarization()
Photon(), D(), mom, QEDbase.AllPolarization()
)

# property test the photon states
Expand All @@ -105,36 +105,36 @@ end
)

# test the single polarization states
@test QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolarizationX()) ==
@test QEDbase.base_state(Photon(), D(), mom, QEDbase.PolarizationX()) ==
both_photon_states[1]
@test QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolarizationY()) ==
@test QEDbase.base_state(Photon(), D(), mom, QEDbase.PolarizationY()) ==
both_photon_states[2]
@test QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolX()) ==
@test QEDbase.base_state(Photon(), D(), mom, QEDbase.PolX()) ==
both_photon_states[1]
@test QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolY()) ==
@test QEDbase.base_state(Photon(), D(), mom, QEDbase.PolY()) ==
both_photon_states[2]

@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolX())
QEDbase.base_state(Photon(), D(), mom, QEDbase.PolX())
) isa SVector
@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolY())
QEDbase.base_state(Photon(), D(), mom, QEDbase.PolY())
) isa SVector
@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.AllPol())
QEDbase.base_state(Photon(), D(), mom, QEDbase.AllPol())
) isa SVector

@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolX())
QEDbase.base_state(Photon(), D(), mom, QEDbase.PolX())
)[1] == both_photon_states[1]
@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.PolY())
QEDbase.base_state(Photon(), D(), mom, QEDbase.PolY())
)[1] == both_photon_states[2]
@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.AllPol())
QEDbase.base_state(Photon(), D(), mom, QEDbase.AllPol())
)[1] == both_photon_states[1]
@test QEDbase._as_svec(
QEDbase.base_state(QEDbase.Photon(), D(), mom, QEDbase.AllPol())
QEDbase.base_state(Photon(), D(), mom, QEDbase.AllPol())
)[2] == both_photon_states[2]
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/particles/propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ function _rand_momentum(rng::AbstractRNG)
return SFourMomentum(rand(rng, 4))
end

groundtruth_propagator(::QEDbase.Photon, mom) = one(eltype(mom)) / (mom * mom)
function groundtruth_propagator(particle::QEDbase.FermionLike, mom)
groundtruth_propagator(::Photon, mom) = one(eltype(mom)) / (mom * mom)
function groundtruth_propagator(particle::FermionLike, mom)
return (slashed(mom) + QEDbase.mass(particle) * one(DiracMatrix)) /
(mom * mom - QEDbase.mass(particle)^2)
end

@testset "propagators" begin
@testset "$P" for P in (QEDbase.Electron(), QEDbase.Positron(), QEDbase.Photon())
@testset "$P" for P in (Electron(), Positron(), Photon())
mom = _rand_momentum(RNG)
groundtruth = groundtruth_propagator(P, mom)
test_prop = QEDbase.propagator(P, mom)
Expand Down
6 changes: 6 additions & 0 deletions test/particles/types.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using QEDbase
using QEDcore
using StaticArrays
using Random

# TODO this can be deleted when QEDbase is released again
# fix ambiguity of the types while both core and base export these
import QEDcore:
AntiFermion, MajoranaFermion, Electron, Positron, Boson, AntiBoson, MajoranaBoson

# TODO this can be deleted when QEDbase is released again
# fix for the broadcast tests
Base.broadcastable(part::QEDbase.AbstractParticleType) = Ref(part)
Expand Down

0 comments on commit a40938b

Please sign in to comment.