def cluster_submit(self, output_dir, user, pwd, resource=None, nodes=4, cores_per_node=4, job_name=None): """ Submit the reduction job to a cluster @param output_dir: directory where the output data will be written @param user: name of the user on the cluster @param pwd: password of the user on the cluster """ Logger("scripter").notice("Preparing remote reduction job submission") if HAS_MANTID: # Generate reduction script and write it to file scripts = self.to_batch() for i in range(len(scripts)): script = scripts[i] script_name = "job_submission_%s.py" % i lower_case_instr = self.instrument_name.lower() job_name_lower = job_name.lower() _job_name = job_name if job_name is None or len(job_name) == 0: _job_name = lower_case_instr elif job_name_lower.find(lower_case_instr) >= 0: _job_name = job_name.strip() else: _job_name = "%s_%s" % (lower_case_instr, job_name.strip()) # Make sure we have unique job names if len(scripts) > 1: _job_name += "_%s" % i # Submit the job # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd = "Authenticate(Version=1, ComputeResource='%s', " % resource submit_cmd += "UserName='******', Password='******')\n" % (user, pwd) # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd += "id=StartRemoteTransaction(Version=1, ComputeResource='%s')\n" % resource # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd += "SubmitRemoteJob(Version=1, ComputeResource='%s', " % resource submit_cmd += "TaskName='%s'," % _job_name submit_cmd += "NumNodes=%s, CoresPerNode=%s, " % ( nodes, cores_per_node) submit_cmd += "TransactionID=id, " submit_cmd += "PythonScript=\"\"\"%s\"\"\", " % script submit_cmd += "ScriptName='%s')" % script_name mantidplot.runPythonScript(submit_cmd, True) else: Logger("scripter").error( "Mantid is unavailable to submit a reduction job")
def load_meta_data(cls, file_path, outputWorkspace): try: if IN_MANTIDPLOT: script = "LoadSpice2D(Filename='%s', OutputWorkspace='%s')" % (file_path, outputWorkspace) mantidplot.runPythonScript(script, True) if not AnalysisDataService.doesExist(outputWorkspace): return False else: api.LoadSpice2D(Filename=file_path, OutputWorkspace=outputWorkspace) return True except: return False
def cluster_submit(self, output_dir, user, pwd, resource=None, nodes=4, cores_per_node=4, job_name=None): """ Submit the reduction job to a cluster @param output_dir: directory where the output data will be written @param user: name of the user on the cluster @param pwd: password of the user on the cluster """ Logger("scripter").notice("Preparing remote reduction job submission") if HAS_MANTID: # Generate reduction script and write it to file scripts = self.to_batch() for i in range(len(scripts)): script = scripts[i] script_name = "job_submission_%s.py" % i lower_case_instr = self.instrument_name.lower() job_name_lower = job_name.lower() _job_name = job_name if job_name is None or len(job_name) == 0: _job_name = lower_case_instr elif job_name_lower.find(lower_case_instr) >= 0: _job_name = job_name.strip() else: _job_name = "%s_%s" % (lower_case_instr, job_name.strip()) # Make sure we have unique job names if len(scripts) > 1: _job_name += "_%s" % i # Submit the job # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd = "Authenticate(Version=1, ComputeResource='%s', " % resource submit_cmd += "UserName='******', Password='******')\n" % (user, pwd) # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd += "id=StartRemoteTransaction(Version=1, ComputeResource='%s')\n" % resource # Note: keeping version 1 for now. See comment about # versions in cluster_status.py submit_cmd += "SubmitRemoteJob(Version=1, ComputeResource='%s', " % resource submit_cmd += "TaskName='%s'," % _job_name submit_cmd += "NumNodes=%s, CoresPerNode=%s, " % (nodes, cores_per_node) submit_cmd += "TransactionID=id, " submit_cmd += "PythonScript=\"\"\"%s\"\"\", " % script submit_cmd += "ScriptName='%s')" % script_name mantidplot.runPythonScript(submit_cmd, True) else: Logger("scripter").error("Mantid is unavailable to submit a reduction job")
def execute_script(self, script): """ Executes the given script code. If MantidPlot is available it calls back to MantidPlot to ensure the code is executed asynchronously, if not then a simple exec call is used @param script :: A chunk of code to execute """ if HAS_MANTIDPLOT: mantidplot.runPythonScript(script, True) else: exec script
def execute_script(self, script): """ Executes the given script code. If MantidPlot is available it calls back to MantidPlot to ensure the code is executed asynchronously, if not then a simple exec call is used @param script :: A chunk of code to execute """ if HAS_MANTIDPLOT: mantidplot.runPythonScript(script, True) else: exec(script)
def set_options(self): """ Set up the reduction options, without executing """ if HAS_MANTID: self.update() table_ws = "__patch_options" script = "SetupHFIRReduction(\n" for item in self._observers: if item.state() is not None: if hasattr(item.state(), "options"): script += item.state().options() script += "ReductionProperties='%s')" % table_ws mantidplot.runPythonScript(script, True) return table_ws else: raise RuntimeError("Reduction could not be executed: Mantid could not be imported")
def _create_sensitivity(self): if IS_IN_MANTIDPLOT and self.options_callback is not None: # Get patch information patch_ws = "" if AnalysisDataService.doesExist(self.patch_ws): patch_ws = self.patch_ws try: reduction_table_ws = self.options_callback() filename = self._content.sensitivity_file_edit.text() script = "ComputeSensitivity(Filename='%s',\n" % filename script += " ReductionProperties='%s',\n" % reduction_table_ws script += " OutputWorkspace='sensitivity',\n" script += " PatchWorkspace='%s')\n" % patch_ws mantidplot.runPythonScript(script, True) except: print("Could not compute sensitivity") print(sys.exc_info()[1])
def _create_sensitivity(self): if IS_IN_MANTIDPLOT and self.options_callback is not None: # Get patch information patch_ws = "" if AnalysisDataService.doesExist(self.patch_ws): patch_ws = self.patch_ws try: reduction_table_ws = self.options_callback() filename = self._content.sensitivity_file_edit.text() script = "ComputeSensitivity(Filename='%s',\n" % filename script += " ReductionProperties='%s',\n" % reduction_table_ws script += " OutputWorkspace='sensitivity',\n" script += " PatchWorkspace='%s')\n" % patch_ws mantidplot.runPythonScript(script, True) except: print "Could not compute sensitivity" print sys.exc_value
def execute_script(script, error_cb=None): """ Executes the given script code. If MantidPlot is available it calls back to MantidPlot to ensure the code is executed asynchronously, if not then a simple exec call is used @param script :: A chunk of code to execute @param error_cb :: method to call on error, only registered in workbench """ if SCRIPT_EXEC_METHOD == 'async': Logger('scripter').information('using PythonCodeExecution') execute_script_async(script, error_cb) elif SCRIPT_EXEC_METHOD == 'mantidplot': Logger('scripter').information('using runPythonScript') mantidplot.runPythonScript(script, True) # TODO this option should get removed else: Logger('scripter').information('using straight exec') exec(script, globals(), locals())