/[escript]/trunk/ripley/test/python/run_escriptOnRipley.py
ViewVC logotype

Contents of /trunk/ripley/test/python/run_escriptOnRipley.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (show annotations)
Mon Jun 2 02:50:34 2014 UTC (4 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 12408 byte(s)
revamping testrunners, now uses automated discovery and allows running specific tests without modifying files (see escriptcore/py_src/testing.py for more info/examples)

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import os
25 import sys
26 import esys.escriptcore.utestselect as unittest
27 from esys.escriptcore.testing import *
28 from esys.escript import *
29 from esys.ripley import Rectangle, Brick, ripleycpp
30 from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation
31 from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy
32
33 from test_shared import Test_Shared
34
35 try:
36 RIPLEY_WORKDIR=os.environ['RIPLEY_WORKDIR']
37 except KeyError:
38 RIPLEY_WORKDIR='.'
39
40 NE=4 # number elements, must be even
41 mpiSize=getMPISizeWorld()
42 for x in [int(sqrt(mpiSize)),2,3,5,7,1]:
43 NX=x
44 NY=mpiSize//x
45 if NX*NY == mpiSize:
46 break
47
48 for x in [(int(mpiSize**(1/3.)),int(mpiSize**(1/3.))),(2,3),(2,2),(1,2),(1,1)]:
49 NXb=x[0]
50 NYb=x[1]
51 NZb=mpiSize//(x[0]*x[1])
52 if NXb*NYb*NZb == mpiSize:
53 break
54
55 class Test_SharedOnRipley(Test_Shared):
56 def setUp(self):
57 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
58 self.tol=0.001
59 def tearDown(self):
60 del self.domain
61 del self.tol
62
63 class Test_DomainOnRipley(Test_Domain):
64 def setUp(self):
65 self.boundary_tag_list = [1, 2, 10, 20]
66 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
67 self.rdomain=Rectangle(n0=(NE+6)*NX-1, n1=(NE+6)*NY-1, l0=1., l1=1., d0=NX, d1=NY)
68
69 def tearDown(self):
70 del self.domain
71 del self.boundary_tag_list
72
73 def test_tagsContinuousFunction(self):
74 ref_tags=[0]
75 tags=ContinuousFunction(self.domain).getListOfTags()
76 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
77 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
78 def test_tagsFunction(self):
79 ref_tags=[0]
80 tags=Function(self.domain).getListOfTags()
81 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
82 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
83 def test_tagsReducedFunction(self):
84 ref_tags=[0]
85 tags=ReducedFunction(self.domain).getListOfTags()
86 self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
87 for i in ref_tags: self.assertTrue(i in tags,"tag %s is missing."%i)
88 def test_tagsFunctionOnBoundary(self):
89 ref_tags=[1, 2, 10, 20]
90 tags=FunctionOnBoundary(self.domain).getListOfTags()
91 # For an MPI-distributed domain some tags may be missing
92 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
93 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
94 def test_tagsReducedFunctionOnBoundary(self):
95 ref_tags=[1, 2, 10, 20]
96 tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
97 # For an MPI-distributed domain some tags may be missing
98 if getMPISizeWorld() == 1: self.assertTrue(len(tags)==len(ref_tags), "tags list has wrong length.")
99 for i in tags: self.assertTrue(i in ref_tags,"tag %s is missing."%i)
100
101 class Test_DataOpsOnRipley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
102 def setUp(self):
103 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
104 self.domain_with_different_number_of_samples=Rectangle(n0=7*NE*NX-1, n1=3*NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
105 self.domain_with_different_number_of_data_points_per_sample=Rectangle(n0=7*NE*NX-1, n1=3*NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
106 self.domain_with_different_sample_ordering=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
107 self.filename_base=RIPLEY_WORKDIR
108 self.mainfs=Function(self.domain)
109 self.otherfs=Solution(self.domain)
110
111 def tearDown(self):
112 del self.domain
113 del self.domain_with_different_number_of_samples
114 del self.domain_with_different_number_of_data_points_per_sample
115 del self.domain_with_different_sample_ordering
116 del self.mainfs
117 del self.otherfs
118
119 class Test_TableInterpolationOnRipley(Test_TableInterpolation):
120 def setUp(self):
121 self.domain = Brick(n0=NE*NXb-1, n1=NE*NYb-1, n2=NE*NZb-1, l0=1., l1=1., l2=1., d0=NXb, d1=NYb, d2=NZb)
122 self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
123 FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain)]
124 #We aren't testing DiracDeltaFunctions
125 self.xn=5 # number of grids on x axis
126 self.yn=5 # number of grids on y axis
127 self.zn=5
128
129 def tearDown(self):
130 del self.domain
131 del self.functionspaces
132
133 class Test_CSVOnRipley(Test_saveCSV):
134 def setUp(self):
135 self.domain=Rectangle(n0=NE*NX-1, n1=NE*NY-1, l0=1., l1=1., d0=NX, d1=NY)
136 self.functionspaces=[ContinuousFunction, Function, ReducedFunction,
137 FunctionOnBoundary, ReducedFunctionOnBoundary]
138
139 NE0=NE*NX-1
140 NE1=NE*NY-1
141
142 # number of total data points for each function space
143 self.linecounts=[ (NE0+1)*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
144 4*NE0+4*NE1+1, 2*NE0+2*NE1+1 ]
145 # number of masked points, i.e. where X[0] is non-zero
146 self.linecounts_masked=[ NE0*(NE1+1)+1, 4*NE0*NE1+1, NE0*NE1+1,
147 4*NE0+2*NE1+1, 2*NE0+NE1+1 ]
148 # expected values in first line of masked data = [ X[:], X[0] ]
149 self.firstline=[ [1./NE0, 0., 1./NE0],
150 [None, None, None],
151 [None, None, None],
152 [None, None, None],
153 [None, None, None] ]
154
155 def tearDown(self):
156 del self.domain
157
158 def test_csv_multiFS(self):
159 fname=os.path.join(RIPLEY_WORKDIR, "test_multifs.csv")
160 sol=Data(8,Solution(self.domain))
161 ctsfn=Data(9,ContinuousFunction(self.domain))
162 #test line 0
163 dirac=Data(-1,DiracDeltaFunctions(self.domain))
164 saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
165 #test line 1
166 fun=Data(5,Function(self.domain))
167 rfun=Data(3,ReducedFunction(self.domain))
168 saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
169 #test line 2
170 bound=Data(1,FunctionOnBoundary(self.domain))
171 rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
172 saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
173
174 class Test_randomOnRipley(unittest.TestCase):
175 def test_FillRectangle(self):
176 fs=ContinuousFunction(Rectangle(10*(int(sqrt(mpiSize)+1)),10*(int(sqrt(mpiSize)+1))))
177 RandomData((), fs, 2,("gaussian",1,0.5))
178 RandomData((), fs, 0,("gaussian",2,0.76))
179 self.assertRaises(RuntimeError, RandomData, (2,2), fs, 0, ("gaussian",2,0.76))
180 self.assertRaises(RuntimeError, RandomData, (), fs, 0, ("gaussian",11,0.1))
181 RandomData((2,3),fs)
182
183 def test_FillBrick(self):
184 # If we are going to do really big tests of this, the size of this brick will need to be reduced
185 fs=ContinuousFunction(Brick(10*mpiSize,10*mpiSize, 10*mpiSize))
186 RandomData((), fs, 2,("gaussian",1,0.5))
187 RandomData((), fs, 0,("gaussian",2,0.76))
188 self.assertRaises(RuntimeError, RandomData, (2,2), fs, 0, ("gaussian",2,0.76))
189 self.assertRaises(RuntimeError, RandomData, (), fs, 0, ("gaussian",20,0.1))
190 RandomData((2,3),fs)
191
192 class Test_binaryGridOnRipley(unittest.TestCase):
193 def setUp(self):
194 self.byteorder = ripleycpp.BYTEORDER_NATIVE
195 self.datatype = ripleycpp.DATATYPE_FLOAT64
196 self.ranks = getMPISizeWorld()
197
198 def read(self, filename, FS, expected, zipped = False):
199 first = [0 for i in expected]
200 reverse = [0 for i in expected]
201 scale = [1 for i in expected]
202 if not zipped:
203 return ripleycpp._readBinaryGrid(filename, FS, (), 50000,
204 self.byteorder, self.datatype, first, expected, scale, reverse)
205 if not hasattr(ripleycpp, "_readBinaryGridFromZipped"):
206 raise unittest.SkipTest("unzip library not available (boost_iostreams)")
207 return ripleycpp._readBinaryGridFromZipped(filename, FS, (), 50000,
208 self.byteorder, self.datatype, first, expected, scale, reverse)
209
210 def write(self, domain, data, filename):
211 domain.writeBinaryGrid(data, filename, self.byteorder, self.datatype)
212
213 def adjust(self, NE, ftype):
214 if ftype == ContinuousFunction:
215 return [i+1 for i in NE]
216 return NE
217
218 def generateUniqueData(self, FS, dim):
219 x = FS.getX()
220 if dim == 2:
221 return x[0] * 10 * (10*self.ranks-1) + x[1]
222 return x[0] * 100 * (10*self.ranks-1) + x[1] * 100 + x[2]
223
224 def test_BrickWriteThenRead(self):
225 NE = [10*self.ranks-1, 10*self.ranks-1, 10]
226 domain = Brick(NE[0], NE[1], NE[2], d2=0)
227 for ftype in [ReducedFunction, ContinuousFunction]:
228 FS = ftype(domain)
229 original = self.generateUniqueData(FS, 3)
230 self.write(domain, original, "ref_data/tempfile")
231 result = self.read("ref_data/tempfile", FS, self.adjust(NE, ftype))
232 MPIBarrierWorld()
233 if getMPIRankWorld() == 0:
234 os.unlink("ref_data/tempfile")
235 self.assertEqual(Lsup(original - result), 0, "Data objects don't match for "+str(FS))
236
237 def test_RectangleWriteThenRead(self):
238 NE = [10*self.ranks-1, 10]
239 domain = Rectangle(NE[0], NE[1], d1=0)
240 for ftype in [ReducedFunction, ContinuousFunction]:
241 FS = ftype(domain)
242 original = self.generateUniqueData(FS, 2)
243 self.write(domain, original, "ref_data/tempfile")
244 result = self.read("ref_data/tempfile", FS, self.adjust(NE, ftype))
245 MPIBarrierWorld()
246 if getMPIRankWorld() == 0:
247 os.unlink("ref_data/tempfile")
248 self.assertEqual(Lsup(original - result), 0, "Data objects don't match for "+str(FS))
249
250 @unittest.skipIf(getMPISizeWorld() > 1,
251 "Skipping compressed binary grid tests due element stretching")
252 def test_BrickCompressed(self):
253 NE = [10*self.ranks-1, 10*self.ranks-1, 10]
254 domain = Brick(NE[0], NE[1], NE[2], d1=0, d2=0)
255 for filename, ftype in [("ref_data/BrickRedF%s.grid.gz", ReducedFunction),
256 ("ref_data/BrickConF%s.grid.gz", ContinuousFunction)]:
257 FS = ftype(domain)
258 filename = filename%self.ranks
259 unzipped = self.read(filename[:-3], FS, self.adjust(NE, ftype))
260 zipped = self.read(filename, FS, self.adjust(NE, ftype), zipped=True)
261 self.assertEqual(Lsup(zipped - unzipped), 0, "Data objects don't match for "+str(FS))
262
263 @unittest.skipIf(getMPISizeWorld() > 1,
264 "Skipping compressed binary grid tests due element stretching")
265 def test_RectangleCompressed(self):
266 NE = [10*self.ranks-1, 10]
267 domain = Rectangle(NE[0], NE[1], d1=0)
268 for filename, ftype in [("ref_data/RectRedF%s.grid.gz", ReducedFunction),
269 ("ref_data/RectConF%s.grid.gz", ContinuousFunction)]:
270 FS = ftype(domain)
271 filename = filename%self.ranks
272 unzipped = self.read(filename[:-3], FS, self.adjust(NE, ftype))
273 zipped = self.read(filename, FS, self.adjust(NE, ftype), zipped=True)
274 self.assertEqual(Lsup(zipped - unzipped), 0, "Data objects don't match for "+str(FS))
275
276 if __name__ == '__main__':
277 run_tests(__name__, exit_on_failure=True)
278

  ViewVC Help
Powered by ViewVC 1.1.26