• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

APN-Pucky / feynamp / 8573202894

05 Apr 2024 05:00PM UTC coverage: 83.939% (+0.1%) from 83.825%
8573202894

Pull #50

github

APN-Pucky
update color
Pull Request #50: gg_gg

79 of 100 new or added lines in 9 files covered. (79.0%)

35 existing lines in 5 files now uncovered.

716 of 853 relevant lines covered (83.94%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.3
/feynamp/amplitude.py
1
import re
1✔
2
from typing import List
1✔
3

4
from feynml.feynmandiagram import FeynmanDiagram
1✔
5
from feynmodel.feyn_model import FeynModel
1✔
6

7
from feynamp.leg import get_leg_math_string
1✔
8
from feynamp.log import debug
1✔
9
from feynamp.propagator import get_propagator_math_string
1✔
10
from feynamp.vertex import get_vertex_math_string
1✔
11

12

13
def complex_conjugate(s: str):
1✔
14
    """"""
15
    # return s
16
    return re.sub(r"complex\((.*?),(.*?)\)", r"complex(\1,-\2)", s)
1✔
17

18

19
def feynman_diagram_to_string(feynman_diagram, feyn_model):
1✔
20
    fd = feynman_diagram
1✔
21
    # TODO use these informations from qgraf, might need to be implemented in feynml
22
    # sign = fd.get_sign()
23
    # symmetry = fd.get_symmetry_factor()
24
    vm = []
1✔
25
    lm = []
1✔
26
    pm = []
1✔
27
    for v in fd.vertices:
1✔
28
        vm.append("(" + get_vertex_math_string(fd, v, feyn_model) + ")")
1✔
29
    for leg in fd.legs:
1✔
30
        lm.append("(" + get_leg_math_string(fd, leg, feyn_model) + ")")
1✔
31
    for p in fd.propagators:
1✔
32
        pm.append("(" + get_propagator_math_string(fd, p, feyn_model) + ")")
1✔
33

34
    ret = ""
1✔
35
    if len(vm) > 0:
1✔
36
        ret += f"{' * '.join(vm)} * "
1✔
37
    if len(lm) > 0:
1✔
38
        ret += f"{' * '.join(lm)} * "
1✔
39
    if len(pm) > 0:
1✔
40
        ret += f"{' * '.join(pm)} * "
1✔
41
    debug(f"{ret=}")
1✔
42
    return ret[0:-3]
1✔
43

44

45
def multiply(
1✔
46
    lst_fd1: List[FeynmanDiagram], lst_fd2: List[FeynmanDiagram], feyn_model: FeynModel
47
):
48
    # TODO should this care about fermion lines!?
NEW
49
    s = ""
×
NEW
50
    lst_fd1 = [feynman_diagram_to_string(l, feyn_model) for l in lst_fd1]
×
NEW
51
    lst_fd2 = [feynman_diagram_to_string(l, feyn_model) for l in lst_fd2]
×
NEW
52
    for fd1 in lst_fd1:
×
NEW
53
        for fd2 in lst_fd2:
×
NEW
54
            s += f"({fd1})*({fd2}) + "
×
NEW
55
    return s[:-3]
×
56

57

58
def square(lst_fd: List[FeynmanDiagram], feyn_model: FeynModel, tag=False) -> str:
1✔
59
    """
60
    Squares the list of feynman diagrams taking the fermion sign into account.
61
    """
62
    return " + ".join(square_parallel(lst_fd, feyn_model, tag))
1✔
63

64

65
def square_parallel(
1✔
66
    lst_fd: List[FeynmanDiagram], feyn_model: FeynModel, tag=False
67
) -> List[str]:
68
    """
69
    Squares the list of feynman diagrams taking the fermion sign into account.
70
    """
71
    dims = lst_fd[0].get_externals_size()
1✔
72
    for fd in lst_fd:
1✔
73
        assert (
1✔
74
            dims == fd.get_externals_size()
75
        ), "All FeynmanDiagrams must have the same external legs"
76
    # TODO handle relative fermion sign (also majorana!) https://cds.cern.ch/record/238903/files/th-6549-92.pdf
77
    # TODO also multiply by the symmetry factor from qgraf
78
    # return multiply(lst_fd,[l.conjugated() for l in lst_fd],feyn_model)
79
    s = ""
1✔
80
    lst_fd1 = [feynman_diagram_to_string(fd, feyn_model) for fd in lst_fd]
1✔
81
    lst_fd2 = [
1✔
82
        complex_conjugate(feynman_diagram_to_string(fd.conjugated(), feyn_model))
83
        for fd in lst_fd
84
    ]
85
    debug(f"{lst_fd1=}")
1✔
86
    debug(f"{lst_fd2=}")
1✔
87
    ret_lst = []
1✔
88
    # TODO this could also be done in multiply by comparing the diagrams
89
    for i, sfd1 in enumerate(lst_fd1):
1✔
90
        # TODO reenable loop from i
91
        for j, sfd2 in enumerate(lst_fd2):
1✔
92
            # TODO reenable
93
            # if i == j:
94
            ttag = ""
1✔
95
            if tag:
1✔
96
                ttag = f"*fd{lst_fd[i].id}*fd{lst_fd[j].id}*fd{lst_fd[i].id}fd{lst_fd[j].id}"
1✔
97
            ferm_fac = lst_fd[i].get_fermion_factor(lst_fd[j])
1✔
98
            debug(f"{ferm_fac=}")
1✔
99
            ret_lst.append(f"({sfd1})*({sfd2}){ttag}*{ferm_fac}")
1✔
100
            # TODO reenable
101
            # elif i < j:
102
            #    ttag = ""
103
            #    if tag:
104
            #        ttag = f"*fd{lst_fd[i].id}*fd{lst_fd[j].id}*fd{lst_fd[i].id}fd{lst_fd[j].id}"
105
            #    ferm_fac = lst_fd[i].get_fermion_factor(lst_fd[j])
106
            #    debug(f"{ferm_fac=}")
107
            #    ret_lst.append(
108
            #        f"2*(+{sfd1})*({sfd2}){ttag}*{ferm_fac}"
109
            #    )  # TODO this needs Re!
110
    return ret_lst
1✔
111

112

113
def add(lst_fd, feyn_model):
1✔
UNCOV
114
    lst_fd1 = [feynman_diagram_to_string(l, feyn_model) for l in lst_fd]
×
UNCOV
115
    ferm_facs = [lst_fd[0].get_fermion_factor(l) for l in lst_fd]
×
UNCOV
116
    s = ""
×
UNCOV
117
    for i in range(len(lst_fd1)):
×
UNCOV
118
        s += f"({lst_fd1[i]})*{ferm_facs[i]} + "
×
UNCOV
119
    return s[:-3]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc