~maddevelopers/mg5amcnlo/2.7.1.3

« back to all changes in this revision

Viewing changes to tests/unit_tests/iolibs/test_export_fks.py

  • Committer: olivier Mattelaer
  • Date: 2016-05-12 11:00:18 UTC
  • mfrom: (262.1.150 2.3.4)
  • Revision ID: olivier.mattelaer@uclouvain.be-20160512110018-sevb79f0wm4g8mpp
pass to 2.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import fractions
21
21
import os 
22
22
import sys
 
23
import tempfile
 
24
import glob
 
25
import shutil
23
26
 
24
27
root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0]
25
28
sys.path.append(os.path.join(root_path, os.path.pardir, os.path.pardir))
31
34
import tests.IOTests as IOTests
32
35
import madgraph.interface.master_interface as MGCmd
33
36
 
 
37
import madgraph.fks.fks_common as fks_common
 
38
 
34
39
_file_path = os.path.dirname(os.path.realpath(__file__))
35
40
_input_file_path = os.path.join(_file_path, os.path.pardir, os.path.pardir,
36
41
                                'input_files')
37
42
 
38
 
#===============================================================================
39
 
# IOExportFKSTest
40
 
#===============================================================================
41
 
class IOExportFKSTest(IOTests.IOTestManager):
42
 
    """Test class for the export fks module"""
43
 
 
44
 
    def generate(self, process, model, multiparticles=[]):
45
 
        """Create a process"""
46
 
 
47
 
        def run_cmd(cmd):
48
 
            interface.exec_cmd(cmd, errorhandling=False, printcmd=False, 
49
 
                               precmd=True, postcmd=True)
50
 
 
51
 
        interface = MGCmd.MasterCmd()
52
 
        
53
 
        run_cmd('import model %s' % model)
54
 
        for multi in multiparticles:
55
 
            run_cmd('define %s' % multi)
56
 
        if isinstance(process, str):
57
 
            run_cmd('generate %s' % process)
58
 
        else:
59
 
            for p in process:
60
 
                run_cmd('add process %s' % p)
61
 
 
62
 
        files.rm(self.IOpath)
63
 
        run_cmd('output %s -f' % self.IOpath)
64
 
 
65
 
 
66
 
    @IOTests.createIOTest()
67
 
    def testIO_test_pptt_fksreal(self):
68
 
        """ target: SubProcesses/[P0.*\/.+\.(inc|f)]"""
69
 
        self.generate(['p p > t t~ [real=QCD]'], 'sm')
70
 
 
71
 
    @IOTests.createIOTest()
72
 
    def testIO_test_tdecay_fksreal(self):
73
 
        """ target: SubProcesses/[P0.*\/.+\.(inc|f)]"""
74
 
        self.generate(['t > j j b [real=QCD]'], 'sm')
75
 
 
76
 
    @IOTests.createIOTest()
77
 
    def testIO_test_pptt_fks_loonly(self):
78
 
        """ target: SubProcesses/[P0.*\/.+\.(inc|f)]"""
79
 
        self.generate(['p p > t t~ [LOonly=QCD]'], 'sm')
 
43
class TestFKSOutput(unittest.TestCase):
 
44
    """ this class is to test that the new and old nlo generation give
 
45
    identical results
 
46
    """
 
47
 
 
48
    def test_w_nlo_gen(self):
 
49
        """check that the new (memory and cpu efficient) and old generation
 
50
        mode at NLO give the same results for p p > w [QCD]
 
51
        """
 
52
        path = tempfile.mkdtemp('', 'TMPWTest', None)
 
53
 
 
54
        def run_cmd(cmd):
 
55
            interface.exec_cmd(cmd, errorhandling=False, printcmd=False, 
 
56
                               precmd=True, postcmd=True)
 
57
 
 
58
        interface = MGCmd.MasterCmd()
 
59
        
 
60
        run_cmd('generate p p > w+ [QCD]')
 
61
        run_cmd('output %s' % os.path.join(path, 'W-oldway'))
 
62
        run_cmd('set low_mem_multicore_nlo_generation True')
 
63
        run_cmd('generate p p > w+ [QCD]')
 
64
        run_cmd('output %s' % os.path.join(path, 'W-newway'))
 
65
        run_cmd('set low_mem_multicore_nlo_generation False')
 
66
        
 
67
        # the P0 dirs
 
68
        for oldf in \
 
69
          (glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', '*.inc')) + \
 
70
           glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', '*.f')) + \
 
71
           [os.path.join(path, 'W-oldway', 'SubProcesses', 'proc_characteristics')]):
 
72
            
 
73
            if os.path.islink(oldf): 
 
74
                continue
 
75
 
 
76
            newf = oldf.replace('oldway', 'newway')
 
77
 
 
78
            for old_l, new_l in zip(open(oldf), open(newf)):
 
79
                self.assertEqual(old_l, new_l)
 
80
 
 
81
        # the V0 dirs
 
82
        for oldf in \
 
83
          (glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', 'V0*', '*.inc')) + \
 
84
           glob.glob(os.path.join(path, 'W-oldway', 'SubProcesses', 'P0*', 'V0*', '*.f'))):
 
85
            
 
86
            if os.path.islink(oldf): 
 
87
                continue
 
88
 
 
89
            newf = oldf.replace('oldway', 'newway')
 
90
 
 
91
            for old_l, new_l in zip(open(oldf), open(newf)):
 
92
                self.assertEqual(old_l, new_l)
 
93
 
 
94
 
 
95
    def test_w_nlo_gen_gosam(self):
 
96
        """check that the new generation mode works when gosam is set 
 
97
        for p p > w [QCD] 
 
98
        """
 
99
        path = tempfile.mkdtemp('', 'TMPWTest', None)
 
100
 
 
101
        def run_cmd(cmd):
 
102
            interface.exec_cmd(cmd, errorhandling=False, printcmd=False, 
 
103
                               precmd=True, postcmd=True)
 
104
 
 
105
        interface = MGCmd.MasterCmd()
 
106
        
 
107
        run_cmd('set low_mem_multicore_nlo_generation True')
 
108
        run_cmd('set OLP GoSam')
 
109
        run_cmd('generate p p > w+ [QCD]')
 
110
        try:
 
111
            run_cmd('output %s' % os.path.join(path, 'W-newway'))
 
112
        except fks_common.FKSProcessError, err:
 
113
            # catch the error if gosam is not there
 
114
            if not 'Generation of the virtuals with GoSam failed' in str(err):
 
115
                raise Exception, err
 
116
        run_cmd('set low_mem_multicore_nlo_generation False')
 
117
        run_cmd('set OLP MadLoop')
 
118
 
 
119
        shutil.rmtree(path)
 
120
 
 
121
 
 
122
 
 
123