Skip to content

Commit

Permalink
DX: add hash test for ReactionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Dec 19, 2024
1 parent f21a31c commit 7bcf84b
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions tests/sympy/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar

import pytest
import qrules
Expand Down Expand Up @@ -52,23 +52,46 @@ def test_get_readable_hash_energy_dependent_width():
assert h == "086a038e35f21ed6eee5788b2adb017c"


@pytest.mark.parametrize(
("expected_hash", "formalism"),
[
("0047c8be9e94ec7d5d0e0a326b9f7266", "canonical-helicity"),
("562d5f1390b56ddb83149d2218ff4aea", "helicity"),
],
)
def test_get_readable_hash_large(expected_hash: str, formalism: SpinFormalism):
reaction = 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",
formalism=formalism,
class TestLargeHash:
initial_state: ClassVar = [("J/psi(1S)", [-1, 1])]
final_state: ClassVar = ["gamma", "pi0", "pi0"]
allowed_intermediate_particles: ClassVar = ["f(0)(980)", "f(0)(1500)"]
allowed_interaction_types: ClassVar = "strong"

@pytest.mark.parametrize(
("expected_hash", "formalism"),
[
("UNSTABLE-HASH", "canonical-helicity"),
("UNSTABLE-HASH", "helicity"),
],
)
def test_reaction(self, expected_hash: str, formalism: SpinFormalism):
reaction = qrules.generate_transitions(
initial_state=self.initial_state,
final_state=self.final_state,
allowed_intermediate_particles=self.allowed_intermediate_particles,
allowed_interaction_types=self.allowed_interaction_types,
formalism=formalism,
)
assert get_readable_hash(reaction) == expected_hash

@pytest.mark.parametrize(
("expected_hash", "formalism"),
[
("0047c8be9e94ec7d5d0e0a326b9f7266", "canonical-helicity"),
("562d5f1390b56ddb83149d2218ff4aea", "helicity"),
],
)
model_builder = get_builder(reaction)
for name in reaction.get_intermediate_particles().names:
model_builder.dynamics.assign(name, create_relativistic_breit_wigner_with_ff)
model = model_builder.formulate()
assert get_readable_hash(model.expression) == expected_hash
def test_amplitude_model(self, expected_hash: str, formalism: SpinFormalism):
reaction = 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",
formalism=formalism,
)
builder = get_builder(reaction)
for name in reaction.get_intermediate_particles().names:
builder.dynamics.assign(name, create_relativistic_breit_wigner_with_ff)
model = builder.formulate()
assert get_readable_hash(model.expression) == expected_hash

0 comments on commit 7bcf84b

Please sign in to comment.