ComPWA/qrules

Merge `conservation_rules` and `rule_priorities` attributes

Opened this issue · 5 comments

While investigating #272, I started to wonder why EdgeSettings and NodeSettings require conservation_rules as well as rule_priorities. Can't these two just be combined into one attribute of type dict[Rule, int]?

@define
class EdgeSettings:
"""Solver settings for a specific edge of a graph."""
conservation_rules: set[GraphElementRule] = field(factory=set)
rule_priorities: dict[GraphElementRule, int] = field(factory=dict)
qn_domains: dict[Any, list] = field(factory=dict)

Aside from tests, Edge/NodeSettings is mainly used in settings.create_interaction_settings(...) but which is then heavily employed in the StateTransitionManager. Should this be in its own branch?

Should this be in its own branch?

Yes as far as possible it is better to keep refactorings isolated and small

Some idea after discussions: we could write something like:

conservation_rules:  dict[GraphElementRule, RulePriorities]

where RulePriorities is Annotated

Rewriting get_rules_by_priority() with the new definitions of Edge|NodeSettings
causes an infinite-loop in tests/channels/test_y_to_d0_d0bar_pi0_pi0.py

Funny, seems that the rule priorities never did anything from the start 😂

(x, graph_element_settings.rule_priorities[type(x)]) # type: ignore[index]
if type(x) in graph_element_settings.rule_priorities
else (x, 1)

The keys are x, not type(x), so it always falls back to 1