diff --git a/docs/usage/conservation.ipynb b/docs/usage/conservation.ipynb index 291ff1ea..5c77e239 100644 --- a/docs/usage/conservation.ipynb +++ b/docs/usage/conservation.ipynb @@ -286,21 +286,10 @@ "interaction = transition.interactions[node_id]\n", "\n", "spin_magnitude_conservation(\n", - " ingoing_spins=[\n", - " SpinEdgeInput(\n", - " spin_magnitude=incoming_state.particle.spin,\n", - " spin_projection=incoming_state.spin_projection,\n", - " )\n", - " ],\n", - " outgoing_spins=[\n", - " SpinEdgeInput(\n", - " spin_magnitude=outgoing_state1.particle.spin,\n", - " spin_projection=outgoing_state1.spin_projection,\n", - " ),\n", - " SpinEdgeInput(\n", - " spin_magnitude=outgoing_state2.particle.spin,\n", - " spin_projection=outgoing_state2.spin_projection,\n", - " ),\n", + " ingoing_spin_magnitudes=[incoming_state.particle.spin],\n", + " outgoing_spin_magnitudes=[\n", + " outgoing_state1.particle.spin,\n", + " outgoing_state2.particle.spin,\n", " ],\n", " interaction_qns=interaction,\n", ")" @@ -417,6 +406,18 @@ "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.7" } }, "nbformat": 4, diff --git a/docs/usage/visualize.ipynb b/docs/usage/visualize.ipynb index ad4456fe..126b4645 100644 --- a/docs/usage/visualize.ipynb +++ b/docs/usage/visualize.ipynb @@ -569,8 +569,8 @@ " text += render_sign(particle.c_parity)\n", " if particle.isospin is not None and particle.g_parity is not None:\n", " text += \"(\"\n", - " text += f\"{render_fraction(particle.isospin.magnitude)}\" # with opening brace\n", - " text += f\"{render_sign(particle.g_parity)}\" # with closing brace\n", + " text += f\"{render_fraction(particle.isospin.magnitude)}\"\n", + " text += f\"{render_sign(particle.g_parity)}\"\n", " text += \")\"\n", " return text\n", "\n", @@ -672,7 +672,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/src/qrules/conservation_rules.py b/src/qrules/conservation_rules.py index cf30bd0e..1863a331 100644 --- a/src/qrules/conservation_rules.py +++ b/src/qrules/conservation_rules.py @@ -692,8 +692,8 @@ def spin_conservation( def spin_magnitude_conservation( - ingoing_spins: List[SpinEdgeInput], - outgoing_spins: List[SpinEdgeInput], + ingoing_spin_magnitudes: List[EdgeQN.spin_magnitude], + outgoing_spin_magnitudes: List[EdgeQN.spin_magnitude], interaction_qns: SpinMagnitudeNodeInput, ) -> bool: r"""Check for spin conservation. @@ -711,20 +711,20 @@ def spin_magnitude_conservation( # L and S can only be used if one side is a single state # and the other side contains of two states (isobar) # So do a full check if this is the case - if (len(ingoing_spins) == 1 and len(outgoing_spins) == 2) or ( - len(ingoing_spins) == 2 and len(outgoing_spins) == 1 + if (len(ingoing_spin_magnitudes) == 1 and len(outgoing_spin_magnitudes) == 2) or ( + len(ingoing_spin_magnitudes) == 2 and len(outgoing_spin_magnitudes) == 1 ): return _check_magnitude( - [x.spin_magnitude for x in ingoing_spins], - [x.spin_magnitude for x in outgoing_spins], + [float(x) for x in ingoing_spin_magnitudes], + [float(x) for x in outgoing_spin_magnitudes], interaction_qns, ) # otherwise don't use S and L and just check magnitude # are integral or non integral on both sides return ( - sum(float(x.spin_magnitude) for x in ingoing_spins).is_integer() # type: ignore[union-attr] - == sum(float(x.spin_magnitude) for x in outgoing_spins).is_integer() # type: ignore[union-attr] + sum(float(x) for x in ingoing_spin_magnitudes).is_integer() # type: ignore[union-attr] + == sum(float(x) for x in outgoing_spin_magnitudes).is_integer() # type: ignore[union-attr] ) diff --git a/tests/unit/conservation_rules/test_spin.py b/tests/unit/conservation_rules/test_spin.py index 3f370d3d..921f1a56 100644 --- a/tests/unit/conservation_rules/test_spin.py +++ b/tests/unit/conservation_rules/test_spin.py @@ -11,8 +11,18 @@ spin_magnitude_conservation, ) from qrules.particle import Spin +from qrules.quantum_numbers import EdgeQuantumNumbers -_SpinRuleInputType = Tuple[List[SpinEdgeInput], List[SpinEdgeInput], SpinNodeInput] +_SpinMagnitudeRuleInputType = Tuple[ + List[EdgeQuantumNumbers.spin_magnitude], + List[EdgeQuantumNumbers.spin_magnitude], + SpinNodeInput, +] +_SpinRuleInputType = Tuple[ + List[SpinEdgeInput], + List[SpinEdgeInput], + SpinNodeInput, +] def __create_two_body_decay_spin_data( @@ -119,13 +129,7 @@ def test_spin_all_defined(rule_input: _SpinRuleInputType, expected: bool) -> Non ("rule_input", "expected"), [ ( - __create_two_body_decay_spin_data( - in_spin=Spin(1, 1), - out_spin1=Spin(spin2_mag, 0), - out_spin2=Spin(1, -1), - angular_momentum=Spin(ang_mom_mag, 0), - coupled_spin=Spin(coupled_spin_mag, -1), - ), + ([1], [spin2_mag, 1], SpinNodeInput(ang_mom_mag, 0, coupled_spin_mag, -1)), True, ) for spin2_mag, ang_mom_mag, coupled_spin_mag in zip( @@ -134,13 +138,7 @@ def test_spin_all_defined(rule_input: _SpinRuleInputType, expected: bool) -> Non ] + [ ( - __create_two_body_decay_spin_data( - in_spin=Spin(1, 1), - out_spin1=Spin(spin2_mag, 0), - out_spin2=Spin(1, -1), - angular_momentum=Spin(ang_mom_mag, 0), - coupled_spin=Spin(coupled_spin_mag, 0), - ), + ([1], [spin2_mag, 1], SpinNodeInput(ang_mom_mag, 0, coupled_spin_mag, 0)), False, ) for spin2_mag, ang_mom_mag, coupled_spin_mag in zip( @@ -149,6 +147,6 @@ def test_spin_all_defined(rule_input: _SpinRuleInputType, expected: bool) -> Non ], ) def test_spin_ignore_z_component( - rule_input: _SpinRuleInputType, expected: bool + rule_input: _SpinMagnitudeRuleInputType, expected: bool ) -> None: assert spin_magnitude_conservation(*rule_input) is expected # type: ignore[arg-type]