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

Formulation of Helicity model in "Modify amplitude model" results in Error #449

Closed
n-idw opened this issue Jan 14, 2025 · 6 comments · Fixed by #450
Closed

Formulation of Helicity model in "Modify amplitude model" results in Error #449

n-idw opened this issue Jan 14, 2025 · 6 comments · Fixed by #450
Assignees
Labels
🐛 Bug Something isn't working
Milestone

Comments

@n-idw
Copy link

n-idw commented Jan 14, 2025

What happened?

When trying to run the "modify.ipynb" notebook including the code of the "Modify amplitude model" chapter in the documentation, an error is returned when trying to run "original_model = model_builder.formulate()".

Relevant log output

/usr/local/lib/python3.10/dist-packages/ampform/helicity/__init__.py in _generate_kinematic_variable_set(transition, node_id)
    935     child2_mass = get_invariant_mass_symbol(topology, decay.children[1].id)
    936     angular_momentum: int | None = decay.interaction.l_magnitude
--> 937     if angular_momentum is None and decay.parent.particle.spin.is_integer():
    938         angular_momentum = int(decay.parent.particle.spin)
    939     return TwoBodyKinematicVariableSet(

AttributeError: 'Fraction' object has no attribute 'is_integer'

Is it possible to reproduce the bug with a small code snippet?

result = qrules.generate_transitions(
    initial_state=("J/psi(1S)", [-1, +1]),
    final_state=["gamma", "pi0", "pi0"],
    allowed_intermediate_particles=["f(0)(980)", "f(0)(1500)"],
    allowed_interaction_types=["strong", "EM"],
    formalism="helicity",
)
model_builder = get_builder(result)
original_model = model_builder.formulate()

Additional steps to reproduce the bug

No response

Which Python version were you using?

Python 3.10

Python dependencies


@n-idw n-idw added the 🐛 Bug Something isn't working label Jan 14, 2025
@redeboer
Copy link
Member

Thanks for posting!
This bug originates from the upgrade to QRules v0.10.4, specifically ComPWA/qrules#288. What I don't get is that the tests didn't catch it – these lines are covered by the unit tests. Would be a good idea to add this channel to the tests.

For you, the easiest fix for now is to downgrade QRules, e.g.

pip install qrules==0.10.3

Does that work?

We'll implement a hotfix in the meantime. @grayson-helmholz?

@n-idw
Copy link
Author

n-idw commented Jan 14, 2025

Thanks for the quick answer!
I downgraded to ampform==0.14.10, that fixed the problem. Apparently the change was made in 0.14.11.

@redeboer
Copy link
Member

I downgraded to ampform==0.14.10, that fixed the problem. Apparently the change was made in 0.14.11.

Also an option 👌 But in 0.14.x you may miss some of the newer functionality. For one, it still uses QRules v0.9.x (which is the reason the bug does not appear here) and there are some other improvements (see releases).

On the other hand, if you upgrade to AmpForm v0.15.x, you might have to spend some time modifying some of your scripts.

@grayson-helmholz
Copy link
Contributor

grayson-helmholz commented Jan 17, 2025

Alternatively, you can also change to Python 3.12 for now, as Fraction.is_integer has been added since then.
But the bug will still have to be fixed, because we currently still support Python >=3.9

@redeboer
Copy link
Member

redeboer commented Jan 17, 2025

@grayson-helmholz, as you noted, the bug fix is quite simple. We need a failing test first though.

  1. Interestingly, the bug in the notebook was not spotted, because the documentation is built on Python 3.12. To quickly check:
    uv run -p3.10 pytest --nbmake docs/usage/modify.ipynb  # fails
    uv run -p3.12 pytest --nbmake docs/usage/modify.ipynb  # works
    It makes me wonder whether we use the notebooks on integration tests on all Python versions, with pytest --nbmake 🤔 So far, I assumed running them while building the documentation was a sufficient test, but that's only done on one Python version.
  2. I don't get though why the unit tests (which are run on all Python versions) didn't catch this. Specifically test_rename_all_parameters_with_stable_final_state(), which uses a parametrized reaction for "helicity" and "canonincal-helicity". The reaction in that test is the same, only the test assigns dynamics, whereas the notebook does not.
    At any rate, that test indeed fails on Python 3.10:
    uv run -p3.10 pytest tests/helicity/test_helicity.py::TestHelicityModel::test_rename_all_parameters_with_stable_final_state
    So why didn't it fail in CI once the lock file updated QRules to v0.10.4 in MAINT: update lock files #445?

@redeboer
Copy link
Member

  1. I don't get though why the unit tests (which are run on all Python versions) didn't catch this.

See ComPWA/actions#124

@redeboer redeboer added this to the 0.15.6 milestone Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants