Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python tweaking #858

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion spynnaker/gsyn_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_sister_gysn(sister, n_neurons, runtime, gsyn):
""" Compare an arrays of conductances with baseline data from a file next\
to a specified module. For testing.

:param sister: A module. The file read from will be ``gsyn.data`` \
:param sister: A module. The file read from will be ``gsyn.data``
adjacent to this module.
:param n_neurons: The number of neurons that produced the data.
:param runtime: The length of time that the generated data represents.
Expand Down
55 changes: 31 additions & 24 deletions spynnaker/pyNN/abstract_spinnaker_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,44 @@
import math
import os
from six import with_metaclass

from spinn_front_end_common.utilities.constants import \
MICRO_TO_MILLISECOND_CONVERSION
from spinn_utilities.abstract_base import AbstractBase
from spinn_utilities.log import FormatAdapter
from spinn_front_end_common.utilities.constants import (
MICRO_TO_MILLISECOND_CONVERSION)
from spinn_front_end_common.interface.abstract_spinnaker_base import (
AbstractSpinnakerBase)
from spinn_front_end_common.utilities.exceptions import ConfigurationException
from spinn_front_end_common.utility_models import CommandSender
from spinn_front_end_common.utilities.utility_objs import ExecutableFinder
from spinn_front_end_common.utilities import globals_variables
from spinn_front_end_common.utilities.globals_variables import unset_simulator
from spinn_front_end_common.utilities.helpful_functions import read_config
from spynnaker.pyNN import extra_algorithms, model_binaries
from spynnaker.pyNN.utilities import constants
from spynnaker.pyNN.utilities.constants import (
MAX_DELAY_BLOCKS, MAX_SUPPORTED_DELAY_TICS,
MAX_TIMER_TICS_SUPPORTED_PER_BLOCK, MIN_SUPPORTED_DELAY)
from spynnaker.pyNN.spynnaker_simulator_interface import (
SpynnakerSimulatorInterface)
from spynnaker.pyNN.utilities.extracted_data import ExtractedData
from spynnaker import __version__ as version
from spynnaker.pyNN.utilities.utility_calls import round_up
from spynnaker.pyNN import model_binaries

logger = FormatAdapter(logging.getLogger(__name__))


def _extra_algo_path():
""" List containing the names of the extra algorithms config files.

.. note::
Need to `import` within this to avoid an import loop.

