Open redeboer opened 2 years ago
Some idea:
from typing import Generic
from attrs import frozen
State = TypeVar("State")
Interaction = TypeVar("Interaction")
@frozen
class IsobarNode(Generic[State, Interaction]):
parent: State
child1: State | IsobarNode
child2: State | IsobarNode
interaction: Interaction | None = field(default=None)
@property
def children(self) -> tuple[State, ...]:
def flatten(
obj: State | IsobarNode[State, Interaction]
) -> Sequence[State]:
if isinstance(obj, IsobarNode):
return obj.children
return [obj]
return (*flatten(self.child1), *flatten(self.child2))
where State
and Interaction
could be further specified with e.g.:
import sympy as sp
@frozen
class Particle: # State
name: str
spin: sp.Rational
# polarization: sp.Rational # (?)
parity: int
@frozen
class LSCoupling: # Interaction
L: int
S: sp.Rational
It would be better if AmpForm modules can be built from an internal data structure, just like is happening in https://github.com/ComPWA/compwa-org/pull/129 and https://github.com/ComPWA/compwa-org/pull/133 (see in particular https://github.com/ComPWA/compwa-org/pull/133#issuecomment-1104053626). That would make it easier to build up an amplitude model without having to generate all transitions with QRules. A problem with QRules is that its
Transition
class is too general for isobar decays, which makes the amplitude building code clunky.So we need a data structure that: