コード例 #1
0
ファイル: scripter.py プロジェクト: tomgriffinstfc/mantid
    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")
コード例 #2
0
 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
コード例 #3
0
ファイル: hfir_catalog.py プロジェクト: tomgriffinstfc/mantid
 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
コード例 #4
0
ファイル: scripter.py プロジェクト: liyulun/mantid
    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")
コード例 #5
0
ファイル: scripter.py プロジェクト: liyulun/mantid
    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
コード例 #6
0
ファイル: scripter.py プロジェクト: tomgriffinstfc/mantid
    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)
コード例 #7
0
    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")
コード例 #8
0
    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")
コード例 #9
0
ファイル: hfir_detector.py プロジェクト: DanNixon/mantid
    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])
コード例 #10
0
    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
コード例 #11
0
ファイル: scripter.py プロジェクト: yutiansut/mantid
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())