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

Use base state from core #78

Merged
merged 4 commits into from
Jun 20, 2024
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 add_QEDcore_dev.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

using Pkg: Pkg
Pkg.add(; url="https://github.com/QEDjl-project/QEDcore.jl", rev="dev")
#Pkg.add(; url="https://github.com/QEDjl-project/QEDbase.jl.git", rev="process_interfaces")
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
QEDbase = "10e22c08-3ccb-4172-bfcf-7d7aa3d04d93"
QEDcore = "35dc0263-cb5f-4c33-a114-1d7f54ab753e"
QEDprocesses = "46de9c38-1bb3-4547-a1ec-da24d767fdad"
6 changes: 4 additions & 2 deletions src/QEDprocesses.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

# TODO: remove after refac
__precompile__(false)

module QEDprocesses

# constants
Expand Down Expand Up @@ -49,8 +53,6 @@ using QEDcore
using StaticArrays
using QuadGK

include("restruct_patch.jl")

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

Expand Down
6 changes: 3 additions & 3 deletions src/patch_QEDbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#############

# fix: https://github.com/QEDjl-project/QEDbase.jl/pull/61
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, ::Electron) = print(io, "electron")
Base.show(io::IO, ::Positron) = print(io, "positron")
Base.show(io::IO, ::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")
Expand Down
14 changes: 7 additions & 7 deletions src/phase_spaces/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ Representation of a particle with a state. It has four fields:
Overloads for `QEDbase.is_fermion`, `QEDbase.is_boson`, `QEDbase.is_particle`, `QEDbase.is_anti_particle`, `QEDbase.is_incoming`, `QEDbase.is_outgoing`, `QEDbase.mass`, and `QEDbase.charge` are provided, delegating the call to the correct field and thus implementing the `QEDbase.AbstractParticle` interface.

```jldoctest
julia> using QEDbase; using QEDprocesses
julia> import QEDbase; using QEDcore; using QEDprocesses

julia> ParticleStateful(Incoming(), Electron(), SFourMomentum(1, 0, 0, 0))
julia> ParticleStateful(QEDbase.Incoming(), Electron(), SFourMomentum(1, 0, 0, 0))
ParticleStateful: incoming electron
momentum: [1.0, 0.0, 0.0, 0.0]

julia> ParticleStateful(Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0))
julia> ParticleStateful(QEDbase.Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0))
ParticleStateful: outgoing photon
momentum: [1.0, 0.0, 0.0, 0.0]
```
Expand Down Expand Up @@ -83,12 +83,12 @@ julia> PhaseSpacePoint(
PerturbativeQED(),
PhasespaceDefinition(SphericalCoordinateSystem(), ElectronRestFrame()),
(
ParticleStateful(QEDbase.Incoming(), QEDbase.Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(QEDbase.Incoming(), QEDbase.Photon(), SFourMomentum(1, 0, 0, 0))
ParticleStateful(QEDbase.Incoming(), Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(QEDbase.Incoming(), 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))
ParticleStateful(QEDbase.Outgoing(), Electron(), SFourMomentum(1, 0, 0, 0)),
ParticleStateful(QEDbase.Outgoing(), Photon(), SFourMomentum(1, 0, 0, 0))
)
)
PhaseSpacePoint:
Expand Down
16 changes: 7 additions & 9 deletions src/processes/one_photon_compton/perturbative/cross_section.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@ end
out_photon_mom = out_ps[2]

in_electron_state = base_state(
QEDbase.Electron(), QEDbase.Incoming(), in_electron_mom, proc.in_spin
)
in_photon_state = base_state(
QEDbase.Photon(), QEDbase.Incoming(), in_photon_mom, proc.in_pol
Electron(), QEDbase.Incoming(), in_electron_mom, proc.in_spin
)
in_photon_state = base_state(Photon(), QEDbase.Incoming(), in_photon_mom, proc.in_pol)

out_electron_state = base_state(
QEDbase.Electron(), QEDbase.Outgoing(), out_electron_mom, proc.out_spin
Electron(), QEDbase.Outgoing(), out_electron_mom, proc.out_spin
)

out_photon_state = base_state(
QEDbase.Photon(), QEDbase.Outgoing(), out_photon_mom, proc.out_pol
Photon(), QEDbase.Outgoing(), out_photon_mom, proc.out_pol
)
return _pert_compton_matrix_element(
in_electron_mom,
Expand Down Expand Up @@ -151,8 +149,8 @@ function _pert_compton_matrix_element_single(
in_ph_slashed = slashed(in_photon_state)
out_ph_slashed = slashed(out_photon_state)

prop1 = _fermion_propagator(in_photon_mom + in_electron_mom, mass(QEDbase.Electron()))
prop2 = _fermion_propagator(in_electron_mom - out_photon_mom, mass(QEDbase.Electron()))
prop1 = _fermion_propagator(in_photon_mom + in_electron_mom, mass(Electron()))
prop2 = _fermion_propagator(in_electron_mom - out_photon_mom, mass(Electron()))

# TODO: fermion propagator is not yet in QEDbase
diagram_1 =
Expand All @@ -179,5 +177,5 @@ function _pert_compton_ps_fac(
# TODO
omega = QEDbase.getE(in_photon_mom)
omega_prime = QEDbase.getE(out_photon_mom)
return omega_prime^2 / (16 * pi^2 * omega * mass(QEDbase.Electron()))
return omega_prime^2 / (16 * pi^2 * omega * mass(Electron()))
end
12 changes: 6 additions & 6 deletions src/processes/one_photon_compton/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ _in_spin_and_pol(proc::Compton) = (proc.in_spin, proc.in_pol)
_out_spin_and_pol(proc::Compton) = (proc.out_spin, proc.out_pol)

function QEDprocesses.incoming_particles(::Compton)
return (QEDbase.Electron(), QEDbase.Photon())
return (Electron(), Photon())
end

function QEDprocesses.outgoing_particles(::Compton)
return (QEDbase.Electron(), QEDbase.Photon())
return (Electron(), Photon())
end

function _spin_or_pol(process::Compton, ::QEDbase.Electron, ::QEDbase.Incoming)
function _spin_or_pol(process::Compton, ::Electron, ::QEDbase.Incoming)
return process.in_spin
end

function _spin_or_pol(process::Compton, ::QEDbase.Electron, ::QEDbase.Outgoing)
function _spin_or_pol(process::Compton, ::Electron, ::QEDbase.Outgoing)
return process.out_spin
end

function _spin_or_pol(process::Compton, ::QEDbase.Photon, ::QEDbase.Incoming)
function _spin_or_pol(process::Compton, ::Photon, ::QEDbase.Incoming)
return process.in_pol
end

function _spin_or_pol(process::Compton, ::QEDbase.Photon, ::QEDbase.Outgoing)
function _spin_or_pol(process::Compton, ::Photon, ::QEDbase.Outgoing)
return process.out_pol
end

Expand Down
6 changes: 3 additions & 3 deletions src/propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function _fermion_propagator(P::QEDbase.AbstractFourMomentum)
return (slashed(P)) * _scalar_propagator(P)
end

function propagator(particle_type::QEDbase.BosonLike, K::QEDbase.AbstractFourMomentum)
function propagator(particle_type::BosonLike, K::QEDbase.AbstractFourMomentum)
return _scalar_propagator(K, mass(particle_type))
end

function propagator(particle_type::QEDbase.Photon, K::QEDbase.AbstractFourMomentum)
function propagator(particle_type::Photon, K::QEDbase.AbstractFourMomentum)
return _scalar_propagator(K)
end

function propagator(particle_type::QEDbase.FermionLike, P::QEDbase.AbstractFourMomentum)
function propagator(particle_type::FermionLike, P::QEDbase.AbstractFourMomentum)
return _fermion_propagator(P, mass(particle_type))
end
52 changes: 0 additions & 52 deletions src/restruct_patch.jl

This file was deleted.

14 changes: 6 additions & 8 deletions test/phase_spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

@testset "Stateful Particle" begin
DIRECTIONS = [QEDbase.Incoming(), QEDbase.Outgoing()]
SPECIES = [QEDbase.Electron(), QEDbase.Positron()] #=, Muon(), AntiMuon(), Tauon(), AntiTauon()=#
SPECIES = [Electron(), Positron()] #=, Muon(), AntiMuon(), Tauon(), AntiTauon()=#

for (species, dir) in Iterators.product(SPECIES, DIRECTIONS)
mom = rand(RNG, SFourMomentum)
Expand Down Expand Up @@ -63,10 +63,10 @@ end
out_el_mom = rand(RNG, SFourMomentum)
out_ph_mom = rand(RNG, SFourMomentum)

in_el = ParticleStateful(QEDbase.Incoming(), QEDbase.Electron(), in_el_mom)
in_ph = ParticleStateful(QEDbase.Incoming(), QEDbase.Photon(), in_ph_mom)
out_el = ParticleStateful(QEDbase.Outgoing(), QEDbase.Electron(), out_el_mom)
out_ph = ParticleStateful(QEDbase.Outgoing(), QEDbase.Photon(), out_ph_mom)
in_el = ParticleStateful(QEDbase.Incoming(), Electron(), in_el_mom)
in_ph = ParticleStateful(QEDbase.Incoming(), Photon(), in_ph_mom)
out_el = ParticleStateful(QEDbase.Outgoing(), Electron(), out_el_mom)
out_ph = ParticleStateful(QEDbase.Outgoing(), Photon(), out_ph_mom)

in_particles_valid = (in_el, in_ph)
in_particles_invalid = (in_el, out_ph)
Expand All @@ -75,9 +75,7 @@ end
out_particles_invalid = (out_el, in_ph)

model = TESTMODEL
process = TestImplementation.TestProcess(
(QEDbase.Electron(), QEDbase.Photon()), (QEDbase.Electron(), QEDbase.Photon())
)
process = TestImplementation.TestProcess((Electron(), Photon()), (Electron(), Photon()))
phasespace_def = TESTPSDEF

psp = PhaseSpacePoint(
Expand Down
42 changes: 18 additions & 24 deletions test/processes/one_photon_compton/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ BUF = IOBuffer()
@testset "constructor" begin
@testset "default" begin
proc = Compton()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Incoming()) ==
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) ==
QEDbase.AllPol()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Incoming()) ==
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) ==
QEDbase.AllSpin()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) ==
QEDbase.AllPol()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) ==
QEDbase.AllSpin()

