Esempio n. 1
0
    def run(self, graph, config, updatehash=False):
        """Executes a pre-defined pipeline in a serial order.

        modifed for XNAT workflow XML updates

        Parameters
        ----------

        graph : networkx digraph
            defines order of execution          
        """

        if not isinstance(graph, nx.DiGraph):
            raise ValueError('Input must be a networkx digraph object')
        logger.info("Running serially.")
        old_wd = os.getcwd()
        notrun = []
        donotrun = []
        nodes = nx.topological_sort(graph)
        for (i, node) in enumerate(nodes):
            try:
                pct = 100.0*i/len(nodes)
                workflow_info.update(str(i+1), str(node), '%.1f' % pct)
                if node in donotrun:
                    continue
                node.run(updatehash=updatehash)
            except:
                os.chdir(old_wd)
                if str2bool(config['execution']['stop_on_first_crash']):
                    raise
                # bare except, but i really don't know where a
                # node might fail
                crashfile = report_crash(node)
                # remove dependencies from queue
                subnodes = [s for s in dfs_preorder(graph, node)]
                notrun.append(dict(node = node,
                                   dependents = subnodes,
                                   crashfile = crashfile))
                donotrun.extend(subnodes)
        report_nodes_not_run(notrun)
Esempio n. 2
0
    def run(self, plugin_args=None, updatehash=False):
        """ Execute the workflow

        XNAT-modified Linear runner only
        
        plugin_args : dictionary containing arguments to be sent to plugin
            constructor. see individual plugin doc strings for details.
        """
        runner = LinearPlugin(plugin_args=plugin_args)
        flatgraph = self._create_flat_graph()
        self.config = merge_dict(deepcopy(config._sections), self.config)
        logger.info(str(sorted(self.config)))
        self._set_needed_outputs(flatgraph)
        execgraph = generate_expanded_graph(deepcopy(flatgraph))
        for index, node in enumerate(execgraph.nodes()):
            node.config = self.config
            node.base_dir = self.base_dir
            node.index = index
            if isinstance(node, MapNode):
                node.use_plugin = (plugin, plugin_args)
        self._configure_exec_nodes(execgraph)
        self._write_report_info(self.base_dir, self.name, execgraph)
        runner.run(execgraph, updatehash=updatehash, config=self.config)
        return execgraph