Skip to content

Commit

Permalink
[WAYANG-#8] pywy - Graph add tuple option
Browse files Browse the repository at this point in the history
Signed-off-by: bertty <[email protected]>
  • Loading branch information
Bertty Contreras-Rojas authored and berttty committed Apr 8, 2022
1 parent 1dbbaaa commit 65ad948
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
4 changes: 2 additions & 2 deletions python/src/pywy/dataquanta.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def flatmap(self: "DataQuanta[I]", f: FlatmapFunction) -> "DataQuanta[IterableO]
def storeTextFile(self: "DataQuanta[I]", path: str) :
last = self.__connect(TextFileSink(path))
plan = PywyPlan(self.context.plugins, [last])
plan.print()

#plan.print()
plan.printTuple()
# TODO add the logic to execute the plan

def __connect(self, op:WyOperator, port_op: int = 0) -> WyOperator:
Expand Down
25 changes: 24 additions & 1 deletion python/src/pywy/graph/graphtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,27 @@ def __init__(self, nodes: List[WyOperator]):
super(WGraphOfOperator, self).__init__(nodes)

def build_node(self, t:WyOperator) -> NodeOperator:
return NodeOperator(t)
return NodeOperator(t)


class NodeTuple(GraphNode[Tuple[WyOperator, WyOperator]]):

def __init__(self, op: WyOperator):
super(NodeTuple, self).__init__((op, None))

def getadjacents(self) -> Iterable[Tuple[WyOperator, WyOperator]]:
operator: WyOperator = self.current[0]
if operator is None or operator.inputs == 0:
return []
return operator.inputOperator

def build_node(self, t:WyOperator) -> 'NodeTuple':
return NodeTuple(t)

class WGraphOfTuple(WayangGraph[NodeTuple]):

def __init__(self, nodes: List[WyOperator]):
super(WGraphOfTuple, self).__init__(nodes)

def build_node(self, t:WyOperator) -> NodeTuple:
return NodeTuple(t)
23 changes: 21 additions & 2 deletions python/src/pywy/wayangplan/wayang.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Iterable, Set

from pywy.graph.graph import WayangGraph
from pywy.graph.graphtypes import WGraphOfOperator, NodeOperator
from pywy.graph.graphtypes import WGraphOfOperator, NodeOperator, WGraphOfTuple, NodeTuple
from pywy.wayangplan.sink import SinkOperator
from pywy.platforms.basic.plugin import Plugin

Expand All @@ -16,7 +16,7 @@ def __init__(self, plugins: Set[Plugin], sinks: Iterable[SinkOperator]):
self.set_graph()

def set_graph(self):
self.graph = WGraphOfOperator(self.sinks)
self.graph = WGraphOfTuple(self.sinks)

def print(self):
def print_plan(current: NodeOperator, previous: NodeOperator):
Expand All @@ -39,4 +39,23 @@ def print_plan(current: NodeOperator, previous: NodeOperator):
self.graph.traversal(None, self.graph.starting_nodes, print_plan)


def printTuple(self):
def print_plan(current: NodeTuple, previous: NodeTuple):
if current is None:
print("this is source")
print(previous.current)
return
if previous is None:
print("this is sink")
print(current.current)
return

print(
"############\n{}\n@@@@@ => previous is\n{}\n############\n"
.format(
current.current,
previous.current
)
)
self.graph.traversal(None, self.graph.starting_nodes, print_plan)

0 comments on commit 65ad948

Please sign in to comment.