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_pols_iter to iterate over a process' spin/pol combinations #118

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

AntonReinhard
Copy link
Member

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> 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 Tuples in its arguments, the compile time is relatively large. If this becomes a problem we could change it to using Vectors instead, likely trading some runtime for much better compile time.

Fixes #107

@SimeonEhrig SimeonEhrig merged commit 25ce9bd into QEDjl-project:dev Sep 12, 2024
4 checks passed
@AntonReinhard AntonReinhard added this to the Release-next milestone Sep 12, 2024
@AntonReinhard AntonReinhard deleted the spin_pol_iterator branch September 12, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Spin/Pol iterator on AbstractProcessDefinition
2 participants