print(BUF, proc)
Expand All @@ -32,13 +32,12 @@ BUF = IOBuffer()
@testset "in_pol" begin
@testset "$pol" for pol in POLS
proc = Compton(pol)
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Incoming()) ==
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) ==
QEDbase.AllSpin()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Incoming()) ==
pol
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == pol
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) ==
QEDbase.AllSpin()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) ==
QEDbase.AllPol()

print(BUF, proc)
Expand All @@ -53,14 +52,12 @@ BUF = IOBuffer()
@testset "in_pol+out_pol" begin
@testset "$in_pol, $out_pol" for (in_pol, out_pol) in POL_COMBINATIONS
proc = Compton(in_pol, out_pol)
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Incoming()) ==
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) ==
QEDbase.AllSpin()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Incoming()) ==
in_pol
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == in_pol
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) ==
QEDbase.AllSpin()
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Outgoing()) ==
out_pol
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == out_pol

print(BUF, proc)
@test String(take!(BUF)) == "one-photon Compton scattering"
Expand All @@ -75,14 +72,11 @@ BUF = IOBuffer()
in_spin, in_pol, out_spin, out_pol
) in POL_AND_SPIN_COMBINATIONS
proc = Compton(in_spin, in_pol, out_spin, out_pol)
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Incoming()) ==
in_spin
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Incoming()) ==
in_pol
@test QEDprocesses._spin_or_pol(proc, QEDbase.Electron(), QEDbase.Outgoing()) ==
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Incoming()) == in_spin
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Incoming()) == in_pol
@test QEDprocesses._spin_or_pol(proc, Electron(), QEDbase.Outgoing()) ==
out_spin
@test QEDprocesses._spin_or_pol(proc, QEDbase.Photon(), QEDbase.Outgoing()) ==
out_pol
@test QEDprocesses._spin_or_pol(proc, Photon(), QEDbase.Outgoing()) == out_pol

