From 04052c69ce5542042d970c6b897c8c3b04440b22 Mon Sep 17 00:00:00 2001 From: Ovidiu MIRCESCU Date: Fri, 4 Dec 2020 13:58:42 +0100 Subject: [PATCH] Cleaning source code. --- src/cpp/PyStudyJob.hxx | 2 +- src/cpp/TPyStudyJob.hxx | 17 +---------------- src/cpp/Test/CTestTestfileInstall.cmake | 6 +++--- src/cpp/Test/PyTestMain.cxx | 6 +++--- src/pydefx/multijobstudy.py | 2 +- src/pydefx/plugins/jobexecutor.py | 6 +++--- src/pydefx/plugins/lightexecutor.py | 14 +------------- src/pydefx/plugins/localexecutor.py | 13 ++----------- src/pydefx/plugins/mainjob.py | 2 +- src/pydefx/plugins/srunexecutor.py | 8 +++----- src/pydefx/slurmstudy.py | 2 +- src/pyexample/multijob/jobstudy.py | 8 ++++---- 12 files changed, 24 insertions(+), 62 deletions(-) diff --git a/src/cpp/PyStudyJob.hxx b/src/cpp/PyStudyJob.hxx index 9daf91d..622ece2 100644 --- a/src/cpp/PyStudyJob.hxx +++ b/src/cpp/PyStudyJob.hxx @@ -27,7 +27,7 @@ class PyStudyJob : public Job { public: PyStudyJob(const std::string& pymodule_name, const std::string& pyclass_name); - PyStudyJob(py2cpp::PyPtr& pyStudyObj); + PyStudyJob(py2cpp::PyPtr& pyStudyObj); PyStudyJob(); virtual ~PyStudyJob(); virtual std::string state(); diff --git a/src/cpp/TPyStudyJob.hxx b/src/cpp/TPyStudyJob.hxx index 57270c5..4b4182d 100644 --- a/src/cpp/TPyStudyJob.hxx +++ b/src/cpp/TPyStudyJob.hxx @@ -37,21 +37,6 @@ public: , _sample(sample) { createNewJob(fnScript, params); - /*if(_lastError.empty()) // no errors during parent construction - { - try - { - py2cpp::PyPtr pySample = createPySample(sample); - py2cpp::PyFunction pyFn; - pyFn.loadExp(_pyStudy, "createNewJob"); - pyFn(fnScript, pySample, params); - } - catch(std::exception& e) - { - _lastError = "An error occured while creating the job.\n"; - _lastError += e.what(); - } - }*/ } TPyStudyJob(py2cpp::PyPtr& pyStudyObj, @@ -84,7 +69,7 @@ public: } } } - + virtual ~TPyStudyJob(){} virtual bool fetch() { diff --git a/src/cpp/Test/CTestTestfileInstall.cmake b/src/cpp/Test/CTestTestfileInstall.cmake index 10fede5..2917d41 100644 --- a/src/cpp/Test/CTestTestfileInstall.cmake +++ b/src/cpp/Test/CTestTestfileInstall.cmake @@ -18,19 +18,19 @@ # SET(TEST_NAME ${COMPONENT_NAME}_SampleTest) -ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ./SampleTest) +ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} ./SampleTest) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" ) SET(TEST_NAME ${COMPONENT_NAME}_StudyGeneralTest) -ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ./StudyGeneralTest) +ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} ./StudyGeneralTest) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" ) SET(TEST_NAME ${COMPONENT_NAME}_StudyRestartTest) -ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ./StudyRestartTest) +ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} ./StudyRestartTest) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" ) diff --git a/src/cpp/Test/PyTestMain.cxx b/src/cpp/Test/PyTestMain.cxx index b5f960e..1cb3378 100644 --- a/src/cpp/Test/PyTestMain.cxx +++ b/src/cpp/Test/PyTestMain.cxx @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) // --- Add a listener that collects test result CPPUNIT_NS::TestResultCollector result; - controller.addListener( &result ); + controller.addListener( &result ); // --- Add a listener that print dots as test run. #ifdef WIN32 @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) #else CPPUNIT_NS::BriefTestProgressListener progress; #endif - controller.addListener( &progress ); + controller.addListener( &progress ); // --- Get the top level suite from the registry @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) testFile.open("test.log", std::ios::out | std::ios::app); testFile << "------ Idefix test log:" << std::endl; CPPUNIT_NS::CompilerOutputter outputter( &result, testFile ); - outputter.write(); + outputter.write(); // --- Run the tests. diff --git a/src/pydefx/multijobstudy.py b/src/pydefx/multijobstudy.py index f46ac53..b6c39e0 100644 --- a/src/pydefx/multijobstudy.py +++ b/src/pydefx/multijobstudy.py @@ -47,7 +47,7 @@ class MultiJobStudy(pystudy.PyStudy): # set the parameters of the local job self.params.salome_parameters.resource_required.name = "localhost" self.params.salome_parameters.job_type = "command_salome" #"python_salome" - + self.params.salome_parameters.work_directory = main_job_work_dir self.params.createTmpResultDirectory() result_directory = self.params.salome_parameters.result_directory diff --git a/src/pydefx/plugins/jobexecutor.py b/src/pydefx/plugins/jobexecutor.py index 0fdfab1..cde7f6e 100644 --- a/src/pydefx/plugins/jobexecutor.py +++ b/src/pydefx/plugins/jobexecutor.py @@ -51,7 +51,7 @@ class JobExecutor: error = str(e) traceback.print_exc() return error, out_values - + def prepare(self, idx, point, context): """ Define local and remote work directory. @@ -84,10 +84,10 @@ class JobExecutor: salome_parameters.out_files = ["idefixresult.txt", "idefixerror.txt"] salome_parameters.work_directory = point_remote_dir salome_parameters.result_directory = context.local_dir - + def noRunFound(self, idx, point, context): return True - + def runjob(self, idx, point, context): """ Create, launch and wait for the end of the job. diff --git a/src/pydefx/plugins/lightexecutor.py b/src/pydefx/plugins/lightexecutor.py index 22f32a9..d5b30c4 100644 --- a/src/pydefx/plugins/lightexecutor.py +++ b/src/pydefx/plugins/lightexecutor.py @@ -1,4 +1,3 @@ -#import pydefx import os import pickle import time @@ -28,25 +27,14 @@ class JobExecutor: error = None out_values = None studymodule=self.config["studymodule"] - #studymodule += ".py" - #with open(studymodule, "r") as study_file: - #study_string = study_file.read() - #try: - #exec(study_string) - #out_values = _exec(**inputvals) - #except Exception as e: - #error=str(e) - #traceback.print_exc() - # another way: import importlib try: idefixstudy=importlib.import_module(studymodule) out_values=idefixstudy._exec(**point) except Exception as e: - error=str(e) + error=str(e) traceback.print_exc() return error, out_values - def createExecutor(config): return JobExecutor(config) diff --git a/src/pydefx/plugins/localexecutor.py b/src/pydefx/plugins/localexecutor.py index 7a0cf46..8111c3c 100644 --- a/src/pydefx/plugins/localexecutor.py +++ b/src/pydefx/plugins/localexecutor.py @@ -1,4 +1,3 @@ -#import pydefx import os import pickle import time @@ -7,7 +6,6 @@ import subprocess class Context: def __init__(self): - #self.launcher = pydefx.salome_proxy.getLauncher() # getLauncher() pass class JobExecutor: @@ -37,7 +35,7 @@ class JobExecutor: error = str(e) traceback.print_exc() return error, out_values - + def prepare(self, idx, point, context): """ Define local and remote work directory. @@ -55,21 +53,14 @@ class JobExecutor: # explicit dict convertion is needed for compatibility between python versions f.write(repr(dict(point))) - def noRunFound(self, idx, point, context): return True - + def runjob(self, idx, point, context): """ Create, launch and wait for the end of the job. """ - # srun - #ntasks = self.config["tasksPerEval"] pointeval = os.path.join(os.getcwd(), "pointeval.py") - #command = "srun --ntasks={} --nodes=1 --chdir={} {} ".format( - #str(ntasks), - #context.local_dir, - #pointeval) return_code = subprocess.check_call(pointeval, shell=True, cwd=context.local_dir) def getResult(self, context): diff --git a/src/pydefx/plugins/mainjob.py b/src/pydefx/plugins/mainjob.py index b9cfe3f..deaeecb 100644 --- a/src/pydefx/plugins/mainjob.py +++ b/src/pydefx/plugins/mainjob.py @@ -31,7 +31,7 @@ class TerminateJob: self.manager.addResult(idx, in_values, out_values, error) except Exception as e: traceback.print_exc() - + if __name__ == '__main__': with open("idefixconfig.json", "r") as f: config = json.load(f) diff --git a/src/pydefx/plugins/srunexecutor.py b/src/pydefx/plugins/srunexecutor.py index a779c92..a679b0f 100644 --- a/src/pydefx/plugins/srunexecutor.py +++ b/src/pydefx/plugins/srunexecutor.py @@ -1,4 +1,3 @@ -#import pydefx import os import pickle import time @@ -15,7 +14,7 @@ class JobExecutor: self.config = config def initialize(self): - """ + """ Execute prescript. """ pointeval = os.path.join(os.getcwd(), "pointeval.py") @@ -36,7 +35,7 @@ class JobExecutor: error = str(e) traceback.print_exc() return error, out_values - + def prepare(self, idx, point, context): """ Define local and remote work directory. @@ -54,10 +53,9 @@ class JobExecutor: # explicit dict convertion is needed for compatibility between python versions f.write(repr(dict(point))) - def noRunFound(self, idx, point, context): return True - + def runjob(self, idx, point, context): """ Create, launch and wait for the end of the job. diff --git a/src/pydefx/slurmstudy.py b/src/pydefx/slurmstudy.py index 3daf48c..156dda7 100644 --- a/src/pydefx/slurmstudy.py +++ b/src/pydefx/slurmstudy.py @@ -41,7 +41,7 @@ class SlurmStudy(pystudy.PyStudy): os.makedirs(main_job_work_dir) # set the parameters of the local job self.params.salome_parameters.job_type = self.jobType() - + result_directory = self.params.salome_parameters.result_directory # export sample to result_directory inputFiles = self.sampleManager.prepareRun(self.sample, result_directory) diff --git a/src/pyexample/multijob/jobstudy.py b/src/pyexample/multijob/jobstudy.py index 6da5d38..5902ef7 100644 --- a/src/pyexample/multijob/jobstudy.py +++ b/src/pyexample/multijob/jobstudy.py @@ -6,19 +6,19 @@ import time def _exec(n): # get the job parameters salome_parameters = pydefx.configuration.loadJobConfig() - + launcher = pydefx.salome_proxy.getLauncher() # CORBA or not CORBA - + # have a different working directory for each computation resource = salome_parameters.resource_required.name default_wd = pydefx.configuration.defaultWorkingDir(resource) new_wd = os.path.join(default_wd, "myjob_"+str(n)) salome_parameters.work_directory = new_wd - + # create and launch the job job_id = launcher.createJob(salome_parameters) launcher.launchJob(job_id) - + # wait for the end of the job jobState = launcher.getJobState(job_id) while jobState != "FINISHED" and jobState != "FAILED" : -- 2.39.2