Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAK: remove spin projections in cons rules #282

Merged
merged 18 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion docs/usage/reaction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
"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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I realize now is that this rule seems to be checking two things and therefore needs $L$ and $S$ of the nodes. It would be better to split that.

Maybe we should write an issue for this if this rule can be split up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also not really a suitable class name:

class SpinMagnitudeNodeInput:
l_magnitude: NodeQN.l_magnitude = field(converter=NodeQN.l_magnitude)
s_magnitude: NodeQN.s_magnitude = field(converter=NodeQN.s_magnitude)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah seems fishy to me. @grayson-helmholz could you post an issue to split this rule into spin magnitude and $LS$ magnitude.

) -> 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)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of hard to read this test, but it was already like that unfortunately

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]
Loading