def __init__(self, fksrealproc=None, real_me_list = [], real_amp_list =[], **opts): """constructor, starts from a fksrealproc and then calls the initialization for HelasMatrixElement. Sets i/j fks and the permutation. real_me_list and real_amp_list are the lists of pre-generated matrix elements in 1-1 correspondance with the amplitudes""" if fksrealproc != None: self.isfinite = False self.colors = fksrealproc.colors self.charges = fksrealproc.charges self.fks_infos = fksrealproc.fks_infos self.is_to_integrate = fksrealproc.is_to_integrate if len(real_me_list) != len(real_amp_list): raise fks_common.FKSProcessError( 'not same number of amplitudes and matrix elements: %d, %d' % \ (len(real_amp_list), len(real_me_list))) if real_me_list and real_amp_list: self.matrix_element = copy.deepcopy(real_me_list[real_amp_list.index(fksrealproc.amplitude)]) self.matrix_element['processes'] = copy.deepcopy(self.matrix_element['processes']) else: logger.info('generating matrix element...') self.matrix_element = helas_objects.HelasMatrixElement( fksrealproc.amplitude, **opts) #generate the color for the real self.matrix_element.get('color_basis').build( self.matrix_element.get('base_amplitude')) self.matrix_element.set('color_matrix', color_amp.ColorMatrix( self.matrix_element.get('color_basis'))) #self.fks_j_from_i = fksrealproc.find_fks_j_from_i() self.fks_j_from_i = fksrealproc.fks_j_from_i
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 ]
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 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
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])
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))
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 ])))