Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-deterministic link source-target ordering #56

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions orca/topology/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,45 +93,43 @@ def _link_node(self, node):
self._graph.add_link(new_links[link_id])

def _get_current_links(self, node):
target_kind = self._get_target_kind(node)
return self._graph.get_node_links(node, kind=target_kind)

def _get_target_kind(self, node):
if node.kind == self.source_spec.kind:
return self.target_spec.kind
return self.source_spec.kind
target_spec = self._get_target_spec(node)
return self._graph.get_node_links(
node, origin=target_spec.origin, kind=target_spec.kind)

def _get_new_links(self, node):
linked_nodes = self._get_linked_nodes(node)
links = []
for linked_node in linked_nodes:
link = graph.Graph.create_link({}, node, linked_node)
links.append(link)
return links
if self._is_source(node):
return self._get_links_from_source(node)
return self._get_links_from_target(node)

def _get_linked_nodes(self, node):
if node.kind == self.source_spec.kind:
return self._get_linked_from_source(node)
else:
return self._get_linked_from_target(node)

def _get_linked_from_source(self, source_node):
linked_nodes = []
def _get_links_from_source(self, source_node):
links = []
target_nodes = self._graph.get_nodes(
origin=self.target_spec.origin, kind=self.target_spec.kind)
for target_node in target_nodes:
if self._matcher.are_linked(source_node, target_node):
linked_nodes.append(target_node)
return linked_nodes
links.append(graph.Graph.create_link({}, source_node, target_node))
return links

def _get_linked_from_target(self, target_node):
linked_nodes = []
def _get_links_from_target(self, target_node):
links = []
source_nodes = self._graph.get_nodes(
origin=self.source_spec.origin, kind=self.source_spec.kind)
for source_node in source_nodes:
if self._matcher.are_linked(source_node, target_node):
linked_nodes.append(source_node)
return linked_nodes
links.append(graph.Graph.create_link({}, source_node, target_node))
return links

def _get_target_spec(self, node):
if self._is_source(node):
return self.target_spec
return self.source_spec

def _is_source(self, node):
if node.origin == self.source_spec.origin and \
node.kind == self.source_spec.kind:
return True
return False

def _build_link_lookup(self, links):
return {link.id: link for link in links}