source: coopr.data.pyomo/trunk/coopr/data/pyomo/test_perf.py @ 5783

Last change on this file since 5783 was 5783, checked in by wehart, 7 years ago

Adding large diagonal models for profiling.

File size: 3.9 KB
Line 
1#
2# Test the Pyomo command-line interface
3#
4
5import os
6import sys
7from os.path import abspath, dirname
8currdir = dirname(abspath(__file__))+os.sep
9datadir = os.path.normpath(currdir+'../../../../coopr.pyomo/examples/pyomo/p-median/')+os.sep
10print datadir
11
12from coopr.pyomo import *
13import pyutilib.th as unittest
14import coopr.pyomo.scripting.convert as convert
15import re
16import glob
17
18
19@unittest.category('performance')
20class Test(unittest.TestCase):
21
22    def setUp(self):
23        self.cwd = os.getcwd()
24        os.chdir(currdir)
25
26    def tearDown(self):
27        os.chdir(self.cwd)
28
29
30@unittest.category('performance')
31class Test1(Test):
32
33    def test1(self):
34        res = convert.pyomo2nl(['--save-model',currdir+'test1.nl',datadir+'pmedian.py',datadir+'pmedian.dat'])
35        if not os.path.exists(currdir+'test1.nl'):
36            raise ValueError, "Missing file test1.nl generated in test1"
37        os.remove(currdir+'test1.nl')
38        if not res.options.max_memory is None:
39            self.recordTestData('maximum memory used', res.options.max_memory)
40
41    def test2(self):
42        res = convert.pyomo2lp(['--save-model',currdir+'test2.lp',datadir+'pmedian.py',datadir+'pmedian.dat'])
43        if not os.path.exists(currdir+'test2.lp'):
44            raise ValueError, "Missing file test2.lp generated in test2"
45        os.remove(currdir+'test2.lp')
46        if not res.options.max_memory is None:
47            self.recordTestData('maximum memory used', res.options.max_memory)
48
49@unittest.category('performance')
50class Test2(Test):
51    pass
52
53
54@unittest.category('performance')
55class Test3(Test):
56    pass
57
58
59@unittest.nottest
60def nl_test(self, name):
61    fname = currdir+name+'.nl'
62    root = name.split('_')[1]
63    #print >>sys.stderr, fname
64    options = self.get_options(name)
65    if os.path.exists(datadir+root+'.dat'):
66        options.append(datadir+root+'.dat')
67    res = convert.pyomo2nl(['--save-model',fname]+options)
68    if not os.path.exists(fname):
69        raise ValueError, "Missing file %s generated in test2" % fname
70    os.remove(fname)
71    if not res.options.max_memory is None:
72        self.recordTestData('maximum memory used', res.options.max_memory)
73
74@unittest.nottest
75def lp_test(self, name):
76    fname = currdir+name+'.lp'
77    root = name.split('_')[1]
78    #print >>sys.stderr, fname
79    options = self.get_options(name)
80    if os.path.exists(datadir+root+'.dat'):
81        options.append(datadir+root+'.dat')
82    res = convert.pyomo2lp(['--save-model',fname]+options)
83    if not os.path.exists(fname):
84        raise ValueError, "Missing file %s generated in test2" % fname
85    os.remove(fname)
86    if not res.options.max_memory is None:
87        self.recordTestData('maximum memory used', res.options.max_memory)
88
89
90for i in range(8):
91    name = 'test'+str(i+1)
92    #
93    Test2.add_fn_test(fn=nl_test, name='nl_pmedian.'+name, options=[datadir+'pmedian.py'])
94    Test2.add_fn_test(fn=nl_test, name='nl-O_pmedian.'+name, options=['--disable-gc', datadir+'pmedian.py'] )
95    #if i < 4:
96        #Test3.add_fn_test(fn=nl_test, name='nl-memcov_pmedian.'+name, options=['--profile-memory','1',datadir+'pmedian.py'] )
97    #
98    Test2.add_fn_test(fn=lp_test, name='lp_pmedian.'+name, options=[datadir+'pmedian.py'])
99    Test2.add_fn_test(fn=lp_test, name='lp-O_pmedian.'+name, options=['--disable-gc', datadir+'pmedian.py'] )
100    #if i < 4:
101        #Test3.add_fn_test(fn=lp_test, name='lp-memcov_pmedian.'+name, options=['--profile-memory','1',datadir+'pmedian.py'] )
102
103for name in ['diag1', 'diag2']:
104    Test3.add_fn_test(fn=nl_test, name='nl_'+name, options=[currdir+'performance'+os.sep+name+'.py'])
105    Test3.add_fn_test(fn=nl_test, name='nl_O_'+name, options=['--disable-gc',currdir+'performance'+os.sep+name+'.py'])
106    Test3.add_fn_test(fn=lp_test, name='lp_'+name, options=[currdir+'performance'+os.sep+name+'.py'])
107    Test3.add_fn_test(fn=lp_test, name='lp_O_'+name, options=['--disable-gc',currdir+'performance'+os.sep+name+'.py'])
108
109if __name__ == "__main__":
110    unittest.main()
Note: See TracBrowser for help on using the repository browser.