|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +import pytest |
| 6 | +import qrules |
| 7 | + |
| 8 | +import ampform |
| 9 | +from ampform.dynamics.builder import create_relativistic_breit_wigner_with_ff |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + import sympy as sp |
| 13 | + from pytest_benchmark.fixture import BenchmarkFixture |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.benchmark(group="doit", min_rounds=1) |
| 17 | +def test_doit_speed(benchmark: BenchmarkFixture): |
| 18 | + reaction = qrules.generate_transitions( |
| 19 | + initial_state=("psi(4160)", [-1, +1]), |
| 20 | + final_state=["D-", "D0", "pi+"], |
| 21 | + allowed_intermediate_particles=["D*(2007)0"], |
| 22 | + formalism="canonical-helicity", |
| 23 | + ) |
| 24 | + builder = ampform.get_builder(reaction) |
| 25 | + for particle in reaction.get_intermediate_particles(): |
| 26 | + builder.dynamics.assign(particle.name, create_relativistic_breit_wigner_with_ff) |
| 27 | + model = builder.formulate() |
| 28 | + |
| 29 | + intensity_expr = benchmark(_perform_doit, model.expression) |
| 30 | + undefined_symbols = intensity_expr.free_symbols |
| 31 | + undefined_symbols -= set(model.parameter_defaults) |
| 32 | + undefined_symbols -= set(model.kinematic_variables) |
| 33 | + assert not undefined_symbols |
| 34 | + |
| 35 | + |
| 36 | +def _perform_doit(expr: sp.Expr): |
| 37 | + return expr.doit() |
0 commit comments