Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Mock module #154

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pages = [
"Phase space layout" => "library/phase_space_layout.md",
"Phase space description" => "library/phase_space.md",
"Probability and cross section" => "library/cross_section.md",
"Testing functionality" => "library/mocks.md",
"Function index" => "library/function_index.md",
],
"refs.md",
Expand Down
66 changes: 66 additions & 0 deletions docs/src/library/mocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Mocking

## Momenta

```@docs
QEDbase.Mocks.MockMomentum
QEDbase.Mocks.MockMomentumMutable
```

## Model

```@docs
QEDbase.Mocks.MockModel
QEDbase.Mocks.MockModel_FAIL
QEDbase.Mocks._groundtruth_interaction_type
```

## Coordinate transformations

```@docs
QEDbase.Mocks.MockCoordinateTrafo
QEDbase.Mocks._groundtruth_coord_trafo
```

## Cross Section/Probability

```@docs
QEDbase.Mocks._groundtruth_incident_flux
QEDbase.Mocks._groundtruth_matrix_element
QEDbase.Mocks._groundtruth_averaging_norm
QEDbase.Mocks._groundtruth_is_in_phasespace
QEDbase.Mocks._groundtruth_phase_space_factor
QEDbase.Mocks._groundtruth_unsafe_probability
QEDbase.Mocks._groundtruth_safe_probability
QEDbase.Mocks._groundtruth_unsafe_diffCS
QEDbase.Mocks._groundtruth_safe_diffCS
QEDbase.Mocks._groundtruth_total_probability
```

### Phase Space Layout

```@docs
QEDbase.Mocks._groundtruth_in_moms
QEDbase.Mocks._groundtruth_out_moms
```

### Phase Space Point

```@docs
QEDbase.Mocks.MockProcess
QEDbase.Mocks.MockProcessSP
QEDbase.Mocks.MockProcess_FAIL_ALL
QEDbase.Mocks.MockProcess_FAIL_DIFFCS
```

## Random Mock Momenta

```@docs
QEDbase.Mocks._rand_momenta
QEDbase.Mocks._rand_in_momenta_failing
QEDbase.Mocks._rand_out_momenta_failing
QEDbase.Mocks._rand_in_momenta_failing_mix
QEDbase.Mocks._rand_in_momenta_failing_all
QEDbase.Mocks._rand_out_momenta_failing_mix
QEDbase.Mocks._rand_out_momenta_failing_all
```
2 changes: 2 additions & 0 deletions src/QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,6 @@ include("implementations/cross_section/diff_cross_section.jl")
include("implementations/cross_section/total_probability.jl")
include("implementations/cross_section/total_cross_section.jl")

include("mocks/Mocks.jl")

end #QEDbase
24 changes: 12 additions & 12 deletions ...test_implementation/TestImplementation.jl → src/mocks/Mocks.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module TestImplementation
module Mocks

export TestMomentum, TestMomentumMutable
export TestFermion, TestBoson
export TestMasslessFermion, TestMasslessBoson
export MockMomentum, MockMomentumMutable
export MockFermion, MockBoson
export MockMasslessFermion, MockMasslessBoson

export TestModel, TestModel_FAIL
export TestProcess, TestProcess_FAIL
export MockModel, MockModel_FAIL
export MockProcess, MockProcess_FAIL

# TODO: to be removed (https://github.com/QEDjl-project/QEDbase.jl/issues/140)
export TestPhasespaceDef, TestPhasespaceDef_FAIL
export MockPhasespaceDef, MockPhasespaceDef_FAIL

export TestInPhaseSpaceLayout, TestInPhaseSpaceLayout_FAIL
export TestOutPhaseSpaceLayout, TestOutPhaseSpaceLayout_FAIL
export MockInPhaseSpaceLayout, MockInPhaseSpaceLayout_FAIL
export MockOutPhaseSpaceLayout, MockOutPhaseSpaceLayout_FAIL

export TestParticleStateful
export TestPhaseSpacePoint, TestInPhaseSpacePoint
export MockParticleStateful
export MockPhaseSpacePoint, MockInPhaseSpacePoint

export TestCoordinateTrafo
export MockCoordinateTrafo

using Random
using QEDbase
Expand Down
20 changes: 20 additions & 0 deletions src/mocks/coordinate_trafo/groundtruth.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

"""
_groundtruth_coord_trafo(p::AbstractMockMomentum)::AbstractMockMomentum
_groundtruth_coord_trafo(psp::MockPhaseSpacePoint)::MockPhaseSpacePoint

Applies a coordinate transformation to a given momentum `p` by multiplying it by 2.
If a phase space point is given, the transformation is applied to all momenta.
"""
_groundtruth_coord_trafo(p::AbstractMockMomentum) = 2 * p

function _groundtruth_coord_trafo(psp::MockPhaseSpacePoint)
in_moms = momenta(psp, Incoming())
out_moms = momenta(psp, Outgoing())
in_moms_prime = _groundtruth_coord_trafo.(in_moms)
out_moms_prime = _groundtruth_coord_trafo.(out_moms)

