Skip to content

Commit 7261286

Browse files
authored
Merge pull request #467 from SpiNNakerManchester/coverage
Increase coverage and some minor fixes.
2 parents 664f336 + da5574e commit 7261286

32 files changed

+1160
-146
lines changed

pacman/model/graphs/abstract_single_source_partition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def __init__(
3535

3636
@overrides(AbstractEdgePartition.add_edge)
3737
def add_edge(self, edge):
38+
super().add_edge(edge)
3839
if edge.pre_vertex != self._pre_vertex:
3940
raise PacmanConfigurationException(
4041
"A partition can only contain edges with the same pre_vertex")
41-
super().add_edge(edge)
4242

4343
@property
4444
def pre_vertex(self):

pacman/model/graphs/application/application_fpga_vertex.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ def incoming_fpga_connections(self):
106106
107107
:rtype: iter(FPGAConnection)
108108
"""
109-
for conn in self._incoming_fpga_connections:
110-
yield from conn.expanded
109+
if self._incoming_fpga_connections:
110+
for conn in self._incoming_fpga_connections:
111+
yield from conn.expanded
111112

112113
@property
113114
def outgoing_fpga_connection(self):

pacman/model/graphs/application/application_graph.py

+3-36
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ def add_edge(self, edge, outgoing_edge_partition_name):
102102
added to this partition that start at a different vertex to this
103103
one
104104
"""
105+
self._check_edge(edge)
105106
# Add the edge to the partition
106107
partition = self.get_outgoing_edge_partition_starting_at_vertex(
107108
edge.pre_vertex, outgoing_edge_partition_name)
108109
if partition is None:
109110
partition = ApplicationEdgePartition(
110111
identifier=outgoing_edge_partition_name,
111112
pre_vertex=edge.pre_vertex)
112-
self.add_outgoing_edge_partition(partition)
113-
self._check_edge(edge)
113+
self._add_outgoing_edge_partition(partition)
114114
partition.add_edge(edge)
115115
return partition
116116

@@ -151,50 +151,17 @@ def edges(self):
151151
for partition in self.outgoing_edge_partitions
152152
for edge in partition.edges]
153153

154-
def add_outgoing_edge_partition(self, edge_partition):
154+
def _add_outgoing_edge_partition(self, edge_partition):
155155
""" Add an edge partition to the graph.
156156
157157
Will also add any edges already in the partition as well
158158
159159
:param ApplicationEdgePartition edge_partition:
160-
The edge partition to add
161-
:raises PacmanAlreadyExistsException:
162-
If a partition already exists with the same pre_vertex and
163-
identifier
164160
"""
165-
# verify that this partition is suitable for this graph
166-
if not isinstance(edge_partition, ApplicationEdgePartition):
167-
raise PacmanInvalidParameterException(
168-
"outgoing_edge_partition", edge_partition.__class__,
169-
"Partitions must be an ApplicationEdgePartition")
170-
171-
# check this partition doesn't already exist
172-
key = (edge_partition.pre_vertex,
173-
edge_partition.identifier)
174-
if edge_partition in self._outgoing_edge_partitions_by_pre_vertex[
175-
edge_partition.pre_vertex]:
176-
raise PacmanAlreadyExistsException(
177-
str(ApplicationEdgePartition), key)
178-
179161
self._outgoing_edge_partitions_by_pre_vertex[
180162
edge_partition.pre_vertex].add(edge_partition)
181-
for edge in edge_partition.edges:
182-
self._check_edge(edge)
183-
184163
self._n_outgoing_edge_partitions += 1
185164

