Beispiel #1
0
def insert_color_links(col_basis, col_obj, links):  #test written
    """insert the color links in col_obj: returns a list of dictionaries
    (one for each link) with the following entries:
    --link: the numbers of the linked legs
    --link_basis: the linked color basis
    --link_matrix: the color matrix created from the original basis and the linked one
    """
    assert isinstance(col_basis, color_amp.ColorBasis)
    assert isinstance(col_obj, list)
    result = []
    for link in links:
        this = {}
        #define the link
        l = []
        for leg in link['legs']:
            l.append(leg.get('number'))
        this['link'] = l

        #replace the indices in col_obj of the linked legs according to
        #   link['replacements']
        # and extend-> product the color strings

        this_col_obj = []
        for old_dict in col_obj:
            dict = copy.copy(old_dict)
            for k, string in dict.items():
                dict[k] = string.create_copy()
                for col in dict[k]:
                    for ind in col:
                        for pair in link['replacements']:
                            if ind == pair[0]:
                                col[col.index(ind)] = pair[1]
                dict[k].product(link['string'])
            this_col_obj.append(dict)
        basis_link = color_amp.ColorBasis()
        for ind, dict in enumerate(this_col_obj):
            basis_link.update_color_basis(dict, ind)

        this['link_basis'] = basis_link
        this['link_matrix'] = color_amp.ColorMatrix(col_basis, basis_link)
        result.append(this)
    basis_orig = color_amp.ColorBasis()
    for ind, dict in enumerate(col_obj):
        basis_orig.update_color_basis(dict, ind)

    for link in result:
        link['orig_basis'] = basis_orig
    return result
def async_finalize_matrix_elements(args):

    i = args[0]
    mefile = args[1]
    duplist = args[2]

    infile = open(mefile, 'rb')
    me = cPickle.load(infile)
    infile.close()

    #set unique id based on position in unique me list
    me.get('processes')[0].set('uid', i)

    # Always create an empty color basis, and the
    # list of raw colorize objects (before
    # simplification) associated with amplitude
    col_basis = color_amp.ColorBasis()
    new_amp = me.born_matrix_element.get_base_amplitude()
    me.born_matrix_element.set('base_amplitude', new_amp)
    colorize_obj = col_basis.create_color_dict_list(new_amp)

    col_basis.build()
    col_matrix = color_amp.ColorMatrix(col_basis)

    me.born_matrix_element.set('color_basis', col_basis)
    me.born_matrix_element.set('color_matrix', col_matrix)

    for iother, othermefile in enumerate(duplist):
        infileother = open(othermefile, 'rb')
        otherme = cPickle.load(infileother)
        infileother.close()
        me.add_process(otherme)

    me.set_color_links()

    initial_states = []
    for fksreal in me.real_processes:
        # Pick out all initial state particles for the two beams
        initial_states.append(sorted(list(set((p.get_initial_pdg(1),p.get_initial_pdg(2)) for \
                                          p in fksreal.matrix_element.get('processes')))))

    if me.virt_matrix_element:
        has_virtual = True
    else:
        has_virtual = False

    #data to write to file
    outdata = me

    output = tempfile.NamedTemporaryFile(delete=False)
    cPickle.dump(outdata, output, protocol=2)
    output.close()

    #data to be returned to parent process (filename plus small objects only)
    return [
        output.name, initial_states,
        me.get_used_lorentz(),
        me.get_used_couplings(), has_virtual
    ]
