]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader_swig/Test/testSaveLoadRun.py
Salome HOME
Use /tmp for temporary files needed by salome tests.
[modules/yacs.git] / src / yacsloader_swig / Test / testSaveLoadRun.py
1 # Copyright (C) 2006-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import unittest
21 import tempfile
22 import os
23
24 import pilot
25 import SALOMERuntime
26 import loader
27
28 import datetime
29
30 class TestSaveLoadRun(unittest.TestCase):
31   def setUp(self):
32     SALOMERuntime.RuntimeSALOME.setRuntime()
33     self.r=SALOMERuntime.getSALOMERuntime()
34     self.workdir = tempfile.mkdtemp(suffix=".yacstest")
35     pass
36
37   def test0(self):
38     """First test of HP Container no loop here only the 3 sorts of python nodes (the Distributed is it still used and useful ?) """
39     fname=os.path.join(self.workdir, "TestSaveLoadRun0.xml")
40     nbOfNodes=8
41     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
42     l=loader.YACSLoader()
43     p=self.r.createProc("prTest0")
44     td=p.createType("double","double")
45     ti=p.createType("int","int")
46     cont=p.createContainer("gg","HPSalome")
47     cont.setSizeOfPool(4)
48     cont.setProperty("name","localhost")
49     cont.setProperty("hostname","localhost")
50     script0="""
51 def ff(nb,dbg):
52     from math import cos
53     import datetime
54     
55     ref=datetime.datetime.now()
56     t=0. ; pas=1./float(nb)
57     for i in range(nb):
58         for j in range(nb):
59             x=j*pas
60             t+=1.+cos(1.*(x*3.14159))
61             pass
62         pass
63     print("coucou from script0-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
64     return t
65 """
66     script1="""
67 from math import cos
68 import datetime
69 ref=datetime.datetime.now()
70 o2=0. ; pas=1./float(i1)
71 for i in range(i1):
72   for j in range(i1):
73     x=j*pas
74     o2+=1.+cos(1.*(x*3.14159))
75     pass
76 print("coucou from script1-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
77 """
78     for i in range(nbOfNodes):
79       node0=self.r.createFuncNode("DistPython","node%i"%(i))
80       p.edAddChild(node0)
81       node0.setFname("ff")
82       node0.setContainer(cont)
83       node0.setScript(script0)
84       nb=node0.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
85       dbg=node0.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
86       out0=node0.edAddOutputPort("s",td)
87       #
88       nodeMiddle=self.r.createFuncNode("Salome","node%i_1"%(i))
89       p.edAddChild(nodeMiddle)
90       p.edAddCFLink(node0,nodeMiddle)
91       nodeMiddle.setFname("ff")
92       nodeMiddle.setContainer(cont)
93       nodeMiddle.setScript(script0)
94       nb=nodeMiddle.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
95       dbg=nodeMiddle.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
96       out0=nodeMiddle.edAddOutputPort("s",td)
97       nodeMiddle.setExecutionMode("remote")
98       #
99       nodeEnd=self.r.createScriptNode("Salome","node%i_2"%(i+1))
100       p.edAddChild(nodeEnd)
101       p.edAddCFLink(nodeMiddle,nodeEnd)
102       nodeEnd.setContainer(cont)
103       nodeEnd.setScript(script1)
104       i1=nodeEnd.edAddInputPort("i1",ti) ; i1.edInitInt(sqrtOfNumberOfTurn)
105       dbg=nodeEnd.edAddInputPort("dbg",ti) ; dbg.edInitInt(i)
106       o2=nodeEnd.edAddOutputPort("o2",td)
107       nodeEnd.setExecutionMode("remote")
108       pass
109     p.saveSchema(fname)
110     p=l.load(fname)
111     ex=pilot.ExecutorSwig()
112     self.assertEqual(p.getState(),pilot.READY)
113     st=datetime.datetime.now()
114     # 1st exec
115     ex.RunW(p,0)
116     print("Time spend of test0 to run 1st %s"%(str(datetime.datetime.now()-st)))
117     self.assertEqual(p.getState(),pilot.DONE)
118     # 2nd exec using the same already launched remote python interpreters
119     st=datetime.datetime.now()
120     ex.RunW(p,0)
121     print("Time spend of test0 to run 2nd %s"%(str(datetime.datetime.now()-st)))
122     self.assertEqual(p.getState(),pilot.DONE)
123     # 3rd exec using the same already launched remote python interpreters
124     st=datetime.datetime.now()
125     ex.RunW(p,0)
126     print("Time spend of test0 to run 3rd %s"%(str(datetime.datetime.now()-st)))
127     self.assertEqual(p.getState(),pilot.DONE)
128     pass
129
130   def test1(self):
131     """ HP Container again like test0 but the initialization key of HPContainer is used here."""
132     fname=os.path.join(self.workdir, "TestSaveLoadRun1.xml")
133     nbOfNodes=8
134     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
135     l=loader.YACSLoader()
136     p=self.r.createProc("prTest1")
137     td=p.createType("double","double")
138     ti=p.createType("int","int")
139     cont=p.createContainer("gg","HPSalome")
140     cont.setSizeOfPool(4)
141     cont.setProperty("InitializeScriptKey","aa=123.456")
142     cont.setProperty("name","localhost")
143     cont.setProperty("hostname","localhost")
144     script0="""
145 def ff(nb,dbg):
146     from math import cos
147     import datetime
148     
149     ref=datetime.datetime.now()
150     t=0. ; pas=1./float(nb)
151     for i in range(nb):
152         for j in range(nb):
153             x=j*pas
154             t+=1.+cos(1.*(x*3.14159))
155             pass
156         pass
157     print("coucou from script0-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
158     return t
159 """
160     # here in script1 aa is refered ! aa will exist thanks to HPCont Init Script
161     script1="""
162 from math import cos
163 import datetime
164 ref=datetime.datetime.now()
165 o2=0. ; pas=1./float(i1)
166 for i in range(i1):
167   for j in range(i1):
168     x=j*pas
169     o2+=1.+cos(1.*(x*3.14159))
170     pass
171 print("coucou %lf from script1-%i  -> %s"%(aa,dbg,str(datetime.datetime.now()-ref)))
172 aa+=1.
173 """
174     #
175     for i in range(nbOfNodes):
176       nodeMiddle=self.r.createFuncNode("Salome","node%i_1"%(i)) # PyFuncNode remote
177       p.edAddChild(nodeMiddle)
178       nodeMiddle.setFname("ff")
179       nodeMiddle.setContainer(cont)
180       nodeMiddle.setScript(script0)
181       nb=nodeMiddle.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
182       dbg=nodeMiddle.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
183       out0=nodeMiddle.edAddOutputPort("s",td)
184       nodeMiddle.setExecutionMode("remote")
185       #
186       nodeEnd=self.r.createScriptNode("Salome","node%i_2"%(i+1)) # PythonNode remote
187       p.edAddChild(nodeEnd)
188       p.edAddCFLink(nodeMiddle,nodeEnd)
189       nodeEnd.setContainer(cont)
190       nodeEnd.setScript(script1)
191       i1=nodeEnd.edAddInputPort("i1",ti) ; i1.edInitInt(sqrtOfNumberOfTurn)
192       dbg=nodeEnd.edAddInputPort("dbg",ti) ; dbg.edInitInt(i)
193       o2=nodeEnd.edAddOutputPort("o2",td)
194       nodeEnd.setExecutionMode("remote")
195       pass
196     #
197     p.saveSchema(fname)
198     p=l.load(fname)
199     self.assertEqual(p.edGetDirectDescendants()[0].getContainer().getProperty("InitializeScriptKey"),"aa=123.456")
200     # 1st exec
201     ex=pilot.ExecutorSwig()
202     self.assertEqual(p.getState(),pilot.READY)
203     st=datetime.datetime.now()
204     ex.RunW(p,0)
205     print("Time spend of test1 to 1st run %s"%(str(datetime.datetime.now()-st)))
206     self.assertEqual(p.getState(),pilot.DONE)
207     # 2nd exec
208     st=datetime.datetime.now()
209     ex.RunW(p,0)
210     print("Time spend of test1 to 2nd run %s"%(str(datetime.datetime.now()-st)))
211     self.assertEqual(p.getState(),pilot.DONE)
212     # 3rd exec
213     st=datetime.datetime.now()
214     ex.RunW(p,0)
215     print("Time spend of test1 to 3rd run %s"%(str(datetime.datetime.now()-st)))
216     self.assertEqual(p.getState(),pilot.DONE)
217     pass
218
219   def test2(self):
220     """ Test on HP Containers in foreach context."""
221     script0="""def ff():
222     global aa
223     print("%%lf - %%s"%%(aa,str(my_container)))
224     return 16*[%i],0
225 """
226     script1="""from math import cos
227 import datetime
228 ref=datetime.datetime.now()
229 o2=0. ; pas=1./float(i1)
230 for i in range(i1):
231   for j in range(i1):
232     x=j*pas
233     o2+=1.+cos(1.*(x*3.14159))
234     pass
235 print("coucou %lf from script  -> %s"%(aa,str(datetime.datetime.now()-ref)))
236 aa+=1.
237 o3=0
238 """
239     script2="""o9=sum(i8)
240 """
241     fname=os.path.join(self.workdir, "TestSaveLoadRun2.xml")
242     nbOfNodes=8
243     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
244     l=loader.YACSLoader()
245     p=self.r.createProc("prTest1")
246     td=p.createType("double","double")
247     ti=p.createType("int","int")
248     tdi=p.createSequenceTc("seqint","seqint",ti)
249     tdd=p.createSequenceTc("seqdouble","seqdouble",td)
250     cont=p.createContainer("gg","HPSalome")
251     cont.setSizeOfPool(4)
252     cont.setProperty("InitializeScriptKey","aa=123.456")
253     cont.setProperty("name","localhost")
254     cont.setProperty("hostname","localhost")
255     #
256     node0=self.r.createFuncNode("Salome","PyFunction0") # PyFuncNode remote
257     p.edAddChild(node0)
258     node0.setFname("ff")
259     node0.setContainer(cont)
260     node0.setScript(script0%(sqrtOfNumberOfTurn))
261     out0_0=node0.edAddOutputPort("o1",tdi)
262     out1_0=node0.edAddOutputPort("o2",ti)
263     node0.setExecutionMode("remote")
264     #
265     node1=self.r.createForEachLoop("node1",ti)
266     p.edAddChild(node1)
267     p.edAddCFLink(node0,node1)
268     p.edAddLink(out0_0,node1.edGetSeqOfSamplesPort())
269     node1.edGetNbOfBranchesPort().edInitInt(8)
270     #
271     node2=self.r.createScriptNode("Salome","PyScript3")
272     node1.edAddChild(node2)
273     node2.setContainer(cont)
274     node2.setScript(script1)
275     i1=node2.edAddInputPort("i1",ti)
276     p.edAddLink(node1.edGetSamplePort(),i1)
277     out0_2=node2.edAddOutputPort("o2",td)
278     out1_2=node2.edAddOutputPort("o3",ti)
279     node2.setExecutionMode("remote")
280     #
281     node3=self.r.createScriptNode("Salome","PyScript7")
282     p.edAddChild(node3)
283     node3.setScript(script2)
284     p.edAddCFLink(node1,node3)
285     i8=node3.edAddInputPort("i8",tdd)
286     o9=node3.edAddOutputPort("o9",td)
287     p.edAddLink(out0_2,i8)
288     #
289     p.saveSchema(fname)
290     p=l.load(fname)
291     o9=p.getChildByName("PyScript7").getOutputPort("o9")
292     self.assertTrue(len(p.edGetDirectDescendants()[1].getChildByName("PyScript3").getContainer().getProperty("InitializeScriptKey"))!=0)
293     # 1st exec
294     refExpected=16016013.514623128
295     ex=pilot.ExecutorSwig()
296     self.assertEqual(p.getState(),pilot.READY)
297     st=datetime.datetime.now()
298     ex.RunW(p,0)
299     print("Time spend of test2 to 1st run %s"%(str(datetime.datetime.now()-st)))
300     self.assertEqual(p.getState(),pilot.DONE)
301     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
302     # 2nd exec
303     st=datetime.datetime.now()
304     ex.RunW(p,0)
305     print("Time spend of test2 to 2nd run %s"%(str(datetime.datetime.now()-st)))
306     self.assertEqual(p.getState(),pilot.DONE)
307     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
308     # 3rd exec
309     st=datetime.datetime.now()
310     ex.RunW(p,0)
311     print("Time spend of test2 to 3rd run %s"%(str(datetime.datetime.now()-st)))
312     self.assertEqual(p.getState(),pilot.DONE)
313     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
314     pass
315
316   def test3(self):
317     """ Test that focuses on parallel load of containers."""
318     script0="""def ff():
319     global aa
320     print("%%lf - %%s"%%(aa,str(my_container)))
321     return 100*[%i],0
322 """
323     script1="""from math import cos
324 import datetime
325 ref=datetime.datetime.now()
326 o2=0. ; pas=1./float(i1)
327 for i in range(i1):
328   for j in range(i1):
329     x=j*pas
330     o2+=1.+cos(1.*(x*3.14159))
331     pass
332 print("coucou %lf from script  -> %s"%(aa,str(datetime.datetime.now()-ref)))
333 aa+=1.
334 o3=0
335 """
336     script2="""o9=sum(i8)
337 """
338     fname=os.path.join(self.workdir, "TestSaveLoadRun3.xml")
339     nbOfNodes=8
340     sqrtOfNumberOfTurn=10
341     l=loader.YACSLoader()
342     p=self.r.createProc("prTest1")
343     td=p.createType("double","double")
344     ti=p.createType("int","int")
345     tdi=p.createSequenceTc("seqint","seqint",ti)
346     tdd=p.createSequenceTc("seqdouble","seqdouble",td)
347     cont=p.createContainer("gg","HPSalome")
348     cont.setSizeOfPool(8)
349     cont.setProperty("InitializeScriptKey","aa=123.456")
350     cont.setProperty("name","localhost")
351     cont.setProperty("hostname","localhost")
352     #
353     node0=self.r.createFuncNode("Salome","PyFunction0") # PyFuncNode remote
354     p.edAddChild(node0)
355     node0.setFname("ff")
356     node0.setContainer(cont)
357     node0.setScript(script0%(sqrtOfNumberOfTurn))
358     out0_0=node0.edAddOutputPort("o1",tdi)
359     out1_0=node0.edAddOutputPort("o2",ti)
360     node0.setExecutionMode("remote")
361     #
362     node1=self.r.createForEachLoop("node1",ti)
363     p.edAddChild(node1)
364     p.edAddCFLink(node0,node1)
365     p.edAddLink(out0_0,node1.edGetSeqOfSamplesPort())
366     node1.edGetNbOfBranchesPort().edInitInt(16)
367     #
368     node2=self.r.createScriptNode("Salome","PyScript3")
369     node1.edAddChild(node2)
370     node2.setContainer(cont)
371     node2.setScript(script1)
372     i1=node2.edAddInputPort("i1",ti)
373     p.edAddLink(node1.edGetSamplePort(),i1)
374     out0_2=node2.edAddOutputPort("o2",td)
375     out1_2=node2.edAddOutputPort("o3",ti)
376     node2.setExecutionMode("remote")
377     #
378     node3=self.r.createScriptNode("Salome","PyScript7")
379     p.edAddChild(node3)
380     node3.setScript(script2)
381     p.edAddCFLink(node1,node3)
382     i8=node3.edAddInputPort("i8",tdd)
383     o9=node3.edAddOutputPort("o9",td)
384     p.edAddLink(out0_2,i8)
385     #
386     p.saveSchema(fname)
387     p=l.load(fname)
388     o9=p.getChildByName("PyScript7").getOutputPort("o9")
389     self.assertTrue(len(p.edGetDirectDescendants()[1].getChildByName("PyScript3").getContainer().getProperty("InitializeScriptKey"))!=0)
390     # 1st exec
391     refExpected=11000.008377058712
392     ex=pilot.ExecutorSwig()
393     self.assertEqual(p.getState(),pilot.READY)
394     st=datetime.datetime.now()
395     ex.RunW(p,0)
396     print("Time spend of test3 to 1st run %s"%(str(datetime.datetime.now()-st)))
397     self.assertEqual(p.getState(),pilot.DONE)
398     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
399     # 2nd exec
400     st=datetime.datetime.now()
401     ex.RunW(p,0)
402     print("Time spend of test3 to 2nd run %s"%(str(datetime.datetime.now()-st)))
403     self.assertEqual(p.getState(),pilot.DONE)
404     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
405     # 3rd exec
406     st=datetime.datetime.now()
407     ex.RunW(p,0)
408     print("Time spend of test3 to 3rd run %s"%(str(datetime.datetime.now()-st)))
409     self.assertEqual(p.getState(),pilot.DONE)
410     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
411     pass
412   
413   def test4(self):
414     """Non regression test of multi pyScriptNode, pyFuncNode sharing the same HPContainer instance."""
415     fname=os.path.join(self.workdir, "TestSaveLoadRun4.xml")
416     script1="""nb=7
417 ii=0
418 o1=nb*[None]
419 for i in range(nb):
420     tmp=(i+10)*[None]
421     for j in range(i+10):
422         tmp[j]=ii
423         ii+=1
424         pass
425     o1[i]=tmp
426     pass
427 """
428     l=loader.YACSLoader()
429     ex=pilot.ExecutorSwig()
430     p=self.r.createProc("pr")
431     cont=p.createContainer("gg","HPSalome")
432     cont.setSizeOfPool(10)
433     td=p.createType("int","int")
434     td2=p.createSequenceTc("seqint","seqint",td)
435     td3=p.createSequenceTc("seqintvec","seqintvec",td2)
436     node1=self.r.createScriptNode("","node1")
437     node1.setScript(script1)
438     o1=node1.edAddOutputPort("o1",td3)
439     p.edAddChild(node1)
440     #
441     node2=self.r.createForEachLoop("node2",td2)
442     p.edAddChild(node2)
443     p.edAddCFLink(node1,node2)
444     p.edAddLink(o1,node2.edGetSeqOfSamplesPort())
445     node2.edGetNbOfBranchesPort().edInitInt(2)
446     node20=self.r.createBloc("node20")
447     node2.edAddChild(node20)
448     node200=self.r.createForEachLoop("node200",td)
449     node20.edAddChild(node200)
450     node200.edGetNbOfBranchesPort().edInitInt(10)
451     p.edAddLink(node2.edGetSamplePort(),node200.edGetSeqOfSamplesPort())
452     node2000=self.r.createScriptNode("","node2000")
453     node2000.setContainer(cont)
454     node2000.setExecutionMode("remote")
455     node200.edAddChild(node2000)
456     i5=node2000.edAddInputPort("i5",td)
457     o6=node2000.edAddOutputPort("o6",td)
458     node2000.setScript("o6=2+i5")
459     p.edAddLink(node200.edGetSamplePort(),i5)
460     #
461     node3=self.r.createForEachLoop("node3",td2)
462     p.edAddChild(node3)
463     p.edAddCFLink(node2,node3)
464     p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
465     node3.edGetNbOfBranchesPort().edInitInt(2)
466     node30=self.r.createBloc("node30")
467     node3.edAddChild(node30)
468     node300=self.r.createForEachLoop("node300",td)
469     node30.edAddChild(node300)
470     node300.edGetNbOfBranchesPort().edInitInt(10)
471     p.edAddLink(node3.edGetSamplePort(),node300.edGetSeqOfSamplesPort())
472     node3000=self.r.createScriptNode("","node3000")
473     node3000.setContainer(cont)
474     node3000.setExecutionMode("remote")
475     node300.edAddChild(node3000)
476     i14=node3000.edAddInputPort("i14",td)
477     o15=node3000.edAddOutputPort("o15",td)
478     node3000.setScript("o15=3+i14")
479     p.edAddLink(node300.edGetSamplePort(),i14)
480     #
481     node4=self.r.createScriptNode("","node4")
482     node4.setScript("o9=i8")
483     p.edAddChild(node4)
484     i8=node4.edAddInputPort("i8",td3)
485     o9=node4.edAddOutputPort("o9",td3)
486     p.edAddCFLink(node3,node4)
487     p.edAddLink(o15,i8)
488     p.saveSchema(fname)
489     p=l.load(fname)
490     ex = pilot.ExecutorSwig()
491     self.assertEqual(p.getState(),pilot.READY)
492     ex.RunW(p,0)
493     self.assertEqual(p.getState(),pilot.DONE)
494     zeResu=p.getChildByName("node4").getOutputPort("o9").get()
495     self.assertEqual(zeResu,[[5,6,7,8,9,10,11,12,13,14],[15,16,17,18,19,20,21,22,23,24,25],[26,27,28,29,30,31,32,33,34,35,36,37],[38,39,40,41,42,43,44,45,46,47,48,49,50],[51,52,53,54,55,56,57,58,59,60,61,62,63,64],[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79], [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95]])
496     pass
497
498   def test5(self):
499     """Non regression test 2 of multi pyNode, pyFuncNode sharing the same HPContainer instance."""
500     fname=os.path.join(self.workdir, "TestSaveLoadRun5.xml")
501     script1="""nb=7
502 ii=0
503 o1=nb*[None]
504 for i in range(nb):
505     tmp=(i+10)*[None]
506     for j in range(i+10):
507         tmp[j]=ii
508         ii+=1
509         pass
510     o1[i]=tmp
511     pass
512 """
513     l=loader.YACSLoader()
514     ex=pilot.ExecutorSwig()
515     p=self.r.createProc("pr")
516     cont=p.createContainer("gg","HPSalome")
517     cont.setSizeOfPool(10)
518     td=p.createType("int","int")
519     td2=p.createSequenceTc("seqint","seqint",td)
520     td3=p.createSequenceTc("seqintvec","seqintvec",td2)
521     node1=self.r.createScriptNode("","node1")
522     node1.setScript(script1)
523     o1=node1.edAddOutputPort("o1",td3)
524     p.edAddChild(node1)
525     #
526     node2=self.r.createForEachLoop("node2",td2)
527     p.edAddChild(node2)
528     p.edAddCFLink(node1,node2)
529     p.edAddLink(o1,node2.edGetSeqOfSamplesPort())
530     node2.edGetNbOfBranchesPort().edInitInt(2)
531     node20=self.r.createBloc("node20")
532     node2.edAddChild(node20)
533     node200=self.r.createForEachLoop("node200",td)
534     node20.edAddChild(node200)
535     node200.edGetNbOfBranchesPort().edInitInt(10)
536     p.edAddLink(node2.edGetSamplePort(),node200.edGetSeqOfSamplesPort())
537     node2000=self.r.createFuncNode("Salome","node2000")
538     node2000.setFname("ff")
539     node2000.setContainer(cont)
540     node2000.setExecutionMode("remote")
541     node200.edAddChild(node2000)
542     i5=node2000.edAddInputPort("i5",td)
543     o6=node2000.edAddOutputPort("o6",td)
544     node2000.setScript("def ff(x):\n  return 2+x")
545     p.edAddLink(node200.edGetSamplePort(),i5)
546     #
547     node3=self.r.createForEachLoop("node3",td2)
548     p.edAddChild(node3)
549     p.edAddCFLink(node2,node3)
550     p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
551     node3.edGetNbOfBranchesPort().edInitInt(2)
552     node30=self.r.createBloc("node30")
553     node3.edAddChild(node30)
554     node300=self.r.createForEachLoop("node300",td)
555     node30.edAddChild(node300)
556     node300.edGetNbOfBranchesPort().edInitInt(10)
557     p.edAddLink(node3.edGetSamplePort(),node300.edGetSeqOfSamplesPort())
558     node3000=self.r.createFuncNode("Salome","node3000")
559     node3000.setFname("ff")
560     node3000.setContainer(cont)
561     node3000.setExecutionMode("remote")
562     node300.edAddChild(node3000)
563     i14=node3000.edAddInputPort("i14",td)
564     o15=node3000.edAddOutputPort("o15",td)
565     node3000.setScript("def ff(x):\n  return 3+x")
566     p.edAddLink(node300.edGetSamplePort(),i14)
567     #
568     node4=self.r.createScriptNode("","node4")
569     node4.setScript("o9=i8")
570     p.edAddChild(node4)
571     i8=node4.edAddInputPort("i8",td3)
572     o9=node4.edAddOutputPort("o9",td3)
573     p.edAddCFLink(node3,node4)
574     p.edAddLink(o15,i8)
575     p.saveSchema(fname)
576     p=l.load(fname)
577     ex = pilot.ExecutorSwig()
578     self.assertEqual(p.getState(),pilot.READY)
579     ex.RunW(p,0)
580     self.assertEqual(p.getState(),pilot.DONE)
581     zeResu=p.getChildByName("node4").getOutputPort("o9").get()
582     self.assertEqual(zeResu,[[5,6,7,8,9,10,11,12,13,14],[15,16,17,18,19,20,21,22,23,24,25],[26,27,28,29,30,31,32,33,34,35,36,37],[38,39,40,41,42,43,44,45,46,47,48,49,50],[51,52,53,54,55,56,57,58,59,60,61,62,63,64],[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79], [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95]])
583     pass
584
585   def test6(self):
586     fname=os.path.join(self.workdir, "test6.xml")
587     p=self.r.createProc("prTest0")
588     td=p.createType("double","double")
589     ti=p.createType("int","int")
590     tsi=p.createSequenceTc("seqint","seqint",ti)
591     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
592     n0=self.r.createScriptNode("","n0")
593     o0=n0.edAddOutputPort("o0",tsi)
594     n0.setScript("o0=[3,6,8,9,-2,5]")
595     p.edAddChild(n0)
596     n1=self.r.createForEachLoop("n1",ti)
597     n10=self.r.createScriptNode("","n10")
598     n1.edAddChild(n10)
599     n10.setScript("o2=2*i1")
600     i1=n10.edAddInputPort("i1",ti)
601     o2=n10.edAddOutputPort("o2",ti)
602     p.edAddChild(n1)
603     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
604     p.edAddLink(n1.edGetSamplePort(),i1)
605     p.edAddCFLink(n0,n1)
606     n1.edGetNbOfBranchesPort().edInitPy(1)
607     n2=self.r.createScriptNode("","n2")
608     n2.setScript("o4=i3")
609     i3=n2.edAddInputPort("i3",tsi)
610     o4=n2.edAddOutputPort("o4",tsi)
611     n2.setScript("o4=i3")
612     p.edAddChild(n2)
613     p.edAddCFLink(n1,n2)
614     p.edAddLink(o2,i3)
615     p.saveSchema(fname)
616     #
617     l=loader.YACSLoader()
618     p=l.load(fname)
619     n1=p.getChildByName("n1")
620     ex=pilot.ExecutorSwig()
621     #
622     ex.RunW(p,0)
623     #
624     self.assertEqual(n1.getState(),pilot.DONE)
625     n1.edGetSeqOfSamplesPort().getPyObj()
626     a,b,c=n1.getPassedResults(ex)
627     self.assertEqual(a,list(range(6)))
628     self.assertEqual([elt.getPyObj() for elt in b],[[6, 12, 16, 18, -4, 10]])
629     self.assertEqual(c,['n10_o2_interceptor'])
630     pass
631
632   def test7(self):
633     fname=os.path.join(self.workdir, "test7.xml")
634     p=self.r.createProc("prTest1")
635     cont=p.createContainer("gg","Salome")
636     cont.setProperty("name","localhost")
637     cont.setProperty("hostname","localhost")
638     cont.setProperty("type","multi")
639     td=p.createType("double","double")
640     ti=p.createType("int","int")
641     tsi=p.createSequenceTc("seqint","seqint",ti)
642     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
643     n0=self.r.createScriptNode("","n0")
644     o0=n0.edAddOutputPort("o0",tsi)
645     n0.setScript("o0=[3,6,8,9,-2,5]")
646     p.edAddChild(n0)
647     n1=self.r.createForEachLoop("n1",ti)
648     n10=self.r.createScriptNode("","n10")
649     n10.setExecutionMode("remote")
650     n10.setContainer(cont)
651     n1.edAddChild(n10)
652     n10.setScript("""
653 import time
654 if i1==9:
655   time.sleep(2)
656   raise Exception("Simulated error !")
657 else:
658   o2=2*i1
659 """)
660     i1=n10.edAddInputPort("i1",ti)
661     o2=n10.edAddOutputPort("o2",ti)
662     p.edAddChild(n1)
663     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
664     p.edAddLink(n1.edGetSamplePort(),i1)
665     p.edAddCFLink(n0,n1)
666     n1.edGetNbOfBranchesPort().edInitPy(1)
667     n2=self.r.createScriptNode("","n2")
668     n2.setScript("o4=i3")
669     i3=n2.edAddInputPort("i3",tsi)
670     o4=n2.edAddOutputPort("o4",tsi)
671     n2.setScript("o4=i3")
672     p.edAddChild(n2)
673     p.edAddCFLink(n1,n2)
674     p.edAddLink(o2,i3)
675     p.saveSchema(fname)
676     #
677     l=loader.YACSLoader()
678     p=l.load(fname)
679     n1=p.getChildByName("n1")
680     ex=pilot.ExecutorSwig()
681     #
682     ex.RunW(p,0)
683     #
684     self.assertEqual(n1.getState(),pilot.FAILED)
685     n1.edGetSeqOfSamplesPort().getPyObj()
686     a,b,c=n1.getPassedResults(ex)
687     self.assertEqual(a,list(range(3)))
688     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16]])
689     self.assertEqual(c,['n10_o2_interceptor'])
690     pass
691
692   def test8(self):
693     from datetime import datetime
694     fname=os.path.join(self.workdir, "test8.xml")
695     p=self.r.createProc("prTest2")
696     cont=p.createContainer("gg","Salome")
697     cont.setProperty("name","localhost")
698     cont.setProperty("hostname","localhost")
699     cont.setProperty("type","multi")
700     td=p.createType("double","double")
701     ti=p.createType("int","int")
702     tsi=p.createSequenceTc("seqint","seqint",ti)
703     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
704     n0=self.r.createScriptNode("","n0")
705     o0=n0.edAddOutputPort("o0",tsi)
706     n0.setScript("o0=[3,6,8,9,-2,5]")
707     p.edAddChild(n0)
708     n1=self.r.createForEachLoop("n1",ti)
709     n10=self.r.createScriptNode("","n10")
710     n10.setExecutionMode("remote")
711     n10.setContainer(cont)
712     n1.edAddChild(n10)
713     n10.setScript("""
714 import time
715 if i1==9:
716   raise Exception("Simulated error !")
717 else:
718   time.sleep(0.1)
719   o2=2*i1
720 """)
721     i1=n10.edAddInputPort("i1",ti)
722     o2=n10.edAddOutputPort("o2",ti)
723     p.edAddChild(n1)
724     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
725     p.edAddLink(n1.edGetSamplePort(),i1)
726     p.edAddCFLink(n0,n1)
727     n1.edGetNbOfBranchesPort().edInitPy(2)
728     n2=self.r.createScriptNode("","n2")
729     n2.setScript("o4=i3")
730     i3=n2.edAddInputPort("i3",tsi)
731     o4=n2.edAddOutputPort("o4",tsi)
732     n2.setScript("o4=i3")
733     p.edAddChild(n2)
734     p.edAddCFLink(n1,n2)
735     p.edAddLink(o2,i3)
736     p.saveSchema(fname)
737     #
738     l=loader.YACSLoader()
739     p=l.load(fname)
740     n1=p.getChildByName("n1")
741     ex=pilot.ExecutorSwig()
742     ex.setKeepGoingProperty(True)
743     #
744     startt=datetime.now()
745     ex.RunW(p,0)
746     t0=datetime.now()-startt
747     #
748     self.assertEqual(n1.getState(),pilot.FAILED)
749     n1.edGetSeqOfSamplesPort().getPyObj()
750     a,b,c=n1.getPassedResults(ex)
751     self.assertEqual(a,[0,1,2,4,5])
752     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
753     self.assertEqual(c,['n10_o2_interceptor'])
754     
755     p.getChildByName("n1").getChildByName("n10").setScript("""
756 import time
757 if i1==3:
758   time.sleep(2)
759   raise Exception("Simulated error !")
760 else:
761   o2=2*i1
762 """)
763     ex=pilot.ExecutorSwig()
764     ex.setKeepGoingProperty(True)
765     #
766     startt=datetime.now()
767     ex.RunW(p,0)
768     t1=datetime.now()-startt
769     #
770     self.assertEqual(n1.getState(),pilot.FAILED)
771     n1.edGetSeqOfSamplesPort().getPyObj()
772     a,b,c=n1.getPassedResults(ex)
773     self.assertEqual(a,[1,2,3,4,5])
774     self.assertEqual([elt.getPyObj() for elt in b],[[12,16,18,-4,10]])
775     self.assertEqual(c,['n10_o2_interceptor'])
776     pass
777
778   def test9(self):
779     """ Test of assignation of already computed values for foreach node."""
780     fname=os.path.join(self.workdir, "test9.xml")
781     from datetime import datetime
782     p=self.r.createProc("prTest2")
783     cont=p.createContainer("gg","Salome")
784     cont.setProperty("name","localhost")
785     cont.setProperty("hostname","localhost")
786     cont.setProperty("type","multi")
787     td=p.createType("double","double")
788     ti=p.createType("int","int")
789     tsi=p.createSequenceTc("seqint","seqint",ti)
790     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
791     n0=self.r.createScriptNode("","n0")
792     o0=n0.edAddOutputPort("o0",tsi)
793     n0.setScript("o0=[3,6,8,9,-2,5]")
794     p.edAddChild(n0)
795     n1=self.r.createForEachLoop("n1",ti)
796     n10=self.r.createScriptNode("","n10")
797     n10.setExecutionMode("remote")
798     n10.setContainer(cont)
799     n1.edAddChild(n10)
800     n10.setScript("""
801 import time
802 if i1==9:
803   raise Exception("Simulated error !")
804 else:
805   time.sleep(0.1)
806   o2=2*i1
807 """)
808     i1=n10.edAddInputPort("i1",ti)
809     o2=n10.edAddOutputPort("o2",ti)
810     p.edAddChild(n1)
811     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
812     p.edAddLink(n1.edGetSamplePort(),i1)
813     p.edAddCFLink(n0,n1)
814     n1.edGetNbOfBranchesPort().edInitPy(2)
815     n2=self.r.createScriptNode("","n2")
816     n2.setScript("o4=i3")
817     i3=n2.edAddInputPort("i3",tsi)
818     o4=n2.edAddOutputPort("o4",tsi)
819     n2.setScript("o4=i3")
820     p.edAddChild(n2)
821     p.edAddCFLink(n1,n2)
822     p.edAddLink(o2,i3)
823     p.saveSchema(fname)
824     #
825     l=loader.YACSLoader()
826     p=l.load(fname)
827     n1=p.getChildByName("n1")
828     ex=pilot.ExecutorSwig()
829     ex.setKeepGoingProperty(True)
830     #
831     startt=datetime.now()
832     ex.RunW(p,0)
833     t0=datetime.now()-startt
834     #
835     self.assertEqual(p.getState(),pilot.FAILED)
836     self.assertEqual(n1.getState(),pilot.FAILED)
837     n1.edGetSeqOfSamplesPort().getPyObj()
838     a,b,c=n1.getPassedResults(ex)
839     self.assertEqual(a,[0,1,2,4,5])
840     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
841     self.assertEqual(c,['n10_o2_interceptor'])
842     
843     p.getChildByName("n1").getChildByName("n10").setScript("""
844 import time
845 time.sleep(2)
846 o2=7*i1
847 """)
848     ex=pilot.ExecutorSwig()
849     ex.setKeepGoingProperty(True)
850     p.getChildByName("n1").assignPassedResults(a,b,c)
851     #
852     startt=datetime.now()
853     ex.RunW(p,0)
854     t1=datetime.now()-startt
855     #
856     self.assertEqual(n1.getState(),pilot.DONE)
857     self.assertEqual(p.getState(),pilot.DONE)
858     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[6,12,16,63,-4,10])
859     pass
860
861   def test10(self):
862     fname=os.path.join(self.workdir, "test10.xml")
863     from datetime import datetime
864     p=self.r.createProc("prTest2")
865     cont=p.createContainer("gg","Salome")
866     cont.setProperty("name","localhost")
867     cont.setProperty("hostname","localhost")
868     cont.setProperty("type","multi")
869     td=p.createType("double","double")
870     ti=p.createType("int","int")
871     tsi=p.createSequenceTc("seqint","seqint",ti)
872     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
873     n0=self.r.createScriptNode("","n0")
874     o0=n0.edAddOutputPort("o0",tsi)
875     n0.setScript("o0=[ 3*elt for elt in range(12) ]")
876     p.edAddChild(n0)
877     n1=self.r.createForEachLoop("n1",ti)
878     n10=self.r.createScriptNode("","n10")
879     n10.setExecutionMode("remote")
880     n10.setContainer(cont)
881     n1.edAddChild(n10)
882     n10.setScript("""
883 import time
884 if i1%2==0:
885   raise Exception("Simulated error !")
886 else:
887   time.sleep(0.1)
888   o2=4*i1
889 """)
890     i1=n10.edAddInputPort("i1",ti)
891     o2=n10.edAddOutputPort("o2",ti)
892     p.edAddChild(n1)
893     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
894     p.edAddLink(n1.edGetSamplePort(),i1)
895     p.edAddCFLink(n0,n1)
896     n1.edGetNbOfBranchesPort().edInitPy(2)
897     n2=self.r.createScriptNode("","n2")
898     n2.setScript("o4=i3")
899     i3=n2.edAddInputPort("i3",tsi)
900     o4=n2.edAddOutputPort("o4",tsi)
901     n2.setScript("o4=i3")
902     p.edAddChild(n2)
903     p.edAddCFLink(n1,n2)
904     p.edAddLink(o2,i3)
905     p.saveSchema(fname)
906     #
907     l=loader.YACSLoader()
908     p=l.load(fname)
909     n1=p.getChildByName("n1")
910     ex=pilot.ExecutorSwig()
911     ex.setKeepGoingProperty(True)
912     #
913     startt=datetime.now()
914     ex.RunW(p,0)
915     t0=datetime.now()-startt
916     #
917     self.assertEqual(p.getState(),pilot.FAILED)
918     self.assertEqual(n1.getState(),pilot.FAILED)
919     n1.edGetSeqOfSamplesPort().getPyObj()
920     a,b,c=n1.getPassedResults(ex)
921     self.assertEqual(a,[1,3,5,7,9,11])
922     self.assertEqual([elt.getPyObj() for elt in b],[[12,36,60,84,108,132]])
923     self.assertEqual(c,['n10_o2_interceptor'])
924     
925     p.getChildByName("n1").getChildByName("n10").setScript("""
926 import time
927 if i1%2==1:
928   raise Exception("Simulated error !")
929 else:
930   time.sleep(1)
931   o2=5*i1
932 """)
933     ex=pilot.ExecutorSwig()
934     ex.setKeepGoingProperty(True)
935     p.getChildByName("n1").assignPassedResults(a,b,c)
936     #
937     startt=datetime.now()
938     ex.RunW(p,0)
939     t1=datetime.now()-startt
940     #assert(t1.total_seconds()<6.+1.)# normally 6/2+1 s (6 remaining elts in 2 // branches + 1s to launch container)
941     #
942     self.assertEqual(n1.getState(),pilot.DONE)
943     self.assertEqual(p.getState(),pilot.DONE)
944     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,12,30,36,60,60,90,84,120,108,150,132])
945     pass
946
947   pass
948
949
950   def test11(self):
951     "test if we do not restart from the begining of the schema after an error in a foreach"
952     fname=os.path.join(self.workdir, "test11.xml")
953     from datetime import datetime
954     p=self.r.createProc("prTest2")
955     cont=p.createContainer("gg","Salome")
956     cont.setProperty("name","localhost")
957     cont.setProperty("hostname","localhost")
958     cont.setProperty("type","multi")
959     td=p.createType("double","double")
960     ti=p.createType("int","int")
961     tsi=p.createSequenceTc("seqint","seqint",ti)
962     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
963     n0=self.r.createScriptNode("","n0")
964     o0=n0.edAddOutputPort("o0",tsi)
965     n0.setScript("o0=[ elt for elt in range(12) ]")
966     p.edAddChild(n0)
967     n1=self.r.createForEachLoop("n1",ti)
968     n10=self.r.createScriptNode("","n10")
969     n10.setExecutionMode("remote")
970     n10.setContainer(cont)
971     n1.edAddChild(n10)
972     n10.setScript("""
973 import time
974 if i1%2==1:
975   raise Exception("Simulated error !")
976 else:
977   time.sleep(0.1)
978   o2=2*i1
979 """)
980     i1=n10.edAddInputPort("i1",ti)
981     o2=n10.edAddOutputPort("o2",ti)
982     p.edAddChild(n1)
983     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
984     p.edAddLink(n1.edGetSamplePort(),i1)
985     p.edAddCFLink(n0,n1)
986     n1.edGetNbOfBranchesPort().edInitPy(2)
987     n2=self.r.createScriptNode("","n2")
988     n2.setScript("o4=i3")
989     i3=n2.edAddInputPort("i3",tsi)
990     o4=n2.edAddOutputPort("o4",tsi)
991     n2.setScript("o4=i3")
992     p.edAddChild(n2)
993     p.edAddCFLink(n1,n2)
994     p.edAddLink(o2,i3)
995     p.saveSchema(fname)
996     #
997     l=loader.YACSLoader()
998     p=l.load(fname)
999     n1=p.getChildByName("n1")
1000     ex=pilot.ExecutorSwig()
1001     ex.setKeepGoingProperty(True)
1002     #
1003     startt=datetime.now()
1004     ex.RunW(p,0)
1005     t0=datetime.now()-startt
1006     #
1007     self.assertEqual(p.getState(),pilot.FAILED)
1008     self.assertEqual(n1.getState(),pilot.FAILED)
1009     n1.edGetSeqOfSamplesPort().getPyObj()
1010     a,b,c=n1.getPassedResults(ex)
1011
1012     self.assertEqual(a,[0,2,4,6,8,10])
1013     self.assertEqual([elt.getPyObj() for elt in b],[[0,4,8,12,16,20]])
1014     
1015     p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(12) ]")
1016     p.getChildByName("n1").getChildByName("n10").setScript("""
1017 import time
1018 if i1%2==0:
1019   raise Exception("Simulated error !")
1020 else:
1021   time.sleep(1)
1022   o2=5*i1
1023 """)
1024     p.resetState(1)
1025
1026
1027     p.getChildByName("n1").assignPassedResults(a,b,c)
1028     p.exUpdateState();
1029     #
1030     startt=datetime.now()
1031     ex.RunW(p,0,False)
1032     t1=datetime.now()-startt
1033     #
1034     self.assertEqual(n1.getState(),pilot.DONE)
1035     self.assertEqual(p.getState(),pilot.DONE)
1036     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,5,4,15,8,25,12,35,16,45,20,55])
1037     pass
1038   
1039   def test12(self):
1040     """ Test of nested ForEachLoop with a port connected inside and outside the loop."""
1041     schema = self.r.createProc("schema")
1042     ti = schema.getTypeCode("int")
1043     tiset = schema.createSequenceTc("", "seqint", ti)
1044     tisetseq = schema.createSequenceTc("", "seqintvec", tiset)
1045
1046     n1 = self.r.createScriptNode("", "PyScript2")
1047     n1.edAddInputPort("i3", ti)
1048     n1.edAddInputPort("i4", ti)
1049     n1.edAddOutputPort("o5", ti)
1050     n1.setScript("o5=i3+i4")
1051
1052     n2 = self.r.createScriptNode("", "PyScript1")
1053     n2.edAddInputPort("i2", ti)
1054     n2.edAddOutputPort("o3", ti)
1055     n2.setScript("o3=i2")
1056
1057     b1 = self.r.createBloc("Bloc1")
1058     b1.edAddChild(n1)
1059     b1.edAddChild(n2)
1060
1061     fe1 = self.r.createForEachLoop("ForEach1", ti)
1062     fe1.getInputPort("nbBranches").edInitPy(2)
1063     fe1.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
1064     fe1.edSetNode(b1)
1065
1066     n3 = self.r.createScriptNode("", "PostProcessing")
1067     n3.edAddInputPort("i7", tiset)
1068     n3.edAddInputPort("i5", tiset)
1069     n3.edAddOutputPort("o4", ti)
1070     n3.setScript("""
1071 o4 = 0
1072 for i in i7:
1073     o4 = i + o4
1074
1075 for i in i5:
1076     o4 = i + o4
1077 """)
1078
1079     b0 = self.r.createBloc("Bloc0")
1080     b0.edAddChild(fe1)
1081     b0.edAddChild(n3)
1082
1083     fe0 = self.r.createForEachLoop("ForEach1", ti)
1084     fe0.getInputPort("nbBranches").edInitPy(2)
1085     fe0.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
1086     fe0.edSetNode(b0)
1087
1088     schema.edAddChild(fe0)
1089
1090     nx = self.r.createScriptNode("", "Result")
1091     nx.edAddInputPort("i8", tiset)
1092     nx.edAddOutputPort("o6", ti)
1093     nx.setScript("""
1094 o6 = 0
1095 for i in i8:
1096     o6 = i + o6
1097 """)
1098     schema.edAddChild(nx)
1099
1100     schema.edAddLink(fe1.getOutputPort("evalSamples"), n1.getInputPort("i3"))
1101     schema.edAddLink(fe0.getOutputPort("evalSamples"), n1.getInputPort("i4"))
1102
1103     schema.edAddDFLink(n1.getOutputPort("o5"), n3.getInputPort("i7"))
1104     schema.edAddDFLink(n2.getOutputPort("o3"), n3.getInputPort("i5"))
1105
1106     po5 = fe1.getOutputPort("Bloc1.PyScript2.o5")
1107     schema.edAddDFLink(po5, n2.getInputPort("i2"))
1108
1109     schema.edAddDFLink(n3.getOutputPort("o4"), nx.getInputPort("i8"))
1110 #    schema.saveSchema("foreach12.xml")
1111     
1112     e = pilot.ExecutorSwig()
1113     e.RunW(schema)
1114     self.assertEqual(schema.getState(),pilot.DONE)
1115     resVal = schema.getChildByName("Result").getOutputPort("o6").getPyObj()
1116     self.assertEqual(resVal, 160)
1117     pass
1118
1119   def test13(self):
1120     """ Non regression test EDF11239. ForEach into ForEach. Problem on cloning linked to DeloymentTree.appendTask method that was too strong."""
1121     p=self.r.createProc("Bug11239")
1122     ti=p.createType("int","int")
1123     ti2=p.createSequenceTc("seqint","seqint",ti)
1124     #
1125     cont=p.createContainer("DefaultContainer","Salome")
1126     #
1127     node0=self.r.createForEachLoop("ForEachLoop_int0",ti)
1128     p.edAddChild(node0)
1129     node0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
1130     node0.edGetNbOfBranchesPort().edInitInt(2)
1131     #
1132     node00=self.r.createBloc("Bloc0")
1133     node0.edAddChild(node00)
1134     node000_0=self.r.createForEachLoop("ForEachLoop_int1",ti)
1135     node00.edAddChild(node000_0)
1136     node000_0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
1137     node000_0.edGetNbOfBranchesPort().edInitInt(3)
1138     #
1139     node0000=self.r.createBloc("Bloc1")
1140     node000_0.edAddChild(node0000)
1141     #
1142     node0000_0=self.r.createScriptNode("","PyScript2")
1143     node0000.edAddChild(node0000_0)
1144     i3=node0000_0.edAddInputPort("i3",ti)
1145     i4=node0000_0.edAddInputPort("i4",ti)
1146     o5=node0000_0.edAddOutputPort("o5",ti)
1147     node0000_0.setScript("o5 = i3 + i4")
1148     node0000_0.setContainer(cont)
1149     node0000_0.setExecutionMode("remote")
1150     p.edAddLink(node0.edGetSamplePort(),i3)
1151     p.edAddLink(node000_0.edGetSamplePort(),i4)
1152     #
1153     node0000_1=self.r.createScriptNode("","PyScript1")
1154     node0000.edAddChild(node0000_1)
1155     o3=node0000_1.edAddOutputPort("o3",ti)
1156     node0000_1.setScript("o3 = 7")
1157     node0000_1.setExecutionMode("local")
1158     p.edAddCFLink(node0000_0,node0000_1)
1159     #
1160     node000_1=self.r.createScriptNode("","PostTraitement")
1161     node00.edAddChild(node000_1)
1162     i7=node000_1.edAddInputPort("i7",ti2)
1163     i5=node000_1.edAddInputPort("i5",ti2)
1164     node000_1.setScript("for i in i7:\n    print(i)\nprint(\"separation\")\nfor i in i5:\n    print(i)")
1165     node000_1.setContainer(cont)
1166     node000_1.setExecutionMode("remote")
1167     p.edAddLink(o5,i7)
1168     p.edAddLink(o3,i5)
1169     p.edAddCFLink(node000_0,node000_1)
1170     #
1171     #p.saveSchema("tmpp.xml")
1172     ex = pilot.ExecutorSwig()
1173     self.assertEqual(p.getState(),pilot.READY)
1174     ex.RunW(p,0)
1175     self.assertEqual(p.getState(),pilot.DONE)
1176     pass
1177
1178   def test14(self):
1179     """ Non regression EDF11027. Problem after Save/Load of a foreach node with type pyobj with input "SmplsCollection" manually set before. Correction in convertToYacsObjref from XML->Neutral. Objref can hide a string !"""
1180     xmlFileName=os.path.join(self.workdir, "test14.xml")
1181     SALOMERuntime.RuntimeSALOME_setRuntime()
1182     r=pilot.getRuntime()
1183     n0=r.createProc("test23/zeRun")
1184     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1185     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
1186     n0bis=r.createBloc("test23/main") ; n0.edAddChild(n0bis)
1187     n00=r.createBloc("test23/run") ; n0bis.edAddChild(n00)
1188     #
1189     n000=r.createForEachLoop("test23/FE",tp) ; n00.edAddChild(n000)
1190     n0000=r.createScriptNode("Salome","test23/run_internal") ; n000.edSetNode(n0000)
1191     i0=n0000.edAddInputPort("i0",tp)
1192     i1=n0000.edAddInputPort("i1",tp) ; i1.edInitPy(3)
1193     o0=n0000.edAddOutputPort("o0",tp)
1194     n0000.setScript("o0=i0+i1")
1195     #
1196     n00.edAddLink(n000.edGetSamplePort(),i0)
1197     #
1198     n000.edGetSeqOfSamplesPort().edInitPy(list(range(10)))
1199     n000.edGetNbOfBranchesPort().edInitInt(2)
1200     #
1201     n01=r.createScriptNode("Salome","test23/check") ; n0bis.edAddChild(n01)
1202     n0bis.edAddCFLink(n00,n01)
1203     i2=n01.edAddInputPort("i2",tp2)
1204     o1=n01.edAddOutputPort("o1",tp2)
1205     n01.setScript("o1=i2")
1206     n0bis.edAddLink(o0,i2)
1207     #
1208     n0.saveSchema(xmlFileName)
1209     #
1210     l=loader.YACSLoader()
1211     p=l.load(xmlFileName) # very import do not use n0 but use p instead !
1212     ex=pilot.ExecutorSwig()
1213     #
1214     self.assertEqual(p.getState(),pilot.READY)
1215     ex.RunW(p,0)
1216     self.assertEqual(p.getState(),pilot.DONE)
1217     self.assertEqual(p.getChildByName("test23/main.test23/check").getOutputPort("o1").getPyObj(),[3,4,5,6,7,8,9,10,11,12])
1218     pass
1219
1220   def test15(self):
1221     #fname=os.path.join(self.workdir, "BugInConcurrentLaunchDftCont.xml")
1222     p=self.r.createProc("pr")
1223     ti=p.createType("int","int")
1224     cont=p.createContainer("DefaultContainer","Salome")
1225     cont.setProperty("container_name","FactoryServer")
1226     b=self.r.createBloc("Bloc") ; p.edAddChild(b)
1227     #
1228     nb=4
1229     outs=[]
1230     for i in range(nb):
1231       node=self.r.createScriptNode("Salome","node%d"%i)
1232       node.setExecutionMode("remote")
1233       node.setContainer(cont)
1234       outs.append(node.edAddOutputPort("i",ti))
1235       node.setScript("i=%d"%i)
1236       b.edAddChild(node)
1237     #
1238     node=self.r.createScriptNode("Salome","nodeEnd")
1239     node.setExecutionMode("remote")
1240     node.setContainer(cont)
1241     res=node.edAddOutputPort("res",ti)
1242     p.edAddChild(node)
1243     l=[]
1244     for i in range(nb):
1245       elt="i%d"%i
1246       inp=node.edAddInputPort(elt,ti) ; l.append(elt)
1247       p.edAddChild(node)
1248       p.edAddLink(outs[i],inp)
1249     node.setScript("res="+"+".join(l))
1250     p.edAddCFLink(b,node)
1251     #
1252     for i in range(10):
1253       p.init()
1254       ex = pilot.ExecutorSwig()
1255       self.assertEqual(p.getState(),pilot.READY)
1256       ex.RunW(p,0)
1257       self.assertEqual(res.getPyObj(),6)
1258       self.assertEqual(p.getState(),pilot.DONE)
1259     pass
1260
1261   def test16(self):
1262     """ Test to check that a list[pyobj] outputport linked to pyobj inputport is OK."""
1263     SALOMERuntime.RuntimeSALOME_setRuntime()
1264     self.r=pilot.getRuntime()
1265     n0=self.r.createProc("test16/zeRun")
1266     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1267     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
1268     
1269     n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
1270     o0=n00.edAddOutputPort("o0",tp2)
1271     n00.setScript("o0=[[i+1] for i in range(8)]")
1272     n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
1273     i1=n01.edAddInputPort("i1",tp)
1274     n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
1275     n0.edAddCFLink(n00,n01)
1276     n0.edAddLink(o0,i1)
1277     #
1278     ex=pilot.ExecutorSwig()
1279     self.assertEqual(n0.getState(),pilot.READY)
1280     ex.RunW(n0,0)
1281     self.assertEqual(n0.getState(),pilot.DONE)
1282     pass
1283
1284   def test17(self):
1285     """ Same as test16 except that tp2 is not list of tp but a list of copy of tp"""
1286     SALOMERuntime.RuntimeSALOME_setRuntime()
1287     self.r=pilot.getRuntime()
1288     n0=self.r.createProc("test17/zeRun")
1289     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1290     tpp=n0.createInterfaceTc("python:obj:1.0","pyobj",[]) # diff is here
1291     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tpp)
1292     
1293     n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
1294     o0=n00.edAddOutputPort("o0",tp2)
1295     n00.setScript("o0=[[i+1] for i in range(8)]")
1296     n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
1297     i1=n01.edAddInputPort("i1",tp)
1298     n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
1299     n0.edAddCFLink(n00,n01)
1300     n0.edAddLink(o0,i1)
1301     #
1302     ex=pilot.ExecutorSwig()
1303     self.assertEqual(n0.getState(),pilot.READY)
1304     ex.RunW(n0,0)
1305     self.assertEqual(n0.getState(),pilot.DONE)
1306     pass
1307
1308   def test18(self):
1309     p=self.r.createProc("prTest18")
1310     n00=self.r.createScriptNode("Salome","n00")
1311     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1312     n00.setExecutionMode("remote")
1313     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1314     cont=p.createContainer("gg","Salome")
1315     n00.setContainer(cont)
1316     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1317     cont.setProperty("nb_proc_per_nod","6")
1318     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1319     cont.setProperty("nb_proc_per_node","7")           # <- here
1320     self.assertEqual(n00.getMaxLevelOfParallelism(),7) # <- here
1321     pass
1322     
1323   def test19(self):
1324     """This test checks the mechanism of YACS that allow PythonNodes to know their DynParaLoop context."""
1325     fname=os.path.join(self.workdir, "test19.xml")
1326     l=loader.YACSLoader()
1327     #
1328     p=self.r.createProc("PROC")
1329     ti=p.createType("int","int")
1330     tdi=p.createSequenceTc("seqint","seqint",ti)
1331     # Level0
1332     fe0=self.r.createForEachLoop("FE0",ti) ; p.edAddChild(fe0)
1333     fe0.edGetNbOfBranchesPort().edInitInt(4)
1334     fe0_end=self.r.createScriptNode("Salome","fe0_end")
1335     fe0.edSetFinalizeNode(fe0_end)
1336     fe0_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
1337 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)""")
1338     n0=self.r.createScriptNode("Salome","n0") ; p.edAddChild(n0)
1339     n0.setScript("o1=range(10)")
1340     a=n0.edAddOutputPort("o1",tdi)
1341     p.edAddLink(a,fe0.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n0,fe0)
1342     # Level1
1343     b0=self.r.createBloc("b0") ; fe0.edAddChild(b0)
1344     n1=self.r.createScriptNode("Salome","n1") ; b0.edAddChild(n1)
1345     n1.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
1346 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)
1347 o1=range(10)""")
1348     b=n1.edAddOutputPort("o1",tdi)
1349     fe1=self.r.createForEachLoop("FE1",ti) ; b0.edAddChild(fe1)
1350     fe1.edGetNbOfBranchesPort().edInitInt(3)
1351     fe1_end=self.r.createScriptNode("Salome","fe1_end")
1352     fe1_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
1353 assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
1354 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
1355 """)
1356     fe1.edSetFinalizeNode(fe1_end)
1357     p.edAddLink(b,fe1.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n1,fe1)
1358     # Level2
1359     n2=self.r.createScriptNode("Salome","n2") ; fe1.edAddChild(n2)
1360     n2.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
1361 assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
1362 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
1363 """)
1364     
1365     p.saveSchema(fname)
1366     ex=pilot.ExecutorSwig()
1367     
1368     # local run of PythonNodes n1 and n2
1369     p=l.load(fname)
1370     p.init()
1371     self.assertEqual(p.getState(),pilot.READY)
1372     ex.setDPLScopeSensitive(True) # <- this line is the aim of the test
1373     ex.RunW(p,0)
1374     self.assertEqual(p.getState(),pilot.DONE)
1375
1376     # run remote
1377     p=l.load(fname)
1378     cont=p.createContainer("gg","HPSalome")
1379     cont.setSizeOfPool(2)
1380     n1=p.getChildByName("FE0.b0.n1") ; n1.setExecutionMode("remote") ; n1.setContainer(cont)
1381     n2=p.getChildByName("FE0.b0.FE1.n2") ; n2.setExecutionMode("remote") ; n2.setContainer(cont)
1382     
1383     p.init()
1384     self.assertEqual(p.getState(),pilot.READY)
1385     ex.RunW(p,0)
1386     self.assertEqual(p.getState(),pilot.DONE)
1387     pass
1388
1389   def test20(self):
1390     """This test revealed a huge bug in ElementaryNode contained in a loop or foreach. The RECONNECT state generated invalid dependancies that only HPContainer can reveal the problem"""
1391     def assignCont(n,cont):
1392       n.setExecutionMode("remote") ; n.setContainer(cont) 
1393       pass
1394     xmlFileName="test20.xml"
1395     p=self.r.createProc("test26")
1396     #
1397     cont=p.createContainer("gg","HPSalome") # very important ! HP Container needed for the test !
1398     cont.setSizeOfPool(8) # important make this figure >= 6
1399     #
1400     po=p.createInterfaceTc("python:obj:1.0","pyobj",[])
1401     sop=p.createSequenceTc("list[pyobj]","list[pyobj]",po)
1402     #
1403     b0=self.r.createBloc("test26/main") ; p.edAddChild(b0)
1404     n0=self.r.createScriptNode("Salome","test26/n0") ; assignCont(n0,cont) # 1
1405     n0.setScript("""import os
1406 dd=range(10)""")
1407     dd=n0.edAddOutputPort("dd",sop) ; b0.edAddChild(n0)
1408     fe0=self.r.createForEachLoop("test26/FE0",po) ; b0.edAddChild(fe0)
1409     fe0.edGetNbOfBranchesPort().edInitInt(1) # very important for the test : 1 !
1410     fe0i=self.r.createBloc("test26/FE0_internal") ; fe0.edSetNode(fe0i)
1411     zeArgInitNode2=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode2,cont) # 2
1412     fe0i.edAddChild(zeArgInitNode2)
1413     c1=zeArgInitNode2.edAddInputPort("c",po)
1414     c2=zeArgInitNode2.edAddOutputPort("c",po)
1415     zeRun=self.r.createBloc("test26/zeRun") ; fe0i.edAddChild(zeRun)
1416     zeArgInitNode=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode,cont) # 3
1417     zeRun.edAddChild(zeArgInitNode)
1418     ff1=zeArgInitNode.edAddInputPort("ff",po)
1419     ff2=zeArgInitNode.edAddOutputPort("ff",po)
1420     line01=self.r.createScriptNode("Salome","line01") ; zeRun.edAddChild(line01) ; assignCont(line01,cont) # 4
1421     line01.setScript("ee=3")
1422     ee0=line01.edAddOutputPort("ee",po)
1423     initt=self.r.createScriptNode("Salome","test26/initt") ; assignCont(initt,cont) # 5
1424     initt.setScript("pass") ; zeRun.edAddChild(initt)
1425     end=self.r.createScriptNode("Salome","test26/end") ; assignCont(end,cont) # 6
1426     end.setScript("import os") ; zeRun.edAddChild(end)
1427     retu=self.r.createScriptNode("Salome","return") ; assignCont(retu,cont) # 7
1428     retu.setScript("ee=i0") ; zeRun.edAddChild(retu)
1429     i0=retu.edAddInputPort("i0",po)
1430     ee=retu.edAddOutputPort("ee",po)
1431     zeRun.edAddCFLink(zeArgInitNode,line01)
1432     zeRun.edAddCFLink(line01,initt)
1433     zeRun.edAddCFLink(initt,end)
1434     zeRun.edAddCFLink(end,retu)
1435     p.edAddLink(ee0,i0)
1436     #
1437     returnn=self.r.createScriptNode("Salome","return") ; assignCont(returnn,cont) # 8
1438     returnn.setScript("elt=i0")
1439     i00=returnn.edAddInputPort("i0",po)
1440     elt=returnn.edAddOutputPort("elt",po)
1441     fe0i.edAddChild(returnn)
1442     fe0i.edAddCFLink(zeArgInitNode2,zeRun)
1443     fe0i.edAddCFLink(zeRun,returnn)
1444     p.edAddLink(c2,ff1)
1445     p.edAddLink(ee,i00)
1446     #
1447     finalize=self.r.createScriptNode("Salome","test26/finalize") ; b0.edAddChild(finalize) ; assignCont(finalize,cont) # 9
1448     finalize.setScript("pass")
1449     b0.edAddCFLink(n0,fe0)
1450     b0.edAddCFLink(fe0,finalize)
1451     #
1452     p.edAddLink(dd,fe0.edGetSeqOfSamplesPort())
1453     p.edAddLink(fe0.edGetSamplePort(),c1)
1454     #
1455     #p.saveSchema(xmlFileName)
1456     p.getChildByName("test26/main.test26/FE0").edGetNbOfBranchesPort().edInitInt(1) # very important 1 !
1457     #
1458     ex=pilot.ExecutorSwig()
1459     self.assertEqual(p.getState(),pilot.READY)
1460     ex.RunW(p,0)
1461     self.assertEqual(p.getState(),pilot.DONE)
1462     pass
1463
1464   pass
1465
1466   def test21(self):
1467     "test if we restart from a saved state in a foreach loop"
1468     fname=os.path.join(self.workdir, "test21.xml")
1469     xmlStateFileName=os.path.join(self.workdir, "saveState21.xml")
1470     from datetime import datetime
1471     p=self.r.createProc("prTest21")
1472     cont=p.createContainer("gg","Salome")
1473     cont.setProperty("name","localhost")
1474     cont.setProperty("hostname","localhost")
1475     cont.setProperty("type","multi")
1476     td=p.createType("double","double")
1477     ti=p.createType("int","int")
1478     tsi=p.createSequenceTc("seqint","seqint",ti)
1479     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
1480     n0=self.r.createScriptNode("","n0")
1481     o0=n0.edAddOutputPort("o0",tsi)
1482     n0.setScript("o0=[ elt for elt in range(6) ]")
1483     p.edAddChild(n0)
1484     n1=self.r.createForEachLoop("n1",ti)
1485     n10=self.r.createScriptNode("","n10")
1486     n10.setExecutionMode("remote")
1487     n10.setContainer(cont)
1488     n1.edAddChild(n10)
1489     n10.setScript("""
1490 import time
1491 time.sleep(2)
1492 o2=2*i1
1493 """)
1494     i1=n10.edAddInputPort("i1",ti)
1495     o2=n10.edAddOutputPort("o2",ti)
1496     p.edAddChild(n1)
1497     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
1498     p.edAddLink(n1.edGetSamplePort(),i1)
1499     p.edAddCFLink(n0,n1)
1500     n1.edGetNbOfBranchesPort().edInitPy(2)
1501     n2=self.r.createScriptNode("","n2")
1502     n2.setScript("o4=i3")
1503     i3=n2.edAddInputPort("i3",tsi)
1504     o4=n2.edAddOutputPort("o4",tsi)
1505     n2.setScript("o4=i3")
1506     p.edAddChild(n2)
1507     p.edAddCFLink(n1,n2)
1508     p.edAddLink(o2,i3)
1509     p.saveSchema(fname)
1510     #
1511     l=loader.YACSLoader()
1512     p=l.load(fname)
1513     n1=p.getChildByName("n1")
1514     ex=pilot.ExecutorSwig()
1515     ex.setKeepGoingProperty(True)
1516     #
1517     startt=datetime.now()
1518     import threading
1519     myRun=threading.Thread(None, ex.RunW, None, (p,0))
1520     myRun.start()
1521     import time
1522     time.sleep(5)
1523     SALOMERuntime.schemaSaveState(p, ex, xmlStateFileName)
1524     a,b,c=n1.getPassedResults(ex)
1525     myRun.join()
1526     t0=datetime.now()-startt
1527     #
1528     self.assertEqual(p.getState(),pilot.DONE)
1529     self.assertEqual(n1.getState(),pilot.DONE)
1530     self.assertEqual(a,[0,1])
1531     self.assertEqual([elt.getPyObj() for elt in b],[[0,2]])
1532     #
1533     p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
1534     p.getChildByName("n1").getChildByName("n10").setScript("""
1535 import time
1536 time.sleep(0.1)
1537 o2=5*i1
1538 """)
1539     loader.loadState(p, xmlStateFileName)
1540     p.resetState(1)
1541     p.getChildByName("n1").assignPassedResults(a,b,c)
1542     p.exUpdateState();
1543     #
1544     ex.RunW(p,0,False)
1545     #
1546     self.assertEqual(n1.getState(),pilot.DONE)
1547     self.assertEqual(p.getState(),pilot.DONE)
1548     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
1549
1550     # Restart from a saved state in a foreach loop without using assignPassedResults.
1551     # This test uses the files test21.xml and saveState21.xml produced by test21.
1552
1553     ex=pilot.ExecutorSwig()
1554     l=loader.YACSLoader()
1555     q=l.load(fname)
1556     q.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
1557     q.getChildByName("n1").getChildByName("n10").setScript("""
1558 import time
1559 time.sleep(0.1)
1560 print("execution n10:", i1)
1561 o2=5*i1
1562 """)
1563     q.getChildByName("n2").setScript("""
1564 print("execution n2:", i3)
1565 o4=i3
1566 """)
1567     loader.loadState(q, xmlStateFileName)
1568     q.resetState(1)
1569     q.exUpdateState()
1570     #
1571     ex.RunW(q,0,False)
1572     #
1573     self.assertEqual(q.getChildByName("n1").getState(),pilot.DONE)
1574     self.assertEqual(q.getState(),pilot.DONE)
1575     self.assertEqual(q.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
1576     pass
1577
1578   def test23(self):
1579     """ test focused on weight attribut after a dump and reload from a xml file
1580     """
1581     fname=os.path.join(self.workdir, "test23.xml")
1582     p=self.r.createProc("prTest23")
1583     cont=p.createContainer("gg","Salome")
1584     cont.setProperty("name","localhost")
1585     cont.setProperty("hostname","localhost")
1586     cont.setProperty("type","multi")
1587     td=p.createType("double","double")
1588     ti=p.createType("int","int")
1589     tsi=p.createSequenceTc("seqint","seqint",ti)
1590     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
1591     n0=self.r.createScriptNode("","n0")
1592     o0=n0.edAddOutputPort("o0",tsi)
1593     n0.setScript("o0=[ elt for elt in range(6) ]")
1594     p.edAddChild(n0)
1595     n1=self.r.createForEachLoop("n1",ti)
1596     n1.setWeight(3)
1597     n10=self.r.createScriptNode("","n10")
1598     n10.setExecutionMode("remote")
1599     n10.setContainer(cont)
1600     n1.edAddChild(n10)
1601     n10.setScript("""
1602 import time
1603 time.sleep(2)
1604 o2=2*i1
1605 """)
1606     n10.setWeight(4.)
1607     i1=n10.edAddInputPort("i1",ti)
1608     o2=n10.edAddOutputPort("o2",ti)
1609     p.edAddChild(n1)
1610     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
1611     p.edAddLink(n1.edGetSamplePort(),i1)
1612     p.edAddCFLink(n0,n1)
1613     n1.edGetNbOfBranchesPort().edInitPy(2)
1614     n2=self.r.createScriptNode("","n2")
1615     n2.setScript("o4=i3")
1616     i3=n2.edAddInputPort("i3",tsi)
1617     o4=n2.edAddOutputPort("o4",tsi)
1618     n2.setScript("o4=i3")
1619     p.edAddChild(n2)
1620     p.edAddCFLink(n1,n2)
1621     p.edAddLink(o2,i3)
1622     p.saveSchema(fname)
1623     #
1624     l=loader.YACSLoader()
1625     p=l.load(fname)
1626     self.assertEqual(p.getChildByName("n1").getWeight().getSimpleLoopWeight(),3.0)
1627     self.assertEqual(p.getChildByName("n1").getChildByName("n10").getWeight().getElementaryWeight(),4.0)
1628     pass
1629
1630   def test24(self):
1631     """ Non regression test EDF17470"""
1632     SALOMERuntime.RuntimeSALOME.setRuntime()
1633     r=SALOMERuntime.getSALOMERuntime()
1634     p=r.createProc("prTest2")
1635     #
1636     cont1=p.createContainer("cont1","Salome")
1637     cont1.setProperty("name","localhost")
1638     cont1.setProperty("hostname","localhost")
1639     cont1.setProperty("type","multi")
1640     cont1.setProperty("container_name","container1@")
1641     #
1642     cont2=p.createContainer("cont2","Salome")
1643     cont2.setProperty("name","localhost")
1644     cont2.setProperty("hostname","localhost")
1645     cont2.setProperty("type","multi")
1646     cont2.setProperty("container_name","container2@")
1647     #
1648     td=p.createType("double","double")
1649     ti=p.createType("int","int")
1650     ts=p.createType("string","string")
1651     n0=r.createScriptNode("","n0")
1652     n0.setScript("""import SalomeSDSClt
1653 import SALOME
1654 import salome
1655 import unittest
1656 import pickle
1657 import gc
1658 import time
1659
1660 def obj2Str(obj):
1661   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1662 def str2Obj(strr):
1663   return pickle.loads(strr)
1664
1665
1666 salome.salome_init()
1667 scopeName="Scope1"
1668 varName="a"
1669 dsm=salome.naming_service.Resolve("/DataServerManager")
1670 dsm.cleanScopesInNS()
1671 if scopeName in dsm.listScopes():
1672   dsm.removeDataScope(scopeName)
1673 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1674 #
1675 t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
1676 dss.atomicApply([t0])
1677 """)
1678     n0_sn=n0.edAddOutputPort("scopeName",ts)
1679     n0_vn=n0.edAddOutputPort("varName",ts)
1680     #
1681     n1=r.createScriptNode("","n1")
1682     n1_sn=n1.edAddInputPort("scopeName",ts)
1683     n1_vn=n1.edAddInputPort("varName",ts)
1684     n1.setScript("""import SalomeSDSClt
1685 import SALOME
1686 import salome
1687 import unittest
1688 import pickle
1689 import gc
1690 import time
1691
1692
1693 def obj2Str(obj):
1694   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1695 def str2Obj(strr):
1696   return pickle.loads(strr)
1697
1698 salome.salome_init()
1699 dsm=salome.naming_service.Resolve("/DataServerManager")
1700 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1701 assert(not isCreated)
1702
1703 t1=dss.addMultiKeyValueSession(varName)
1704 # lecture 'ef'
1705 wk2=dss.waitForKeyInVar(varName,obj2Str("ef"))
1706 wk2.waitFor()
1707 assert(str2Obj(dss.waitForMonoThrRev(wk2))==[11,12])""")
1708     n1.setContainer(cont1)
1709     #
1710     n2=r.createScriptNode("","n2")
1711     n2_sn=n2.edAddInputPort("scopeName",ts)
1712     n2_vn=n2.edAddInputPort("varName",ts)
1713     n2.setScript("""import SalomeSDSClt
1714 import SALOME
1715 import salome
1716 import unittest
1717 import pickle
1718 import gc
1719 import time
1720
1721
1722 def obj2Str(obj):
1723   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1724 def str2Obj(strr):
1725   return pickle.loads(strr)
1726
1727 salome.salome_init()
1728 dsm=salome.naming_service.Resolve("/DataServerManager")
1729 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1730 assert(not isCreated)
1731 time.sleep(3.)
1732 t1=dss.addMultiKeyValueSession(varName)
1733 t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10]))
1734 t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("ef"),obj2Str([11,12]))
1735 """)
1736     n2.setContainer(cont2)
1737     #
1738     p.edAddChild(n0)
1739     p.edAddChild(n1)
1740     p.edAddChild(n2)
1741     p.edAddCFLink(n0,n1)
1742     p.edAddCFLink(n0,n2)
1743     p.edAddLink(n0_sn,n1_sn)
1744     p.edAddLink(n0_vn,n1_vn)
1745     p.edAddLink(n0_sn,n2_sn)
1746     p.edAddLink(n0_vn,n2_vn)
1747     #
1748     ex=pilot.ExecutorSwig()
1749     ex.RunW(p,0)
1750     self.assertEqual(p.getState(),pilot.DONE)
1751     pass
1752
1753   def test25(self):
1754     fname=os.path.join(self.workdir, "test25.xml")
1755     p=self.r.createProc("p0")
1756     tp=p.createInterfaceTc("python:obj:1.0","pyobj",[])
1757     n1_0_sc=self.r.createScriptNode("Salome","n1_0_sc")
1758     p.edAddChild(n1_0_sc)
1759     n1_0_sc.setExecutionMode("remote")
1760     n1_0_sc.setScript("""""")
1761     i1_0_sc=n1_0_sc.edAddInputPort("i1",tp)
1762     i1_0_sc.edInitPy(list(range(4)))
1763
1764     cont=p.createContainer("gg","Salome")
1765     cont.setProperty("name","localhost")
1766     cont.setProperty("hostname","localhost")
1767     n1_0_sc.setContainer(cont)
1768
1769     p.saveSchema(fname)
1770     l=loader.YACSLoader()
1771     p=l.load(fname)
1772     ex=pilot.ExecutorSwig()
1773     self.assertEqual(p.getState(),pilot.READY)
1774     ex.RunW(p,0)
1775     self.assertEqual(p.getState(),pilot.DONE)
1776     pass
1777
1778   def test27(self):
1779     """ 
1780     This test is here to check that old (<=930) graphs are always loadable.
1781     So an xml file coming from test14 in 930 has been generated and converted into home made "base64" like format.
1782     This test puts unbased64 byte array into test_930.xml and load it to check that everything is OK.
1783     """
1784     import os
1785     content_of_file = b'DDkShXM2PeNCndPqRfnYX5EAt.GaRgPq7dNqtfnYZgvqh=kQf7moXCE2z5lED.tCxgM2RcOqdfl29ePC9YnAx3uaGetqF5lE=.E2D0uS1eM2RcOqdfl2FjPqBYE2pdNq7fl2FjPqBYHoT3.2=.Ew9dsCdUFqVfOaj2Eaxet4BeN2=BOKRWOwF0PqfYMqdYHoT3.2=.EwxYNKHeNa=5O4heOwF4OKBeN2=7Maj2FaZXOaFDFwI.E2=1kibUua=5O4heOwF7Nq9YE2pdNq7fl2ZbMiFDFwI.E2=1nqFZNCdaM2RcOqdfl21dvqFZN2=7Maj2ECbWsKxbNQxYNKL6lo12HoT3.2=.EwneOCfeNqleM2RcOqdfl2BdPC9hcCbjN4Jfd2=APqRWuaRWuwF.uSxYNKFDFwI.E2=1kibUua=5O4heOwFAsiHdNqtYE2pdNq7fl2nWtCZbPaFDFwI.E2=1n4xbMiVdNqdYs2RcOqdfl26eNaVesq9g9qRWu4ZbOaHYFwI.E2=.E2=1kCHjMCdYsibUFqVfOaj2H4xbMiVdNqdYvupdNq7YE2PcMqfeOwFAe4BjOqdYHoT3.2=.E2=.Ew1Yvq1eNC9ds2RcOqdfl2VWsiVgMKdWPuxbPulXPqRdNqtYE2PcMqfeOwF.l2x5lE=.E2=.E2D.tCxUuaHWuS=5O4heOwFAPqRWu4ZbOaHjdqVfOaF.FiVXOidfl2McP49jNCbgeaHauaHYHoT3.2=.E2=.Ew1Yvq1eNC9ds2RcOqdfl2RcOqdYE2PcMqfeOwF1PqlcMq3jPC9YHoT3.2=.EwxAPqRWu4ZbOaHblE=.E2D2MqxgM2RcOqdfl29ePC9YnAx9O4ZbN2T3.2=.E2=.EwFXPqlUFqVfOaj2EidgsiHAnoHetqF5lE=.E2=.E2=.E2D4PqHeO4lVM2RcOqdfl29ePC9YnAx48WF.FqFYu4RgMKj2FAF.EqxjMCueOKtVMij2GoX2E29dsCdfl21dvqFZN2T3.2=.E2=.E2=.E2=.EwZbMqZbOa=5O4heOwF0uanWtAnDFCfbPuZbMidYtqVXN2T3.2=.E2=.E2=.E2=.E2=.EwngNCZUsiT1n4xWOaT1m2qg6WUWe0qjMAj7MAp7OAifdwDDH4xWOaT1nongNCZUsiT3.2=.E2=.E2=.E2=.E2=.EwZbMCxYsi=5O4heOwF7MAF.EibUuaj2ECbjN4JYHoT3.2=.E2=.E2=.E2=.E2=.EwZbMCxYsi=5O4heOwF7OAF.EibUuaj2ECbjN4JYHoT3.2=.E2=.E2=.E2=.E2=.Ewxesi1jNC9UFqVfOaj2Hq12E29dsCdfl21dvqFZN2x5lE=.E2=.E2=.E2=.E2DDGKRXOKReNwI.E2=.E2=.E2=1noNjNCdcP43blE=.E2=.E2=.E2D0O49cMqZbPK=APqRWtCxXOwF4O4BguaF5lE=.E2=.E2=.E2=.E2D4NCxfNqxWOaT0uanWtAnDFWcXnoNYvqhbPq7eNw=1laHjOq1jNC9bmaPcMqmcOq1XOanXnoNYvqhUvqHWtwI.E2=.E2=.E2=.E2=1kixbPq7eNw9ePC9YnAx48WR0uanWtAnDFCfbPuZbMidYtqVXMwx0vqRjMadbk2D0vq1jNC9bmK11no9jMCxYsiT3.2=.E2=.E2=.Ewx0O49cMqZbPKT3.2=.E2=.Ewx2MqxgNwI.E2=.E2=1mKRXOKReM2RcOqdfl29ePC9YnAxAMKdgPKF5lE=.E2=.E2=.E2DAv4HdMC9bkwljMadbkwVBf06c6eUhfqX9mKH9euT1noljMadbkwxAv4HdMC9blE=.E2=.E2=.E2D7Nq1jNC9UFqVfOaj2GKH2E29dsCdfl2BdPC9hcCbjN4Jfd2x5lE=.E2=.E2=.E2DDOi9UvqHWs2RcOqdfl2xcl2=0uS1eOwF1OKnWvO1dvqFZOuFDFwI.E2=.E2=1noZbMqZbOaT3.2=.E2=.EwljNq9YvqBbk2D4NCxfNqxWOaT0uanWtAnDFCfbMwx4NCxfNqxWOaT.Ew9jNqxWOaT0uanWtAnDH43eP4pXno9jNqxWOaT.EwxAPqRWtCxXNwI.E2=.E2=1kaVWu4BdNqpUH4xbMiHjMqj2FaVXPCdYFwI.E2=.E2=.E2=1laHjOqRjMadbkidgsiHAnoHetqR0uanWtAnDFWcbEidgsiHAnoHetqydNq9eNCRcMqDDFaHjOqRjMadbk2D4NCxfMCxYsiTDMADDFaHjOq1jNC9blE=.E2=.E2=.E2D0vqRjMadbkidgsiHAnolVOalhMwx0vqRjMadbk2D0vq1jNC9bmKH1no9jMCxYsiT3.2=.E2=.Ewx0O49cMqZbPKT3.2=.Ewx2MqxgNwI.E2=1kCVYu4heMidYtwI.E2=.E2=1kixbPq7eNw9ePC9YnAx9O4ZbNo9ePC9YnAx2uiRbEidgsiHAnoMe6wx0vqRjMadbkw9jMCxYsiT5N4EYu4RgMKdgswx0vq1jNC9blE=.E2=.E2D4u4BeuaT1mKRWtwH1noZbMiT1noPcMqfeNwI.E2=1no1cNCVfOa9eNCT3.2=.Ew1cNCVfOa9eNCT3.2=.E2=.Ew9jNqxWOaT0uanWtAnDGqVdNqR0uanWtAnDFCfbNo9ePC9YnAx48WDDEixbPq7eNwD0vq1jNC9bn8hUsqng9qBXOalWuKxbMwx0vq1jNC9blE=.E2=.E2D4u4BeuaT1m4HYu4bbkw7cMiVblED4u4BeuaT1nC9YuKRiNwAUkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkmX17ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT17AAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAgkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkm917ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT18gAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAakmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkmv17ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT16QAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAdkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wx0O49cNwDDG4HYu4bbkwx4u4BeuaT3.2=.Ewx.u4HcOqdWuaHblE=.E2D.u4HcOqdWuaHblE=.E2=.E2D0vqRjMadbkidgsiHAnohcOKRbEidgsiHAnoHetqR0uanWtAnDFWcbEidgsiHAnoHetqydNq9eNCRcMqDDEixbPq7eNwD0vq1jNC9bmKX1no9jMCxYsiT3.2=.E2=.EwPcMqfeNwDDN4JYuaNbkwVBf06c6eUhcmn17ER9euT1noxYNKHeNaT1noPcMqfeNwI.E2=1no1cNCVfOa9eNCT3.wx.tCxgNwI3'
1786
1787     fname=os.path.join(self.workdir, "test_930.xml")
1788     with open(fname,"wb") as f:
1789       f.write( pilot.FromBase64Swig(content_of_file) )
1790
1791     SALOMERuntime.RuntimeSALOME_setRuntime()
1792     l=loader.YACSLoader()
1793     p=l.load(fname)
1794     self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").getChildByName("test23/run_internal").getInputPort("i1").getPyObj() == 3)
1795     self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").edGetSeqOfSamplesPort().getPyObj()==list(range(10)))
1796     os.remove(fname)
1797     pass
1798
1799 if __name__ == '__main__':
1800   import os,sys
1801   U = os.getenv('USER')
1802   with open("/tmp/" + U + "/UnitTestsResult", 'a') as f:
1803       f.write("  --- TEST src/yacsloader: testSaveLoadRun.py\n")
1804       suite = unittest.makeSuite(TestSaveLoadRun)
1805       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
1806   sys.exit(not result.wasSuccessful())