Skip to content

Commit

Permalink
required in global data
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jan 17, 2022
1 parent 5bb682e commit 6641c3f
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spinn_front_end_common/data/fec_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class _FecDataModel(object):
"_first_machine_time_step",
"_hardware_time_step_ms",
"_hardware_time_step_us",
"_n_boards_required",
"_n_calls_to_run",
"_n_chips_required",
"_n_chips_in_graph",
"_max_run_time_steps",
"_report_dir_path",
"_simulation_time_step_ms",
Expand Down Expand Up @@ -75,7 +78,9 @@ def _clear(self):
"""
self._hardware_time_step_ms = None
self._hardware_time_step_us = None
self._n_boards_required = None
self._n_calls_to_run = None
self._n_chips_required = None
self._simulation_time_step_ms = None
self._simulation_time_step_per_ms = None
self._simulation_time_step_per_s = None
Expand All @@ -94,6 +99,7 @@ def _hard_reset(self):
self._buffer_manager = None
self._data_in_multicast_key_to_chip_map = None
self._data_in_multicast_routing_tables = None
self._n_chips_in_graph = None
self._max_run_time_steps = None
self._system_multicast_router_timeout_keys = None
self._soft_reset()
Expand Down Expand Up @@ -391,6 +397,42 @@ def has_n_calls_to_run(cls):
# There are NO has or get methods for directories
# This allow directories to be created on the fly

# n_boards/chips required

@classmethod
def get_n_boards_required(cls):
"""
Gets the number of boards requested by the user during setup.
Highly likely to be None
Guaranteed to be positive if not None
:rtype: int or None
"""
return cls.__fec_data._n_boards_required

@classmethod
def get_n_chips_needed(cls):
"""
Gets the number of chips needed.
This will be the number of chips requested by the use during setup,
even if this is less that what the partitioner reported.
If the partitioner has run and the user has not specified a number,
this will be what the partitioner requested.
Highly likely to be None before the partitioner has run
Guaranteed to be positive if not None
:rtype: int or None
"""
if cls.__fec_data._n_chips_required:
return cls.__fec_data._n_chips_required
return cls.__fec_data._n_chips_in_graph

@classmethod
def get_report_dir_path(cls):
"""
Expand Down
47 changes: 47 additions & 0 deletions spinn_front_end_common/data/fec_data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,50 @@ def set_system_multicast_routing_data(self, data):
data_in_multicast_routing_tables
self.__fec_data._system_multicast_router_timeout_keys = \
system_multicast_router_timeout_keys

def set_n_required(self, n_boards_required, n_chips_required):
"""
Sets (if not None) the number of boards/chips requested by the user
:param n_boards_required: None or the number of boards requested by
the user
:type n_boards_required: int or None
:param n_chips_required: None or the number of chips requested by
the user
:type n_chips_required: int or None
"""
if n_boards_required is None:
if n_chips_required is None:
return
elif not isinstance(n_chips_required, int):
raise TypeError("n_chips_required must be an int (or None)")
if n_chips_required <= 0:
raise ConfigurationException(
f"n_chips_required must be positive and not "
f"{n_chips_required}")
else:
if n_chips_required is not None:
raise ConfigurationException(
f"Illegal call with both both param provided as "
f"{n_boards_required}, {n_chips_required}")
if not isinstance(n_boards_required, int):
raise TypeError("n_boards_required must be an int (or None)")
if n_boards_required <= 0:
raise ConfigurationException(
f"n_boards_required must be positive and not "
f"{n_boards_required}")
if self.__fec_data._n_boards_required is not None or \
self.__fec_data._n_chips_required is not None:
raise ConfigurationException(
"Illegal second call to set_n_required")
self.__fec_data._n_boards_required = n_boards_required
self.__fec_data._n_chips_required = n_chips_required

def set_n_chips_in_graph(self, n_chips_in_graph):
if not isinstance(n_chips_in_graph, int):
raise TypeError("n_chips_in_graph must be an int (or None)")
if n_chips_in_graph <= 0:
raise ConfigurationException(
f"n_chips_in_graph must be positive and not "
f"{n_chips_in_graph}")
self.__fec_data._n_chips_in_graph = n_chips_in_graph
69 changes: 69 additions & 0 deletions unittests/data/test_simulator_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,72 @@ def test_system_multicast_routing_data(self):
FecDataView.get_data_in_multicast_routing_tables()
with self.assertRaises(DataNotYetAvialable):
FecDataView.get_system_multicast_router_timeout_keys()

def test_required(self):
writer = FecDataWriter.setup()
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertIsNone(FecDataView.get_n_chips_needed())

# required higher than in graph
writer.set_n_required(None, 20)
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertEquals(20, FecDataView.get_n_chips_needed())
writer.set_n_chips_in_graph(15)
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertEquals(20, FecDataView.get_n_chips_needed())

# required higher than in graph
writer.set_n_chips_in_graph(25)
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertEquals(20, FecDataView.get_n_chips_needed())

# reset does not remove required
writer.hard_reset()
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertEquals(20, FecDataView.get_n_chips_needed())

writer = FecDataWriter.setup()
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertIsNone(FecDataView.get_n_chips_needed())

# in graph only
writer.set_n_chips_in_graph(25)
self.assertEquals(25, FecDataView.get_n_chips_needed())

# reset clears in graph
writer.hard_reset()
self.assertIsNone(FecDataView.get_n_chips_needed())

# N boards
writer = FecDataWriter.setup()
writer.set_n_required(5, None)
self.assertEquals(5, FecDataView.get_n_boards_required())
self.assertIsNone(FecDataView.get_n_chips_needed())

# boards does not hide in graph
writer.set_n_chips_in_graph(40)
self.assertEquals(5, FecDataView.get_n_boards_required())
self.assertEquals(40, FecDataView.get_n_chips_needed())

# reset does not clear required
writer.hard_reset()
self.assertEquals(5, FecDataView.get_n_boards_required())
self.assertIsNone(FecDataView.get_n_chips_needed())

# two Nones fine
writer = FecDataWriter.setup()
writer.set_n_required(None, None)
self.assertIsNone(FecDataView.get_n_boards_required())
self.assertIsNone(FecDataView.get_n_chips_needed())

# Ilegal calls
with self.assertRaises(ConfigurationException):
writer.set_n_required(5, 5)
with self.assertRaises(ConfigurationException):
writer.set_n_required(None, -5)
with self.assertRaises(ConfigurationException):
writer.set_n_required(0, None)
with self.assertRaises(TypeError):
writer.set_n_required(None, "five")
with self.assertRaises(TypeError):
writer.set_n_required("2.3", None)

0 comments on commit 6641c3f

Please sign in to comment.