Salome HOME
82e087de6a9e4e7ae73b44184b2b9c8046989fe0
[modules/yacs.git] / src / evalyfx_swig / test3.py
1 # first test using cluster
2
3 import os,getpass
4
5 CatalogResources="""<?xml version="1.0"?>
6 <resources>
7   <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"/>
8   <machine name="athos" hostname="athos" type="cluster" appliPath="/home/H87074/ATHOS_V771/appli_V7_7_1" 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"/>
9 </resources>"""
10
11 def buildScheme(fname):
12     import SALOMERuntime
13     import loader
14     SALOMERuntime.RuntimeSALOME.setRuntime()
15     r=SALOMERuntime.getSALOMERuntime()
16     p0=r.createProc("run")
17     #
18     p=r.createBloc("toto")
19     p0.edAddChild(p)
20     #
21     cont=p0.createContainer("MyWonderfulContainer","Salome")
22     td=p0.createType("double","double")
23     n0=r.createScriptNode("Salome","PyScript0")
24     p.edAddChild(n0)
25     q=n0.edAddInputPort("q",td)
26     ep=n0.edAddOutputPort("ep",td)
27     n0.setScript("ep=1./(4.-q)") # <- force division by 0
28     n0.setExecutionMode("remote")
29     n0.setContainer(cont)
30     p0.saveSchema(fname)
31     pass
32
33 fname="test3.xml"
34 import evalyfx
35 session=evalyfx.YACSEvalSession()
36 session.launch()
37 buildScheme(fname)
38 efx=evalyfx.YACSEvalYFX.BuildFromFile(fname)
39 efx.getParams().setStopASAPAfterErrorStatus(False)
40 inps=efx.getFreeInputPorts()
41 assert(len(inps)==1)
42 outps=efx.getFreeOutputPorts()
43 inps[0].setSequenceOfValuesToEval([-7.,2.,3.,5.,6.])
44 efx.lockPortsForEvaluation(inps,outps)
45 #
46 rss=efx.giveResources()
47 rss[0][0].setWantedMachine("athos")
48 cp=rss.getAddParamsForCluster() ; cp.setRemoteWorkingDir(os.path.join("/scratch",getpass.getuser(),"TMP3")) ; cp.setLocalWorkingDir(os.path.join(os.path.expanduser("~"),"TMP52"))
49 cp.setWCKey("P11U50:CARBONES") ; cp.setNbProcs(5) ; cp.setMaxDuration("00:05")
50 assert(not rss.isInteractive())
51 a,b=efx.run(session)
52 print("************",a,b)
53 print efx.getResults()