]> SALOME platform Git repositories - tools/ydefx.git/commitdiff
Salome HOME
Configuration reworked.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 28 Oct 2020 15:48:39 +0000 (16:48 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 28 Oct 2020 15:48:39 +0000 (16:48 +0100)
src/pydefx/configuration.py
src/pydefx/localstudy.py
src/pydefx/multijobstudy.py
src/pydefx/pystudy.py
src/pydefx/slurmstudy.py

index 4e07e822463c504365cc468fa3519764347337e1..84516f65ed9339a468a6c8d111a53ba87e3e1e94 100644 (file)
@@ -65,12 +65,14 @@ def exportConfig(dicconfig, directory = None):
   """ Save the configuration to a directory.
       dicconfig is a dictionary which contains the parameters to be saved.
       If directory is None, the configuration is saved to the current directory.
+      Return the path to the configuration file.
   """
   if directory is None:
     directory = os.getcwd()
   configpath = os.path.join(directory, "idefixconfig.json")
   with open(configpath, "w") as f:
     json.dump(dicconfig, f, indent=2)
+  return configpath
 
 def loadConfig(directory = None):
   """ Return the configuration dictionary from a directory.
@@ -79,7 +81,12 @@ def loadConfig(directory = None):
   if directory is None:
     directory = os.getcwd()
   configpath = os.path.join(directory, "idefixconfig.json")
-  with open("idefixconfig.json", "r") as f:
+  if not pathlib.Path(configpath).is_file():
+    configpath = os.path.join(directory, "..", "idefixconfig.json")
+  if not pathlib.Path(configpath).is_file():
+    message = "Configuration file not found in directory " + str(directory)
+    raise FileNotFoundError(message)
+  with open(configpath, "r") as f:
     config = json.load(f)
   return config
 
@@ -88,12 +95,8 @@ def loadJobConfig(directory = None):
       a idefixconfig.json file.
       If the directory is None, use the current directory.
   """
-  result = None
-  try:
-    config = loadConfig(directory)
-    params = parameters.Parameters()
-    params.loadDict(config["params"])
-    result = params.salome_parameters
-  except:
-    result = None
+  config = loadConfig(directory)
+  params = parameters.Parameters()
+  params.loadDict(config["params"])
+  result = params.salome_parameters
   return result
index e733cb8742e823211888e0e68179442d1aa4fb5b..a6b455fbcfcbd751ef16c3f3299951b3a6b7c73d 100644 (file)
@@ -23,7 +23,7 @@ import json
 from . import pystudy
 from . import localbuilder
 from . import salome_proxy
-
+from . import configuration
 
 class LocalStudy(pystudy.PyStudy):
   """
@@ -38,15 +38,11 @@ class LocalStudy(pystudy.PyStudy):
     self._check(script,sample)
     self.sample = sample
     self.params = copy.deepcopy(params)
-    main_job_work_dir = os.path.join(
-                                 self.params.salome_parameters.work_directory,
-                                 "idefixjob")
     # dump the remote jobs parameters to the configuration file
     params_dic = params.dumpDict()
     # modify the parameters for the local loop 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
     # export sample to result_directory
@@ -56,15 +52,13 @@ class LocalStudy(pystudy.PyStudy):
     self.params.salome_parameters.job_file = self.schemaBuilder.getMainJob()
 
     # export config
-    configpath = os.path.join(result_directory, "idefixconfig.json")
     dicconfig = {}
     dicconfig["nbbranches"]  = self.params.nb_branches
     dicconfig["studymodule"] = "idefixstudy"
     dicconfig["sampleIterator"] = self.sampleManager.getModuleName()
     dicconfig["params"] = params_dic
     dicconfig["plugin"] = self.schemaBuilder.getPluginName()
-    with open(configpath, "w") as f:
-      json.dump(dicconfig, f, indent=2)
+    configpath = configuration.exportConfig(dicconfig, result_directory)
     studypath = os.path.join(result_directory, "idefixstudy.py")
     with open(studypath, "w") as f:
       f.write(script.script)
index 2f31656eb6db3d8af41bcc294da984236f8aa310..f46ac531f2272d85994338237fc4a3bba07afa28 100644 (file)
@@ -23,6 +23,7 @@ import json
 from . import pystudy
 from . import multijobbuilder
 from . import salome_proxy
+from . import configuration
 
 
 class MultiJobStudy(pystudy.PyStudy):
@@ -57,15 +58,13 @@ class MultiJobStudy(pystudy.PyStudy):
     self.params.salome_parameters.job_file = self.schemaBuilder.getMainJob()
 
     # export config
-    configpath = os.path.join(result_directory, "idefixconfig.json")
     dicconfig = {}
     dicconfig["nbbranches"]  = self.params.nb_branches
     dicconfig["studymodule"] = "idefixstudy"
     dicconfig["sampleIterator"] = self.sampleManager.getModuleName()
     dicconfig["params"] = params_dic
     dicconfig["plugin"] = self.schemaBuilder.getPluginName()
-    with open(configpath, "w") as f:
-      json.dump(dicconfig, f, indent=2)
+    configpath = configuration.exportConfig(dicconfig, result_directory)
     studypath = os.path.join(result_directory, "idefixstudy.py")
     with open(studypath, "w") as f:
       f.write(script.script)
index c2d59286e0eb1660944c92549e65a494968e6cdd..ed3673b3e7bc52a142dff71338eee7793edc7d8a 100644 (file)
@@ -287,13 +287,11 @@ For further details, see {}/logs directory on {}.""".format(
     inputFiles = self.sampleManager.prepareRun(self.sample, result_directory)
 
     # export nbbranches
-    configpath = os.path.join(result_directory, "idefixconfig.json")
     dicconfig = {}
     dicconfig["nbbranches"]  = self.params.nb_branches
     dicconfig["studymodule"] = "idefixstudy"
     dicconfig["sampleIterator"] = self.sampleManager.getModuleName()
-    with open(configpath, "w") as f:
-      json.dump(dicconfig, f, indent=2)
+    configpath = configuration.exportConfig(dicconfig, result_directory)
     studypath = os.path.join(result_directory, "idefixstudy.py")
     with open(studypath, "w") as f:
       f.write(script.script)
index 8be211bdb623f2b68846b0db31c15e1df2734bdd..3daf48c03d59926a743648d662da0ea2984901d0 100644 (file)
@@ -23,7 +23,7 @@ import json
 from . import pystudy
 from . import slurmbuilder
 from . import salome_proxy
-
+from . import configuration
 
 class SlurmStudy(pystudy.PyStudy):
   def __init__(self, sampleManager=None, schemaBuilder=None):
@@ -50,7 +50,6 @@ class SlurmStudy(pystudy.PyStudy):
     self.params.salome_parameters.job_file = self.schemaBuilder.getMainJob()
 
     # export config
-    configpath = os.path.join(result_directory, "idefixconfig.json")
     dicconfig = {}
     dicconfig["nbbranches"]  = self.params.nb_branches
     dicconfig["studymodule"] = "idefixstudy"
@@ -58,8 +57,7 @@ class SlurmStudy(pystudy.PyStudy):
     dicconfig["plugin"] = self.schemaBuilder.getPluginName()
     nbproc = self.params.salome_parameters.resource_required.nb_proc
     dicconfig["tasksPerEval"] = nbproc // self.params.nb_branches
-    with open(configpath, "w") as f:
-      json.dump(dicconfig, f, indent=2)
+    configpath = configuration.exportConfig(dicconfig, result_directory)
     studypath = os.path.join(result_directory, "idefixstudy.py")
     with open(studypath, "w") as f:
       f.write(script.script)