186-
def get_edges_starting_at_vertex(self, vertex):
187-
""" Get all the edges that start at the given vertex.
188-
189-
:param AbstractVertex vertex:
190-
The vertex at which the edges to get start
191-
:rtype: iterable(AbstractEdge)
192-
"""
193-
parts = self.get_outgoing_edge_partitions_starting_at_vertex(vertex)
194-
for partition in parts:
195-
for edge in partition.edges:
196-
yield edge
197-
198165
@property
199166
def outgoing_edge_partitions(self):
200167
""" The edge partitions in the graph.

pacman/model/graphs/machine/constant_sdram_machine_partition.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def get_sdram_base_address_for(self, vertex):
8585

8686
@overrides(AbstractSDRAMPartition.get_sdram_size_of_region_for)
8787
def get_sdram_size_of_region_for(self, vertex):
88-
if len(self._edges) == 0:
89-
return 0
90-
return self._edges.peek().sdram_size
88+
if self._sdram_size is None:
89+
raise PartitionMissingEdgesException(
90+
self.MISSING_EDGE_ERROR_MESSAGE.format(self))
91+
return self._sdram_size

pacman/model/graphs/machine/destination_segmented_sdram_machine_partition.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
from spinn_utilities.overrides import overrides
1717
from pacman.exceptions import (
18-
PacmanConfigurationException, PartitionMissingEdgesException)
18+
PacmanConfigurationException, PartitionMissingEdgesException,
19+
PacmanValueError)
1920
from pacman.model.graphs import AbstractSingleSourcePartition
2021
from pacman.model.graphs.machine import (
2122
AbstractSDRAMPartition, SDRAMMachineEdge)
@@ -77,7 +78,7 @@ def get_sdram_base_address_for(self, vertex):
7778
for edge in self._edges:
7879
if edge.post_vertex == vertex:
7980
return edge.sdram_base_address
80-
return None
81+
raise PacmanValueError(f"Vertex {vertex} is not in this partition")
8182

8283
@overrides(AbstractSDRAMPartition.get_sdram_size_of_region_for)
8384
def get_sdram_size_of_region_for(self, vertex):
@@ -86,4 +87,4 @@ def get_sdram_size_of_region_for(self, vertex):
8687
for edge in self._edges:
8788
if edge.post_vertex == vertex:
8889
return edge.sdram_size
89-
return None
90+
raise PacmanValueError(f"Vertex {vertex} is not in this partition")

pacman/model/graphs/machine/source_segmented_sdram_machine_partition.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -55,52 +55,52 @@ def sdram_base_address(self):
5555

5656
@overrides(AbstractMultiplePartition.add_edge)
5757
def add_edge(self, edge):
58-
# add
59-
super().add_edge(edge)
60-
6158
# check
62-
if len(self._destinations.keys()) != 1:
59+
if len(self._destinations):
60+
if edge.post_vertex not in self._destinations:
61+
raise PacmanConfigurationException(
62+
"The {} can only support 1 destination vertex".format(
63+
self.__class__.__name__))
64+
try:
65+
if len(self._pre_vertices[edge.pre_vertex]) != 0:
66+
raise PacmanConfigurationException(
67+
f"The {self.__class__.__name__} only supports 1 edge from "
68+
f"a given pre vertex.")
69+
except KeyError as ex:
6370
raise PacmanConfigurationException(
64-
"The {} can only support 1 destination vertex".format(
65-
self.__class__.__name__))
66-
if len(self._pre_vertices[edge.pre_vertex]) != 1:
67-
raise PacmanConfigurationException(
68-
"The {} only supports 1 edge from a given pre vertex.".format(
69-
self.__class__.__name__))
70-
71-
if self._sdram_base_address is not None:
72-
raise PacmanConfigurationException(
73-
"Illegal attempt to add an edge after sdram_base_address set")
71+
"Edge pre_vertex is not a Partition. pre vertex") from ex
72+
# add
73+
super().add_edge(edge)
7474

7575
@sdram_base_address.setter
7676
def sdram_base_address(self, new_value):
77+
if len(self.pre_vertices) != len(self.edges):
78+
raise PartitionMissingEdgesException(
79+
f"There are {len(self.pre_vertices)} pre vertices "
80+
f"but only {len(self.edges)} edges")
81+
7782
self._sdram_base_address = new_value
7883

7984
for pre_vertex in self._pre_vertices.keys():
80-
try:
81-
# allocate for the pre_vertex
82-
edge = self._pre_vertices[pre_vertex].peek()
83-
edge.sdram_base_address = new_value
84-
new_value += edge.sdram_size
85-
except KeyError as e:
86-
raise PartitionMissingEdgesException(
87-
"This partition has no edge from {}".format(
88-
pre_vertex)) from e
85+
# allocate for the pre_vertex
86+
edge = self._pre_vertices[pre_vertex].peek()
87+
edge.sdram_base_address = new_value
88+
new_value += edge.sdram_size
8989

9090
@overrides(AbstractSDRAMPartition.get_sdram_base_address_for)
9191
def get_sdram_base_address_for(self, vertex):
92+
if self._sdram_base_address is None:
93+
return None
9294
if vertex in self._pre_vertices:
93-
for edge in self._edges:
94-
if edge.pre_vertex == vertex:
95-
return edge.sdram_base_address
95+
edge = self._pre_vertices[vertex].peek()
96+
return edge.sdram_base_address
9697
else:
9798
return self._sdram_base_address
9899

99100
@overrides(AbstractSDRAMPartition.get_sdram_size_of_region_for)
100101
def get_sdram_size_of_region_for(self, vertex):
101102
if vertex in self._pre_vertices:
102-
for edge in self._edges:
103-
if edge.pre_vertex == vertex:
104-
return edge.sdram_size
103+
edge = self._pre_vertices[vertex].peek()
104+
return edge.sdram_size
105105
else:
106106
return self.total_sdram_requirements()

pacman/model/partitioner_splitters/splitter_external_device.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,22 @@ def set_governed_app_vertex(self, app_vertex):
4848

4949
if isinstance(app_vertex, ApplicationFPGAVertex):
5050
# This can have multiple FPGA connections per board
51-
if app_vertex.incoming_fpga_connections:
52-
for fpga in app_vertex.incoming_fpga_connections:
53-
for i in range(app_vertex.n_machine_vertices_per_link):
54-
label = (
55-
f"Incoming Machine vertex {i} for"
56-
f" {app_vertex.label}"
57-
f":{fpga.fpga_id}:{fpga.fpga_link_id}"
58-
f":{fpga.board_address}:{fpga.chip_coords}")
59-
vertex_slice = app_vertex.get_incoming_slice_for_link(
60-
fpga, i)
61-
vertex = MachineFPGAVertex(
62-
fpga.fpga_id, fpga.fpga_link_id,
63-
fpga.board_address, fpga.chip_coords, label=label,
64-
app_vertex=app_vertex, vertex_slice=vertex_slice,
65-
incoming=True, outgoing=False)
66-
self.__incoming_vertices.append(vertex)
67-
self.__incoming_slices.append(vertex_slice)
51+
for fpga in app_vertex.incoming_fpga_connections:
52+
for i in range(app_vertex.n_machine_vertices_per_link):
53+
label = (
54+
f"Incoming Machine vertex {i} for"
55+
f" {app_vertex.label}"
56+
f":{fpga.fpga_id}:{fpga.fpga_link_id}"
57+
f":{fpga.board_address}:{fpga.chip_coords}")
58+
vertex_slice = app_vertex.get_incoming_slice_for_link(
59+
fpga, i)
60+
vertex = MachineFPGAVertex(
61+
fpga.fpga_id, fpga.fpga_link_id,
62+
fpga.board_address, fpga.chip_coords, label=label,
63+
app_vertex=app_vertex, vertex_slice=vertex_slice,
64+
incoming=True, outgoing=False)
65+
self.__incoming_vertices.append(vertex)
66+
self.__incoming_slices.append(vertex_slice)
6867
fpga = app_vertex.outgoing_fpga_connection
6968
if fpga is not None:
7069
label = (

pacman/model/resources/multi_region_sdram.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ def nest(self, region, other):
8383
self._per_timestep_sdram + other.per_timestep
8484
if region in self.__regions:
8585
if isinstance(other, MultiRegionSDRAM):
86-
self.__regions[region].merge(other)
86+
if isinstance(self.__regions[region], MultiRegionSDRAM):
87+
self.__regions[region].merge(other)
88+
else:
89+
old = self.__regions[region]
90+
other.add_cost(region, old.fixed, old.per_timestep)
91+
self.__regions[region] = other
8792
else:
8893
self.__regions[region] += other
8994
else:

pacman/model/resources/reverse_iptag_resource.py

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def __repr__(self):
8787
)
8888

8989
def __eq__(self, other):
90+
if not isinstance(other, ReverseIPtagResource):
91+
return False
9092
return (self._port == other._port and
9193
self._sdp_port == other._sdp_port and
9294
self._tag == other._tag)

pacman/operations/routing_table_generators/merged_routing_table_generator.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def __create_routing_table(x, y, partitions_in_table, routing_info):
5555
table = UnCompressedMulticastRoutingTable(x, y)
5656
iterator = _IteratorWithNext(partitions_in_table.items())
5757
while iterator.has_next:
58-
(vertex, part_id), entry = iterator.next
58+
(vertex, part_id), entry = iterator.pop()
5959
r_info = routing_info.get_routing_info_from_pre_vertex(vertex, part_id)
6060
if r_info is None:
6161
raise Exception(
6262
f"Missing Routing information for {vertex}, {part_id}")
6363
entries = [(vertex, part_id, entry, r_info)]
6464
while __match(iterator, vertex, part_id, r_info, entry, routing_info):
65-
(vertex, part_id), entry = iterator.next
65+
(vertex, part_id), entry = iterator.pop()
6666
r_info = routing_info.get_routing_info_from_pre_vertex(
6767
vertex, part_id)
6868
entries.append((vertex, part_id, entry, r_info))
@@ -71,9 +71,6 @@ def __create_routing_table(x, y, partitions_in_table, routing_info):
7171
for entry in __merged_keys_and_masks(entries, routing_info):
7272
table.add_multicast_routing_entry(entry)
7373

74-
for source_vertex, partition_id in partitions_in_table:
75-
entry = partitions_in_table[source_vertex, partition_id]
76-
7774
return table
7875

7976

@@ -82,7 +79,7 @@ def __match(iterator, vertex, part_id, r_info, entry, routing_info):
8279
return False
8380
if isinstance(vertex, ApplicationVertex):
8481
return False
85-
(next_vertex, next_part_id), next_entry = iterator.peek
82+
(next_vertex, next_part_id), next_entry = iterator.peek()
8683
if isinstance(next_vertex, ApplicationVertex):
8784
return False
8885
if part_id != next_part_id:
@@ -128,18 +125,6 @@ def __merged_keys_and_masks(entries, routing_info):
128125
yield from app_r_info.merge_machine_entries(entries)
129126

130127

131-
def __create_entry(key_and_mask, entry):
132-
"""
133-
:param BaseKeyAndMask key_and_mask:
134-
:param MulticastRoutingTableByPartitionEntry entry:
135-
:rtype: MulticastRoutingEntry
136-
"""
137-
return MulticastRoutingEntry(
138-
routing_entry_key=key_and_mask.key_combo,
139-
defaultable=entry.defaultable, mask=key_and_mask.mask,
140-
link_ids=entry.link_ids, processor_ids=entry.processor_ids)
141-
142-
143128
class _IteratorWithNext(object):
144129

145130
def __init__(self, iterable):
@@ -151,16 +136,14 @@ def __init__(self, iterable):
151136
self.__next = None
152137
self.__has_next = False
153138

154-
@property
155139
def peek(self):
156140
return self.__next
157141

158142
@property
159143
def has_next(self):
160144
return self.__has_next
161145

162-
@property
163-
def next(self):
146+
def pop(self):
164147
if not self.__has_next:
165148
raise StopIteration
166149
nxt = self.__next

pacman/utilities/algorithm_utilities/routing_tree.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, chip, label=None):
4747
:param tuple(int,int) chip:
4848
The chip the route is currently passing through.
4949
"""
50-
self.chip = chip
50+
self._chip_x, self._chip_y = chip
5151
self._children = []
5252
self._label = label
5353

@@ -63,10 +63,6 @@ def chip(self):
6363
"""
6464
return (self._chip_x, self._chip_y)
6565

66-
@chip.setter
67-
def chip(self, chip):
68-
self._chip_x, self._chip_y = chip
69-
7066
@property
7167
def children(self):
7268
"""
@@ -91,22 +87,22 @@ def children(self):
9187
additional logic may be required to determine what core to target to\
9288
reach the vertex.
9389
94-
:rtype: iterable(RoutingTree or MachineVertex)
90+
:rtype: iterable(tuple(int, RoutingTree or MachineVertex))
9591
"""
9692
for child in self._children:
9793
yield child
9894

9995
def append_child(self, child):
10096
"""
10197
:param child:
102-
:type child: RoutingTree or MachineVertex
98+
:type child: tuple(int, RoutingTree or MachineVertex)
10399
"""
104100
self._children.append(child)
105101

106102
def remove_child(self, child):
107103
"""
108104
:param child:
109-
:type child: RoutingTree or MachineVertex
105+
:type child: tuple(int, RoutingTree or MachineVertex)
110106
"""
111107
self._children.remove(child)
112108

0 commit comments

Comments
 (0)