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

FEAT: implement cached.unfold for amplitude models #458

Merged
merged 4 commits into from
Mar 3, 2025
Merged

Conversation

redeboer
Copy link
Member

@redeboer redeboer commented Mar 3, 2025

Implemented a convenience function, cached.unfold(), which does two things:

  1. It combines and 'unfolds' (evaluates) the model.intensity and its model.amplitudes in one go.
  2. It unfolds and combines a top expression (like model.intensity) and its definitions (like model.amplitudes) efficiently by first calling doit on the top expression, then calling doit on all the expressions in the definitions, and finally combining them with xreplace. This is more efficient than using xreplace and then doit on the whole result. The function also uses caching internally.

Note that cached.unfold takes either a single amplitude model or a top expression and a list of definitions. This is motivated by ComPWA/polarimetry, where instead of using model.intensity as the top expression, you use the polarimeter field definition $\vec\alpha$.

See also this test

amplitudes = {k: v.doit() for k, v in model.amplitudes.items()}
intensity_expr_direct = model.intensity.doit().xreplace(amplitudes)
intensity_expr_unfold = cached.unfold(model.intensity, model.amplitudes)
assert intensity_expr_direct == intensity_expr_unfold

@redeboer redeboer added the ✨ Feature New feature added to the package label Mar 3, 2025
@redeboer redeboer added this to the 0.15.7 milestone Mar 3, 2025
@redeboer redeboer self-assigned this Mar 3, 2025
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@redeboer redeboer marked this pull request as ready for review March 3, 2025 11:09
@redeboer redeboer merged commit 5bb72e4 into main Mar 3, 2025
21 checks passed
@redeboer redeboer deleted the FEAT/unfold branch March 3, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New feature added to the package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant