1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2019 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 from . import localbuilder
25 from . import salome_proxy
26 from . import configuration
28 class LocalStudy(pystudy.PyStudy):
30 This study is always localy evaluated.
32 def __init__(self, sampleManager=None, schemaBuilder=None):
33 if schemaBuilder is None:
34 schemaBuilder = localbuilder.LocalBuilder()
35 super().__init__(sampleManager, schemaBuilder)
37 def createNewJob(self, script, sample, params):
38 self._check(script,sample)
40 self.params = copy.deepcopy(params)
41 # dump the remote jobs parameters to the configuration file
42 params_dic = params.dumpDict()
43 # modify the parameters for the local loop job
44 self.params.salome_parameters.resource_required.name = "localhost"
45 self.params.salome_parameters.job_type = "command_salome" #"python_salome"
46 self.params.createTmpResultDirectory()
47 result_directory = self.params.salome_parameters.result_directory
48 # export sample to result_directory
49 inputFiles = self.sampleManager.prepareRun(self.sample, result_directory)
50 inputFiles.extend([self.schemaBuilder.getExecutor(),
51 self.schemaBuilder.getPointEval()])
52 self.params.salome_parameters.job_file = self.schemaBuilder.getMainJob()
56 dicconfig["nbbranches"] = self.params.nb_branches
57 dicconfig["studymodule"] = "idefixstudy"
58 dicconfig["sampleIterator"] = self.sampleManager.getModuleName()
59 dicconfig["params"] = params_dic
60 dicconfig["plugin"] = self.schemaBuilder.getPluginName()
61 configpath = configuration.exportConfig(dicconfig, result_directory)
62 studypath = os.path.join(result_directory, "idefixstudy.py")
63 with open(studypath, "w") as f:
64 f.write(script.script)
66 inputFiles.extend([configpath, studypath])
68 # this list manipulation is needed because in_files is not a python list
69 # if we don't use a salome session. In that case swig uses a python tuple
70 # in order to map a std::list as a parameter of a structure.
71 in_files_as_list = list(self.params.salome_parameters.in_files)
72 self.params.salome_parameters.in_files = in_files_as_list + inputFiles
73 launcher = salome_proxy.getLauncher()
74 self.job_id = launcher.createJob(self.params.salome_parameters)
78 return "command_salome"