From 4b55a62aed57e18f53108055ef4689fd864a6f59 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 20 Mar 2025 17:28:15 +0100 Subject: [PATCH] DX: import pickling example from #471 --- tests/helicity/test_pickle.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/helicity/test_pickle.py diff --git a/tests/helicity/test_pickle.py b/tests/helicity/test_pickle.py new file mode 100644 index 000000000..99a458ed6 --- /dev/null +++ b/tests/helicity/test_pickle.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +import io +import pickle # noqa: S403 +from typing import TYPE_CHECKING + +import ampform + +if TYPE_CHECKING: + from qrules import ReactionInfo + + from ampform.helicity import HelicityModel + + +def test_model_pickling(reaction: ReactionInfo): + """See https://github.com/ComPWA/ampform/issues/471.""" + builder = ampform.get_builder(reaction) + model = builder.formulate() + stream = io.BytesIO() + pickle.dump(model, stream) + stream.seek(0) + loaded_model: HelicityModel = pickle.load(stream) # noqa: S301 + assert loaded_model.kinematic_variables == model.kinematic_variables