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

MAINT: have qn_domains-keys in Node/EdgeSettings be typed #292

Merged
merged 14 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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: 31 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,36 @@
nb_execution_show_tb = True
nb_execution_timeout = -1
nb_output_stderr = "remove"
nitpik_temp_names = [
"pid",
"mass",
"width",
"spin_magnitude",
"spin_projection",
"charge",
"isospin_magnitude",
"isospin_projection",
"strangeness",
"charmness",
"bottomness",
"topness",
"baryon_number",
"electron_lepton_number",
"muon_lepton_number",
"tau_lepton_number",
"parity",
"c_parity",
"g_parity",
"l_magnitude",
"l_projection",
"s_magnitude",
"s_projection",
"parity_prefactor",
]
grayson-helmholz marked this conversation as resolved.
Show resolved Hide resolved
nitpick_temp_patterns = [
(r"py:(class|obj)", r"qrules\.quantum_numbers\." + name)
for name in nitpik_temp_names
]
nitpick_ignore_regex = [
(r"py:(class|obj)", "json.encoder.JSONEncoder"),
(r"py:(class|obj)", r"qrules\.topology\.EdgeType"),
Expand All @@ -267,6 +297,7 @@
(r"py:(class|obj)", r"qrules\.topology\.NewNodeType"),
(r"py:(class|obj)", r"qrules\.topology\.NodeType"),
(r"py:(class|obj)", r"qrules\.topology\.VT"),
*nitpick_temp_patterns,
]
nitpicky = True
primary_domain = "py"
Expand Down
32 changes: 32 additions & 0 deletions src/qrules/quantum_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ class EdgeQuantumNumbers:
EdgeQuantumNumbers.g_parity,
]

# for accessing the keys of the dicts in EdgeSettings
EdgeQuantumNumberTypes = Union[
type[EdgeQuantumNumbers.pid],
type[EdgeQuantumNumbers.mass],
type[EdgeQuantumNumbers.width],
type[EdgeQuantumNumbers.spin_magnitude],
type[EdgeQuantumNumbers.spin_projection],
type[EdgeQuantumNumbers.charge],
type[EdgeQuantumNumbers.isospin_magnitude],
type[EdgeQuantumNumbers.isospin_projection],
type[EdgeQuantumNumbers.strangeness],
type[EdgeQuantumNumbers.charmness],
type[EdgeQuantumNumbers.bottomness],
type[EdgeQuantumNumbers.topness],
type[EdgeQuantumNumbers.baryon_number],
type[EdgeQuantumNumbers.electron_lepton_number],
type[EdgeQuantumNumbers.muon_lepton_number],
type[EdgeQuantumNumbers.tau_lepton_number],
type[EdgeQuantumNumbers.parity],
type[EdgeQuantumNumbers.c_parity],
type[EdgeQuantumNumbers.g_parity],
]


@frozen(init=False)
class NodeQuantumNumbers:
Expand Down Expand Up @@ -155,6 +178,15 @@ class NodeQuantumNumbers:
]
"""Type hint for quantum numbers of interaction nodes."""

# for accessing the keys of the dicts in NodeSettings
NodeQuantumNumberTypes = Union[
type[NodeQuantumNumbers.l_magnitude],
type[NodeQuantumNumbers.l_projection],
type[NodeQuantumNumbers.s_magnitude],
type[NodeQuantumNumbers.s_projection],
type[NodeQuantumNumbers.parity_prefactor],
]


def _to_optional_float(optional_float: float | None) -> float | None:
if optional_float is None:
Expand Down
6 changes: 4 additions & 2 deletions src/qrules/solving.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
from qrules.quantum_numbers import (
EdgeQuantumNumber,
EdgeQuantumNumbers,
EdgeQuantumNumberTypes,
NodeQuantumNumber,
NodeQuantumNumberTypes,
)
from qrules.topology import MutableTransition, Topology

Expand All @@ -50,7 +52,7 @@ class EdgeSettings:

conservation_rules: set[GraphElementRule] = field(factory=set)
rule_priorities: dict[GraphElementRule, int] = field(factory=dict)
qn_domains: dict[Any, list] = field(factory=dict)
qn_domains: dict[EdgeQuantumNumberTypes, list] = field(factory=dict)
redeboer marked this conversation as resolved.
Show resolved Hide resolved


@implement_pretty_repr
Expand All @@ -70,7 +72,7 @@ class NodeSettings:

conservation_rules: set[Rule] = field(factory=set)
rule_priorities: dict[Rule, int] = field(factory=dict)
qn_domains: dict[Any, list] = field(factory=dict)
qn_domains: dict[NodeQuantumNumberTypes, list] = field(factory=dict)
interaction_strength: float = 1.0


Expand Down
Loading