Skip to content

Commit

Permalink
protect methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jul 28, 2023
1 parent 04480e1 commit b6b3251
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 70 deletions.
12 changes: 6 additions & 6 deletions spinnman/extended/extended_transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def read_neighbour_memory(self, x, y, link, base_address, length, cpu=0):
return process.read_link_memory(
x, y, cpu, link, base_address, length)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def _get_next_nearest_neighbour_id(self):
Expand Down Expand Up @@ -689,7 +689,7 @@ def set_leds(self, x, y, cpu, led_states):
process = SendSingleCommandProcess(self._scamp_connection_selector)
process.execute(SetLED(x, y, cpu, led_states))
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def free_sdram(self, x, y, base_address, app_id):
Expand All @@ -710,7 +710,7 @@ def free_sdram(self, x, y, base_address, app_id):
process = DeAllocSDRAMProcess(self._scamp_connection_selector)
process.de_alloc_sdram(x, y, app_id, base_address)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def free_sdram_by_app_id(self, x, y, app_id):
Expand All @@ -735,7 +735,7 @@ def free_sdram_by_app_id(self, x, y, app_id):
process.de_alloc_sdram(x, y, app_id)
return process.no_blocks_freed
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def get_router_diagnostic_filter(self, x, y, position):
Expand Down Expand Up @@ -776,7 +776,7 @@ def get_router_diagnostic_filter(self, x, y, position):
response.data, response.offset)[0])
# pylint: disable=no-member
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

