""" 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.
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
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
from . import pystudy
from . import localbuilder
from . import salome_proxy
-
+from . import configuration
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
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)
from . import pystudy
from . import multijobbuilder
from . import salome_proxy
+from . import configuration
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)
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)
from . import pystudy
from . import slurmbuilder
from . import salome_proxy
-
+from . import configuration
class SlurmStudy(pystudy.PyStudy):
def __init__(self, sampleManager=None, schemaBuilder=None):
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["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)