Skip to content

Commit

Permalink
Merge pull request #1511 from SpiNNakerManchester/reset_and_segment_t…
Browse files Browse the repository at this point in the history
…he_same

reset_number and segment_counter are the same thing
  • Loading branch information
rowleya authored Dec 6, 2024
2 parents c4c3605 + 1cc624e commit 64d0914
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 90 deletions.
14 changes: 1 addition & 13 deletions spynnaker/pyNN/data/spynnaker_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class _SpynnakerDataModel(object):
"_min_delay",
"_neurons_per_core_set",
"_populations",
"_projections",
"_segment_counter")
"_projections")

def __new__(cls) -> '_SpynnakerDataModel':
if cls.__singleton is not None:
Expand All @@ -72,7 +71,6 @@ def _clear(self) -> None:
self._neurons_per_core_set: Set[Type[AbstractPyNNModel]] = set()
self._populations: Set[Population] = set()
self._projections: Set[Projection] = set()
self._segment_counter = 0

def _hard_reset(self) -> None:
"""
Expand Down Expand Up @@ -255,16 +253,6 @@ def set_number_of_neurons_per_dimension_per_core(
neuron_type.set_model_max_atoms_per_dimension_per_core(max_permitted)
cls.__spy_data._neurons_per_core_set.add(neuron_type)

@classmethod
def get_segment_counter(cls) -> int:
"""
The number of the current recording segment being generated.
:return: the segment counter
:rtype: int
"""
return cls.__spy_data._segment_counter

@classmethod
def get_sim_name(cls) -> str:
"""
Expand Down
4 changes: 0 additions & 4 deletions spynnaker/pyNN/data/spynnaker_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ def _mock(self) -> None:

@overrides(FecDataWriter._hard_reset)
def _hard_reset(self) -> None:
if not self.is_soft_reset():
# Only increase it if this is a hard not following a soft
self.__spy_data._segment_counter += 1
FecDataWriter._hard_reset(self)
self.__spy_data._hard_reset()

@overrides(FecDataWriter._soft_reset)
def _soft_reset(self) -> None:
self.__spy_data._segment_counter += 1
FecDataWriter._soft_reset(self)
self.__spy_data._soft_reset()