@property
Expand Down Expand Up @@ -826,5 +826,5 @@ def get_heap(self, x, y, heap=SystemVariableDefinition.sdram_heap_address):
process = GetHeapProcess(self._scamp_connection_selector)
return process.get_heap((x, y), heap)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise
86 changes: 36 additions & 50 deletions spinnman/transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(
# build connection selectors for the processes.
self._bmp_connection_selectors = dict()
self._scamp_connection_selector = \
self._identify_connections(connections)
self.__identify_connections(connections)

# A lock against single chip executions (entry is (x, y))
# The condition should be acquired before the locks are
Expand All @@ -252,11 +252,11 @@ def __init__(
self._n_chip_execute_locks = 0

# Check that the BMP connections are valid
self._check_bmp_connections()
self.__check_bmp_connections()

self._machine_off = False

def __where_is_xy(self, x, y):
def _where_is_xy(self, x, y):
"""
Attempts to get where_is_x_y info from the machine
Expand All @@ -275,7 +275,7 @@ def __where_is_xy(self, x, y):
except Exception as ex: # pylint: disable=broad-except
return str(ex)

def _identify_connections(self, connections):
def __identify_connections(self, connections):
for conn in connections:

# locate the only boot send conn
Expand All @@ -299,7 +299,7 @@ def _identify_connections(self, connections):
# update the transceiver with the conn selectors.
return MostDirectConnectionSelector(self._scamp_connections)

def _check_bmp_connections(self):
def __check_bmp_connections(self):
"""
Check that the BMP connections are actually connected to valid BMPs.
Expand All @@ -311,7 +311,7 @@ def _check_bmp_connections(self):

# try to send a BMP sver to check if it responds as expected
try:
version_info = self.get_scamp_version(
version_info = self._get_scamp_version(
conn.chip_x, conn.chip_y,
self._bmp_connection_selectors[conn.cabinet, conn.frame])
fail_version_name = version_info.name != _BMP_NAME
Expand Down Expand Up @@ -369,7 +369,7 @@ def _check_connection(
return None

@contextmanager
def _flood_execute_lock(self):
def __flood_execute_lock(self):
"""
Get a lock for executing a flood fill of an executable.
"""
Expand Down Expand Up @@ -459,7 +459,7 @@ def discover_scamp_connections(self):
return list()

# Get the machine dimensions
dims = self.get_machine_dimensions()
dims = self._get_machine_dimensions()

# Find all the new connections via the machine Ethernet-connected chips
version = SpiNNManDataView.get_machine_version()
Expand Down Expand Up @@ -504,7 +504,7 @@ def add_scamp_connections(self, connections):
self._scamp_connection_selector = MostDirectConnectionSelector(
self._scamp_connections)

def get_machine_dimensions(self):
def _get_machine_dimensions(self):
"""
Get the maximum chip X-coordinate and maximum chip Y-coordinate of
the chips in the machine.
Expand Down Expand Up @@ -547,10 +547,10 @@ def get_machine_details(self):
If a response indicates an error during the exchange
"""
# Get the width and height of the machine
self.get_machine_dimensions()
self._get_machine_dimensions()

# Get the coordinates of the boot chip
version_info = self.get_scamp_version()
version_info = self._get_scamp_version()

# Get the details of all the chips
get_machine_process = GetMachineProcess(
Expand All @@ -566,7 +566,7 @@ def get_machine_details(self):
logger.info(f"Detected {machine.summary_string()}")
return machine

def get_scamp_version(
def _get_scamp_version(
self, chip_x=AbstractSCPRequest.DEFAULT_DEST_X_COORD,
chip_y=AbstractSCPRequest.DEFAULT_DEST_Y_COORD,
connection_selector=None, n_retries=N_RETRIES):
Expand Down Expand Up @@ -596,7 +596,7 @@ def get_scamp_version(
process = GetVersionProcess(connection_selector, n_retries)
return process.get_version(x=chip_x, y=chip_y, p=0)

def boot_board(
def _boot_board(
self, number_of_boards=None, width=None, height=None,
extra_boot_values=None):
"""
Expand Down Expand Up @@ -628,7 +628,7 @@ def boot_board(
time.sleep(2.0)

@staticmethod
def is_scamp_version_compabible(version):
def _is_scamp_version_compabible(version):
"""
Determine if the version of SCAMP is compatible with this transceiver.
Expand Down Expand Up @@ -696,7 +696,7 @@ def ensure_board_is_ready(

# start by powering up each BMP connection
logger.info("Attempting to power on machine")
self.power_on_machine()
self._power_on_machine()

# Sleep a bit to let things get going
time.sleep(2.0)
Expand All @@ -711,7 +711,7 @@ def ensure_board_is_ready(
raise SpinnmanIOException(
"Failed to communicate with the machine")
if (version_info.name != _SCAMP_NAME or
not self.is_scamp_version_compabible(
not self._is_scamp_version_compabible(
version_info.version_number)):
raise SpinnmanIOException(
f"The machine is currently booted with {version_info.name}"
Expand Down Expand Up @@ -771,14 +771,14 @@ def _try_to_find_scamp_and_boot(
current_tries_to_go = tries_to_go
while version_info is None and current_tries_to_go > 0:
try:
version_info = self.get_scamp_version(n_retries=BOOT_RETRIES)
version_info = self._get_scamp_version(n_retries=BOOT_RETRIES)
if self.__is_default_destination(version_info):
version_info = None
time.sleep(0.1)
except SpinnmanGenericProcessException as e:
if isinstance(e.exception, SpinnmanTimeoutException):
logger.info("Attempting to boot machine")
self.boot_board(
self._boot_board(
number_of_boards, width, height, extra_boot_values)
current_tries_to_go -= 1
elif isinstance(e.exception, SpinnmanIOException):
Expand All @@ -788,7 +788,7 @@ def _try_to_find_scamp_and_boot(
raise
except SpinnmanTimeoutException:
logger.info("Attempting to boot machine")
self.boot_board(
self._boot_board(
number_of_boards, width, height, extra_boot_values)
current_tries_to_go -= 1
except SpinnmanIOException as e:
Expand All @@ -798,7 +798,7 @@ def _try_to_find_scamp_and_boot(
# The last thing we tried was booting, so try again to get the version
if version_info is None:
with suppress(SpinnmanException):
version_info = self.get_scamp_version()
version_info = self._get_scamp_version()
if self.__is_default_destination(version_info):
version_info = None
if version_info is not None:
Expand Down Expand Up @@ -1058,7 +1058,7 @@ def execute_flood(
If a response indicates an error during the exchange
"""
# Lock against other executable's
with self._flood_execute_lock():
with self.__flood_execute_lock():
# Flood fill the system with the binary
n_bytes, chksum = self.write_memory(
0, 0, _EXECUTABLE_ADDRESS, executable, n_bytes,
Expand All @@ -1077,7 +1077,7 @@ def execute_flood(
self._scamp_connection_selector)
process.run(n_bytes, app_id, core_subsets, chksum, wait)

def power_on_machine(self):
def _power_on_machine(self):
"""
Power on the whole machine.
Expand Down Expand Up @@ -1351,7 +1351,7 @@ def read_memory(self, x, y, base_address, length, cpu=0):
process = ReadMemoryProcess(self._scamp_connection_selector)
return process.read_memory(x, y, cpu, base_address, length)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def read_word(self, x, y, base_address, cpu=0):
Expand Down Expand Up @@ -1385,7 +1385,7 @@ def read_word(self, x, y, base_address, cpu=0):
(value, ) = _ONE_WORD.unpack(data)
return value
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def stop_application(self, app_id):
Expand Down Expand Up @@ -1425,7 +1425,7 @@ def __log_where_is_info(self, cpu_infos):
else:
xys.add((cpu_info.x, cpu_info.y))
for (x, y) in xys:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))

def wait_for_cores_to_be_in_state(
self, all_core_subsets, app_id, cpu_states, timeout=None,
Expand Down Expand Up @@ -1547,7 +1547,7 @@ def send_signal(self, app_id, signal):
process = SendSingleCommandProcess(self._scamp_connection_selector)
process.execute(SendSignal(app_id, signal))

def locate_spinnaker_connection_for_board_address(self, board_address):
def _locate_spinnaker_connection_for_board_address(self, board_address):
"""
Find a connection that matches the given board IP address.
Expand Down Expand Up @@ -1625,7 +1625,7 @@ def __get_connection_list(self, connection=None, board_address=None):
elif board_address is None:
return self._scamp_connections

connection = self.locate_spinnaker_connection_for_board_address(
connection = self._locate_spinnaker_connection_for_board_address(
board_address)
if connection is None:
return []
Expand Down Expand Up @@ -1754,7 +1754,7 @@ def malloc_sdram(self, x, y, size, app_id, tag=None):
process.malloc_sdram(x, y, size, app_id, tag)
return process.base_address
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def load_multicast_routes(self, x, y, routes, app_id):
Expand Down Expand Up @@ -1784,7 +1784,7 @@ def load_multicast_routes(self, x, y, routes, app_id):
self._scamp_connection_selector)
process.load_routes(x, y, routes, app_id)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def load_fixed_route(self, x, y, fixed_route, app_id):
Expand Down Expand Up @@ -1814,7 +1814,7 @@ def load_fixed_route(self, x, y, fixed_route, app_id):
self._scamp_connection_selector)
process.load_fixed_route(x, y, fixed_route, app_id)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def read_fixed_route(self, x, y, app_id):
Expand All @@ -1835,7 +1835,7 @@ def read_fixed_route(self, x, y, app_id):
self._scamp_connection_selector)
return process.read_fixed_route(x, y, app_id)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def get_multicast_routes(self, x, y, app_id=None):
Expand Down Expand Up @@ -1867,7 +1867,7 @@ def get_multicast_routes(self, x, y, app_id=None):
self._scamp_connection_selector, app_id)
return process.get_routes(x, y, base_address)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def clear_multicast_routes(self, x, y):
Expand All @@ -1889,7 +1889,7 @@ def clear_multicast_routes(self, x, y):
process = SendSingleCommandProcess(self._scamp_connection_selector)
process.execute(RouterClear(x, y))
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def get_router_diagnostics(self, x, y):
Expand All @@ -1916,7 +1916,7 @@ def get_router_diagnostics(self, x, y):
self._scamp_connection_selector)
return process.get_router_diagnostics(x, y)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def set_router_diagnostic_filter(self, x, y, position, diagnostic_filter):
Expand Down Expand Up @@ -1951,7 +1951,7 @@ def set_router_diagnostic_filter(self, x, y, position, diagnostic_filter):
self.__set_router_diagnostic_filter(
x, y, position, diagnostic_filter)
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def __set_router_diagnostic_filter(
Expand Down Expand Up @@ -1999,7 +1999,7 @@ def clear_router_diagnostic_counters(self, x, y):
process.execute(WriteMemory(
x, y, 0xf100002c, _ONE_WORD.pack(0xFFFFFFFF)))
except Exception:
logger.info(self.__where_is_xy(x, y))
logger.info(self._where_is_xy(x, y))
raise

def close(self):
Expand All @@ -2013,20 +2013,6 @@ def close(self):
for connection in self._all_connections:
connection.close()

@property
def bmp_connection(self):
"""
The BMP connections.
.. warning::
This property is currently deprecated and likely to be removed.
:rtype: dict(tuple(int,int),MostDirectConnectionSelector)
"""
warn_once(logger, "The bmp_connection property is deprecated and "
"likely to be removed.")
return self._bmp_connection_selectors

def control_sync(self, do_sync):
"""
Control the synchronisation of the chips.
Expand Down
Loading

0 comments on commit b6b3251

Please sign in to comment.