From 2394818fcc9e04cae6359b069d6258eeb46bd70d Mon Sep 17 00:00:00 2001 From: Rubydragon Date: Fri, 28 Jun 2024 11:17:31 +0200 Subject: [PATCH] Remove test implementation CI_UNIT_PKG_URL_QEDbase: https://github.com/szabo137/QEDbase.jl#fb4c800acc99ffe83efe558a5a094e63eed9abde --- test/runtests.jl | 6 - .../test_implementation/TestImplementation.jl | 40 --- test/test_implementation/groundtruths.jl | 263 ------------------ test/test_implementation/random_momenta.jl | 83 ------ test/test_implementation/test_model.jl | 5 - test/test_implementation/test_process.jl | 131 --------- test/test_implementation/utils.jl | 44 --- 7 files changed, 572 deletions(-) delete mode 100644 test/test_implementation/TestImplementation.jl delete mode 100644 test/test_implementation/groundtruths.jl delete mode 100644 test/test_implementation/random_momenta.jl delete mode 100644 test/test_implementation/test_model.jl delete mode 100644 test/test_implementation/test_process.jl delete mode 100644 test/test_implementation/utils.jl diff --git a/test/runtests.jl b/test/runtests.jl index e5d7a1e..8661249 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,7 @@ -using QEDprocesses using Test using SafeTestsets begin - # modules - @time @safetestset "cross section & probability" begin - include("cross_sections.jl") - end - # scattering processes include("processes/run_process_test.jl") end diff --git a/test/test_implementation/TestImplementation.jl b/test/test_implementation/TestImplementation.jl deleted file mode 100644 index 714fda2..0000000 --- a/test/test_implementation/TestImplementation.jl +++ /dev/null @@ -1,40 +0,0 @@ -""" -This module provides a full implementation of the model and process interface. Its purpose is only for testing and it does not reflect any -real-world physics. - -The module exports: - -``` -TestParticle1 # set of test particles without properties -TestParticle2 -TestParticle3 -TestParticle4 -TestModel # dummy compute model -TestModel_FAIL # failing compute model -TestProcess # dummy scattering process -TestProcess_FAIL # failing scattering process -TestPhasespaceDef # dummy phase space definition -TestPhasespaceDef_FAIL # failing phase space definition -``` -The respective groundtruth implementations for the interface functions are stored in `groundtruths.jl` -""" -module TestImplementation - -export TestParticle1, TestParticle2, TestParticle3, TestParticle4, PARTICLE_SET -export TestModel, TestModel_FAIL -export TestProcess, TestProcess_FAIL -export TestPhasespaceDef, TestPhasespaceDef_FAIL - -using Random -using QEDbase -using QEDcore -using QEDprocesses -using StaticArrays - -include("groundtruths.jl") -include("test_model.jl") -include("test_process.jl") -include("random_momenta.jl") -include("utils.jl") - -end diff --git a/test/test_implementation/groundtruths.jl b/test/test_implementation/groundtruths.jl deleted file mode 100644 index fce9891..0000000 --- a/test/test_implementation/groundtruths.jl +++ /dev/null @@ -1,263 +0,0 @@ -""" - _groundtruth_incident_flux(in_ps) - -Test implementation of the incident flux. Return the Minkowski square of the sum of the incoming momenta: - -```math -\\begin{align} -I = \\left(\\sum p_i\\right)^2, -\\end{align} -``` -where \$p_i\\in\\mathrm{ps_in}\$. -""" -function _groundtruth_incident_flux(in_ps) - s = sum(in_ps) - return s * s -end - -""" - _groundtruth_matrix_element(in_ps, out_ps) - -Test implementation for a matrix elements. Returns a list of three complex numbers without any physical meaning. -""" -function _groundtruth_matrix_element(in_ps, out_ps) - s_in = sum(in_ps) - s_out = sum(out_ps) - res = s_in * s_in + 1im * (s_out * s_out) - return (res, 2 * res, 3 * res) -end - -""" - _groundtruth_averaging_norm(proc) - -Test implementation of the averaging norm. Returns the inverse of the sum of all external particles of the passed process. -""" -function _groundtruth_averaging_norm(proc) - return 1.0 / (number_incoming_particles(proc) + number_outgoing_particles(proc)) -end - -""" - _groundtruth_is_in_phasespace(in_ps, out_ps) - -Test implementation of the phase space check. Return `false` if either the momentum of the first incoming particle is exactly `zero(SFourMomentum)`, or if the momentum of the last outgoing momentum is exactly `ones(SFourMomentum)`. Otherwise, return true. -""" -function _groundtruth_is_in_phasespace(in_ps, out_ps) - if in_ps[1] == SFourMomentum(zeros(4)) - return false - end - if out_ps[end] == ones(SFourMomentum) - return false - end - return true -end - -""" - _groundtruth_phase_space_factor(in_ps, out_ps) - -Test implementation of the phase space factor. Return the inverse of the product of the energies of all external particles. -""" -function _groundtruth_phase_space_factor(in_ps, out_ps) - en_in = getE.(in_ps) - en_out = getE.(out_ps) - return 1 / (prod(en_in) * prod(en_out)) -end - -function _groundtruth_generate_momenta(ps_coords) - moms = _furl_moms(ps_coords) - return moms -end -""" - _groundtruth_unsafe_probability(proc, in_ps, out_ps) - -Test implementation of the unsafe differential probability. Uses the test implementations of `_groundtruth_matrix_element`,`_groundtruth_averaging_norm` and `_groundtruth_phase_space_factor`. -""" -function _groundtruth_unsafe_probability(proc, in_ps, out_ps) - mat_el = _groundtruth_matrix_element(in_ps, out_ps) - mat_el_sq = abs2.(mat_el) - normalization = _groundtruth_averaging_norm(proc) - ps_fac = _groundtruth_phase_space_factor(in_ps, out_ps) - return sum(mat_el_sq) * ps_fac * normalization -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractVector, out_ps::AbstractMatrix -) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractVector -) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_probability( - proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix -) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_safe_probability(proc, in_ps, out_ps) - -Test implementation of the safe differential probability. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_probability`. -""" -function _groundtruth_safe_probability(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_probability(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_probability(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_probability(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_probability( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) - -Test implementation of the unsafe differential cross section. Uses the test implementations of `_groundtruth_incident_flux` and `_groundtruth_unsafe_probability`. -""" -function _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_unsafe_probability(proc, in_ps, out_ps) / (4 * init_flux) -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_unsafe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_unsafe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_unsafe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_safe_diffCS(proc, in_ps, out_ps) - -Test implementation of the safe differential cross section. Uses the test implementations of `_groundtruth_is_in_phasespace` and `_groundtruth_unsafe_diffCS`. -""" -function _groundtruth_safe_diffCS(proc, in_ps, out_ps) - if !_groundtruth_is_in_phasespace(in_ps, out_ps) - return zero(Float64) - end - return _groundtruth_unsafe_diffCS(proc, in_ps, out_ps) -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractVector, out_ps::AbstractMatrix) - res = Vector{Float64}(undef, size(out_ps, 2)) - for i in 1:size(out_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, in_ps, view(out_ps, :, i)) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractVector) - res = Vector{Float64}(undef, size(in_ps, 2)) - for i in 1:size(in_ps, 2) - res[i] = _groundtruth_safe_diffCS(proc, view(in_ps, :, i), out_ps) - end - return res -end - -function _groundtruth_safe_diffCS(proc, in_ps::AbstractMatrix, out_ps::AbstractMatrix) - res = Matrix{Float64}(undef, size(in_ps, 2), size(out_ps, 2)) - for i in 1:size(in_ps, 2) - for j in 1:size(out_ps, 2) - res[i, j] = _groundtruth_safe_diffCS( - proc, view(in_ps, :, i), view(out_ps, :, j) - ) - end - end - return res -end - -""" - _groundtruth_total_probability(in_ps::AbstractVector) - -Test implementation of the total cross section. Return the Minkowski square of the sum the momenta of all incoming particles. -""" -function _groundtruth_total_probability( - in_ps::NTuple{N,T} -) where {N,T<:AbstractFourMomentum} - Ptot = sum(in_ps) - return Ptot * Ptot -end - -function _groundtruth_total_probability( - in_pss::Vector{NTuple{N,T}} -) where {N,T<:AbstractFourMomentum} - return _groundtruth_total_probability.(in_pss) -end - -function _groundtruth_total_cross_section( - in_ps::NTuple{N,T} -) where {N,T<:AbstractFourMomentum} - init_flux = _groundtruth_incident_flux(in_ps) - return _groundtruth_total_probability(in_ps) / (4 * init_flux) -end - -function _groundtruth_total_cross_section( - in_pss::Vector{NTuple{N,T}} -) where {N,T<:AbstractFourMomentum} - return _groundtruth_total_cross_section.(in_psps) -end diff --git a/test/test_implementation/random_momenta.jl b/test/test_implementation/random_momenta.jl deleted file mode 100644 index b631551..0000000 --- a/test/test_implementation/random_momenta.jl +++ /dev/null @@ -1,83 +0,0 @@ - -""" -Return a tuple of random four momenta, i.e. a random phase space point. -""" -function _rand_momenta(rng::AbstractRNG, n) - return NTuple{n,SFourMomentum}(SFourMomentum(rand(rng, 4)) for _ in 1:n) -end - -""" -Return a vector of tuples of random four momenta, i.e. a collection of phase space points. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_momenta(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_momenta(rng, n1) - end - return moms -end - -""" -Return a random phase space point that is failing the incoming phase space constraint, -i.e. the first entry of the phase space is the null momentum. -""" -function _rand_in_momenta_failing(rng::AbstractRNG, n) - return (zero(SFourMomentum), _rand_momenta(rng, n - 1)...) -end - -""" -Return a random phase space point that is failing the outgoing phase space constraint, -i.e. the last entry of the phase space is the unit momentum. -""" -function _rand_out_momenta_failing(rng::AbstractRNG, n) - return (_rand_momenta(rng, n - 1)..., ones(SFourMomentum)) -end - -""" -Return a collection of incoming phase space points, where the first point is failing the phase space constraint, -i.e. the first entry of the vector is invalid but the others pass. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_in_momenta_failing_mix(rng::AbstractRNG, n1, n2) - moms = _rand_momenta(rng, n1, n2) - moms[1] = _rand_in_momenta_failing(rng, n1) - return moms -end - -""" -Return a collection of incoming phase space points, where all points are failing the phase space constraint, -i.e. their first entries are null momenta. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_in_momenta_failing_all(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_in_momenta_failing(rng, n1) - end - return moms -end - -""" -Return a vector of outgoing phase space points, where the first point is failing the phase space constraint, -i.e. the last entry of the vector is invalid but the others pass. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_out_momenta_failing_mix(rng::AbstractRNG, n1, n2) - moms = _rand_momenta(rng, n1, n2) - moms[end] = _rand_out_momenta_failing(rng, n1) - return moms -end - -""" -Return a vector of outgoing phase space points, where all points are failing the phase space constraint, -i.e. their last entries are unit momenta. -n1 is the size of the phase space point, n2 is the number of points. -""" -function _rand_out_momenta_failing_all(rng::AbstractRNG, n1, n2) - moms = Vector{NTuple{n1,SFourMomentum}}(undef, n2) - for i in 1:n2 - moms[i] = _rand_out_momenta_failing(rng, n1) - end - return moms -end diff --git a/test/test_implementation/test_model.jl b/test/test_implementation/test_model.jl deleted file mode 100644 index 12b961f..0000000 --- a/test/test_implementation/test_model.jl +++ /dev/null @@ -1,5 +0,0 @@ - -struct TestModel <: AbstractModelDefinition end -QEDbase.fundamental_interaction_type(::TestModel) = :test_interaction - -struct TestModel_FAIL <: AbstractModelDefinition end diff --git a/test/test_implementation/test_process.jl b/test/test_implementation/test_process.jl deleted file mode 100644 index 5a81146..0000000 --- a/test/test_implementation/test_process.jl +++ /dev/null @@ -1,131 +0,0 @@ -# dummy particles -struct TestParticleFermion <: FermionLike end -struct TestParticleBoson <: BosonLike end - -const PARTICLE_SET = [TestParticleFermion(), TestParticleBoson()] - -""" - TestProcess(rng,incoming_particles,outgoing_particles) - -""" -struct TestProcess{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = rand(rng, PARTICLE_SET, N_in) - out_particles = rand(rng, PARTICLE_SET, N_out) - return TestProcess(in_particles, out_particles) -end - -QEDbase.incoming_particles(proc::TestProcess) = proc.incoming_particles -QEDbase.outgoing_particles(proc::TestProcess) = proc.outgoing_particles - -struct TestProcess_FAIL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL(in_particles, out_particles) -end - -function QEDbase.in_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_incoming_particles(proc) * 4 -end -function QEDbase.out_phase_space_dimension(proc::TestProcess, ::TestModel) - return number_outgoing_particles(proc) * 4 -end - -""" -Test process with no implemented interface. Should fail every usage except construction. -""" -struct TestProcess_FAIL_ALL{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL_ALL(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL_ALL(in_particles, out_particles) -end - -""" -Test process with no implemented interface except the incoming and outgoing particles. -Should fail every usage except construction of itself and the respective phase space point for given four-momenta. -""" -struct TestProcess_FAIL_DIFFCS{IP<:Tuple,OP<:Tuple} <: AbstractProcessDefinition - incoming_particles::IP - outgoing_particles::OP -end - -function TestProcess_FAIL_DIFFCS(rng::AbstractRNG, N_in::Int, N_out::Int) - in_particles = Tuple(rand(rng, PARTICLE_SET, N_in)) - out_particles = Tuple(rand(rng, PARTICLE_SET, N_out)) - return TestProcess_FAIL_DIFFCS(in_particles, out_particles) -end - -QEDbase.incoming_particles(proc::TestProcess_FAIL_DIFFCS) = proc.incoming_particles -QEDbase.outgoing_particles(proc::TestProcess_FAIL_DIFFCS) = proc.outgoing_particles - -# dummy phase space definition + failing phase space definition -struct TestPhasespaceDef <: AbstractPhasespaceDefinition end -struct TestPhasespaceDef_FAIL <: AbstractPhasespaceDefinition end - -# dummy implementation of the process interface - -function QEDbase._incident_flux(in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel}) - return _groundtruth_incident_flux(momenta(in_psp, Incoming())) -end - -function QEDbase._averaging_norm(proc::TestProcess) - return _groundtruth_averaging_norm(proc) -end - -function QEDbase._matrix_element(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, Incoming()) - out_ps = momenta(psp, Outgoing()) - return _groundtruth_matrix_element(in_ps, out_ps) -end - -function QEDbase._is_in_phasespace(psp::PhaseSpacePoint{<:TestProcess,TestModel}) - in_ps = momenta(psp, Incoming()) - out_ps = momenta(psp, Outgoing()) - return _groundtruth_is_in_phasespace(in_ps, out_ps) -end - -function QEDbase._phase_space_factor( - psp::PhaseSpacePoint{<:TestProcess,TestModel,TestPhasespaceDef} -) - in_ps = momenta(psp, Incoming()) - out_ps = momenta(psp, Outgoing()) - return _groundtruth_phase_space_factor(in_ps, out_ps) -end - -function QEDbase._generate_incoming_momenta( - proc::TestProcess, - model::TestModel, - phase_space_def::TestPhasespaceDef, - in_phase_space::NTuple{N,T}, -) where {N,T<:Real} - return _groundtruth_generate_momenta(in_phase_space) -end - -function QEDbase._generate_outgoing_momenta( - proc::TestProcess, - model::TestModel, - phase_space_def::TestPhasespaceDef, - out_phase_space::NTuple{N,T}, -) where {N,T<:Real} - return _groundtruth_generate_momenta(out_phase_space) -end - -function QEDbase._total_probability( - in_psp::InPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef} -) - return _groundtruth_total_probability(momenta(in_psp, Incoming())) -end diff --git a/test/test_implementation/utils.jl b/test/test_implementation/utils.jl deleted file mode 100644 index 8804b29..0000000 --- a/test/test_implementation/utils.jl +++ /dev/null @@ -1,44 +0,0 @@ - -# Check if any failed type is in the input -_any_fail(x...) = true -_any_fail(::TestProcess, ::TestModel) = false -_any_fail(::TestProcess, ::TestModel, ::TestPhasespaceDef) = false - -# unrolls all elements of a list of four-momenta into vector of coordinates -function _unroll_moms(ps_moms::AbstractVector{T}) where {T<:AbstractFourMomentum} - return collect(Iterators.flatten(ps_moms)) -end - -function _unroll_moms(ps_moms::AbstractMatrix{T}) where {T<:AbstractFourMomentum} - res = Matrix{eltype(T)}(undef, size(ps_moms, 1) * 4, size(ps_moms, 2)) - for i in 1:size(ps_moms, 2) - res[:, i] .= _unroll_moms(view(ps_moms, :, i)) - end - return res -end - -flat_components(moms::AbstractVecOrMat) = _unroll_moms(moms) -flat_components(moms::Tuple) = Tuple(_unroll_moms([moms...])) - -# collect components of four-momenta from a vector of coordinates -function __furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - return SFourMomentum.(eachcol(reshape(ps_coords, 4, :))) -end - -function _furl_moms(ps_coords::AbstractVector{T}) where {T<:Real} - @assert length(ps_coords) % 4 == 0 - return __furl_moms(ps_coords) -end - -function _furl_moms(ps_coords::AbstractMatrix{T}) where {T<:Real} - @assert size(ps_coords, 1) % 4 == 0 - res = Matrix{SFourMomentum}(undef, Int(size(ps_coords, 1)//4), size(ps_coords, 2)) - for i in 1:size(ps_coords, 2) - res[:, i] .= __furl_moms(view(ps_coords, :, i)) - end - return res -end - -function _furl_moms(moms::NTuple{N,Float64}) where {N} - return Tuple(_furl_moms(Vector{Float64}([moms...]))) -end