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

Add Spin/Pol iterator on AbstractProcessDefinition #107

Closed
AntonReinhard opened this issue Aug 6, 2024 · 0 comments · Fixed by #118
Closed

Add Spin/Pol iterator on AbstractProcessDefinition #107

AntonReinhard opened this issue Aug 6, 2024 · 0 comments · Fixed by #118
Labels
06 - Feature-request Missing feature or functionality
Milestone

Comments

@AntonReinhard
Copy link
Member

It would be nice to have an iterator to iterate over all possible definite spin/pol configurations of a given process. Something like a function definite_spin_pols(proc::AbstractProcessDefinition) that would allow code such as

proc = QEDprocesses.Compton()
for spin_pol_config in definite_spin_pols(proc)
    # do things with spin_pol_config, which is an NTuple of only definite spins and polarizations
end

The length of this iterator corresponds to the multiplicity of the whole process.

@AntonReinhard AntonReinhard added the 06 - Feature-request Missing feature or functionality label Aug 6, 2024
@AntonReinhard AntonReinhard added this to the Release-next milestone Aug 6, 2024
SimeonEhrig pushed a commit that referenced this issue Sep 12, 2024
…118)

As the title says, this adds an iterator to yield all possible
combinations of spins and polarizations allowed by a process' set
`spin_pols()`. For example:

```Julia
julia> using QEDbase; using QEDcore; using QEDprocesses;

julia> proc = ScatteringProcess((Photon(), Photon(), Photon(), Electron()), (Photon(), Electron()), (SyncedPolarization(1), SyncedPolarization(2), SyncedPolarization(1), SpinUp()), (SyncedPolarization(2), AllSpin()))
generic QED process
    incoming: photon (synced polarization 1), photon (synced polarization 2), photon (synced polarization 1), electron (spin up)
    outgoing: photon (synced polarization 2), electron (all spins)


julia> for sp_combo in spin_pols_iter(proc) println(sp_combo) end
((x-polarized, x-polarized, x-polarized, spin up), (x-polarized, spin up))
((y-polarized, x-polarized, y-polarized, spin up), (x-polarized, spin up))
((x-polarized, y-polarized, x-polarized, spin up), (y-polarized, spin up))
((y-polarized, y-polarized, y-polarized, spin up), (y-polarized, spin up))
((x-polarized, x-polarized, x-polarized, spin up), (x-polarized, spin down))
((y-polarized, x-polarized, y-polarized, spin up), (x-polarized, spin down))
((x-polarized, y-polarized, x-polarized, spin up), (y-polarized, spin down))
((y-polarized, y-polarized, y-polarized, spin up), (y-polarized, spin down))

julia> length(spin_pols_iter(proc))
8
```
The above is also a `jldoctest`.

As a side-note I also added an alias of `SyncedPol` to
`SyncedPolarization`.

The code is not incredibly concise and also not incredibly fast, but for
the reasonable cases that I tested `@benchmark` reports well under 1ms.
Since I don't think this iterator would be the critical path of anything
this should be fine.
The only problem I could see is that due to everything using `Tuple`s in
its arguments, the compile time is relatively large. If this becomes a
problem we could change it to using `Vector`s instead, likely trading
some runtime for much better compile time.

Fixes #107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
06 - Feature-request Missing feature or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant