Ejemplo n.º 1
0
 def test_exceptions():
     with pytest.raises(FrozenInstanceError):
         test_state = Particle(
             "MyParticle",
             123,
             mass=1.2,
             width=0.1,
             spin=1,
             charge=0,
             isospin=Spin(1, 0),
         )
         test_state.charge = 1  # type: ignore
     with pytest.raises(ValueError):
         Particle(
             name="Fails Gell-Mann–Nishijima formula",
             pid=666,
             mass=0.0,
             spin=1,
             charge=0,
             parity=Parity(-1),
             c_parity=Parity(-1),
             g_parity=Parity(-1),
             isospin=Spin(0.0, 0.0),
             charmness=1,
         )
Ejemplo n.º 2
0
 def test_comparison():
     neg = Parity(-1)
     pos = Parity(+1)
     assert pos > 0
     assert neg < 0
     assert neg < pos
     assert neg <= pos
     assert pos > neg
     assert pos >= neg
     assert pos >= 0
     assert neg <= 0
     assert 0 < pos  # pylint: disable=misplaced-comparison-constant
Ejemplo n.º 3
0
def __convert_pdg_instance(pdg_particle: PdgDatabase) -> Particle:
    def convert_mass_width(value: Optional[float]) -> float:
        if value is None:
            return 0.0
        return (  # https://github.com/ComPWA/expertsystem/issues/178
            float(value) / 1e3)

    if pdg_particle.charge is None:
        raise ValueError(f"PDG instance has no charge:\n{pdg_particle}")
    quark_numbers = __compute_quark_numbers(pdg_particle)
    lepton_numbers = __compute_lepton_numbers(pdg_particle)
    if pdg_particle.pdgid.is_lepton:  # convention: C(fermion)=+1
        parity: Optional[Parity] = Parity(__sign(
            pdg_particle.pdgid))  # type: ignore
    else:
        parity = __create_parity(pdg_particle.P)
    return Particle(
        name=str(pdg_particle.name),
        pid=int(pdg_particle.pdgid),
        mass=convert_mass_width(pdg_particle.mass),
        width=convert_mass_width(pdg_particle.width),
        charge=int(pdg_particle.charge),
        spin=float(pdg_particle.J),
        strangeness=quark_numbers[0],
        charmness=quark_numbers[1],
        bottomness=quark_numbers[2],
        topness=quark_numbers[3],
        baryon_number=__compute_baryonnumber(pdg_particle),
        electron_lepton_number=lepton_numbers[0],
        muon_lepton_number=lepton_numbers[1],
        tau_lepton_number=lepton_numbers[2],
        isospin=__create_isospin(pdg_particle),
        parity=parity,
        c_parity=__create_parity(pdg_particle.C),
        g_parity=__create_parity(pdg_particle.G),
    )
Ejemplo n.º 4
0
)

# Currently need to cast to the proper Edge/NodeQuantumNumber type, see
# https://github.com/ComPWA/expertsystem/issues/255


@pytest.mark.parametrize(
    "rule_input, expected",
    [
        (
            (
                [
                    CParityEdgeInput(
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0.0),
                        pid=EdgeQuantumNumbers.pid(1),
                        c_parity=EdgeQuantumNumbers.c_parity(Parity(-1)),
                    )
                ],
                [
                    CParityEdgeInput(
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0.0),
                        pid=EdgeQuantumNumbers.pid(1),
                        c_parity=EdgeQuantumNumbers.c_parity(Parity(-1)),
                    ),
                    CParityEdgeInput(
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0.0),
                        pid=EdgeQuantumNumbers.pid(1),
                        c_parity=EdgeQuantumNumbers.c_parity(Parity(1)),
                    ),
                ],
                None,
Ejemplo n.º 5
0
def __xml_to_parity(definition: dict) -> Parity:
    return Parity(__xml_to_int(definition))
from expertsystem.particle import Parity
from expertsystem.reaction.conservation_rules import (
    IdenticalParticleSymmetryOutEdgeInput,
    identical_particle_symmetrization,
)
from expertsystem.reaction.quantum_numbers import EdgeQuantumNumbers

# Currently need to cast to the proper Edge/NodeQuantumNumber type, see
# https://github.com/ComPWA/expertsystem/issues/255


@pytest.mark.parametrize(
    "in_edges, out_edges, expected",
    [(
        [
            EdgeQuantumNumbers.parity(Parity(parity)),
        ],
        [
            IdenticalParticleSymmetryOutEdgeInput(
                spin_magnitude=EdgeQuantumNumbers.spin_magnitude(1.0),
                spin_projection=EdgeQuantumNumbers.spin_projection(0),
                pid=EdgeQuantumNumbers.pid(10),
            ),
            IdenticalParticleSymmetryOutEdgeInput(
                spin_magnitude=EdgeQuantumNumbers.spin_magnitude(1.0),
                spin_projection=EdgeQuantumNumbers.spin_projection(0),
                pid=EdgeQuantumNumbers.pid(10),
            ),
        ],
        parity == 1,
    ) for parity in [-1, 1]],
Ejemplo n.º 7
0
def __create_parity(parity_enum: enums.Parity) -> Optional[Parity]:
    if parity_enum is None or parity_enum == enums.Parity.u:
        return None
    if parity_enum == getattr(parity_enum, "o", None):  # particle < 0.14
        return None
    return Parity(parity_enum)
Ejemplo n.º 8
0
# Currently need to cast to the proper Edge/NodeQuantumNumber type, see
# https://github.com/ComPWA/expertsystem/issues/255


@pytest.mark.parametrize(
    "rule_input, expected",
    [
        (
            (
                [
                    GParityEdgeInput(
                        isospin=EdgeQuantumNumbers.isospin_magnitude(0),
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0),
                        pid=EdgeQuantumNumbers.pid(123),
                        g_parity=EdgeQuantumNumbers.g_parity(
                            Parity(g_parity_in[0])
                        ),
                    )
                ],
                [
                    GParityEdgeInput(
                        isospin=EdgeQuantumNumbers.isospin_magnitude(0),
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0),
                        pid=EdgeQuantumNumbers.pid(0),
                        g_parity=EdgeQuantumNumbers.g_parity(
                            Parity(g_parity_out[0][0])
                        ),
                    ),
                    GParityEdgeInput(
                        isospin=EdgeQuantumNumbers.isospin_magnitude(0),
                        spin_mag=EdgeQuantumNumbers.spin_magnitude(0),
)
from expertsystem.reaction.quantum_numbers import (
    EdgeQuantumNumbers,
    NodeQuantumNumbers,
)

# Currently need to cast to the proper Edge/NodeQuantumNumber type, see
# https://github.com/ComPWA/expertsystem/issues/255


@pytest.mark.parametrize(
    "in_parities, out_parities, l_mag, expected",
    [
        (
            [
                EdgeQuantumNumbers.parity(Parity(parity_in)),
            ],
            [
                EdgeQuantumNumbers.parity(Parity(parity_out1)),
                EdgeQuantumNumbers.parity(Parity(1)),
            ],
            NodeQuantumNumbers.l_magnitude(l_mag),
            parity_in == parity_out1 * (-1)**(l_mag),  # pylint: disable=undefined-variable
        ) for parity_in, parity_out1, l_mag in product([-1, 1], [-1, 1],
                                                       range(0, 5))
    ],
)
def test_parity_conservation(in_parities, out_parities, l_mag, expected):
    assert parity_conservation(in_parities, out_parities, l_mag) is expected

Ejemplo n.º 10
0
def __yaml_to_parity(
        definition: Optional[Union[float, int, str]]) -> Optional[Parity]:
    if definition is None:
        return None
    return Parity(definition)
Ejemplo n.º 11
0
 def test_hash():
     neg = Parity(-1)
     pos = Parity(+1)
     assert {pos, neg, deepcopy(pos)} == {neg, pos}
Ejemplo n.º 12
0
 def test_init_and_eq():
     parity = Parity(+1)
     assert parity == +1
     assert int(parity) == +1
Ejemplo n.º 13
0
 def test_exceptions():
     with pytest.raises(ValueError):
         Parity(1.2)
Ejemplo n.º 14
0
 def test_repr(self, value):
     parity = Parity(value)
     from_repr = eval(repr(parity))  # pylint: disable=eval-used
     assert from_repr == parity
Ejemplo n.º 15
0
 def test_neg():
     parity = Parity(+1)
     flipped_parity = -parity
     assert flipped_parity.value == -parity.value