Skip to content

Commit

Permalink
Release 0.2.2 (#99)
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
AntonReinhard authored Jul 12, 2024
2 parents 16472ce + e66e295 commit 3af6d7e
Show file tree
Hide file tree
Showing 27 changed files with 1,266 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/BuildDeployDoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1.9'
version: '1.10'
- name: Add custom registry
run: |
julia --project=docs/ -e 'import Pkg; Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/QEDjl-project/registry.git"));'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/formatter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.9
version: 1.10
- name: Install Julia requirements
run: julia --project=${GITHUB_WORKSPACE}/.formatting -e 'import Pkg; Pkg.instantiate()'
- name: Check code style
Expand Down
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ unit_tests_releases:
extends: .untit_test_template
parallel:
matrix:
- JULIA_VERSION: ["1.6", "1.7", "1.8", "1.9"]
- JULIA_VERSION: ["1.6", "1.7", "1.8", "1.9", "1.10", "rc"]
image: julia:$JULIA_VERSION

unit_tests_nightly:
Expand Down Expand Up @@ -65,7 +65,7 @@ unit_tests_nightly:
- cpuonly

generate_integration_tests:
image: julia:1.9
image: julia:1.10
stage: generate_integration_test
script:
# extract package name
Expand Down Expand Up @@ -104,8 +104,8 @@ run_integration_tests:
job: generate_integration_tests
strategy: depend

verify-unit-test-deps_julia1.9:
image: julia:1.9
verify-unit-test-deps_julia1.10:
image: julia:1.10
stage: verify-unit-test-deps
script:
- apt update && apt install -y git
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## Version 0.2.2

[diff since 0.2.0](https://github.com/QEDjl-project/QEDbase.jl/compare/release-0.2.0...release-0.2.2)

This release adds some convenience overloads to existing functions, some code maintenance and small fixes.

### Breaking Changes

This release removes the compute setup interface completely since it was deprecated already.
See [#91](https://github.com/QEDjl-project/QEDbase.jl/pull/91) or [#73](https://github.com/QEDjl-project/QEDbase.jl/issues/73) for details.

### New features

- [#87](https://github.com/QEDjl-project/QEDbase.jl/pull/87): Implementation of `differential_probability`, `differential_cross_section`, `total_probability`, and `total_cross_section` on top of the `AbstractProcessDefinition` interface.
- [#88](https://github.com/QEDjl-project/QEDbase.jl/pull/88): Additional overloads for the `momentum` function on `PhaseSpacePoint`s. One can now request the n-th momentum of a particle with specified direction and species.
- [#90](https://github.com/QEDjl-project/QEDbase.jl/pull/90): Additional overloads for `number_particles` for specific particle direction and species.
- [#94](https://github.com/QEDjl-project/QEDbase.jl/pull/94): Added a new `ParticleDirection` type `UnknownDirection`.

### Maintenance

- [#91](https://github.com/QEDjl-project/QEDbase.jl/pull/91): Remove the deprecated compute setup interface.
- [#92](https://github.com/QEDjl-project/QEDbase.jl/pull/92): Reenable jldoctests for `base_state`.
- [#93](https://github.com/QEDjl-project/QEDbase.jl/pull/93): Update the Julia versions used by the CI for unit tests to include 1.10 and rc. Use 1.10 by default.
- [#95](https://github.com/QEDjl-project/QEDbase.jl/pull/95): Fix the description of the momentum generation interface.
- [#96](https://github.com/QEDjl-project/QEDbase.jl/pull/96): Add tests for the `AbstractProcessDefinition` interface.

## Version 0.2.1

This is a hotfix which adds `ConstructionBase` to the dependencies and the respective
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Tom Jungnickel",
"Anton Reinhard",
]
version = "0.2.1"
version = "0.2.2"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand All @@ -22,12 +22,12 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
ArgCheck = "2.3.0"
ConstructionBase = "1"
DocStringExtensions = "0.8.5, 0.9"
PhysicalConstants = "0.2.1"
SimpleTraits = "0.9.4"
StaticArrays = "1.2.13"
julia = "1.6"
ConstructionBase = "1"

[extras]
QEDcore = "35dc0263-cb5f-4c33-a114-1d7f54ab753e"
Expand Down
14 changes: 6 additions & 8 deletions src/QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export mass, charge
export base_state, propagator

# directions
export ParticleDirection, Incoming, Outgoing
export ParticleDirection, Incoming, Outgoing, UnknownDirection
export is_incoming, is_outgoing

# polarizations and spins
Expand All @@ -64,10 +64,6 @@ export AbstractProcessDefinition, incoming_particles, outgoing_particles
export number_incoming_particles, number_outgoing_particles
export particles, number_particles

# Abstract setup interface
export AbstractComputationSetup, compute
export AbstractProcessSetup, scattering_process, physical_model

# Abstract phase space definition interface
export AbstractCoordinateSystem, AbstractFrameOfReference, AbstractPhasespaceDefinition

Expand Down Expand Up @@ -110,11 +106,13 @@ include("particles/direction.jl")
include("particles/spin_pol.jl")

include("interfaces/phase_space.jl")
include("interfaces/process.jl")
include("interfaces/particle_stateful.jl")
include("interfaces/process.jl")
include("interfaces/phase_space_point.jl")
include("interfaces/setup.jl")

include("total_cross_section.jl")
include("cross_section/diff_probability.jl")
include("cross_section/diff_cross_section.jl")
include("cross_section/total_probability.jl")
include("cross_section/total_cross_section.jl")

end #QEDbase
32 changes: 32 additions & 0 deletions src/cross_section/diff_cross_section.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
########################
# differential and total cross sections.
#
# This file contains default implementations for differential
# cross sections based on the scattering process interface
########################

"""
unsafe_differential_cross_section(phase_space_point::AbstractPhaseSpacePoint)
Return the differential cross section evaluated on a phase space point without checking if the given phase space is physical.
"""
function unsafe_differential_cross_section(phase_space_point::AbstractPhaseSpacePoint)
I = 1 / (4 * _incident_flux(phase_space_point))

return I * unsafe_differential_probability(phase_space_point)
end

"""
differential_cross_section(phase_space_point::PhaseSpacePoint)
If the given phase spaces are physical, return differential cross section evaluated on a phase space point. Zero otherwise.
"""
function differential_cross_section(phase_space_point::AbstractPhaseSpacePoint)
if !_is_in_phasespace(phase_space_point)
# TODO: use the correct type here, i.e. implement a function `eltype` for psp or
# make `momentum_type` an interface function.
return zero(Float64)
end

return unsafe_differential_cross_section(phase_space_point)
end
42 changes: 42 additions & 0 deletions src/cross_section/diff_probability.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
############
# scattering probabilities
#
# This file contains implementations of the scattering probability based on the
# process interface with and without input validation and/or phase space
# constraint.
############

# convenience function
# can be overloaded if an analytical version is known
function _matrix_element_square(psp::AbstractPhaseSpacePoint)
mat_el = _matrix_element(psp)
return abs2.(mat_el)
end

"""
unsafe_differential_probability(phase_space_point::AbstractPhaseSpacePoint)
Return differential probability evaluated on a phase space point without checking if the given phase space(s) are physical.
"""
function unsafe_differential_probability(psp::AbstractPhaseSpacePoint)
matrix_elements_sq = _matrix_element_square(psp)

normalization = _averaging_norm(psp.proc)

ps_fac = _phase_space_factor(psp)

return normalization * sum(matrix_elements_sq) * ps_fac
end

"""
differential_probability(phase_space_point::AbstractPhaseSpacePoint)
If the given phase spaces are physical, return differential probability evaluated on a phase space point. Zero otherwise.
"""
function differential_probability(phase_space_point::AbstractPhaseSpacePoint)
if !_is_in_phasespace(phase_space_point)
return zero(eltype(momentum(phase_space_point, Incoming(), 1)))
end

return unsafe_differential_probability(phase_space_point)
end
14 changes: 14 additions & 0 deletions src/cross_section/total_cross_section.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

############
# Total cross sections
############

"""
total_cross_section(in_psp::AbstractInPhaseSpacePoint)
Return the total cross section for a given [`AbstractInPhaseSpacePoint`](@ref).
"""
function total_cross_section(in_psp::AbstractInPhaseSpacePoint)
I = 1 / (4 * _incident_flux(in_psp))
return I * _total_probability(in_psp)
end
12 changes: 12 additions & 0 deletions src/cross_section/total_probability.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
###########
# Total probability
###########

"""
total_probability(in_psp::AbstractInPhaseSpacePoint)
Return the total probability of a given [`AbstractInPhaseSpacePoint`](@ref).
"""
function total_probability(in_psp::AbstractInPhaseSpacePoint)
return _total_probability(in_psp)
end
2 changes: 1 addition & 1 deletion src/errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract type AbstractInvalidInputException <: Exception end
"""
InvalidInputError(msg::String)
Exception which is thrown if a given input is invalid, e.g. passed to [`_assert_valid_input`](@ref).
Exception which is thrown if a function input is invalid.
"""
struct InvalidInputError <: AbstractInvalidInputException
msg::String
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/particle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Return the propagator of a particle for a given four-momentum. If `mass` is pass
"""
function propagator end

# TODO: Turn the doctest on again when QEDcore has QEDprocesses functionality
"""
```julia
base_state(
Expand Down Expand Up @@ -174,8 +173,7 @@ mom = SFourMomentum(E, px, py, pz) # initialize the four-momentum of the el
electron_state = base_state(QEDcore.Electron(), Incoming(), mom, SpinUp())
```
TODO: Reenable doctests
```Julia
```jldoctest
julia> using QEDbase; using QEDcore
julia> mass = 1.0; px,py,pz = (0.1, 0.2, 0.3); E = sqrt(px^2 + py^2 + pz^2 + mass^2); mom = SFourMomentum(E, px, py, pz)
Expand Down
102 changes: 102 additions & 0 deletions src/interfaces/phase_space_point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,108 @@ function momentum(psp::AbstractPhaseSpacePoint, dir::ParticleDirection, n::Int)
return momentum(psp[dir, n])
end

function _momentum_helper(particles::Tuple{}, species::SPECIES, n::Val{N}) where {SPECIES,N}
throw(
BoundsError(
"momentum(): requested $species momentum is not in this phase space point"
),
)
end

function _momentum_helper(
particles::Tuple{AbstractParticleStateful{DIR,SPECIES,EL},Vararg},
species::SPECIES,
n::Val{1},
) where {DIR,SPECIES,EL}
return momentum(particles[1])
end

function _momentum_helper(
particles::Tuple{AbstractParticleStateful{DIR,SPECIES1,EL},Vararg},
species::SPECIES2,
n::Val{N},
) where {DIR,SPECIES1,SPECIES2,EL,N}
return _momentum_helper(particles[2:end], species, n)
end

function _momentum_helper(
particles::Tuple{AbstractParticleStateful{DIR,SPECIES,EL},Vararg},
species::SPECIES,
n::Val{N},
) where {DIR,SPECIES,EL,N}
return _momentum_helper(particles[2:end], species, Val(N - 1))
end

"""
momentum(psp::AbstractPhaseSpacePoint, dir::ParticleDirection, species::AbstractParticleType, n::Val{N})
Returns the momentum of the `n`th particle in the given [`AbstractPhaseSpacePoint`](@ref) which has direction `dir` and species `species`. If `n` is outside the valid range for this phase space point, a `BoundsError` is thrown.
!!! note
This function accepts n as a `Val{N}` type, i.e., a compile-time constant value (for example a literal `1` or `2`). This allows this function to add zero overhead, but **only** if `N` is actually known at compile time.
If it is not, use the overload of this function that uses `n::Int` instead. That function is faster than calling this one with `Val(n)`.
"""
function momentum(
psp::AbstractPhaseSpacePoint,
dir::ParticleDirection,
species::AbstractParticleType,
n::Val{N},
) where {N}
return _momentum_helper(particles(psp, dir), species, n)
end

"""
momentum(psp::AbstractPhaseSpacePoint, dir::ParticleDirection, species::AbstractParticleType)
Returns the momentum of the particle in the given [`AbstractPhaseSpacePoint`](@ref) with `dir` and `species`, *if* there is only one such particle. If there are multiple or none, an [`InvalidInputError`](@ref) is thrown.
"""
function momentum(
psp::AbstractPhaseSpacePoint, dir::ParticleDirection, species::AbstractParticleType
)
if (number_particles(process(psp), dir, species) != 1)
throw(
InvalidInputError(
"this overload only works when exactly one $dir $species exists in the phase space point, but $(number_particles(process(psp), dir, species)) exist in this one; to specify an index, use momentum(psp, dir, species, n)",
),
)
end

return momentum(psp, dir, species, Val(1))
end

"""
momentum(psp::AbstractPhaseSpacePoint, dir::ParticleDirection, species::AbstractParticleType, n::Int)
Returns the momentum of the `n`th particle in the given [`AbstractPhaseSpacePoint`](@ref) which has direction `dir` and species `species`. If `n` is outside the valid range for this phase space point, a `BoundsError` is thrown.
!!! note
This function accepts n as an `Int` value. If `n` is a compile-time constant (for example, a literal `1` or `2`), you can use `Val(n)` instead to call a zero overhead version of this function.
"""
function momentum(
psp::AbstractPhaseSpacePoint,
dir::ParticleDirection,
species::AbstractParticleType,
n::Int,
)
i = 0
c = n
for p in particles(psp, dir)
i += 1
if particle_species(p) == species
c -= 1
end
if c == 0
break
end
end

if c != 0 || n <= 0
throw(BoundsError("could not get $n-th momentum of $dir $species, does not exist"))
end

return momenta(psp, dir)[i]
end

"""
momenta(psp::AbstractPhaseSpacePoint, ::ParticleDirection)
Expand Down
Loading

0 comments on commit 3af6d7e

Please sign in to comment.