Salome HOME
Add a global result for a study.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 8 Jul 2019 14:20:33 +0000 (16:20 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Mon, 8 Jul 2019 14:20:33 +0000 (16:20 +0200)
Preparation for a insitu feature.

src/cpp/TMonoPyJob.hxx
src/pydefx/CMakeLists.txt
src/pydefx/pystudy.py
src/pydefx/samplecsvmanager.py
src/pyexample/syrthes_launch.py
src/pyexample/temposcen.py

index 72b2e850b608b3937782cf47a5e0ff4020a0affc..54bc43f17bb57f12d46b55ac68eeebcf9e894fc5 100644 (file)
@@ -82,7 +82,8 @@ public:
     {
       py2cpp::PyFunction pyFn;
       pyFn.loadExp(_pyStudy, "getResult");
-      fetchResults(pyFn(), _sample);
+      pyFn(); // python call: _pyStudy.getResult()
+      fetchResults(_pyStudy.getAttr("sample"), _sample);
     }
     catch(std::exception& e)
     {
index 6d5d94c894427c21285cd363b04a7a3b45de752e..8d532e428aaaf0ef46923030fa85e54e58417236 100644 (file)
@@ -26,6 +26,8 @@ SET(SCRIPTS
   samplecsviterator.py
   samplecsvmanager.py
   defaultschemabuilder.py
+  studyexception.py
+  studyresult.py
   )
 
 INSTALL(FILES ${SCRIPTS} DESTINATION ${SALOME_INSTALL_PYTHON}/pydefx)
index 0b43a165607c76486008e4a5772bf2b015614a7a..6172bb37fa0c61006223f147b4ded923c5f0da20 100644 (file)
@@ -27,6 +27,8 @@ from . import samplecsvmanager
 from . import parameters
 from . import configuration
 from . import defaultschemabuilder
+from .studyexception import StudyUseException, StudyRunException
+from .studyresult import StudyResult
 
 def defaultSampleManager():
   return samplecsvmanager.SampleManager()
@@ -35,6 +37,7 @@ class PyStudy:
   JOB_DUMP_NAME = "jobDump.xml"
   def __init__(self, sampleManager=None, schemaBuilder=None):
     self.job_id = -1
+    self.global_result = StudyResult()
     if sampleManager is None:
       self.sampleManager = defaultSampleManager()
     else:
@@ -98,7 +101,7 @@ class PyStudy:
                                                  salome_params.result_directory)
       self.getResult()
     else:
-      raise Exception("Failed to restore the job.")
+      raise StudyRunException("Failed to restore the job.")
 
   def loadFromId(self, jobid):
     """
@@ -140,7 +143,7 @@ class PyStudy:
     The job should have been already created.
     """
     if self.job_id < 0 :
-      raise Exception("Nothing to launch! Job is not created!")
+      raise StudyUseException("Nothing to launch! Job is not created!")
     tmp_workdir = self.params.salome_parameters.result_directory
     # run the job
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
@@ -156,9 +159,11 @@ class PyStudy:
     Try to get the result file and if it was possible the results are loaded in
     the sample.
     An exception may be thrown if it was not possible to get the file.
+    Return a StudyResult object.
     """
+    self.global_result = StudyResult()
     if self.job_id < 0 :
-      raise Exception("Cannot get the results if the job is not created!")
+      raise StudyUseException("Cannot get the results if the job is not created!")
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
     state = launcher.getJobState(self.job_id)
     tmp_workdir = self.params.salome_parameters.result_directory
@@ -166,7 +171,7 @@ class PyStudy:
     errorIfNoResults = False
     errorMessage = ""
     if state == "CREATED" :
-      raise Exception("Cannot get the results if the job is not launched!")
+      raise StudyUseException("Cannot get the results if the job is not launched!")
     elif state ==  "QUEUED" or state == "IN_PROCESS":
       # no results available at this point. Try again later! Not an error.
       searchResults = False
@@ -180,6 +185,7 @@ class PyStudy:
           with open(exit_code_file) as myfile:
             exit_code = myfile.read()
             exit_code = exit_code.strip()
+        self.global_result.exit_code = exit_code
         if exit_code == "0" :
           errorIfNoResults = True # we expect to have full results
         else:
@@ -200,7 +206,8 @@ class PyStudy:
                                       self.sampleManager.getResultFileName(),
                                       tmp_workdir):
         try:
-          self.sampleManager.loadResult(self.sample, tmp_workdir)
+          res = self.sampleManager.loadResult(self.sample, tmp_workdir)
+          self.global_result.result = res
         except Exception as err:
           if errorIfNoResults:
             raise err
@@ -213,8 +220,9 @@ For further details, see {}/logs directory on {}.""".format(
                           self.params.salome_parameters.work_directory,
                           self.params.salome_parameters.resource_required.name)
       errorMessage += warningMessage
-      raise Exception(errorMessage)
-    return self.sample
+      self.global_result.error_message = errorMessage
+      raise StudyRunException(errorMessage)
+    return self.global_result
 
   def resultAvailable(self):
     """
@@ -247,7 +255,7 @@ For further details, see {}/logs directory on {}.""".format(
 
   def dump(self):
     if self.job_id < 0 :
-      raise Exception("Cannot dump the job if it is not created!")
+      raise StudyUseException("Cannot dump the job if it is not created!")
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
     return launcher.dumpJob(self.job_id)
 
index 05db2f940fa2d0c7dce2096406d1a02eac0c81fd..013ffa3899775e4bb1be04acb89c9fedae8b4acd 100644 (file)
@@ -78,7 +78,8 @@ class SampleManager:
     """
     The directory should contain a RESULTDIR directory with the result files.
     The results are loaded into the sample.
-    Return the modified sample.
+    Return the global result of the study which can be used by an insitu
+    computation.
     """
     resultdir = os.path.join(directory, SampleIterator.RESULTDIR)
     datapath = os.path.join(resultdir, SampleIterator.RESULTFILE)
@@ -97,10 +98,10 @@ class SampleManager:
           sample.checkId(index, input_vals)
         except Exception as err:
           extraInfo = "Error on processing file {} index number {}:".format(
-                                                datapath,       str(index))
+                                                datapath, str(index))
           raise Exception(extraInfo + str(err))
         sample.addResult(index, output_vals, elt[SampleIterator.ERRORCOLUMN])
-    return sample
+    return None
 
   def restoreSample(self, directory):
     """ The directory should contain the files created by prepareRun. A new
index 93904b2126c80b0ea7c01b6bcbd0f2a8b8743d21..9158eadcf6e7cc8e1d13f84dedbb849ba21656fa 100755 (executable)
@@ -37,4 +37,5 @@ myStudy = pydefix.PyStudy(myScript, mySample, myParams)
 myStudy.run()
 
 print(myStudy.getJobState())
-print(myStudy.getResult().progressRate())
+print(myStudy.getResult())
+print(myStudy.getProgress())
index 573739fd51e6d988e4cc9921647dfc6901a9bdcb..cd62e4837c7cc195c5340e0995b8c20a571aa21e 100644 (file)
@@ -33,4 +33,7 @@ myStudy.createNewJob(myScript, mySample, myParams)
 myStudy.launch()
 
 print(myStudy.getJobState())
-print(myStudy.getResult().progressRate())
+print(myStudy.getResult())
+print(myStudy.sample)
+print(myStudy.global_result)
+print(myStudy.getProgress())