Salome HOME
updated copyright message
[modules/yacs.git] / src / evalyfx_swig / test3.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 # first test using cluster
21
22 import os,getpass
23
24 CatalogResources="""<?xml version="1.0"?>
25 <resources>
26   <machine name="localhost" hostname="dsp0698184" type="single_machine" appliPath="" batchQueue="" userCommands="" protocol="ssh" iprotocol="ssh" workingDirectory="" canLaunchBatchJobs="false" canRunContainers="true" batch="none" mpi="no mpi" userName="" OS="" memInMB="0" CPUFreqMHz="0" nbOfNodes="1" nbOfProcPerNode="4"/>
27   <machine name="athos" hostname="athos" type="cluster" appliPath="/home/H87074/ATHOS_V830/appli_V8_3_0" batchQueue="" userCommands="" protocol="ssh" iprotocol="ssh" workingDirectory="" canLaunchBatchJobs="true" canRunContainers="false" batch="slurm" mpi="no mpi" userName="" OS="" memInMB="0" CPUFreqMHz="0" nbOfNodes="250" nbOfProcPerNode="28"/>
28 </resources>"""
29
30 def buildScheme(fname):
31     import SALOMERuntime
32     import loader
33     SALOMERuntime.RuntimeSALOME.setRuntime()
34     r=SALOMERuntime.getSALOMERuntime()
35     p0=r.createProc("run")
36     #
37     p=r.createBloc("toto")
38     p0.edAddChild(p)
39     #
40     cont=p0.createContainer("MyWonderfulContainer","Salome")
41     td=p0.createType("double","double")
42     n0=r.createScriptNode("Salome","PyScript0")
43     p.edAddChild(n0)
44     q=n0.edAddInputPort("q",td)
45     ep=n0.edAddOutputPort("ep",td)
46     #n0.setScript("ep=1./(4.-q)") # <- force division by 0
47     n0.setScript("ep=2.*float(___idx___)")
48     n0.setExecutionMode("remote")
49     n0.setContainer(cont)
50     p0.saveSchema(fname)
51     pass
52
53 fname="test3.xml"
54 import evalyfx
55 session=evalyfx.YACSEvalSession()
56 session.launch()
57 buildScheme(fname)
58 efx=evalyfx.YACSEvalYFX.BuildFromFile(fname)
59 efx.getParams().setStopASAPAfterErrorStatus(False)
60 inps=efx.getFreeInputPorts()
61 assert(len(inps)==1)
62 outps=efx.getFreeOutputPorts()
63 inps[0].setSequenceOfValuesToEval([-7.,2.,3.,5.,6.])
64 efx.lockPortsForEvaluation(inps,outps)
65 #
66 rss=efx.giveResources()
67 rss[0][0].setWantedMachine("athos")
68 cp=rss.getAddParamsForCluster() ; cp.setRemoteWorkingDir(os.path.join("/scratch",getpass.getuser(),"TMP3")) ; cp.setLocalWorkingDir(os.path.join(os.path.expanduser("~"),"TMP52"))
69 cp.setWCKey("P11U5:CARBONES") ; cp.setNbProcs(5) ; cp.setMaxDuration("00:05")
70 assert(not rss.isInteractive())
71 a,b=efx.run(session)
72 print(("************",a,b))
73 print(efx.getResults())