From 49e604c3c87b56937e6927abf5073ec484794441 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 3 Dec 2024 10:47:45 +0000 Subject: [PATCH 1/4] remove duplicate code --- spynnaker/pyNN/spinnaker.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/spynnaker/pyNN/spinnaker.py b/spynnaker/pyNN/spinnaker.py index 07bb331578..aa93ed753c 100644 --- a/spynnaker/pyNN/spinnaker.py +++ b/spynnaker/pyNN/spinnaker.py @@ -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': """ From 4e6e0f6ec63235951ede3d8ccdad157241d3257b Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 3 Dec 2024 11:06:36 +0000 Subject: [PATCH 2/4] use reset number as segment counter --- spynnaker/pyNN/models/recorder.py | 8 ++++---- spynnaker/pyNN/spinnaker.py | 2 +- spynnaker/pyNN/utilities/neo_buffer_database.py | 4 ++-- unittests/data/test_simulator_data.py | 16 +++++++++++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/spynnaker/pyNN/models/recorder.py b/spynnaker/pyNN/models/recorder.py index 65f422d685..490cbe6c45 100644 --- a/spynnaker/pyNN/models/recorder.py +++ b/spynnaker/pyNN/models/recorder.py @@ -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) @@ -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_counter()): with NeoBufferDatabase.segement_db(segment) as db: if not wrote_metadata: wrote_metadata = db.csv_block_metadata( @@ -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_counter() - 1) return else: raise ConfigurationException( @@ -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, diff --git a/spynnaker/pyNN/spinnaker.py b/spynnaker/pyNN/spinnaker.py index aa93ed753c..bed657c20c 100644 --- a/spynnaker/pyNN/spinnaker.py +++ b/spynnaker/pyNN/spinnaker.py @@ -271,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, _): diff --git a/spynnaker/pyNN/utilities/neo_buffer_database.py b/spynnaker/pyNN/utilities/neo_buffer_database.py index a21a423b43..5fef01efcb 100644 --- a/spynnaker/pyNN/utilities/neo_buffer_database.py +++ b/spynnaker/pyNN/utilities/neo_buffer_database.py @@ -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: @@ -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())) diff --git a/unittests/data/test_simulator_data.py b/unittests/data/test_simulator_data.py index aec2e5dd02..95d1d80a37 100644 --- a/unittests/data/test_simulator_data.py +++ b/unittests/data/test_simulator_data.py @@ -142,54 +142,68 @@ def test_populations_and_projections(self): def test_segment_counter(self): writer = SpynnakerDataWriter.setup() self.assertEqual(0, SpynnakerDataView.get_segment_counter()) - + self.assertEqual(0, SpynnakerDataView.get_reset_number()) # Not changed by running writer.start_run() self.assertEqual(0, SpynnakerDataView.get_segment_counter()) + self.assertEqual(0, SpynnakerDataView.get_reset_number()) writer.finish_run() self.assertEqual(0, SpynnakerDataView.get_segment_counter()) + self.assertEqual(0, SpynnakerDataView.get_reset_number()) # Not changed by running again writer.start_run() writer.finish_run() self.assertEqual(0, SpynnakerDataView.get_segment_counter()) + self.assertEqual(0, SpynnakerDataView.get_reset_number()) # Changed by a soft reset writer.soft_reset() self.assertEqual(1, SpynnakerDataView.get_segment_counter()) + self.assertEqual(1, SpynnakerDataView.get_reset_number()) writer.start_run() writer.finish_run() self.assertEqual(1, SpynnakerDataView.get_segment_counter()) + self.assertEqual(1, SpynnakerDataView.get_reset_number()) # Changed by a hard reset writer.hard_reset() self.assertEqual(2, SpynnakerDataView.get_segment_counter()) + self.assertEqual(2, SpynnakerDataView.get_reset_number()) 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()) + self.assertEqual(3, SpynnakerDataView.get_reset_number()) writer.hard_reset() self.assertEqual(3, SpynnakerDataView.get_segment_counter()) + self.assertEqual(3, SpynnakerDataView.get_reset_number()) writer.start_run() writer.finish_run() self.assertEqual(3, SpynnakerDataView.get_segment_counter()) + self.assertEqual(3, SpynnakerDataView.get_reset_number()) # Changed once by a soft than not by the hard reset in run writer.soft_reset() self.assertEqual(4, SpynnakerDataView.get_segment_counter()) + self.assertEqual(4, SpynnakerDataView.get_reset_number()) writer.start_run() writer.hard_reset() self.assertEqual(4, SpynnakerDataView.get_segment_counter()) + self.assertEqual(4, SpynnakerDataView.get_reset_number()) writer.finish_run() self.assertEqual(4, SpynnakerDataView.get_segment_counter()) + self.assertEqual(4, SpynnakerDataView.get_reset_number()) # shutting down does not change the value writer.stopping() self.assertEqual(4, SpynnakerDataView.get_segment_counter()) + self.assertEqual(4, SpynnakerDataView.get_reset_number()) writer.shut_down() self.assertEqual(4, SpynnakerDataView.get_segment_counter()) + self.assertEqual(4, SpynnakerDataView.get_reset_number()) def test_sim_name(self): self.assertEqual(SpynnakerDataView.get_sim_name(), sim.name()) From a5d760f98121b600fe185319be72145b4d43b154 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 3 Dec 2024 11:14:23 +0000 Subject: [PATCH 3/4] get_reset_number --- spynnaker/pyNN/models/recorder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spynnaker/pyNN/models/recorder.py b/spynnaker/pyNN/models/recorder.py index 490cbe6c45..58a45688d8 100644 --- a/spynnaker/pyNN/models/recorder.py +++ b/spynnaker/pyNN/models/recorder.py @@ -265,7 +265,7 @@ def csv_neo_block( pop_label = self.__population.label wrote_metadata = False - for segment in range(SpynnakerDataView.get_reset_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( @@ -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_reset_counter() - 1) + SpynnakerDataView.get_reset_number() - 1) return else: raise ConfigurationException( From 1cc624e41890e1aa1d533843a646ac16d52b1bca Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 6 Dec 2024 13:58:38 +0000 Subject: [PATCH 4/4] remove segment counter --- spynnaker/pyNN/data/spynnaker_data_view.py | 14 +---- spynnaker/pyNN/data/spynnaker_data_writer.py | 4 -- unittests/data/test_simulator_data.py | 66 -------------------- 3 files changed, 1 insertion(+), 83 deletions(-) diff --git a/spynnaker/pyNN/data/spynnaker_data_view.py b/spynnaker/pyNN/data/spynnaker_data_view.py index 5576a60ce5..81f83d1b42 100644 --- a/spynnaker/pyNN/data/spynnaker_data_view.py +++ b/spynnaker/pyNN/data/spynnaker_data_view.py @@ -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: @@ -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: """ @@ -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: """ diff --git a/spynnaker/pyNN/data/spynnaker_data_writer.py b/spynnaker/pyNN/data/spynnaker_data_writer.py index c663f884df..c93909633d 100644 --- a/spynnaker/pyNN/data/spynnaker_data_writer.py +++ b/spynnaker/pyNN/data/spynnaker_data_writer.py @@ -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() diff --git a/unittests/data/test_simulator_data.py b/unittests/data/test_simulator_data.py index 95d1d80a37..4e702d6240 100644 --- a/unittests/data/test_simulator_data.py +++ b/unittests/data/test_simulator_data.py @@ -139,72 +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()) - self.assertEqual(0, SpynnakerDataView.get_reset_number()) - # Not changed by running - writer.start_run() - self.assertEqual(0, SpynnakerDataView.get_segment_counter()) - self.assertEqual(0, SpynnakerDataView.get_reset_number()) - writer.finish_run() - self.assertEqual(0, SpynnakerDataView.get_segment_counter()) - self.assertEqual(0, SpynnakerDataView.get_reset_number()) - - # Not changed by running again - writer.start_run() - writer.finish_run() - self.assertEqual(0, SpynnakerDataView.get_segment_counter()) - self.assertEqual(0, SpynnakerDataView.get_reset_number()) - - # Changed by a soft reset - writer.soft_reset() - self.assertEqual(1, SpynnakerDataView.get_segment_counter()) - self.assertEqual(1, SpynnakerDataView.get_reset_number()) - writer.start_run() - writer.finish_run() - self.assertEqual(1, SpynnakerDataView.get_segment_counter()) - self.assertEqual(1, SpynnakerDataView.get_reset_number()) - - # Changed by a hard reset - writer.hard_reset() - self.assertEqual(2, SpynnakerDataView.get_segment_counter()) - self.assertEqual(2, SpynnakerDataView.get_reset_number()) - 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()) - self.assertEqual(3, SpynnakerDataView.get_reset_number()) - writer.hard_reset() - self.assertEqual(3, SpynnakerDataView.get_segment_counter()) - self.assertEqual(3, SpynnakerDataView.get_reset_number()) - writer.start_run() - writer.finish_run() - self.assertEqual(3, SpynnakerDataView.get_segment_counter()) - self.assertEqual(3, SpynnakerDataView.get_reset_number()) - - # Changed once by a soft than not by the hard reset in run - writer.soft_reset() - self.assertEqual(4, SpynnakerDataView.get_segment_counter()) - self.assertEqual(4, SpynnakerDataView.get_reset_number()) - writer.start_run() - writer.hard_reset() - self.assertEqual(4, SpynnakerDataView.get_segment_counter()) - self.assertEqual(4, SpynnakerDataView.get_reset_number()) - writer.finish_run() - self.assertEqual(4, SpynnakerDataView.get_segment_counter()) - self.assertEqual(4, SpynnakerDataView.get_reset_number()) - - # shutting down does not change the value - writer.stopping() - self.assertEqual(4, SpynnakerDataView.get_segment_counter()) - self.assertEqual(4, SpynnakerDataView.get_reset_number()) - writer.shut_down() - self.assertEqual(4, SpynnakerDataView.get_segment_counter()) - self.assertEqual(4, SpynnakerDataView.get_reset_number()) - def test_sim_name(self): self.assertEqual(SpynnakerDataView.get_sim_name(), sim.name()) self.assertIn("sPyNNaker", SpynnakerDataView.get_sim_name())