print(BUF, proc)
@test String(take!(BUF)) == "one-photon Compton scattering"
Expand All @@ -95,8 +89,8 @@ BUF = IOBuffer()
end
@testset "particle content" begin
proc = Compton()
@test incoming_particles(proc) == (QEDbase.Electron(), QEDbase.Photon())
@test outgoing_particles(proc) == (QEDbase.Electron(), QEDbase.Photon())
@test incoming_particles(proc) == (Electron(), Photon())
@test outgoing_particles(proc) == (Electron(), Photon())
@test number_incoming_particles(proc) == 2
@test number_outgoing_particles(proc) == 2
end
6 changes: 3 additions & 3 deletions test/propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,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 = propagator(P, mom)
Expand Down
8 changes: 5 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ begin
@time @safetestset "process interface" begin
include("interfaces/process_interface.jl")
end
@time @safetestset "computation setup interface" begin
include("interfaces/setup_interface.jl")
end

# TODO: remove after restructuring
#@time @safetestset "computation setup interface" begin
# include("interfaces/setup_interface.jl")
#end

# modules
@time @safetestset "propagators" begin
Expand Down
4 changes: 2 additions & 2 deletions test/test_implementation/test_process.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dummy particles
struct TestParticleFermion <: QEDbase.FermionLike end
struct TestParticleBoson <: QEDbase.BosonLike end
struct TestParticleFermion <: FermionLike end
struct TestParticleBoson <: BosonLike end

const PARTICLE_SET = [TestParticleFermion(), TestParticleBoson()]

Expand Down
Loading