:rtype: list(str)
"""
import spynnaker.pyNN.extra_algorithms
return [os.path.join(
os.path.dirname(spynnaker.pyNN.extra_algorithms.__file__),
"algorithms_metadata.xml")]


class AbstractSpiNNakerCommon(with_metaclass(
AbstractBase, AbstractSpinnakerBase, SpynnakerSimulatorInterface)):
""" Main interface for neural code.
Expand Down Expand Up @@ -85,15 +101,15 @@ def __init__(
:param user_extra_algorithms_pre_run:
:type user_extra_algorithms_pre_run: list(str) or None
:param time_scale_factor:
:type time_scale_factor:
:type time_scale_factor: int or None
:param extra_post_run_algorithms:
:type extra_post_run_algorithms: list(str) or None
:param extra_mapping_algorithms:
:type extra_mapping_algorithms: list(str) or None
:param extra_load_algorithms:
:type extra_load_algorithms: list(str) or None
:param front_end_versions:
:type front_end_versions:
:type front_end_versions: list(tuple(str,str)) or None
"""
# pylint: disable=too-many-arguments, too-many-locals

Expand All @@ -114,10 +130,7 @@ def __init__(

# create XML path for where to locate sPyNNaker related functions when
# using auto pause and resume
extra_algorithm_xml_path = list()
extra_algorithm_xml_path.append(os.path.join(
os.path.dirname(extra_algorithms.__file__),
"algorithms_metadata.xml"))
extra_algorithm_xml_path = _extra_algo_path()
if user_extra_algorithm_xml_path is not None:
extra_algorithm_xml_path.extend(user_extra_algorithm_xml_path)

Expand Down Expand Up @@ -238,7 +251,7 @@ def _set_up_timings(
self.set_up_timings(timestep, time_scale_factor)
else:
self.set_up_timings(
math.ceil(timestep * MICRO_TO_MILLISECOND_CONVERSION),
round_up(timestep * MICRO_TO_MILLISECOND_CONVERSION),
time_scale_factor)

# Sort out the minimum delay
Expand All @@ -248,19 +261,17 @@ def _set_up_timings(
raise ConfigurationException(
"Pacman does not support min delays below {} ms with the "
"current machine time step".format(
constants.MIN_SUPPORTED_DELAY * self.machine_time_step))
MIN_SUPPORTED_DELAY * self.machine_time_step))
if min_delay is not None:
self.__min_delay = min_delay
else:
self.__min_delay = (
self.machine_time_step / MICRO_TO_MILLISECOND_CONVERSION)

# Sort out the maximum delay
natively_supported_delay_for_models = \
constants.MAX_SUPPORTED_DELAY_TICS
natively_supported_delay_for_models = MAX_SUPPORTED_DELAY_TICS
delay_extension_max_supported_delay = (
constants.MAX_DELAY_BLOCKS *
constants.MAX_TIMER_TICS_SUPPORTED_PER_BLOCK)
MAX_DELAY_BLOCKS * MAX_TIMER_TICS_SUPPORTED_PER_BLOCK)
max_delay_tics_supported = \
natively_supported_delay_for_models + \
delay_extension_max_supported_delay
Expand All @@ -276,8 +287,7 @@ def _set_up_timings(
else:
self.__max_delay = (
max_delay_tics_supported * (
self.machine_time_step /
MICRO_TO_MILLISECOND_CONVERSION))
self.machine_time_step / MICRO_TO_MILLISECOND_CONVERSION))

# Sort out the time scale factor if not user specified
# (including config)
Expand Down Expand Up @@ -387,7 +397,6 @@ def stop(self, turn_off_machine=None, clear_routing_tables=None,
:param clear_tags: informs the tool chain if it should clear the tags
off the machine at stop
:type clear_tags: bool or None
:rtype: None
"""
# pylint: disable=protected-access
for population in self._populations:
Expand All @@ -396,14 +405,13 @@ def stop(self, turn_off_machine=None, clear_routing_tables=None,
super(AbstractSpiNNakerCommon, self).stop(
turn_off_machine, clear_routing_tables, clear_tags)
self.reset_number_of_neurons_per_core()
globals_variables.unset_simulator(self)
unset_simulator(self)

def run(self, run_time):
""" Run the model created.

:param run_time: the time (in milliseconds) to run the simulation for
:type run_time: float or int
:rtype: None
"""
# pylint: disable=protected-access

Expand All @@ -428,7 +436,6 @@ def register_binary_search_path(search_path):
""" Register an additional binary search path for executables.

:param str search_path: absolute search path for binaries
:rtype: None
"""
# pylint: disable=protected-access
AbstractSpiNNakerCommon.__EXECUTABLE_FINDER.add_path(search_path)
Expand Down
3 changes: 0 additions & 3 deletions spynnaker/pyNN/connections/ethernet_control_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from spinn_front_end_common.utility_models import MultiCastCommand
from spinn_front_end_common.utilities.connections import LiveEventConnection

logger = logging.getLogger(__name__)


class EthernetControlConnection(LiveEventConnection):
""" A connection that can translate Ethernet control messages received\
Expand Down
4 changes: 2 additions & 2 deletions spynnaker/pyNN/external_devices_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .abstract_ethernet_sensor import AbstractEthernetSensor
from .abstract_ethernet_translator import AbstractEthernetTranslator
from .abstract_multicast_controllable_device import (
AbstractMulticastControllableDevice)
AbstractMulticastControllableDevice, SendType)
from .arbitrary_fpga_device import ArbitraryFPGADevice
from .external_device_lif_control import ExternalDeviceLifControl
from .external_spinnaker_link_cochlea_device import ExternalCochleaDevice
Expand All @@ -32,5 +32,5 @@
"AbstractEthernetTranslator", "ArbitraryFPGADevice",
"AbstractMulticastControllableDevice", "ExternalDeviceLifControl",
"ExternalCochleaDevice", "ExternalFPGARetinaDevice",
"MunichMotorDevice", "MunichRetinaDevice",
"MunichMotorDevice", "MunichRetinaDevice", "SendType",
"ThresholdTypeMulticastDeviceControl"]
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ def translate_control_packet(self, multicast_packet):
:param multicast_packet: A received multicast packet
:type multicast_packet:
~spinnman.messages.eieio.data_messages.AbstractEIEIODataElement
:rtype: None
"""
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from spinn_utilities.overrides import overrides
from spinn_front_end_common.utilities.exceptions import ConfigurationException
from spynnaker.pyNN.models.neuron import AbstractPyNNNeuronModelStandard
from spynnaker.pyNN.models.defaults import default_initial_values,\
default_parameters
from spynnaker.pyNN.models.defaults import (
default_initial_values, default_parameters)
from spynnaker.pyNN.models.neuron.input_types import InputTypeCurrent
from spynnaker.pyNN.models.neuron.neuron_models import (
NeuronModelLeakyIntegrateAndFire)
Expand All @@ -27,8 +26,6 @@
from .threshold_type_multicast_device_control import (
ThresholdTypeMulticastDeviceControl)

logger = logging.getLogger(__name__)


class ExternalDeviceLifControl(AbstractPyNNNeuronModelStandard):
""" Abstract control module for the PushBot, based on the LIF neuron,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
import logging
from spinn_utilities.overrides import overrides
from pacman.model.constraints.key_allocator_constraints import (
FixedKeyAndMaskConstraint)
Expand All @@ -26,8 +25,6 @@
from spynnaker.pyNN.models.neuron import AbstractPopulationVertex
from .abstract_ethernet_controller import AbstractEthernetController

logger = logging.getLogger(__name__)


class ExternalDeviceLifControlVertex(
AbstractPopulationVertex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from spinn_utilities.overrides import overrides
from pacman.model.constraints.key_allocator_constraints import (
FixedKeyAndMaskConstraint)
Expand All @@ -28,8 +26,6 @@
from spinn_front_end_common.utility_models import MultiCastCommand
from spynnaker.pyNN.exceptions import SpynnakerException

logger = logging.getLogger(__name__)


def get_y_from_fpga_retina(key, mode):
if mode == 128:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from spinn_utilities.overrides import overrides
from pacman.executor.injection_decorator import inject_items
from pacman.model.constraints.key_allocator_constraints import (
Expand All @@ -36,7 +35,6 @@
from spynnaker.pyNN.exceptions import SpynnakerException
from spynnaker.pyNN.models.defaults import defaults

logger = logging.getLogger(__name__)
MOTOR_PARTITION_ID = "MOTOR"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from enum import Enum
from spynnaker.pyNN.external_devices_models\
.abstract_multicast_controllable_device import SendType
from spynnaker.pyNN.external_devices_models import SendType


class AbstractPushBotOutputDevice(Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
from spynnaker.pyNN.models.defaults import default_initial_values
from spynnaker.pyNN.external_devices_models.push_bot.push_bot_ethernet \
import (
PushBotTranslator)
PushBotTranslator, get_pushbot_wifi_connection)
from spynnaker.pyNN.external_devices_models import ExternalDeviceLifControl
from spynnaker.pyNN.external_devices_models.push_bot.push_bot_ethernet \
import (
get_pushbot_wifi_connection)


class PushBotLifEthernet(ExternalDeviceLifControl):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from spynnaker.pyNN.external_devices_models import ExternalDeviceLifControl
from spynnaker.pyNN.protocols import MunichIoSpiNNakerLinkProtocol
from spynnaker.pyNN.models.defaults import default_initial_values

logger = logging.getLogger(__name__)


class PushBotLifSpinnakerLink(ExternalDeviceLifControl):
""" Control module for a PushBot connected to a SpiNNaker Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
from threading import RLock
import numpy
from spinnman.connections import ConnectionListener
Expand All @@ -23,7 +21,6 @@
import (
PushBotRetinaResolution)

logger = logging.getLogger(__name__)
_RETINA_PACKET_SIZE = BYTES_PER_SHORT


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import logging
import platform
import select
import socket
import subprocess
from six import raise_from
from spinn_utilities.overrides import overrides
from spinn_utilities.ping import Ping
from spinnman.connections.abstract_classes import Listenable, Connection
from spinnman.exceptions import SpinnmanIOException, SpinnmanTimeoutException
from spinn_front_end_common.utilities.constants import BYTES_PER_KB
Expand Down Expand Up @@ -102,28 +102,9 @@ def __init__(self, remote_host, remote_port=56000):
# Set a general timeout on the socket
self.__socket.settimeout(0)

@overrides(Connection.is_connected)
def is_connected(self):
""" See\
:py:meth:`~spinnman.connections.Connection.is_connected`
"""
if platform.platform().lower().startswith("windows"):
cmd_args = "-n 1 -w 1"
else:
cmd_args = "-c 1 -W 1"

# check if machine is active and on the network
for _ in range(5): # Try up to five times...
# Start a ping process
process = subprocess.Popen(
"ping " + cmd_args + " " + self.__remote_ip_address,
shell=True, stdout=subprocess.PIPE)
process.wait()
if process.returncode == 0:
# ping worked
return True

# If the ping fails this number of times, the host cannot be contacted
return False
return Ping.host_is_reachable(self.__remote_ip_address)

@property
def local_ip_address(self):
Expand Down Expand Up @@ -190,18 +171,18 @@ def send(self, data):
except Exception as e: # pylint: disable=broad-except
raise_from(SpinnmanIOException(str(e)), e)

@overrides(Connection.close)
def close(self):
""" See\
:py:meth:`spinnman.connections.Connection.close`
"""
try:
self.__socket.shutdown(socket.SHUT_WR)
except Exception: # pylint: disable=broad-except
pass
self.__socket.close()

@overrides(Listenable.is_ready_to_receive, extend_defaults=True)
def is_ready_to_receive(self, timeout=0):
return bool(select.select([self.__socket], [], [], timeout)[0])

@overrides(Listenable.get_receive_method)
def get_receive_method(self):
return self.receive
Loading