Beispiel #3
0
    def test_colorize_uu_gg(self):
        """Test the colorize function for uu~ > gg"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': -2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))

        myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 2)

        myprocess = base_objects.Process({
            'legs': myleglist,
            'model': self.mymodel
        })

        myamplitude = diagram_generation.Amplitude()

        myamplitude.set('process', myprocess)

        myamplitude.generate_diagrams()

        my_col_basis = color_amp.ColorBasis()

        # S channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][0],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(-1000, 1, 2),
                               color.f(3, 4, -1000)])
        }

        self.assertEqual(col_dict, goal_dict)

        # T channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][1],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(3, 1, -1000),
                               color.T(4, -1000, 2)])
        }

        self.assertEqual(col_dict, goal_dict)

        # U channel
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][2],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([color.T(4, 1, -1000),
                               color.T(3, -1000, 2)])
        }

        self.assertEqual(col_dict, goal_dict)
Beispiel #4
0
    def test_color_matrix_Nc_restrictions(self):
        """Test the Nc power restriction during color basis building """

        goal = [
            fractions.Fraction(3, 8),
            fractions.Fraction(-9, 4),
            fractions.Fraction(45, 16)
        ]

        for n in range(3):
            myleglist = base_objects.LegList()

            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))
            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))

            myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 2)

            myprocess = base_objects.Process({
                'legs': myleglist,
                'model': self.mymodel
            })

            myamplitude = diagram_generation.Amplitude()

            myamplitude.set('process', myprocess)

            myamplitude.generate_diagrams()

            col_basis = color_amp.ColorBasis(myamplitude)

            col_matrix = color_amp.ColorMatrix(col_basis,
                                               Nc=3,
                                               Nc_power_min=n,
                                               Nc_power_max=2 * n)

            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(i, i)],
                                 (goal[n], 0))
    def generate_matrix_elements_fks(self,
                                     fksmulti,
                                     gen_color=True,
                                     decay_ids=[]):
        """Generate the HelasMatrixElements for the amplitudes,
        identifying processes with identical matrix elements, as
        defined by HelasMatrixElement.__eq__. Returns a
        HelasMatrixElementList and an amplitude map (used by the
        SubprocessGroup functionality). decay_ids is a list of decayed
        particle ids, since those should not be combined even if
        matrix element is identical."""

        fksprocs = fksmulti['born_processes']
        assert isinstance(fksprocs, fks_base.FKSProcessList), \
                  "%s is not valid FKSProcessList" % \
                   repr(fksprocs)

        # Keep track of already generated color objects, to reuse as
        # much as possible
        list_colorize = []
        list_color_links = []
        list_color_basis = []
        list_color_matrices = []
        real_me_list = []
        me_id_list = []

        matrix_elements = FKSHelasProcessList()

        for i, proc in enumerate(fksprocs):
            logger.info("Generating Helas calls for FKS %s (%d / %d)" % \
              (proc.born_amp.get('process').nice_string(print_weighted = False).\
                                                  replace('Process', 'process'),
                i + 1, len(fksprocs)))
            matrix_element_list = [
                FKSHelasProcess(proc,
                                self['real_matrix_elements'],
                                fksmulti['real_amplitudes'],
                                loop_optimized=self.loop_optimized,
                                decay_ids=decay_ids,
                                gen_color=False)
            ]
            for matrix_element in matrix_element_list:
                assert isinstance(matrix_element, FKSHelasProcess), \
                          "Not a FKSHelasProcess: %s" % matrix_element

                try:
                    # If an identical matrix element is already in the list,
                    # then simply add this process to the list of
                    # processes for that matrix element
                    other = \
                          matrix_elements[matrix_elements.index(matrix_element)]
                except ValueError:
                    # Otherwise, if the matrix element has any diagrams,
                    # add this matrix element.
                    if matrix_element.born_matrix_element.get('processes') and \
                           matrix_element.born_matrix_element.get('diagrams'):
                        matrix_elements.append(matrix_element)

                        if not gen_color:
                            continue

                        # Always create an empty color basis, and the
                        # list of raw colorize objects (before
                        # simplification) associated with amplitude
                        col_basis = color_amp.ColorBasis()
                        new_amp = matrix_element.born_matrix_element.get_base_amplitude(
                        )
                        matrix_element.born_matrix_element.set(
                            'base_amplitude', new_amp)
                        colorize_obj = col_basis.create_color_dict_list(
                            new_amp)

                        try:
                            # If the color configuration of the ME has
                            # already been considered before, recycle
                            # the information
                            col_index = list_colorize.index(colorize_obj)
                            logger.info(\
                              "Reusing existing color information for %s" % \
                              matrix_element.born_matrix_element.get('processes')\
                              [0].nice_string(print_weighted=False).\
                                                 replace('Process', 'process'))
                        except ValueError:
                            # If not, create color basis and color
                            # matrix accordingly
                            list_colorize.append(colorize_obj)
                            col_basis.build()
                            list_color_basis.append(col_basis)
                            col_matrix = color_amp.ColorMatrix(col_basis)
                            list_color_matrices.append(col_matrix)
                            col_index = -1

                            logger.info(\
                              "Processing color information for %s" % \
                              matrix_element.born_matrix_element.\
                              get('processes')[0].nice_string(print_weighted=False).\
                                             replace('Process', 'process'))
                        matrix_element.born_matrix_element.set(
                            'color_basis', list_color_basis[col_index])
                        matrix_element.born_matrix_element.set(
                            'color_matrix', list_color_matrices[col_index])
                else:
                    # this is in order not to handle valueErrors coming from other plaeces,
                    # e.g. from the add_process function
                    other.add_process(matrix_element)

        for me in matrix_elements:
            me.set_color_links()
        return matrix_elements
Beispiel #6
0
    def test_color_matrix_multi_quarks(self):
        """Test the color matrix building for qq~ > n*(qq~) with n up to 2"""

        goal = [fractions.Fraction(9, 1), fractions.Fraction(27, 1)]

        goal_line1 = [(fractions.Fraction(9, 1), fractions.Fraction(3, 1)),
                      (fractions.Fraction(27, 1), fractions.Fraction(9, 1),
                       fractions.Fraction(9, 1), fractions.Fraction(3, 1),
                       fractions.Fraction(3, 1), fractions.Fraction(9, 1))]

        goal_den_list = [[1] * 2, [1] * 6]

        goal_first_line_num = [[9, 3], [27, 9, 9, 3, 3, 9]]

        for n in range(2):
            myleglist = base_objects.LegList()

            myleglist.append(base_objects.Leg({'id': -2, 'state': False}))
            myleglist.append(base_objects.Leg({'id': 2, 'state': False}))

            myleglist.extend([
                base_objects.Leg({
                    'id': -2,
                    'state': True
                }),
                base_objects.Leg({
                    'id': 2,
                    'state': True
                })
            ] * (n + 1))

            myprocess = base_objects.Process({
                'legs': myleglist,
                'model': self.mymodel
            })

            myamplitude = diagram_generation.Amplitude()

            myamplitude.set('process', myprocess)

            myamplitude.generate_diagrams()

            col_basis = color_amp.ColorBasis(myamplitude)

            col_matrix = color_amp.ColorMatrix(col_basis, Nc=3)
            # Check diagonal
            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(i, i)],
                                 (goal[n], 0))

            # Check first line
            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(0, i)],
                                 (goal_line1[n][i], 0))

            self.assertEqual(col_matrix.get_line_denominators(),
                             goal_den_list[n])
            self.assertEqual(
                col_matrix.get_line_numerators(
                    0,
                    col_matrix.get_line_denominators()[0]),
                goal_first_line_num[n])
Beispiel #7
0
    def test_color_matrix_multi_gluons(self):
        """Test the color matrix building for gg > n*g with n up to 3"""

        goal = [
            fractions.Fraction(7, 3),
            fractions.Fraction(19, 6),
            fractions.Fraction(455, 108),
            fractions.Fraction(3641, 648)
        ]

        goal_line1 = [(fractions.Fraction(7, 3), fractions.Fraction(-2, 3)),
                      (fractions.Fraction(19, 6), fractions.Fraction(-1, 3),
                       fractions.Fraction(-1, 3), fractions.Fraction(-1, 3),
                       fractions.Fraction(-1, 3), fractions.Fraction(2, 3)),
                      (fractions.Fraction(455,
                                          108), fractions.Fraction(-29, 54),
                       fractions.Fraction(-29, 54), fractions.Fraction(7, 54),
                       fractions.Fraction(7, 54), fractions.Fraction(17, 27),
                       fractions.Fraction(-29, 54), fractions.Fraction(-1, 27),
                       fractions.Fraction(7, 54), fractions.Fraction(-29, 54),
                       fractions.Fraction(5, 108), fractions.Fraction(-1, 27),
                       fractions.Fraction(7, 54), fractions.Fraction(5, 108),
                       fractions.Fraction(17, 27), fractions.Fraction(-1, 27),
                       fractions.Fraction(7, 54), fractions.Fraction(17, 27),
                       fractions.Fraction(-29, 54), fractions.Fraction(-1, 27),
                       fractions.Fraction(-1, 27), fractions.Fraction(17, 27),
                       fractions.Fraction(17, 27), fractions.Fraction(-10,
                                                                      27))]

        for n in range(3):
            myleglist = base_objects.LegList()

            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))
            myleglist.append(base_objects.Leg({'id': 21, 'state': False}))

            myleglist.extend([base_objects.Leg({
                'id': 21,
                'state': True
            })] * (n + 1))

            myprocess = base_objects.Process({
                'legs': myleglist,
                'model': self.mymodel
            })

            myamplitude = diagram_generation.Amplitude()

            myamplitude.set('process', myprocess)

            myamplitude.generate_diagrams()

            col_basis = color_amp.ColorBasis(myamplitude)

            col_matrix = color_amp.ColorMatrix(col_basis, Nc=3)
            # Check diagonal
            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(i, i)],
                                 (goal[n], 0))

            # Check first line
            for i in range(len(col_basis.items())):
                self.assertEqual(col_matrix.col_matrix_fixed_Nc[(0, i)],
                                 (goal_line1[n][i], 0))
Beispiel #8
0
    def test_color_basis_uux_aggg(self):
        """Test the color basis building for uu~ > aggg (3! elements)"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': -2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))

        myleglist.append(base_objects.Leg({'id': 22, 'state': True}))
        myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 3)

        myprocess = base_objects.Process({
            'legs': myleglist,
            'model': self.mymodel
        })

        myamplitude = diagram_generation.Amplitude()

        myamplitude.set('process', myprocess)

        myamplitude.generate_diagrams()

        new_col_basis = color_amp.ColorBasis(myamplitude)

        self.assertEqual(len(new_col_basis), 6)

        # Test the color flow decomposition
        self.assertEqual(
            new_col_basis.color_flow_decomposition(
                {
                    1: 3,
                    2: -3,
                    3: 1,
                    4: 8,
                    5: 8,
                    6: -8
                }, 2), [{
                    1: [0, 501],
                    2: [504, 0],
                    3: [0, 0],
                    4: [502, 501],
                    5: [503, 502],
                    6: [504, 503]
                }, {
                    1: [0, 501],
                    2: [503, 0],
                    3: [0, 0],
                    4: [502, 501],
                    5: [503, 504],
                    6: [504, 502]
                }, {
                    1: [0, 501],
                    2: [504, 0],
                    3: [0, 0],
                    4: [502, 503],
                    5: [503, 501],
                    6: [504, 502]
                }, {
                    1: [0, 501],
                    2: [502, 0],
                    3: [0, 0],
                    4: [502, 504],
                    5: [503, 501],
                    6: [504, 503]
                }, {
                    1: [0, 501],
                    2: [503, 0],
                    3: [0, 0],
                    4: [502, 504],
                    5: [503, 502],
                    6: [504, 501]
                }, {
                    1: [0, 501],
                    2: [502, 0],
                    3: [0, 0],
                    4: [502, 503],
                    5: [503, 504],
                    6: [504, 501]
                }])
