Skip to content

Commit

Permalink
BREAK: remove spin projections in cons rules (#282)
Browse files Browse the repository at this point in the history
* removed projections from spin-mag.-cons.
  • Loading branch information
grayson-helmholz authored Aug 26, 2024
1 parent e60ff89 commit 924548f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
31 changes: 16 additions & 15 deletions docs/usage/conservation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
")"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/visualize.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -672,7 +672,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
16 changes: 8 additions & 8 deletions src/qrules/conservation_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
)


Expand Down
30 changes: 14 additions & 16 deletions tests/unit/conservation_rules/test_spin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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]

0 comments on commit 924548f

Please sign in to comment.