Skip to content

Commit

Permalink
Merge be93f30 into 9077db1
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Jul 17, 2018
2 parents 9077db1 + be93f30 commit c56263c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
43 changes: 43 additions & 0 deletions spinn_machine/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,46 @@ def has_wrap_arounds(self):
return ((self.max_chip_x + 1 == 2 and self.max_chip_y+1 == 2) or
((self.max_chip_x + 1) % 12 == 0 and
(self.max_chip_y + 1) % 12 == 0))

def remove_unreachable_chips(self):
""" Remove chips that can't be reached or that can't reach other chips\
due to missing links
"""
for (x, y) in self._unreachable_incoming_chips:
if (x, y) in self._chips:
del self._chips[x, y]
for (x, y) in self._unreachable_outgoing_chips:
if (x, y) in self._chips:
del self._chips[x, y]

@property
def _unreachable_outgoing_chips(self):
removable_coords = list()
for (x, y) in self.chip_coordinates:
# If no links out of the chip work, remove it
is_link = False
for link in range(6):
if self.is_link_at(x, y, link):
is_link = True
break
if not is_link:
removable_coords.append((x, y))
return removable_coords

@property
def _unreachable_incoming_chips(self):
removable_coords = list()
for (x, y) in self.chip_coordinates:
# Go through all the chips that surround this one
moves = [(1, 0), (1, 1), (0, 1), (-1, 0), (-1, -1), (0, -1)]
is_link = False
for link, (x_move, y_move) in enumerate(moves):
opposite = (link + 3) % 6
next_x = x + x_move
next_y = y + y_move
if self.is_link_at(next_x, next_y, opposite):
is_link = True
break
if not is_link:
removable_coords.append((x, y))
return removable_coords
7 changes: 6 additions & 1 deletion spinn_machine/virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,18 @@ def __init__(
(x + eth_x, y + eth_y) for x in range(8) for y in range(8)
for eth_x, eth_y in ethernet_chips
if (x, y) not in Machine.BOARD_48_CHIP_GAPS and
(x, y) not in down_chips)
(x + eth_x, y + eth_y) not in down_chips)
else:
self._configured_chips = OrderedSet(
(x, y) for x in range(width)
for y in range(height)
if (x, y) not in down_chips)

for chip in self._unreachable_outgoing_chips:
self._configured_chips.remove(chip)
for chip in self._unreachable_incoming_chips:
self._configured_chips.remove(chip)

# Assign "IP addresses" to the Ethernet chips
for i, (x, y) in enumerate(ethernet_chips):
(a, b) = divmod(i + 1, 128)
Expand Down
26 changes: 26 additions & 0 deletions unittests/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,32 @@ def test_machine_get_chips_on_board(self):
def test_misc(self):
self.assertEqual(Machine.get_chip_over_link(0, 0, 4, 24, 24), (23, 23))

def test_unreachable_incoming_chips(self):
chips = self._create_chips()
machine = Machine(chips, 0, 0)

# Delete links incoming to 3, 3
down_links = [
(2, 2, 1), (2, 3, 0), (3, 4, 5), (4, 4, 4), (4, 3, 3), (3, 2, 2)]
for (x, y, link) in down_links:
if machine.is_link_at(x, y, link):
del machine._chips[x, y].router._links[link]

machine.remove_unreachable_chips()
self.assertFalse(machine.is_chip_at(3, 3))

def test_unreachable_outgoing_chips(self):
chips = self._create_chips()
machine = Machine(chips, 0, 0)

# Delete links outgoing from 3, 3
for link in range(6):
if machine.is_link_at(3, 3, link):
del machine._chips[3, 3].router._links[link]

machine.remove_unreachable_chips()
self.assertFalse(machine.is_chip_at(3, 3))


if __name__ == '__main__':
unittest.main()

0 comments on commit c56263c

Please sign in to comment.