Skip to content

Commit

Permalink
when given links autodetect defaultable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Mar 28, 2024
1 parent b083b8f commit 5c80802
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 76 deletions.
4 changes: 1 addition & 3 deletions spinn_machine/routing_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self, *,
if spinnaker_route is None:
assert processor_ids is not None
assert link_ids is not None
assert defaultable is None
if isinstance(processor_ids, int):
processor_ids = [processor_ids]
if isinstance(link_ids, int):
Expand All @@ -103,9 +104,6 @@ def __init__(self, *,
"incoming_processor", incoming_processor,
"The incoming direction for a path can only be from "
"either one link or one processors, not both")
# TODO remove this GIGO!
if defaultable is not None:
self._defaultable: bool = defaultable
else:
assert processor_ids is None
assert link_ids is None
Expand Down
73 changes: 37 additions & 36 deletions unittests/test_multicast_routing_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def test_creating_new_multicast_routing_entry(self):
key = 1
mask = 1
a_multicast = MulticastRoutingEntry(
key, mask, RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, defaultable=True))
key, mask, RoutingEntry(processor_ids=proc_ids, link_ids=link_ids))

self.assertEqual(a_multicast.key, key)
self.assertEqual(a_multicast.link_ids, set(link_ids))
Expand All @@ -45,7 +44,30 @@ def test_creating_new_multicast_routing_entry(self):
self.assertEqual(
str(a_multicast),
"1:1:{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, "
"16, 17}:{0, 1, 2, 3, 4, 5}(defaultable)")
"16, 17}:{0, 1, 2, 3, 4, 5}")
self.assertEqual(
a_multicast,
pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL)))
hash(a_multicast)

def test_creating_defaulatble_multicast_routing_entry(self):
link_ids = list()
proc_ids = list()
link_ids.append(2)
key = 1
mask = 1
a_multicast = MulticastRoutingEntry(
key, mask, RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, incoming_link=5))

self.assertEqual(a_multicast.key, key)
self.assertEqual(a_multicast.link_ids, set(link_ids))
self.assertEqual(a_multicast.mask, mask)
self.assertEqual(a_multicast.processor_ids, set(proc_ids))
# While we're here, let's check a few other basic operations
self.assertEqual(
str(a_multicast),
"1:1:{}:{2}(defaultable)")
self.assertEqual(
a_multicast,
pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL)))
Expand Down Expand Up @@ -85,9 +107,9 @@ def test_merger(self):
mask = 1
a_multicast = MulticastRoutingEntry(
key, mask, RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, defaultable=True))
processor_ids=proc_ids, link_ids=link_ids))
b_multicast = MulticastRoutingEntry(key, mask, RoutingEntry(
processor_ids=proc_ids2, link_ids=link_ids2, defaultable=True))
processor_ids=proc_ids2, link_ids=link_ids2))

result_multicast = a_multicast.merge(b_multicast)
comparison_link_ids = list()
Expand All @@ -107,43 +129,22 @@ def test_merger(self):
set(comparison_proc_ids))

def test_merger_with_different_defaultable(self):
link_ids = list()
link_ids2 = list()
proc_ids = list()
proc_ids2 = list()
for i in range(3):
link_ids.append(i)
for i in range(3, 6):
link_ids2.append(i)
for i in range(9):
proc_ids.append(i)
for i in range(9, 18):
proc_ids2.append(i)
key = 1
mask = 1
a_multicast = MulticastRoutingEntry(key, mask, RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, defaultable=True))
processor_ids=[], link_ids=[3], incoming_link=6))
assert a_multicast.defaultable
b_multicast = MulticastRoutingEntry(key, mask, RoutingEntry(
processor_ids=proc_ids2, link_ids=link_ids2, defaultable=False))
processor_ids=[], link_ids=[3], incoming_link=4))
assert not b_multicast.defaultable

result_multicast = a_multicast.merge(b_multicast)
comparison_link_ids = list()
comparison_proc_ids = list()
for i in range(6):
comparison_link_ids.append(i)
self.assertEqual(link_ids + link_ids2, comparison_link_ids)
for i in range(18):
comparison_proc_ids.append(i)
self.assertEqual(proc_ids + proc_ids2, comparison_proc_ids)

self.assertEqual(result_multicast.key, key)
self.assertEqual(result_multicast.link_ids,
set(comparison_link_ids))
self.assertEqual(result_multicast.link_ids, set([3]))
self.assertEqual(result_multicast.mask, mask)
self.assertEqual(result_multicast.processor_ids,
set(comparison_proc_ids))
self.assertNotEqual(result_multicast, a_multicast)
self.assertNotEqual(result_multicast, b_multicast)
self.assertEqual(result_multicast.processor_ids, set())
assert not result_multicast.defaultable

