Skip to content

Commit

Permalink
Replace deprecated function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Oct 10, 2024
1 parent 21f78d6 commit 730c2c0
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ def generate_data_specification(

# Get the key
routing_info = SpynnakerDataView.get_routing_infos()
edge_key = routing_info.get_first_key_from_pre_vertex(
edge_key = routing_info.get_safe_first_key_from_pre_vertex(
placement.vertex, self.MOTOR_PARTITION_ID)
if edge_key is None:
raise SpynnakerException(
"This motor should have one outgoing edge to the robot")

# write params to memory
spec.switch_write_focus(region=self._PARAMS_REGION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def new_key_command_payload(self):
:rtype: int
"""
routing_info = SpynnakerDataView.get_routing_infos()
key = routing_info.get_first_key_from_pre_vertex(
key = routing_info.get_safe_first_key_from_pre_vertex(
self, SPIKE_PARTITION_ID)
return key

Expand Down
22 changes: 10 additions & 12 deletions spynnaker/pyNN/external_devices_models/spif_output_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _get_set_key_payload(self, index):
:rtype: int
"""
r_infos = SpynnakerDataView.get_routing_infos()
return r_infos.get_first_key_from_pre_vertex(
return r_infos.get_safe_first_key_from_pre_vertex(
self.__incoming_partitions[index].pre_vertex,
self.__incoming_partitions[index].identifier)

Expand All @@ -182,15 +182,15 @@ def _get_set_mask_payload(self, index):
:rtype: int
"""
r_infos = SpynnakerDataView.get_routing_infos()
return r_infos.get_routing_info_from_pre_vertex(
return r_infos.get_safe_routing_info_from_pre_vertex(
self.__incoming_partitions[index].pre_vertex,
self.__incoming_partitions[index].identifier).mask

def _get_set_dist_mask_payload(self, index):
""" Get the payload for the command to set the distiller mask
"""
r_infos = SpynnakerDataView.get_routing_infos()
return ~r_infos.get_routing_info_from_pre_vertex(
return ~r_infos.get_safe_routing_info_from_pre_vertex(
self.__incoming_partitions[index].pre_vertex,
self.__incoming_partitions[index].identifier).mask & 0xFFFFFFFF

Expand Down Expand Up @@ -245,15 +245,13 @@ def get_device_output_keys(self) -> Dict[MachineVertex,
atom_keys = m_vertex.app_vertex.get_atom_key_map(
m_vertex, part.identifier, routing_infos)
else:
r_info = routing_infos.get_routing_info_from_pre_vertex(
m_vertex, part.identifier)
# r_info could be None if there are no outgoing edges,
# at which point there is nothing to do here anyway
if r_info is not None:
vertex_slice = m_vertex.vertex_slice
keys = get_keys(r_info.key, vertex_slice)
start = vertex_slice.lo_atom
atom_keys = [(i, k) for i, k in enumerate(keys, start)]
r_info = \
routing_infos.get_safe_routing_info_from_pre_vertex(
m_vertex, part.identifier)
vertex_slice = m_vertex.vertex_slice
keys = get_keys(r_info.key, vertex_slice)
start = vertex_slice.lo_atom
atom_keys = [(i, k) for i, k in enumerate(keys, start)]

atom_keys_mapped = list((i, key | ((k & mask) >> shift))
for i, k in atom_keys)
Expand Down
2 changes: 1 addition & 1 deletion spynnaker/pyNN/models/common/local_only_2d_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_rinfo_for_spike_source(pre_vertex, partition_id):
routing_info = SpynnakerDataView.get_routing_infos()

# Find the routing information
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
pre_vertex, partition_id)

n_cores = len(r_info.vertex.splitter.get_out_going_vertices(partition_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,8 @@ def n_colour_bits(self) -> int:
def get_atom_key_map(
self, pre_vertex: MachineVertex, partition_id: str,
routing_info: RoutingInfo) -> Iterable[Tuple[int, int]]:
base_key = routing_info.get_first_key_from_pre_vertex(
base_key = routing_info.get_safe_first_key_from_pre_vertex(
pre_vertex, partition_id)
# This might happen if there are no edges
if base_key is None:
base_key = 0
vertex_slice = pre_vertex.vertex_slice
keys = get_keys(base_key, vertex_slice, self.n_colour_bits)
return zip(vertex_slice.get_raster_ids(), keys)
4 changes: 2 additions & 2 deletions spynnaker/pyNN/models/neuron/population_machine_neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def _write_neuron_data_spec(
"""
# Get and store the key
routing_info = SpynnakerDataView.get_routing_infos()
key = routing_info.get_first_key_from_pre_vertex(
cast(AbstractVertex, self), SPIKE_PARTITION_ID)
key = routing_info.get_single_first_key_from_pre_vertex(
cast(AbstractVertex, self))
if key is not None:
self._set_key(key)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,8 @@ def _write_key_spec(self, spec: DataSpecificationGenerator):
else:
assert self.__partition_id is not None
routing_info = SpynnakerDataView.get_routing_infos()
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
self.__neuron_vertex, self.__partition_id)
assert r_info is not None
spec.write_value(r_info.key)
spec.write_value(r_info.mask)
spec.write_value(~r_info.mask & 0xFFFFFFFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ def __write_prepopulation_info(
spec.write_value(app_edge.pre_vertex.n_atoms)
# Machine edge information
for sub, m_vertex in enumerate(out_verts):
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
m_vertex, synapse_info.partition_id)
assert r_info is not None
vertex_slice = m_vertex.vertex_slice
spec.write_value(r_info.key)
spec.write_value(r_info.mask)
Expand Down
12 changes: 4 additions & 8 deletions spynnaker/pyNN/models/neuron/synaptic_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ def generate_data(self) -> None:
app_edge = proj._projection_edge
synapse_info = proj._synapse_information
app_key_info = self.__app_key_and_mask(app_edge, synapse_info)
if app_key_info is None:
continue
d_app_key_info = self.__delay_app_key_and_mask(
app_edge, synapse_info)
app_matrix = SynapticMatrixApp(
Expand Down Expand Up @@ -490,10 +488,9 @@ def __app_key_and_mask(
The synapse information of the projection
"""
routing_info = SpynnakerDataView.get_routing_infos()
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
app_edge.pre_vertex, s_info.partition_id)
if not isinstance(r_info, AppVertexRoutingInfo):
return None
assert isinstance(r_info, AppVertexRoutingInfo)
return self.__get_app_key_and_mask(
r_info, 1, app_edge.pre_vertex, s_info.partition_id)

Expand All @@ -513,10 +510,9 @@ def __delay_app_key_and_mask(
if delay_edge is None:
return None
routing_info = SpynnakerDataView.get_routing_infos()
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
delay_edge.pre_vertex, s_info.partition_id)
if not isinstance(r_info, AppVertexRoutingInfo):
return None
assert isinstance(r_info, AppVertexRoutingInfo)

# We use the app_edge pre-vertex max atoms here as the delay vertex
# is split according to this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ def _write_poisson_parameters(self, spec: DataSpecificationBase):

# Write Key info for this core:
routing_info = SpynnakerDataView.get_routing_infos()
key = routing_info.get_first_key_from_pre_vertex(
self, constants.SPIKE_PARTITION_ID)
key = routing_info.get_single_first_key_from_pre_vertex(self)
keys: Union[Sequence[int], numpy.ndarray]
if key is None:
spec.write_value(0)
Expand All @@ -520,11 +519,10 @@ def _write_poisson_parameters(self, spec: DataSpecificationBase):
incoming_mask = 0
if self._pop_vertex.incoming_control_edge is not None:
routing_info = SpynnakerDataView.get_routing_infos()
r_info = routing_info.get_routing_info_from_pre_vertex(
r_info = routing_info.get_safe_routing_info_from_pre_vertex(
self._pop_vertex.incoming_control_edge.pre_vertex,
LIVE_POISSON_CONTROL_PARTITION_ID)
if r_info:
incoming_mask = ~r_info.mask & 0xFFFFFFFF
incoming_mask = ~r_info.mask & 0xFFFFFFFF
spec.write_value(incoming_mask)

# Write the number of seconds per timestep (unsigned long fract)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,15 @@ def generate_data_specification(
spec.comment("\n*** Spec for Delay Extension Instance ***\n\n")

routing_infos = SpynnakerDataView.get_routing_infos()
key = routing_infos.get_first_key_from_pre_vertex(
key = routing_infos.get_single_first_key_from_pre_vertex(
vertex, self.app_vertex.partition.identifier)

srcs = self.app_vertex.source_vertex.splitter.get_out_going_vertices(
self.app_vertex.partition.identifier)
for source_vertex in srcs:
if source_vertex.vertex_slice == self.vertex_slice:
r_info = routing_infos.get_routing_info_from_pre_vertex(
r_info = routing_infos.get_safe_routing_info_from_pre_vertex(
source_vertex, self.app_vertex.partition.identifier)
assert (r_info is not None)
incoming_key = r_info.key
incoming_mask = r_info.mask
break
Expand Down
14 changes: 6 additions & 8 deletions spynnaker/pyNN/utilities/bit_field_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ def get_bitfield_key_map_data(
routing_infos = SpynnakerDataView.get_routing_infos()
sources = []
for in_edge, part_id in _unique_edges(incoming_projections):
key = routing_infos.get_first_key_from_pre_vertex(
key = routing_infos.get_safe_first_key_from_pre_vertex(
in_edge.pre_vertex, part_id)
if key is not None:
sources.append([key, in_edge.pre_vertex.n_atoms])
sources.append([key, in_edge.pre_vertex.n_atoms])
if in_edge.delay_edge is not None:
delay_key = routing_infos.get_first_key_from_pre_vertex(
delay_key = routing_infos.get_safe_first_key_from_pre_vertex(
in_edge.delay_edge.pre_vertex, part_id)
if delay_key is not None:
n_delay_atoms = (
in_edge.pre_vertex.n_atoms * in_edge.n_delay_stages)
sources.append([delay_key, n_delay_atoms])
n_delay_atoms = (
in_edge.pre_vertex.n_atoms * in_edge.n_delay_stages)
sources.append([delay_key, n_delay_atoms])

if not sources:
return numpy.array([], dtype=uint32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def do_run(self):
synapse_type=sim.StaticSynapse(weight=5.0))
proj_2 = sim.Projection(
source_2, target, sim.FromListConnector([(0, 1)]),
synapse_type=sim.StaticSynapse(weight=5.0), partition_id="Test")
synapse_type=sim.StaticSynapse(weight=5.0), partition_id="Bacon")
proj_3 = sim.Projection(
injector, target, sim.FromListConnector([(0, 2)]),
synapse_type=sim.StaticSynapse(weight=5.0), partition_id="Inject")
Expand Down

0 comments on commit 730c2c0

Please sign in to comment.