Expand Down
8 changes: 4 additions & 4 deletions spynnaker/pyNN/models/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def extract_neo_block(
SpynnakerDataView.check_user_can_act()

block: Optional[neo.Block] = None
for previous in range(SpynnakerDataView.get_segment_counter()):
for previous in range(SpynnakerDataView.get_reset_number()):
block = self.__append_previous_segment(
block, previous, variables, view_indexes, clear, annotations)

Expand Down Expand Up @@ -265,7 +265,7 @@ def csv_neo_block(
pop_label = self.__population.label

wrote_metadata = False
for segment in range(SpynnakerDataView.get_segment_counter()):
for segment in range(SpynnakerDataView.get_reset_number()):
with NeoBufferDatabase.segement_db(segment) as db:
if not wrote_metadata:
wrote_metadata = db.csv_block_metadata(
Expand All @@ -279,7 +279,7 @@ def csv_neo_block(
logger.warning(
"Due to the call directly after reset, "
"the data will only contain {} segments",
SpynnakerDataView.get_segment_counter() - 1)
SpynnakerDataView.get_reset_number() - 1)
return
else:
raise ConfigurationException(
Expand Down Expand Up @@ -316,7 +316,7 @@ def __append_current_segment(
logger.warning(
"Due to the call directly after reset, "
"the data will only contain {} segments",
SpynnakerDataView.get_segment_counter() - 1)
SpynnakerDataView.get_reset_number() - 1)
else:
db.add_segment(
block, self.__population.label, variables, view_indexes,
Expand Down
16 changes: 1 addition & 15 deletions spynnaker/pyNN/spinnaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,6 @@ def clear(self) -> None:
# Stop any currently running SpiNNaker application
self.stop()

def reset(self) -> None:
"""
Reset the state of the current network to time t = 0.
"""
if not self.__writer.is_ran_last():
if not self.__writer.is_ran_ever():
logger.error("Ignoring the reset before the run")
else:
logger.error("Ignoring the repeated reset call")
return

# Call superclass implementation
AbstractSpinnakerBase.reset(self)

@property
def state(self) -> 'SpiNNaker':
"""
Expand Down Expand Up @@ -285,7 +271,7 @@ def segment_counter(self) -> int:
:return: the segment counter
:rtype: int
"""
return self.__writer.get_segment_counter()
return self.__writer.get_reset_number()

@segment_counter.setter
def segment_counter(self, _):
Expand Down
4 changes: 2 additions & 2 deletions spynnaker/pyNN/utilities/neo_buffer_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, database_file: Optional[str] = None,

super().__init__(database_file, read_only=read_only)

segment = SpynnakerDataView.get_segment_counter()
segment = SpynnakerDataView.get_reset_number()
if (segment not in segment_cache or
segment_cache[segment] != database_file):
with open(self.__NEO_DDL_FILE, encoding="utf-8") as f:
Expand Down Expand Up @@ -154,7 +154,7 @@ def write_segment_metadata(self) -> None:
dt, simulator)
VALUES (?, ?, ?, ?, ?)
""", (SpynnakerDataView.get_simulation_time_step_ms(),
SpynnakerDataView.get_segment_counter(),
SpynnakerDataView.get_reset_number(),
datetime.now(),
SpynnakerDataView.get_simulation_time_step_ms(),
SpynnakerDataView.get_sim_name()))
Expand Down
52 changes: 0 additions & 52 deletions unittests/data/test_simulator_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,58 +139,6 @@ def test_populations_and_projections(self):
with self.assertRaises(TypeError):
writer.add_projection("bacon")

def test_segment_counter(self):
writer = SpynnakerDataWriter.setup()
self.assertEqual(0, SpynnakerDataView.get_segment_counter())

# Not changed by running
writer.start_run()
self.assertEqual(0, SpynnakerDataView.get_segment_counter())
writer.finish_run()
self.assertEqual(0, SpynnakerDataView.get_segment_counter())

# Not changed by running again
writer.start_run()
writer.finish_run()
self.assertEqual(0, SpynnakerDataView.get_segment_counter())

# Changed by a soft reset
writer.soft_reset()
self.assertEqual(1, SpynnakerDataView.get_segment_counter())
writer.start_run()
writer.finish_run()
self.assertEqual(1, SpynnakerDataView.get_segment_counter())

# Changed by a hard reset
writer.hard_reset()
self.assertEqual(2, SpynnakerDataView.get_segment_counter())
writer.start_run()
writer.finish_run()

# Changed once by a soft than not by the hard reset before run
writer.soft_reset()
self.assertEqual(3, SpynnakerDataView.get_segment_counter())
writer.hard_reset()
self.assertEqual(3, SpynnakerDataView.get_segment_counter())
writer.start_run()
writer.finish_run()
self.assertEqual(3, SpynnakerDataView.get_segment_counter())

# Changed once by a soft than not by the hard reset in run
writer.soft_reset()
self.assertEqual(4, SpynnakerDataView.get_segment_counter())
writer.start_run()
writer.hard_reset()
self.assertEqual(4, SpynnakerDataView.get_segment_counter())
writer.finish_run()
self.assertEqual(4, SpynnakerDataView.get_segment_counter())

# shutting down does not change the value
writer.stopping()
self.assertEqual(4, SpynnakerDataView.get_segment_counter())
writer.shut_down()
self.assertEqual(4, SpynnakerDataView.get_segment_counter())

def test_sim_name(self):
self.assertEqual(SpynnakerDataView.get_sim_name(), sim.name())
self.assertIn("sPyNNaker", SpynnakerDataView.get_sim_name())

0 comments on commit 64d0914

Please sign in to comment.