Esempio n. 1
0
    def test_output_reload(self):
        """ Outputs existing HwU histograms in the gnuplot format and makes sure
        that they remain identical when reloading them."""

        one_histo = histograms.HwUList([copy.copy(self.histo_list[0])])

        with misc.TMP_directory() as tmpdir:
            one_histo.output(pjoin(tmpdir, 'OUT'), format='gnuplot')
            new_histo = histograms.HwUList(pjoin(tmpdir, 'OUT.HwU'))

        one_histo = one_histo[0][0]
        one_histo.trim_auxiliary_weights()
        new_histo = new_histo[0]
        self.assertEqual(one_histo.type, new_histo.type)
        self.assertEqual(one_histo.title, new_histo.title)
        self.assertEqual(one_histo.x_axis_mode, new_histo.x_axis_mode)
        self.assertEqual(one_histo.y_axis_mode, new_histo.y_axis_mode)
        self.assertEqual(one_histo.bins.weight_labels,
                         new_histo.bins.weight_labels)
        self.assertEqual(len(one_histo.bins), len(new_histo.bins))
        for i, bin in enumerate(one_histo.bins):
            self.assertEqual(set(bin.wgts.keys()),
                             set(new_histo.bins[i].wgts.keys()))
            for label, wgt in bin.wgts.items():
                self.assertEqual(wgt, new_histo.bins[i].wgts[label])
    def test_short_OfflineHEPToolsInstaller(self):
        """ Test whether the current OfflineHEPToolsInstaller is up to date."""

        with misc.TMP_directory() as tmp_path:
            subprocess.call(
                'bzr branch lp:~maddevelopers/mg5amcnlo/HEPToolsInstallers BZR_VERSION',
                cwd=tmp_path,
                shell=True)
            #                shutil.copy(pjoin(MG5DIR,'vendor','OfflineHEPToolsInstaller.tar.gz'),
            #                            pjoin(tmp_path,'OfflineHEPToolsInstaller.tar.gz'))
            #                subprocess.call('tar -xzf OfflineHEPToolsInstaller.tar.gz', cwd=tmp_path, shell=True)
            #                shutil.move(pjoin(tmp_path,'HEPToolsInstallers'),pjoin(tmp_path,'OFFLINE_VERSION'))
            online_path = dict(
                tuple(line.decode().split()[:2])
                for line in six.moves.urllib.request.urlopen(
                    'http://madgraph.phys.ucl.ac.be/package_info.dat')
            )['HEPToolsInstaller']
            subprocess.call(
                'tar -xzf %s' %
                TestMG5aMCDistribution.get_data(online_path, tmp_path),
                cwd=tmp_path,
                shell=True)
            shutil.move(pjoin(tmp_path, 'HEPToolsInstallers'),
                        pjoin(tmp_path, 'ONLINE_VERSION_UCL'))
            online_path = dict(
                tuple(line.decode().split()[:2])
                for line in six.moves.urllib.request.urlopen(
                    'http://madgraph.physics.illinois.edu/package_info.dat')
            )['HEPToolsInstaller']
            subprocess.call(
                'tar -xzf %s' %
                TestMG5aMCDistribution.get_data(online_path, tmp_path),
                cwd=tmp_path,
                shell=True)
            shutil.move(pjoin(tmp_path, 'HEPToolsInstallers'),
                        pjoin(tmp_path, 'ONLINE_VERSION_UIUC'))
            for path in misc.glob(pjoin('BZR_VERSION', '*'), tmp_path):
                if os.path.basename(path) == '.bzr':
                    continue
                file_name = os.path.basename(path)
                #                    for comparison in ['OFFLINE_VERSION','ONLINE_VERSION_UCL','ONLINE_VERSION_UIUC']:
                for comparison in [
                        'ONLINE_VERSION_UCL', 'ONLINE_VERSION_UIUC'
                ]:
                    #                        misc.sprint('Testing %s in %s vs %s.'%(file_name,'BZR_VERSION',comparison))
                    diff = subprocess.Popen(
                        'diff %s %s' %
                        (path, pjoin(tmp_path, comparison, file_name)),
                        cwd=tmp_path,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
                    diff = diff.communicate()[0].decode()
                    self.assertEqual(
                        diff, '',
                        'Comparison of HEPToolsInstallers | %s vs %s | %s failed.\n'
                        % ('BZR_VERSION', comparison, file_name) +
                        "Consider updating MG servers and '%s'." %
                        pjoin(MG5DIR, 'vendor',
                              'OfflineHEPToolsInstaller.tar.gz'))
    def test_short_OfflineToolsTarballs(self):
        """ Test whether the current Offline Ninja+oneloop+collier tarball is up to date."""

        test_tarballs = [
            ('ninja',
             'https://bitbucket.org/peraro/ninja/downloads/ninja-latest.tar.gz',
             pjoin(MG5DIR, 'vendor', 'ninja.tar.gz')),
            ('collier', 'http://collier.hepforge.org/collier-latest.tar.gz',
             pjoin(MG5DIR, 'vendor', 'collier.tar.gz')),
            ('oneloop',
             'http://helac-phegas.web.cern.ch/helac-phegas/tar-files/OneLOop-3.6.tgz',
             pjoin(MG5DIR, 'vendor', 'oneloop.tar.gz'))
        ]
        with misc.TMP_directory() as tmp_path:
            for (name, online_path, local_path) in test_tarballs:
                diff = subprocess.Popen(
                    'diff %s %s' % (TestMG5aMCDistribution.get_data(
                        online_path, tmp_path), local_path),
                    cwd=tmp_path,
                    shell=True,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                diff = diff.communicate()[0].decode()
                self.assertEqual(
                    diff, '',
                    "Comparison of the online and offline tarball '%s' failed. Consider updating it."
                    % local_path)
Esempio n. 4
0
    def testIO_current_generation_and_access(self):
        """ target: Counterterms_R.txt
            target: Counterterms_V.txt
            target: Currents_Local.txt
            target: Currents_Integ.txt
        """

        # Test the generation of counterterms in single real-emission and virtual
        # type of contributions. Also make sure that they can be exported.

        verbose = False 
        
        # Real counterterms

        # Fetch the real contribution
        real_emission_contrib = self.NLO_contributions.get_contributions_of_type(
            contributions.Contribution_R )[0]
        # Use the ME accessor dictionary with all Born MEs to filter
        # the unphysical counterterms,
        # for example those with the reduced process g g > a g
        n_CTs_before_filtering = len(
            sum(real_emission_contrib.counterterms.values(), []) )
        for CT_list in real_emission_contrib.counterterms.values():
            contributions.Contribution_R.remove_counterterms_with_no_reduced_process(
                self.all_born_MEs_accessor, CT_list )
        n_CTs_after_filtering = len(
            sum(real_emission_contrib.counterterms.values(), []) )
        n_CTs_difference = n_CTs_before_filtering - n_CTs_after_filtering
        if verbose:
            print_string = 'A total of %d local counterterms were filtered'
            print_string += 'because a reduced process did not exist.'
            misc.sprint(print_string % (n_CTs_difference))
        # Check the number of filtered local counterterms
        self.assertEqual(n_CTs_difference, 6)
        # Output all local counterterms
        counterterm_strings = [
            CT.__str__(print_n=True, print_pdg=True, print_state=True)
            for CT in sum(real_emission_contrib.counterterms.values(), []) ]
        open(pjoin(self.IOpath,'Counterterms_R.txt'),'w').write(
            "\n".join(sorted(counterterm_strings)) )

        # Virtual counterterms

        # Fetch the virtual contribution
        virtual_contrib = self.NLO_contributions.get_contributions_of_type(
            contributions.Contribution_V)[0]
        # Apply the filter to integrated counterterms
        n_CTs_before_filtering = len(
            sum(virtual_contrib.integrated_counterterms.values(),[]) )
        for CT_list in virtual_contrib.integrated_counterterms.values():
            contributions.Contribution_V.remove_counterterms_with_no_reduced_process(
                self.all_born_MEs_accessor, CT_list )
        n_CTs_after_filtering = len(
            sum(virtual_contrib.integrated_counterterms.values(),[]) )
        n_CTs_difference = n_CTs_before_filtering - n_CTs_after_filtering
        if verbose:
            print_string = 'A total of %d integrated counterterms were filtered'
            print_string += 'because a reduced process did not exist.'
            misc.sprint(print_string % (n_CTs_difference))

        # Check the number of filtered integrated counterterms
        self.assertEqual(n_CTs_difference, 0)
        # Output all integrated counterterms
        counterterm_strings = [
            CT['integrated_counterterm'].__str__(
                print_n=True, print_pdg=True, print_state=True )
            for CT in sum(virtual_contrib.integrated_counterterms.values(), []) ]
        open(pjoin(self.IOpath,'Counterterms_V.txt'),'w').write(
            "\n".join(sorted(counterterm_strings)) )

        # Check the number of counterterms that did not find a host contribution
        refused_cts = len(self.exporter.integrated_counterterms_refused_from_all_contribs)
        if verbose:
            print_string = 'A total of %d integrated subtraction counterterms'
            print_string += 'did not find a host contribution.'
            misc.sprint(print_string % refused_cts)
        self.assertEqual(refused_cts, 14)

        # Local currents

        # Initialize an empty accessor dictionary for the currents.
        # No currents are ignored because of potential pre-existing ones.
        accessors_dict = accessors.MEAccessorDict()
        all_local_currents = \
            real_emission_contrib.get_all_necessary_local_currents(accessors_dict)
        current_strings = [str(current) for current in all_local_currents]
        # Print all local currents
        if verbose: misc.sprint('Local currents:\n' + '\n'.join(current_strings))
        # Output all local currents
        open(pjoin(self.IOpath, 'Currents_Local.txt'), 'w').write(
            "\n".join(sorted(current_strings)) )

        # Integrated currents

        # Use the ME accessor dictionary with all Born MEs to filter what are the
        # unphysical counterterms, for example those with the reduced process g g > a g
        all_integrated_currents = virtual_contrib.get_all_necessary_integrated_currents(
            self.all_born_MEs_accessor )
        current_strings = [str(current) for current in all_integrated_currents]
        # Print all currents
        if verbose: misc.sprint('Integrated currents:\n' + '\n'.join(current_strings))
        # Output all local currents
        open(pjoin(self.IOpath, 'Currents_Integ.txt'), 'w').write(
            "\n".join(sorted(current_strings)) )

        with misc.TMP_directory(debug=False) as tmp_path:

            print_string = "A total of %d accessor keys have been generated"
            print_string += "for %s subtraction currents."

            # Reset the accessor dictionary so as to monitor only the newly added keys
            accessors_dict = accessors.MEAccessorDict()
            real_emission_contrib.add_current_accessors(
                self.mymodel, accessors_dict, tmp_path, 'colorful', all_local_currents )
            # Print all accessor keys
            if verbose: misc.sprint(print_string % (len(accessors_dict), "local"))
            self.assertEqual(len(accessors_dict), 43)

            # Reset the accessor dictionary so as to monitor only the newly added keys
            accessors_dict = accessors.MEAccessorDict()
            virtual_contrib.add_current_accessors(
                self.mymodel, accessors_dict, tmp_path, 'colorful', all_integrated_currents )
            # Print all accessor keys
            if verbose: misc.sprint(print_string % (len(accessors_dict), "integrated"))
            self.assertEqual(len(accessors_dict), 50)
Esempio n. 5
0
    def setUp(self):

        self.mymodel = import_ufo.import_model(
            pjoin(MG5DIR,'tests','input_files','LoopSMTest'),
            prefix=True, complex_mass_scheme = False )
        self.mymodel.pass_particles_name_in_mg_default()

        # Setting up the process p p > h j j and its subtraction
        self.mylegs = base_objects.MultiLegList([
            base_objects.MultiLeg(
                    {'ids': [1,2,-1,-2,21], 'state': base_objects.Leg.INITIAL}),
            base_objects.MultiLeg(
                    {'ids': [1,2,-1,-2,21], 'state': base_objects.Leg.INITIAL}),
            base_objects.MultiLeg(
                    {'ids': [22], 'state': base_objects.Leg.FINAL}),
            base_objects.MultiLeg(
                    {'ids': [21,1,-1,2,-2], 'state': base_objects.Leg.FINAL})
        ])

        self.myprocdef = base_objects.ProcessDefinition({
            'legs': self.mylegs,
            'model': self.mymodel,
            'split_orders': ['QCD','QED']
        })

        # The general accessor with the Born ME registered
        self.all_born_MEs_accessor = accessors.MEAccessorDict()
        # Generate only Born LO contributions
        with misc.TMP_directory(debug=False) as tmp_path:
            
            # Generate the output for this.
            self.madgraph_cmd = cmd.MasterCmd(main='MadGraph')
            self.madgraph_cmd._curr_model = self.mymodel
            self.madgraph_cmd.reset_interface_before_new_generation()            
            self.madgraph_cmd._export_dir = pjoin(tmp_path,'ME7ContributionTest_LO')

            # Generate contributions
            generation_options = {'ME7_definition': True, 
                                  'diagram_filter': False, 
                                  'LO': True, 
                                  'NNLO': [], 
                                  'NNNLO': [],
                                  'optimize': False, 
                                  'NLO': [], 
                                  'loop_induced': [],
                                  'ignore_contributions' : [],
                                  'beam_types': ['auto', 'auto'],
                                  'loop_filter'          : None,
                                  'process_definitions'  : {}}

            self.madgraph_cmd.add_contributions(self.myprocdef, generation_options)
            LO_contributions = self.madgraph_cmd._curr_contribs
            LO_contributions.apply_method_to_all_contribs(
                    'generate_amplitudes', log='Generate diagrams for')

            self.exporter = export_ME7.ME7Exporter(
                self.madgraph_cmd, False, group_subprocesses=True )
            self.exporter.pass_information_from_cmd(self.madgraph_cmd)
            self.exporter.copy_template(self.madgraph_cmd._curr_model)
            self.exporter.export(True, args=[])
            # We want to finalize and output the model for the Born, because need to
            # register its MEs in the accessor.
            self.exporter.finalize(['nojpeg'], self.madgraph_cmd.history)
            self.LO_contributions = self.madgraph_cmd._curr_contribs         
            # Add the Born ME accessors to the dictionary
            self.LO_contributions[0].add_ME_accessors(
                self.all_born_MEs_accessor, pjoin(tmp_path,'ME7ContributionTest_LO') )

        # Generate all NLO contributions 
        with misc.TMP_directory(debug=False) as tmp_path:

            # Generate the output for this.
            self.madgraph_cmd = cmd.MasterCmd(main='MadGraph')
            self.madgraph_cmd._curr_model = self.mymodel
            self.madgraph_cmd.reset_interface_before_new_generation()
            self.madgraph_cmd._export_dir = pjoin(tmp_path,'ME7ContributionTest_LO')

            # Generate contributions
            generation_options = {'ME7_definition': True, 
                                  'diagram_filter': False, 
                                  'LO': True, 
                                  'NNLO': [], 
                                  'NNNLO': [],
                                  'optimize': False, 
                                  'NLO': ['QCD'], 
                                  'loop_induced': [],
                                  'ignore_contributions' : [],
                                  'beam_types': ['auto', 'auto'],
                                  'loop_filter'          : None,
                                  'process_definitions'  : {},
                                  }

            self.madgraph_cmd.add_contributions(self.myprocdef, generation_options)  

            self.madgraph_cmd._curr_contribs.apply_method_to_all_contribs(
                    'generate_amplitudes', log='Generate diagrams for')

            self.exporter = export_ME7.ME7Exporter(
                self.madgraph_cmd, False, group_subprocesses=True )
            self.exporter.pass_information_from_cmd(self.madgraph_cmd)
            self.exporter.copy_template(self.madgraph_cmd._curr_model)
            self.exporter.export(True, args=[])
            # The export above was enough to have fully functional contributions to test            
            # self.exporter.finalize(['nojpeg'], self.madgraph_cmd.history)
            self.NLO_contributions = self.madgraph_cmd._curr_contribs