Beispiel #9
0
    def test_colorize_funny_model(self):
        """Test the colorize function for uu~ > ggg"""

        mypartlist = base_objects.ParticleList()
        myinterlist = base_objects.InteractionList()
        mymodel = base_objects.Model()

        # A gluon
        mypartlist.append(
            base_objects.Particle({
                'name': 'g',
                'antiname': 'g',
                'spin': 3,
                'color': 8,
                'mass': 'zero',
                'width': 'zero',
                'texname': 'g',
                'antitexname': 'g',
                'line': 'curly',
                'charge': 0.,
                'pdg_code': 21,
                'propagating': True,
                'is_part': True,
                'self_antipart': True
            }))

        # 3 gluon vertiex
        myinterlist.append(base_objects.Interaction({
                      'id': 1,
                      'particles': base_objects.ParticleList(\
                                            [mypartlist[0]] * 3),
                      'color': [color.ColorString([color.f(0, 1, 2)]),
                                color.ColorString([color.f(0, 2, 1)]),
                                color.ColorString([color.f(1, 2, 0)])],
                      'lorentz':['L1'],
            'couplings':{(0, 0):'G', (2,0):'G'},
                      'orders':{'QCD':1}}))

        mymodel.set('particles', mypartlist)
        mymodel.set('interactions', myinterlist)

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': 21, 'state': False}))
        myleglist.append(base_objects.Leg({'id': 21, 'state': False}))

        myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 2)

        myprocess = base_objects.Process({'legs': myleglist, 'model': mymodel})

        myamplitude = diagram_generation.Amplitude()

        myamplitude.set('process', myprocess)

        myamplitude.generate_diagrams()

        my_col_basis = color_amp.ColorBasis()

        # Check that only the color structures that are actually used are included
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][0], mymodel)
        goal_dict = {
            (2, 0):
            color.ColorString([color.f(1, 2, -1000),
                               color.f(3, 4, -1000)]),
            (0, 0):
            color.ColorString([color.f(-1000, 1, 2),
                               color.f(3, 4, -1000)]),
            (0, 2):
            color.ColorString([color.f(-1000, 1, 2),
                               color.f(4, -1000, 3)]),
            (2, 2):
            color.ColorString([color.f(1, 2, -1000),
                               color.f(4, -1000, 3)])
        }

        self.assertEqual(col_dict, goal_dict)