def test_merger_with_invalid_parameter_key(self):
link_ids = list()
Expand All @@ -161,7 +162,7 @@ def test_merger_with_invalid_parameter_key(self):
key_combo = 1
mask = 1
entry = RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, defaultable=True)
processor_ids=proc_ids, link_ids=link_ids)
a_multicast = MulticastRoutingEntry(key_combo, mask, entry)
b_multicast = MulticastRoutingEntry(key_combo + 1, mask + 1, entry)
with self.assertRaises(SpinnMachineInvalidParameterException) as e:
Expand All @@ -186,9 +187,9 @@ def test_merger_with_invalid_parameter_mask(self):
key = 0
mask = 2
a_multicast = MulticastRoutingEntry(key, mask, RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids, defaultable=True))
processor_ids=proc_ids, link_ids=link_ids))
b_multicast = MulticastRoutingEntry(key, 4, RoutingEntry(
processor_ids=proc_ids2, link_ids=link_ids2, defaultable=True))
processor_ids=proc_ids2, link_ids=link_ids2))
self.assertNotEqual(a_multicast, b_multicast)
self.assertNotEqual(a_multicast, "foo")
with self.assertRaises(SpinnMachineInvalidParameterException):
Expand Down
60 changes: 23 additions & 37 deletions unittests/test_routing_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@ def test_creating_new_routing_entry(self):
for i in range(18):
proc_ids.append(i)
a_multicast = RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids,
defaultable=True)
processor_ids=proc_ids, link_ids=link_ids)

self.assertEqual(a_multicast.link_ids, set(link_ids))
self.assertEqual(a_multicast.processor_ids, set(proc_ids))
# While we're here, let's check a few other basic operations
self.assertEqual(str(a_multicast),
"{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, "
"15, 16, 17}:{0, 1, 2, 3, 4, 5}(defaultable)")
"15, 16, 17}:{0, 1, 2, 3, 4, 5}")
self.assertEqual(
a_multicast,
pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL)))
hash(a_multicast)

def test_defualtable_routing_entry(self):
a_multicast = RoutingEntry(
processor_ids=[], link_ids=[4], incoming_link=1)

self.assertEqual(a_multicast.link_ids, set([4]))
self.assertEqual(a_multicast.processor_ids, set())
# While we're here, let's check a few other basic operations
self.assertEqual(str(a_multicast),
"{}:{4}(defaultable)")
self.assertEqual(
a_multicast,
pickle.loads(pickle.dumps(a_multicast, pickle.HIGHEST_PROTOCOL)))
Expand Down Expand Up @@ -69,12 +82,8 @@ def test_merger(self):
proc_ids.append(i)
for i in range(9, 18):
proc_ids2.append(i)
a_multicast = RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids,
defaultable=True)
b_multicast = RoutingEntry(
processor_ids=proc_ids2, link_ids=link_ids2,
defaultable=True)
a_multicast = RoutingEntry(processor_ids=proc_ids, link_ids=link_ids)
b_multicast = RoutingEntry(processor_ids=proc_ids2, link_ids=link_ids2)

result_multicast = a_multicast.merge(b_multicast)
comparison_link_ids = list()
Expand All @@ -91,40 +100,17 @@ def test_merger(self):
set(comparison_proc_ids))

def test_merger_with_different_defaultable(self):
link_ids = list()
link_ids2 = list()
proc_ids = list()
proc_ids2 = list()
for i in range(3):
link_ids.append(i)
for i in range(3, 6):
link_ids2.append(i)
for i in range(9):
proc_ids.append(i)
for i in range(9, 18):
proc_ids2.append(i)
a_multicast = RoutingEntry(
processor_ids=proc_ids, link_ids=link_ids,
defaultable=True)
processor_ids=[], link_ids=[1], incoming_link=4)
b_multicast = RoutingEntry(
processor_ids=proc_ids2, link_ids=link_ids2,
defaultable=False)
processor_ids=[], link_ids=[1], incoming_link=5)

result_multicast = a_multicast.merge(b_multicast)
comparison_link_ids = list()
comparison_proc_ids = list()
for i in range(6):
comparison_link_ids.append(i)
self.assertEqual(link_ids + link_ids2, comparison_link_ids)
for i in range(18):
comparison_proc_ids.append(i)
self.assertEqual(proc_ids + proc_ids2, comparison_proc_ids)

self.assertEqual(result_multicast.link_ids, set(comparison_link_ids))
self.assertEqual(result_multicast.processor_ids,
set(comparison_proc_ids))
self.assertEqual(result_multicast.link_ids, set([1]))
self.assertEqual(result_multicast.processor_ids, set())
self.assertNotEqual(result_multicast, a_multicast)
self.assertNotEqual(result_multicast, b_multicast)
self.assertNotEqual(hash(result_multicast), hash(a_multicast))

"""
From FixedRouteEntry use or loose
Expand Down

0 comments on commit 5c80802

Please sign in to comment.