示例#1
0
    def refine(self, g, tick, known_inputs):
        if "$test" not in known_inputs:
            return
        if self.has_breaked_input and "$breaked" not in known_inputs:
            return

        if self.has_breaked_input and known_inputs["$breaked"]:
            # `break` was called. Abort iteration
            refine.replace_task(g, tick, graph.Graph())

        test = known_inputs["$test"]

        use_body = test == True

        if use_body:
            if self.is_tail:
                # the last tick item is the tail
                # the one before that is the iteration_tick
                # and then we have the tick of the original loop task.
                orig_for_tick = tick >> 2
                iteration_counter = tick._elements[-2] + 1
                iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
            else:
                # First iteration
                iteration_counter = 1
                iteration_tick = graph.START_TICK + iteration_counter << tick

            subgraph_tick = iteration_tick

            refine.replace_task(g,
                                tick,
                                self.body_graph,
                                subgraph_tick=subgraph_tick)
        else:
            refine.replace_task(g, tick, self.orelse_graph)
示例#2
0
    def execute(self, g, inputs):
        """
        Runs the given graph with the given inputs.
        
        :param g: Graph to traverse. Won't be changed.
        
        :param inputs: `dict` with port to `ValueRef` map.
        
        :returns: deferred `dict` with port to `ValueRef` map for the outputs.
            The deferred can be cancelled.
        """
        
        if self._started:
            raise ValueError("Traverser can only be started once.")
        self._started = True
        
        self._graph = graph.Graph()
        self._graph = graphdecorator.DataGraphDecorator(self._graph)
        self._graph = graphdecorator.RefineDecorator(self._graph)
        self._graph = graphdecorator.ReadyDecorator(self._graph)
        
        # copy the graph into g
        for tick in g.get_all_ticks():
            self._graph.add_task(tick, g.get_task(tick), g.get_task_properties(tick))
        for tick in g.get_all_ticks() + [graph.FINAL_TICK]:
            for source, dest in g.get_in_connections(tick):
                self._graph.connect(source, dest)

        # ingest graph inputs
        self._graph.set_output_data(graph.START_TICK, inputs)
        
        self._iterate()
        
        return self._result
示例#3
0
 def __init__(self, method):
     """
     Initializes the builder with a method that defines the top-level pipeline workflow.
     It parses the pipeline specification and creates an expression tree (or the like) 
     which serves as a basis to build the graph - see build-method.
     @param method: pipeline function that describes the top-level pipeline workflow.
     """
     self.method = method
     self.invocation = invoke_pipeline(method)
     self.graph = graph.Graph()
     self.ticks = {}  # invocation as key, tick as value
示例#4
0
    def __init__(self, unassinged_local_strategy=UnassignedLocalStrategy.FAIL):
        self._unassinged_local_strategy = unassinged_local_strategy
        self._graph = graph.Graph()
        self._next_tick = graph.START_TICK + 1

        # known local variables.
        # maps variable name to Endpoint.
        self._varmap = {}

        # Variablenames that were assigned.
        # not all in varmap were assigned, see `unassinged_local_strategy`.
        self._assigned_vars = set()
示例#5
0
    def refine(self, g, tick, known_inputs):
        if "$iterator" not in known_inputs:
            return
        if self.has_breaked_input and "$breaked" not in known_inputs:
            return

        if self.has_breaked_input and known_inputs["$breaked"]:
            # `break` was called. Abort iteration
            refine.replace_task(g, tick, graph.Graph())

        iterator = known_inputs["$iterator"]

        try:
            item = next(iterator)
            use_body = True
        except StopIteration:
            use_body = False

        if use_body:
            if self.is_tail:
                # the last tick item is the for-tail
                # the prev. to last is the subgraph_tick
                # the one before that is the iteration_tick
                # and then we have the tick of the original for-loop task.
                orig_for_tick = tick >> 3
                #orig_for_tick = graph.Tick(tick._elements[:-3])
                iteration_counter = tick._elements[-3] + 1
                iteration_tick = graph.START_TICK + iteration_counter << orig_for_tick
            else:
                # First iteration
                iteration_counter = 1
                iteration_tick = graph.START_TICK + iteration_counter << tick

            item_tick = graph.START_TICK + 1 << iteration_tick
            subgraph_tick = graph.START_TICK + 2 << iteration_tick

            g.add_task(item_tick, ConstTask(item))
            item_endpoint = graph.Endpoint(item_tick, "value")

            refine.replace_task(g,
                                tick,
                                self.body_graph,
                                subgraph_tick=subgraph_tick,
                                additional_inputs={'$target': item_endpoint})
        else:
            refine.replace_task(g, tick, self.orelse_graph)
示例#6
0
 def setUp(self):
     self.target = graph.Graph()
     self.observer = MockObserver()
示例#7
0
 def setUp(self):
     self.target = graphdecorator.ReadyDecorator(
         graphdecorator.DataGraphDecorator(graph.Graph()))