Beispiel #10
0
    def test_colorize_uux_ggg(self):
        """Test the colorize function for uu~ > ggg"""

        myleglist = base_objects.LegList()

        myleglist.append(base_objects.Leg({'id': 2, 'state': False}))
        myleglist.append(base_objects.Leg({'id': -2, 'state': False}))

        myleglist.extend([base_objects.Leg({'id': 21, 'state': True})] * 3)

        myprocess = base_objects.Process({
            'legs': myleglist,
            'model': self.mymodel
        })

        myamplitude = diagram_generation.Amplitude()

        myamplitude.set('process', myprocess)

        myamplitude.generate_diagrams()

        my_col_basis = color_amp.ColorBasis()

        # First diagram with two 3-gluon vertices
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][0],
                                         self.mymodel)
        goal_dict = {
            (0, 0, 0):
            color.ColorString([
                color.T(-1000, 2, 1),
                color.f(-1001, 3, 4),
                color.f(-1000, -1001, 5)
            ])
        }

        self.assertEqual(col_dict, goal_dict)

        # Diagram with one 4-gluon vertex
        col_dict = my_col_basis.colorize(myamplitude['diagrams'][3],
                                         self.mymodel)

        goal_dict = {
            (0, 0):
            color.ColorString([
                color.T(-1000, 2, 1),
                color.f(-1001, 3, 5),
                color.f(-1001, 4, -1000)
            ]),
            (0, 1):
            color.ColorString([
                color.T(-1000, 2, 1),
                color.f(-1002, 3, -1000),
                color.f(-1002, 4, 5)
            ]),
            (0, 2):
            color.ColorString([
                color.T(-1000, 2, 1),
                color.f(-1003, 3, 4),
                color.f(-1003, 5, -1000)
            ])
        }

        self.assertEqual(col_dict, goal_dict)
