Skip to content

Commit

Permalink
Refactoring QED.jl (#76)
Browse files Browse the repository at this point in the history
This opts out the `QEDbase` namespace and adds the dependency on
`QEDcore`.

This is part of the general restructuring of `QED.jl`, see
QEDjl-project/QuantumElectrodynamics.jl#35 for details.

---------

Co-authored-by: Uwe Hernandez Acosta <[email protected]>
  • Loading branch information
szabo137 and Uwe Hernandez Acosta authored Jun 19, 2024
1 parent c768a57 commit f686b13
Show file tree
Hide file tree
Showing 25 changed files with 308 additions and 207 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/BuildDeployDoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
- dev
tags: '*'
tags: "*"
pull_request:

jobs:
Expand All @@ -18,9 +18,11 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1.9'
version: "1.9"
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
run: |
julia --project=docs/ add_QEDcore_dev.jl
julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
Expand Down
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stages:
script:
- apt update && apt install -y git
- git clone --depth 1 -b dev https://github.com/QEDjl-project/QED.jl.git /QEDjl
- julia --project=. add_QEDcore_dev.jl
- >
if [[ $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_REF_NAME == "main" || $CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_REF_NAME == "dev" ]]; then
# set name of the commit message from CI_COMMIT_MESSAGE to NO_MESSAGE, that the script does not read accidentally custom packages from the commit message of a merge commit
Expand Down
9 changes: 2 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
name = "QEDprocesses"
uuid = "46de9c38-1bb3-4547-a1ec-da24d767fdad"
authors = [
"Uwe Hernandez Acosta <[email protected]>",
"Simeon Ehrig",
"Klaus Steiniger",
"Tom Jungnickel",
"Anton Reinhard",
]
authors = ["Uwe Hernandez Acosta <[email protected]>", "Simeon Ehrig", "Klaus Steiniger", "Tom Jungnickel", "Anton Reinhard"]
version = "0.1.0"

[deps]
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"
QEDcore = "35dc0263-cb5f-4c33-a114-1d7f54ab753e"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

Expand Down
5 changes: 5 additions & 0 deletions add_QEDcore_dev.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@warn "This repository depends on the dev branch of QEDcore.jl\n It is NOT ready for release!"

using Pkg: Pkg
Pkg.add(; url="https://github.com/QEDjl-project/QEDcore.jl", rev="dev")
5 changes: 4 additions & 1 deletion src/QEDprocesses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export PerturbativeQED
# specific scattering processes
export Compton, omega_prime

using QEDbase
using QEDbase: QEDbase
using QEDcore
using StaticArrays
using QuadGK

include("restruct_patch.jl")

include("constants.jl")
include("utils.jl")

Expand Down
2 changes: 1 addition & 1 deletion src/cross_section/diff_probability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ If the given phase spaces are physical, return differential probability evaluate
"""
function differential_probability(phase_space_point::PhaseSpacePoint)
if !_is_in_phasespace(phase_space_point)
return zero(eltype(momentum(phase_space_point, Incoming(), 1)))
return zero(eltype(momentum(phase_space_point, QEDbase.Incoming(), 1)))
end

return unsafe_differential_probability(phase_space_point)
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/process_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ end
Convenience function dispatching to [`incoming_particles`](@ref) or [`outgoing_particles`](@ref) depending on the given direction.
"""
@inline particles(proc_def::AbstractProcessDefinition, ::Incoming) =
@inline particles(proc_def::AbstractProcessDefinition, ::QEDbase.Incoming) =
incoming_particles(proc_def)
@inline particles(proc_def::AbstractProcessDefinition, ::Outgoing) =
@inline particles(proc_def::AbstractProcessDefinition, ::QEDbase.Outgoing) =
outgoing_particles(proc_def)

"""
number_particles(proc_def::AbstractProcessDefinition, ::ParticleDirection)
Convenience function dispatching to [`number_incoming_particles`](@ref) or [`number_outgoing_particles`](@ref) depending on the given direction.
"""
@inline number_particles(proc_def::AbstractProcessDefinition, ::Incoming) =
@inline number_particles(proc_def::AbstractProcessDefinition, ::QEDbase.Incoming) =
number_incoming_particles(proc_def)
@inline number_particles(proc_def::AbstractProcessDefinition, ::Outgoing) =
@inline number_particles(proc_def::AbstractProcessDefinition, ::QEDbase.Outgoing) =
number_outgoing_particles(proc_def)

"""
Expand Down
38 changes: 19 additions & 19 deletions src/patch_QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
#############

# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/61
Base.show(io::IO, ::Electron) = print(io, "electron")
Base.show(io::IO, ::Positron) = print(io, "positron")
Base.show(io::IO, ::Photon) = print(io, "photon")
Base.show(io::IO, ::Incoming) = print(io, "incoming")
Base.show(io::IO, ::Outgoing) = print(io, "outgoing")
Base.show(io::IO, ::PolX) = print(io, "x-polarized")
Base.show(io::IO, ::PolY) = print(io, "y-polarized")
Base.show(io::IO, ::AllPol) = print(io, "all polarizations")
Base.show(io::IO, ::SpinUp) = print(io, "spin up")
Base.show(io::IO, ::SpinDown) = print(io, "spin down")
Base.show(io::IO, ::AllSpin) = print(io, "all spins")
Base.show(io::IO, ::QEDbase.Electron) = print(io, "electron")
Base.show(io::IO, ::QEDbase.Positron) = print(io, "positron")
Base.show(io::IO, ::QEDbase.Photon) = print(io, "photon")
Base.show(io::IO, ::QEDbase.Incoming) = print(io, "incoming")
Base.show(io::IO, ::QEDbase.Outgoing) = print(io, "outgoing")
Base.show(io::IO, ::QEDbase.PolX) = print(io, "x-polarized")
Base.show(io::IO, ::QEDbase.PolY) = print(io, "y-polarized")
Base.show(io::IO, ::QEDbase.AllPol) = print(io, "all polarizations")
Base.show(io::IO, ::QEDbase.SpinUp) = print(io, "spin up")
Base.show(io::IO, ::QEDbase.SpinDown) = print(io, "spin down")
Base.show(io::IO, ::QEDbase.AllSpin) = print(io, "all spins")

# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/62
Broadcast.broadcastable(dir::Incoming) = Ref(dir)
Broadcast.broadcastable(dir::Outgoing) = Ref(dir)
Broadcast.broadcastable(part::AbstractParticleType) = Ref(part)
Broadcast.broadcastable(spin_or_pol::AbstractSpinOrPolarization) = Ref(spin_or_pol)
Broadcast.broadcastable(dir::QEDbase.Incoming) = Ref(dir)
Broadcast.broadcastable(dir::QEDbase.Outgoing) = Ref(dir)
Broadcast.broadcastable(part::QEDbase.AbstractParticleType) = Ref(part)
Broadcast.broadcastable(spin_or_pol::QEDbase.AbstractSpinOrPolarization) = Ref(spin_or_pol)

# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/63
number_of_spin_pol(::AbstractDefinitePolarization) = 1
number_of_spin_pol(::AbstractDefiniteSpin) = 1
number_of_spin_pol(::AbstractIndefinitePolarization) = 2
number_of_spin_pol(::AbstractIndefiniteSpin) = 2
number_of_spin_pol(::QEDbase.AbstractDefinitePolarization) = 1
number_of_spin_pol(::QEDbase.AbstractDefiniteSpin) = 1
number_of_spin_pol(::QEDbase.AbstractIndefinitePolarization) = 2
number_of_spin_pol(::QEDbase.AbstractIndefiniteSpin) = 2
10 changes: 5 additions & 5 deletions src/phase_spaces/access.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ momentum(part::ParticleStateful) = part.mom
Return a `Tuple` of all the particles' momenta for the given `ParticleDirection`.
"""
momenta(psp::PhaseSpacePoint, ::Incoming) = momentum.(psp.in_particles)
momenta(psp::PhaseSpacePoint, ::Outgoing) = momentum.(psp.out_particles)
momenta(psp::PhaseSpacePoint, ::QEDbase.Incoming) = momentum.(psp.in_particles)
momenta(psp::PhaseSpacePoint, ::QEDbase.Outgoing) = momentum.(psp.out_particles)

"""
Base.getindex(psp::PhaseSpacePoint, dir::Incoming, n::Int)
Overload for the array indexing operator `[]`. Returns the nth incoming particle in this phase space point.
"""
function Base.getindex(psp::PhaseSpacePoint, ::Incoming, n::Int)
function Base.getindex(psp::PhaseSpacePoint, ::QEDbase.Incoming, n::Int)
return psp.in_particles[n]
end

Expand All @@ -45,7 +45,7 @@ end
Overload for the array indexing operator `[]`. Returns the nth outgoing particle in this phase space point.
"""
function Base.getindex(psp::PhaseSpacePoint, ::Outgoing, n::Int)
function Base.getindex(psp::PhaseSpacePoint, ::QEDbase.Outgoing, n::Int)
return psp.out_particles[n]
end

Expand All @@ -54,6 +54,6 @@ end
Returns the momentum of the `n`th particle in the given [`PhaseSpacePoint`](@ref) which has direction `dir`. If `n` is outside the valid range for this phase space point, a `BoundsError` is thrown.
"""
function momentum(psp::PhaseSpacePoint, dir::ParticleDirection, n::Int)
function momentum(psp::PhaseSpacePoint, dir::QEDbase.ParticleDirection, n::Int)
return psp[dir, n].mom
end
8 changes: 4 additions & 4 deletions src/phase_spaces/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function PhaseSpacePoint(
in_momenta::NTuple{N,ELEMENT},
out_momenta::NTuple{M,ELEMENT},
) where {N,M,ELEMENT<:QEDbase.AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())
in_particles = _build_particle_statefuls(proc, in_momenta, QEDbase.Incoming())
out_particles = _build_particle_statefuls(proc, out_momenta, QEDbase.Outgoing())

return PhaseSpacePoint(proc, model, ps_def, in_particles, out_particles)
end
Expand All @@ -84,7 +84,7 @@ function InPhaseSpacePoint(
ps_def::AbstractPhasespaceDefinition,
in_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:QEDbase.AbstractFourMomentum}
in_particles = _build_particle_statefuls(proc, in_momenta, Incoming())
in_particles = _build_particle_statefuls(proc, in_momenta, QEDbase.Incoming())

return PhaseSpacePoint(proc, model, ps_def, in_particles, ())
end
Expand All @@ -105,7 +105,7 @@ function OutPhaseSpacePoint(
ps_def::AbstractPhasespaceDefinition,
out_momenta::NTuple{N,ELEMENT},
) where {N,ELEMENT<:QEDbase.AbstractFourMomentum}
out_particles = _build_particle_statefuls(proc, out_momenta, Outgoing())
out_particles = _build_particle_statefuls(proc, out_momenta, QEDbase.Outgoing())

return PhaseSpacePoint(proc, model, ps_def, (), out_particles)
end
Expand Down
20 changes: 10 additions & 10 deletions src/phase_spaces/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ ParticleStateful: outgoing photon
```
"""
struct ParticleStateful{
DIR<:ParticleDirection,
SPECIES<:AbstractParticleType,
DIR<:QEDbase.ParticleDirection,
SPECIES<:QEDbase.AbstractParticleType,
ELEMENT<:QEDbase.AbstractFourMomentum,
} <: AbstractParticle
} <: QEDbase.AbstractParticle
dir::DIR
species::SPECIES
mom::ELEMENT

function ParticleStateful(
dir::DIR, species::SPECIES, mom::ELEMENT
) where {
DIR<:ParticleDirection,
SPECIES<:AbstractParticleType,
DIR<:QEDbase.ParticleDirection,
SPECIES<:QEDbase.AbstractParticleType,
ELEMENT<:QEDbase.AbstractFourMomentum,
}
return new{DIR,SPECIES,ELEMENT}(dir, species, mom)
Expand All @@ -76,19 +76,19 @@ Representation of a point in the phase space of a process. Contains the process
The legality of the combination of the given process and the incoming and outgoing particles is checked on construction. If the numbers of particles mismatch, the types of particles mismatch (note that order is important), or incoming particles have an `Outgoing` direction, an error is thrown.
```jldoctest
julia> using QEDprocesses; using QEDbase
julia> using QEDprocesses; import QEDbase; using QEDcore
julia> PhaseSpacePoint(
Compton(),
PerturbativeQED(),
PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()),
(
ParticleStateful(Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(Incoming(), Photon(), SFourMomentum(1, 0, 0, 0))
ParticleStateful(QEDbase.Incoming(), QEDbase.Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(QEDbase.Incoming(), QEDbase.Photon(), SFourMomentum(1, 0, 0, 0))
),
(
ParticleStateful(Outgoing(), Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0))
ParticleStateful(QEDbase.Outgoing(), QEDbase.Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(QEDbase.Outgoing(), QEDbase.Photon(), SFourMomentum(1, 0, 0, 0))
)
)
PhaseSpacePoint:
Expand Down
Loading

0 comments on commit f686b13

Please sign in to comment.