Salome HOME
First implementation of evalyfx.
[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,b=inps[2].hasSequenceOfValuesToEval()
60 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3,40.4])
61 a,b=inps[2].hasSequenceOfValuesToEval()
62 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3])
63 efx.lockPortsForEvaluation([outps[0],outps[2]])
64 #
65 g=efx.getUndergroundGeneratedGraph()
66 g.saveSchema("toto.xml")
67 rss=efx.giveResources()
68 rss[0][0].setWantedMachine("localhost")
69 a,b=efx.run(session)
70 assert(a)
71 assert(b==4)
72 assert(efx.getResults()==[[11.110000000000001, 11.22, 11.330000000000002], [93.63, 94.26, 124.89000000000001]])
73 #import loader
74 #import pilot
75 #l=loader.YACSLoader()
76 #p=l.load("/home/H87074/aaaaaaa.xml")
77 #ex=pilot.ExecutorSwig()
78 #ex.RunW(efx.getUndergroundGeneratedGraph())
79 #
80 """
81 import pilot
82 import SALOMERuntime
83 import loader
84 import os,sys
85 zePath=os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","appliskel")
86 sys.path.append(zePath)
87 import salome_test_session
88 port=salome_test_session.startSession(shutdownAtExit=False)
89 omniorb_cfg=os.environ["OMNIORB_CONFIG"]
90 SALOMERuntime.RuntimeSALOME.setRuntime()
91 r=SALOMERuntime.getSALOMERuntime()
92 l=loader.YACSLoader()
93 p=l.load("/home/H87074/aaaaaaa.xml")
94 ex=pilot.ExecutorSwig()
95 ex.RunW(p)
96 salome_test_session.terminateSession(port)
97 """