Ejemplo n.º 1
0
 def _add_inputs_to_graph(inputs: Optional[Dict[Text, Any]], graph: Any) -> None:
     for input_name, input_value in inputs.items():
         if isinstance(input_value, str) and input_value in graph.keys():
             raise GraphRunError(
                 f"Input value '{input_value}' clashes with a node name. Make sure "
                 f"that none of the input names passed to the `run` method are the "
                 f"same as node names in the graph schema."
             )
         graph[input_name] = (input_name, input_value)
Ejemplo n.º 2
0
    def run(
        self,
        inputs: Optional[Dict[Text, Any]] = None,
        targets: Optional[List[Text]] = None,
    ) -> Dict[Text, Any]:
        """Runs the graph (see parent class for full docstring)."""
        run_targets = targets if targets else self._graph_schema.target_names
        minimal_schema = self._graph_schema.minimal_graph_schema(run_targets)
        run_graph = self._build_dask_graph(minimal_schema)

        if inputs:
            self._add_inputs_to_graph(inputs, run_graph)

        logger.debug(
            f"Running graph with inputs: {inputs}, targets: {targets} "
            f"and {self._execution_context}.")

        try:
            dask_result = dask.get(run_graph, run_targets)
            return dict(dask_result)
        except RuntimeError as e:
            raise GraphRunError("Error running runner.") from e