Beispiel #11
0
    def perform_color_connections_test(self, combinations):
        """ Handy wrapping function to test selected cases for the color correlated matrices."""
        def compare_result(color_matrices, color_connections, reference):

            important_info_CM = [(c[0], dict(c[1][1].col_matrix_fixed_Nc))
                                 for c in color_matrices
                                 if c[1][1].col_matrix_fixed_Nc is not None]

            important_info_CC = {
                k: [(i, cc['tuple_representation']) for i, cc in enumerate(v)]
                for k, v in color_connections.items()
            }

            #pprint(important_info_CM)
            #pprint(important_info_CC)
            self.assertListEqual(important_info_CM,
                                 reference['color_matrices'])
            self.assertDictEqual(important_info_CC,
                                 reference['color_connections'])

        for n_gluons, initial_states, max_order, reference in combinations:
            myleglist = base_objects.LegList()
            myleglist.append(
                base_objects.Leg({
                    'id': initial_states[0],
                    'state': False
                }))
            myleglist.append(
                base_objects.Leg({
                    'id': initial_states[1],
                    'state': False
                }))
            myleglist.append(base_objects.Leg({'id': 1, 'state': True}))
            myleglist.append(base_objects.Leg({'id': -1, 'state': True}))
            myleglist.extend([base_objects.Leg({
                'id': 21,
                'state': True
            })] * (n_gluons))

            myprocess = base_objects.Process({
                'legs': myleglist,
                'model': self.mymodel
            })

            myamplitude = diagram_generation.Amplitude()
            myamplitude.set('process', myprocess)
            myamplitude.generate_diagrams()

            col_basis = color_amp.ColorBasis(myamplitude)

            col_matrix = color_amp.ColorMatrix(col_basis, Nc=3)

            all_color_matrices, color_connections = col_matrix.build_color_correlated_matrices(
                myleglist,
                self.mymodel,
                order=max_order,
                Nc=3,
                Nc_power_min=None,
                Nc_power_max=None)

            # Now aggregate all color_connections in a single list:
            all_color_connections = []
            for o in range(max_order.count('N') + 1):
                all_color_connections.extend(color_connections['N' * o + 'LO'])

            sorted_color_matrices = sorted(all_color_matrices.items(),
                                           key=lambda el: el[0])

            compare_result(sorted_color_matrices, color_connections, reference)

            if False:
                pprint([(
                    '(%d,%d) -> [ %s | %s ]' %
                    (k[0], k[1],
                     str(all_color_connections[k[0]]['tuple_representation']),
                     str(all_color_connections[k[1]]['tuple_representation'])),
                    (v[0], v[1].col_matrix_fixed_Nc))
                        for k, v in sorted_color_matrices])

            if False:
                print(
                    "\nA total of %d correlator matrices have been computed (among which %d are zero)"
                    % (len(sorted_color_matrices),
                       len([
                           _ for _ in sorted_color_matrices
                           if _[1][1].col_matrix_fixed_Nc is None
                       ])))