return MockPhaseSpacePoint(
process(psp), model(psp), phase_space_definition(psp), in_moms_prime, out_moms_prime
)
end
21 changes: 21 additions & 0 deletions src/mocks/coordinate_trafo/test_impl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

"""
MockCoordinateTrafo <: AbstractCoordinateTransformation

A mock coordinate transformation that scales all momentum components by a factor of 2.

This transformation internally calls [`_groundtruth_coord_trafo`](@ref).

# Usage
This type is used as a coordinate transformation within the context of `QEDbase`,
applying `_groundtruth_coord_trafo` to momenta.

# Example
```julia
p = MockMomentum(rand(4))
trafo = MockCoordinateTrafo()
transformed_p = trafo(p)
```
"""
struct MockCoordinateTrafo <: AbstractCoordinateTransformation end
QEDbase._transform(::MockCoordinateTrafo, p) = _groundtruth_coord_trafo(p)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
_groundtruth_incident_flux(in_ps)

Test implementation of the incident flux. Return the Minkowski square of the sum of the incoming momenta:
Mock implementation of the incident flux. Return the Minkowski square of the sum of the incoming momenta:

```math
\\begin{align}
Expand All @@ -18,7 +18,7 @@ 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.
Mock 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)
Expand All @@ -30,7 +30,7 @@ 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.
Mock 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))
Expand All @@ -39,7 +39,7 @@ 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.
Mock 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 iszero(in_ps[1])
Expand All @@ -54,7 +54,7 @@ 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.
Mock 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)
Expand All @@ -65,7 +65,7 @@ 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`.
Mock 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)
Expand Down Expand Up @@ -113,7 +113,7 @@ 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`.
Mock 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)
Expand Down Expand Up @@ -153,7 +153,7 @@ 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`.
Mock 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)
Expand Down Expand Up @@ -191,7 +191,7 @@ 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`.
Mock 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)
Expand Down Expand Up @@ -231,7 +231,7 @@ 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.
Mock 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}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@

function QEDbase._incident_flux(
in_psp::TestPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
in_psp::MockPhaseSpacePoint{<:MockProcess,<:MockModel,<:MockPhasespaceDef}
)
return _groundtruth_incident_flux(momenta(in_psp, Incoming()))
end

function QEDbase._averaging_norm(proc::TestProcess)
function QEDbase._averaging_norm(proc::MockProcess)
return _groundtruth_averaging_norm(proc)
end

function QEDbase._matrix_element(
psp::TestPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
psp::MockPhaseSpacePoint{<:MockProcess,<:MockModel,<:MockPhasespaceDef}
)
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::TestPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
psp::MockPhaseSpacePoint{<:MockProcess,<:MockModel,<:MockPhasespaceDef}
)
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::TestPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
psp::MockPhaseSpacePoint{<:MockProcess,<:MockModel,<:MockPhasespaceDef}
)
in_ps = momenta(psp, Incoming())
out_ps = momenta(psp, Outgoing())
return _groundtruth_phase_space_factor(in_ps, out_ps)
end

function QEDbase._total_probability(
in_psp::TestPhaseSpacePoint{<:TestProcess,<:TestModel,<:TestPhasespaceDef}
in_psp::MockPhaseSpacePoint{<:MockProcess,<:MockModel,<:MockPhasespaceDef}
)
return _groundtruth_total_probability(momenta(in_psp, Incoming()))
end
7 changes: 7 additions & 0 deletions src/mocks/model/groundtruth.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
_groundtruth_interaction_type()::Symbol

Returns the type of interaction associated with the mock setup.

"""
_groundtruth_interaction_type() = :mock_interaction
43 changes: 43 additions & 0 deletions src/mocks/model/test_impl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

"""
struct MockModel <: AbstractModelDefinition

A mock model definition used for testing and validation purposes.

This model serves as a placeholder within the framework, returning a predefined
interaction type when queried.

# Methods
- `QEDbase.fundamental_interaction_type(::MockModel)`: Returns the fundamental
interaction type by calling `_groundtruth_interaction_type()`.

# Example
```julia
model = MockModel()
interaction_type = QEDbase.fundamental_interaction_type(model)
# Output: :mock_interaction
```
"""
struct MockModel <: AbstractModelDefinition end

QEDbase.fundamental_interaction_type(::MockModel) = _groundtruth_interaction_type()

"""
struct MockModel_FAIL <: AbstractModelDefinition

A mock model definition intended to represent an incorrect or failing model.

This type can be used in tests to verify error handling and robustness of the
framework when encountering invalid models.

# Usage
`MockModel_FAIL` does not define `fundamental_interaction_type` and can be used
to test behavior when a model lacks proper definitions.

# Example
```julia
model_fail = MockModel_FAIL()
# This may trigger an error if the framework expects a valid interaction type.
```
"""
struct MockModel_FAIL <: AbstractModelDefinition end
Loading