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