Salome HOME
Correction on evalyfx to take into account about first feedback.
[modules/yacs.git] / src / evalyfx_swig / test.py
1 def buildScheme(fname):
2     import SALOMERuntime
3     import loader
4     SALOMERuntime.RuntimeSALOME.setRuntime()
5     r=SALOMERuntime.getSALOMERuntime()
6     p=r.createProc("run")
7     td=p.createType("double","double")
8     #
9     cont=p.createContainer("zeCont","Salome")
10     #
11     n0=r.createFuncNode("Salome","node0")
12     p.edAddChild(n0)
13     n0.setFname("func0")
14     n0.setContainer(cont)
15     n0.setScript("""def func0(a,b):
16   return a*b
17 """)
18     n0.setExecutionMode("remote")
19     a=n0.edAddInputPort("a",td)
20     b=n0.edAddInputPort("b",td)  ; b.edInitPy(1.3)
21     c=n0.edAddOutputPort("c",td)
22     #
23     n1=r.createFuncNode("Salome","node1")
24     p.edAddChild(n1)
25     n1.setFname("func1")
26     n1.setContainer(cont)
27     n1.setScript("""def func1(a,b):
28   return a+b,3*(a+b)
29 """)
30     n1.setExecutionMode("remote")
31     d=n1.edAddInputPort("d",td)
32     e=n1.edAddInputPort("e",td)  ; e.edInitPy(2.5) # agy : useless but for test
33     f=n1.edAddOutputPort("f",td)
34     g=n1.edAddOutputPort("g",td)
35     #
36     p.edAddCFLink(n0,n1)
37     p.edAddLink(c,d)
38     #
39     p.saveSchema(fname)
40
41 fileName="test0.xml"
42 import evalyfx
43 session=evalyfx.YACSEvalSession()
44 session.launch()
45 buildScheme(fileName)
46 efx=evalyfx.YACSEvalYFX.BuildFromFile(fileName)
47 inps=efx.getFreeInputPorts()
48 #
49 inps[0].setDefaultValue(3.4)
50 #
51 inps[0].setDefaultValue(None)
52 inps[2].setDefaultValue(2.7)
53 inps[2].setDefaultValue(None)
54 #
55 outps=efx.getFreeOutputPorts()
56 # prepare for execution
57 inps[0].setDefaultValue(1.1)
58 inps[1].setSequenceOfValuesToEval([10.1,10.2,10.3])
59 a=inps[2].hasSequenceOfValuesToEval()
60 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3,40.4])
61 a=inps[2].hasSequenceOfValuesToEval()
62 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3])
63 efx.lockPortsForEvaluation([inps[1],inps[2]],[outps[0],outps[2]])
64 #
65 """
66 g=efx.getUndergroundGeneratedGraph()
67 g.saveSchema("toto.xml")
68 rss=efx.giveResources()
69 rss[0][0].setWantedMachine("localhost")
70 a,b=efx.run(session)
71 assert(a)
72 assert(b==4)
73 assert(efx.getResults()==[[11.110000000000001, 11.22, 11.330000000000002], [93.63, 94.26, 124.89000000000001]])
74 """
75 #import loader
76 #import pilot
77 #l=loader.YACSLoader()
78 #p=l.load("/home/H87074/aaaaaaa.xml")
79 #ex=pilot.ExecutorSwig()
80 #ex.RunW(efx.getUndergroundGeneratedGraph())
81 #
82 """
83 import pilot
84 import SALOMERuntime
85 import loader
86 import os,sys
87 zePath=os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","appliskel")
88 sys.path.append(zePath)
89 import salome_test_session
90 port=salome_test_session.startSession(shutdownAtExit=False)
91 omniorb_cfg=os.environ["OMNIORB_CONFIG"]
92 SALOMERuntime.RuntimeSALOME.setRuntime()
93 r=SALOMERuntime.getSALOMERuntime()
94 l=loader.YACSLoader()
95 p=l.load("/home/H87074/aaaaaaa.xml")
96 ex=pilot.ExecutorSwig()
97 ex.RunW(p)
98 salome_test_session.terminateSession(port)
99 """