diff --git a/Makefile b/Makefile index f2d4b3edba5a655f71b4bc86ae9072db3058bb06..91af83910598fc4dc6bbbabc7ab7be126d712135 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,14 @@ #modules that have tests -#TEST_MODULES=hbp_nrp_music_xml/hbp_nrp_music_xml hbp_nrp_music_interface/hbp_nrp_music_interface hbp_nrp_distributed_nest/hbp_nrp_distributed_nest -# HOTFIX: as import music fails in tests (NRRPLT-6949), remove music packages from the tests TEST_MODULES=hbp_nrp_distributed_nest/hbp_nrp_distributed_nest #modules that are installable (ie: ones w/ setup.py) -INSTALL_MODULES=hbp_nrp_music_xml hbp_nrp_music_interface hbp_nrp_distributed_nest +INSTALL_MODULES=hbp_nrp_distributed_nest #packages to cover -#COVER_PACKAGES=hbp_nrp_music_xml hbp_nrp_music_interface hbp_nrp_distributed_nest -# HOTFIX: as import music fails in tests (NRRPLT-6949), remove music packages from the tests COVER_PACKAGES=hbp_nrp_distributed_nest #documentation to build -#DOC_MODULES=hbp_nrp_music_xml/doc hbp_nrp_music_interface/doc hbp_nrp_distributed_nest/doc +#DOC_MODULES=hbp_nrp_distributed_nest/doc PYTHON_PIP_VERSION?=pip==9.0.3 diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index 063cb87e4b738285a492b7b90272abfe518f84bb..d62b366d92ab34ba2de55998e3e16b51a28311e1 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -19,12 +19,12 @@ pipelines: # Configure build has to be placed before make devinstall - export VIRTUAL_ENV_PATH=$VIRTUAL_ENV - export NRP_INSTALL_MODE=dev - - export PYTHONPATH=hbp_nrp_music_xml:hbp_nrp_music_interface:$VIRTUAL_ENV_PATH/lib/python2.7/site-packages:$PYTHONPATH + - export PYTHONPATH=$VIRTUAL_ENV_PATH/lib/python2.7/site-packages:$PYTHONPATH # Concatenate all build requirements, ensure newline in between - - (echo; cat $HBP/ExperimentControl/hbp_nrp_excontrol/requirements.txt) >> hbp_nrp_music_interface/requirements.txt - - (echo; cat $HBP/CLE/hbp_nrp_cle/requirements.txt) >> hbp_nrp_music_interface/requirements.txt - - (echo; cat $HBP/ExDBackend/hbp_nrp_commons/requirements.txt) >> hbp_nrp_music_interface/requirements.txt + - (echo; cat $HBP/ExperimentControl/hbp_nrp_excontrol/requirements.txt) >> hbp_nrp_distributed_nest/requirements.txt + - (echo; cat $HBP/CLE/hbp_nrp_cle/requirements.txt) >> hbp_nrp_distributed_nest/requirements.txt + - (echo; cat $HBP/ExDBackend/hbp_nrp_commons/requirements.txt) >> hbp_nrp_distributed_nest/requirements.txt # Checkout config.ini.sample from user-scripts - cp $HBP/user-scripts/config_files/CLE/config.ini.sample $HBP/CLE/hbp_nrp_cle/hbp_nrp_cle/config.ini @@ -34,7 +34,7 @@ pipelines: # Generate schemas # Egg-links have to be removed because make devinstall set them up wrongly - - pushd $VIRTUAL_ENV_PATH/lib/python2.7/site-packages && rm -f hbp-nrp-music-interface.egg-link hbp-nrp-music-xml.egg-link hbp-nrp-distributed-nest.egg-link && popd + - pushd $VIRTUAL_ENV_PATH/lib/python2.7/site-packages && rm -f hbp-nrp-distributed-nest.egg-link && popd - make devinstall # Otherwise it can't find pyxbgen - export pyxb_version=`grep "pyxb" $HBP/ExDBackend/hbp_nrp_commons/requirements.txt` - . $VIRTUAL_ENV_PATH/bin/activate && pip install ${pyxb_version} && pyxbgen -u $HBP/Experiments/bibi_configuration.xsd -m bibi_api_gen && pyxbgen -u $HBP/Experiments/ExDConfFile.xsd -m exp_conf_api_gen && pyxbgen -u $HBP/Models/robot_model_configuration.xsd -m robot_conf_api_gen && pyxbgen -u $HBP/Models/environment_model_configuration.xsd -m environment_conf_api_gen @@ -43,11 +43,10 @@ pipelines: - deactivate # Run tests - # HOTFIX: Exclude music packages from pylint because of NRRPLT-6949 - - export IGNORE_LINT='platform_venv|hbp_nrp_music_xml|hbp_nrp_music_interface|hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated|migrations|nest' + - export IGNORE_LINT='platform_venv|migrations|nest' # Egg-links have to be removed because make devinstall set them up wrongly - - pushd $VIRTUAL_ENV_PATH/lib/python2.7/site-packages && rm -f hbp-nrp-music-interface.egg-link hbp-nrp-music-xml.egg-link hbp-nrp-distributed-nest.egg-link && popd - - . $VIRTUAL_ENV_PATH/bin/activate && source /opt/ros/kinetic/setup.$CURR_SHELL && echo "PYTHONPATH $PYTHONPATH" && make verify_base || { if [ -f pylint.txt ]; then echo "----------"; echo "PYLINT.TXT"; echo "----------";cat pylint.txt; fi; if [ -f pep8.txt ]; then echo "----------"; echo "PEP8.TXT"; echo "----------";cat pep8.txt; fi; exit 1; } + - pushd $VIRTUAL_ENV_PATH/lib/python2.7/site-packages && rm -f hbp-nrp-distributed-nest.egg-link && popd + - . $VIRTUAL_ENV_PATH/bin/activate && source /opt/ros/melodic/setup.$CURR_SHELL && echo "PYTHONPATH $PYTHONPATH" && make verify_base || { if [ -f pylint.txt ]; then echo "----------"; echo "PYLINT.TXT"; echo "----------";cat pylint.txt; fi; if [ -f pep8.txt ]; then echo "----------"; echo "PEP8.TXT"; echo "----------";cat pep8.txt; fi; exit 1; } # Coverage check - $HBP/admin-scripts/nrp_cobertura_check coverage.xml diff --git a/hbp_nrp_distributed_nest/README.txt b/hbp_nrp_distributed_nest/README.txt index 0fb57180fb95728c2db1fa2057d6b2b66b4afa29..b9e05ae684a37f64815af5cf7179d7cb30c96ee2 100644 --- a/hbp_nrp_distributed_nest/README.txt +++ b/hbp_nrp_distributed_nest/README.txt @@ -1,2 +1 @@ -This package provides interfaces for standalone distributed Nest simulation without -any MUSIC dependencies for the CLE/ExDBackend. \ No newline at end of file +This package provides interfaces for standalone distributed Nest simulation for the CLE/ExDBackend. \ No newline at end of file diff --git a/hbp_nrp_music_interface/MANIFEST.in b/hbp_nrp_music_interface/MANIFEST.in deleted file mode 100644 index 540b72040df162428003e7ff8fc4d46a80823bca..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include requirements.txt \ No newline at end of file diff --git a/hbp_nrp_music_interface/README.txt b/hbp_nrp_music_interface/README.txt deleted file mode 100644 index 532ebdf34e4750821140be3546e69436f85d4f78..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -This package provides interfaces between the generic MUSIC/PyNN hbp_nrp_music_xml -package and the CLE/ExDBackend by implementing and overriding required interfaces. diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/__init__.py deleted file mode 100644 index c87a8818168711e82488cbd7a3cdc54723199db9..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -This package contains NRP specific implementations utilizing the MUSIC XML configuration -and PyNN packages. -""" - -from hbp_nrp_music_interface.version import VERSION as __version__ # pylint: disable=W0611 - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/__init__.py deleted file mode 100644 index 227a3db2712622094b319b5830cb0eedffd0bcae..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -This package contains classes to translate from a parsed BIBI specification to -a MUSIC launch file and XML connectivity specification. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/bibi_music_config.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/bibi_music_config.py deleted file mode 100644 index be3a2ded9a6a3c25ab2def32d51c6c846ae88be3..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/bibi/bibi_music_config.py +++ /dev/null @@ -1,245 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Provdes a class to generate a MUSIC configuration from a BIBI configuration. -""" - -from hbp_nrp_commons.generated import bibi_api_gen # pylint:disable=no-name-in-module -from hbp_nrp_music_xml.schema.generated import music_xml -from hbp_nrp_music_xml.config.music_config import Application, MusicConfigWriter, MusicConfigPort - -import os -import logging - -logger = logging.getLogger(__name__) -logger.setLevel(logging.DEBUG) - - -class MUSICConfiguration(object): - """ - This class offers a high-level API for assembling MUSIC configuration that contains - ports between the Closed-Loop-Engine (CLE) and MUSIC-enabled neuro-simulators. - - The MUSIC configuration is assembled by converting a BIBI specification into a - synapse/neuron specification MUSIC XML representation and also produces a formatted - MUSIC script that can be used to launch the distributed simulation components. - """ - - # FIXME: [NRRPLT-4722] fudge factor for faux dynamic ports - FAUX_DYNAMIC_FUDGE_FACTOR = 5 - - def __init__(self, bibi): - """ - Convert the given BIBI configuration into a MUSIC XML configuration. - - :param bibi: A parsed BIBI file to convert. - """ - assert isinstance(bibi, bibi_api_gen.BIBIConfiguration) - - #TODO: The BIBI schema currently does not require population definitions, - # but they are required to properly generate a BIBI->MUSIC mapping. - # This check should be removed after the BIBI is updated and consistent - # for Python and h5 brains. - if bibi.brainModel.populations is None or len(bibi.brainModel.populations) == 0: - raise Exception("This BIBI file cannot be used for multi-process simulations " - "as it does not specify neuron populations in the brainModel " - "section. Please contact neurorobotics@humanbrainproject.eu if " - "you require assistance to update this file or restrict this " - "experiment to single process mode.") - - self.__conf_xml = music_xml.root() - self.__conf_script = None - - # construct the bidirectional xml port/synapse definitions - for bibi_population in bibi.brainModel.populations: - name = bibi_population.population - width = MUSICConfiguration.get_neuron_count(bibi_population) - music_population = self.__bibi_to_music_population(bibi_population) - - # FIXME: [NRRPLT-4722] Workaround for lack of dynamic MUSIC ports, allow the user - # <fudge> the size of the population for devices (the neurons will be frozen - # by default, which should not impact performance (too much)) - faux_w = width * MUSICConfiguration.FAUX_DYNAMIC_FUDGE_FACTOR - self.__add_port('%s_to_brain' % name, faux_w, 'CLE', 'BRAIN', name, music_population) - self.__add_port('%s_to_cle' % name, width, 'BRAIN', 'CLE', name, music_population) - - # empty dict of applications, CLE and BRAIN definitions are required - self.__applications = {} - - @staticmethod - def get_neuron_count(neurons): - """ - Gets the amount of neurons connected - - :param neurons: The neuron selector - :return: The amount of neurons as int - """ - if isinstance(neurons, bibi_api_gen.Index): - return 1 - elif isinstance(neurons, bibi_api_gen.Range): - if neurons.step is None: - return neurons.to - neurons.from_ - return (neurons.to - neurons.from_) / neurons.step - elif isinstance(neurons, bibi_api_gen.List): - return len(neurons.element) - elif isinstance(neurons, bibi_api_gen.Population): - return neurons.count - raise Exception("Neuron Count: Don't know how to process neuron selector " - + str(type(neurons))) - - def add_application(self, name, binary, args, processes): - """ - Add a sending or receiving MUSIC application definition. - - :param name: The application name, currently only CLE and BRAIN are supported. - :param binary: The binary to execute for this application. - :param args: A list of arguments to python. - :param processes: The number of processes to allocate for this application. - """ - if name not in ['CLE', 'BRAIN']: - raise Exception("Invalid application name {name} specified, must be " - "either CLE or BRAIN.".format(name=name)) - - if name in self.__applications: - raise Exception("Duplicate application definition for {name}, this does not " - "appear to be a valid request.".format(name=name)) - - self.__applications[name] = Application(name, binary, args, int(processes)) - - def save(self, path): - """ - Save the MUSIC XML and application configuration files to the specified directory. - - :patam path: The path of the directory to save to. - """ - - if 'CLE' not in self.__applications or 'BRAIN' not in self.__applications: - raise Exception('Missing CLE or BRAIN application definitions, cannote create MUSIC' - 'configuration script!') - - # write the xml connectivity specification to proxy.xml - proxy_file = os.path.join(path, 'proxy.xml') - with open(proxy_file, 'w') as f: - f.write(self.__conf_xml.toxml()) - - # write the actual music launching script to cle.music - music_file = os.path.join(path, 'cle.music') - with open(music_file, 'w') as f: - ports = [MusicConfigPort(p) for p in self.__conf_xml.port] - applications = [self.__applications['CLE'], self.__applications['BRAIN']] - self.__conf_script = MusicConfigWriter(None, applications, ports) - self.__conf_script.write(f) - - @staticmethod # required to avoid "no self use" pylint error - def __bibi_to_music_population(bibi_population): - """ - This function converts BIBI NeuronSelector object (population specification) into - a MUSIC-XML SynapticSelector objects. Currently only Range types are supported in - population definitions, but this function supports all potential types. - - :param bibi_population: A BIBI MultiNeuronSelector object - """ - - def make_list_selector(iterable): - """ - Helper function to create a list of neurons from multiple BIBI selector types. - - :param iterable: A list of neuron ids to add to this list selector. - """ - neuron_list = music_xml.ListSelector() - for element in iterable: - neuron_list.append(element) - return neuron_list - - if isinstance(bibi_population, bibi_api_gen.Range): - neuron_slice = music_xml.SliceSelector() - neuron_slice.start = bibi_population.from_ - neuron_slice.stop = bibi_population.to - step = getattr(bibi_population, 'step', 1) - if not step: - step = 1 - neuron_slice.step = step - return neuron_slice - - elif isinstance(bibi_population, bibi_api_gen.List): - return make_list_selector(bibi_population.element) - - elif isinstance(bibi_population, bibi_api_gen.Population): - return make_list_selector(list(range(0, bibi_population.count))) - - else: - raise Exception("The deduction from type {} (for population declaration " - "'{}') to the MUSIC equivalent population declaration " - "is not implemented".format(type(bibi_population), - bibi_population.population)) - - def __add_port(self, name, width, sender, receiver, target, selector): - """ - Generates a MUSIC XML spike event port for the named population with given width between - the specified source and target. - - :param name: Base name of the MUSIC port (NOT the population name). - :param width: The MUSIC port width (number of neurons to - :param sender: The name of the producing MUSIC application (e.g. CLE, BRAIN) - :param receiver: The name of the receiving MUSIC application (e.g. CLE, BRAIN) - :param target: The neuron population name to connect to/from. - :param selector: The MUSIC XML population selector (e.g. slice/etc.) - """ - - if sender not in ['CLE', 'BRAIN'] or receiver not in ['CLE', 'BRAIN']: - raise Exception("Invalid sender {sender} or receiver {receiver} specified, must be " - "either CLE or BRAIN.".format(sender=sender, receiver=receiver)) - - port = music_xml.Port() - port.type = music_xml.PortType.Event - port.name = name - port.width = width - port.sender = music_xml.Peer(name=sender) - port.receiver.append(music_xml.Peer(name=receiver)) - - synapse = music_xml.SynapticConnection() - synapse.type = music_xml.ConnectionType.one_to_one - synapse.target = target - synapse.selector = selector - port.receiver[0].synapse = [synapse] - - logger.debug("Created MUSIC port for spike event proxy: " - "{sender_name}.{port_name} ---/port_width:{port_width}/---> " - "{receiver_name}.{port_name}" - .format(sender_name=port.sender.name, port_width=port.width, - receiver_name=port.receiver[0].name, port_name=port.name)) - - self.__conf_xml.port.append(port) - - def __str__(self): - """ - Returns the formatted MUSIC configuration script as a string. - """ - return str(self.__conf_script) - - def xml(self): - """ - Returns the XML string representation of the underlying generated configuration. - """ - return str(self.__conf_xml.toxml()) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICBrainLoader.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICBrainLoader.py deleted file mode 100644 index fd43c6d2d21c8b11bc76ac30f572ae1dbc1a60a6..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICBrainLoader.py +++ /dev/null @@ -1,112 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -"""` -Load a brain network's MUSIC proxies -""" -import pyNN.nest as sim -import hbp_nrp_cle.tf_framework.config as tf_config - -from hbp_nrp_music_xml.pynn.factory import PyNNProxyFactory -from hbp_nrp_music_xml.pynn.connector_factory import PyNNConnectorFactory -from hbp_nrp_music_xml.pynn.xml_factory import XmlFactory - -import imp - -__brainIndex = 0 - - -# pylint: disable=global-statement -def load_proxies_from_xml(xml_file, **populations): - """ - Load neuron population proxy devices from the specified music_xml file and create a - mapping between population names and their proxy devices. This will allow the - communications adapter or any other components to lookup the appropriate input or - output proxy for a given named population. - - :param xml_file: Path to the music_xml ile containing proxy population definitions. - :param populations: A named list of population proxies to create - """ - - # ensure a Python brain module has not been loaded or set - if tf_config.brain_root is not None: - raise Exception("A brain module has been loaded in this process, no brain should be" - "present when loading MUSIC proxies. Invalid configuration, aborting.") - - # attempt to read the XML file, abort if doesn't exist or cannot be read - try: - with open(xml_file, 'r') as f: - xml = f.read() - except IOError: - raise Exception("Cannot create MUSIC proxy devices for simulation, unable to access " - "XML specification file {}. Aborting!".format(xml_file)) - - # simulator specific configuration (not through PyNN, make sure simulator is supported) - if sim.simulator.name != "NEST": - raise Exception("Unable to load MUSIC proxy devices for simulator {}, currently only " - "NEST is supported. Aborting!".format(sim.simulator.name)) - - # build proxy factories and store a dictionary of built proxies - proxy_model_factory = PyNNProxyFactory(sim) - connector_factory = PyNNConnectorFactory(sim) - xml_factory = XmlFactory("CLE", connector_factory, proxy_model_factory, {}) - proxy_dict = xml_factory.create_proxies(xml) - - # create a surrogate python brain module in place of loading the actual brain module - global __brainIndex - tf_config.brain_root = imp.new_module('__brain_model{}'.format(__brainIndex)) - __brainIndex += 1 - - # the CLE will only be able to access named proxy populations that were specified in the BIBI - # create a population -> proxy dictionary in the tf config so that the communications adapter - # can appropriately locate and use named input or output proxies as need - # store a proxy population in the root brain module for each population so that the existing - # tf framework can create population views without modification - understanding that the - # communications adapter will replace the base proxy with the input/output population as needed - try: - tf_config.music_proxies = {} - - for p in populations: - - # create population views to mimic how normal neuron populations are created - proxy_to_brain = proxy_dict['{}_to_brain'.format(p)] - proxy_to_brain_view = sim.PopulationView(proxy_to_brain, - slice(0, len(proxy_to_brain), None), - label=p) - proxy_to_cle = proxy_dict['{}_to_cle'.format(p)] - proxy_to_cle_view = sim.PopulationView(proxy_to_cle, - slice(0, len(proxy_to_cle), None), - label=p) - - # default named proxy population, a named population for p must be in the brain_root - # dictionary for transfer functions to create slices, but the correct population for - # a source or sink will be properly selected in the communication adapter, so this - # specification is arbitrary but definitely required - tf_config.brain_root.__dict__[p] = proxy_to_brain_view - - # store the named proxies by direction - tf_config.music_proxies[p] = {'source': proxy_to_brain_view, 'sink': proxy_to_cle_view} - - except KeyError: - raise Exception("Could not find proxy-specification of population {} in MUSIC " - "XML specification file: {}".format(p, xml_file)) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNCommunicationAdapter.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNCommunicationAdapter.py deleted file mode 100644 index 6588a936c3824763b508290b41e30fe0f0bfae45..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNCommunicationAdapter.py +++ /dev/null @@ -1,255 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Extensions of the base CLE PyNNCommunicationAdapter to use MUSIC specific proxies -instead of direct population access. Maxmimum code reuse and minimal duplication -where possible. -""" -from hbp_nrp_cle.brainsim.pynn_nest.PyNNNestCommunicationAdapter import PyNNNestCommunicationAdapter -import pyNN.nest as sim -import hbp_nrp_cle.tf_framework.config as tf_config - -from hbp_nrp_music_interface.bibi.bibi_music_config import MUSICConfiguration -from hbp_nrp_distributed_nest.launch.NestBrainProcess import NestBrainProcess - -from mpi4py import MPI - -import logging - -logger = logging.getLogger(__name__) - - -class MUSICPyNNCommunicationAdapter(PyNNNestCommunicationAdapter): - """ - Represents a MUSIC/PyNN proxy communication adapter for the neuronal simulation - """ - - def initialize(self): - """ - Marks the MUSICPyNN adapter as initialized. - """ - logger.info("MUSICPyNN communication adapter initialized") - super(MUSICPyNNCommunicationAdapter, self).initialize() - - def register_spike_source(self, populations, spike_generator_type, **params): - """ - Intercepts default PyNNNestCommunicationAdapter request and replaces specified - population with a new set of proxy neurons for each individual TF. This is required - to ensure weighting between the TF and target node is maintained properly as multiple - TFs can target a single neuron and we must weight their inputs separately. - - This function is over-complicated due to backwards comaptibility for the single process - CLE, it can be simplified in the future if we merge these repositories and especially - when MUSIC supports dynamic ports. - - :param populations: A reference to the populations to which the spike generator - should be connected - :param spike_generator_type: A spike generator type (see documentation - or a list of allowed values) - :param params: A dictionary of configuration parameters - :return: A communication object or a group of objects - """ - # get the next set of free parrot neurons with real connectivity to proxy_out neuron - proxies = self.__get_population_proxy(populations, 'source') - - # connect the device generator to the new proxy neurons, this will create synapses with - # given parameters that we will need to duplicate from proxy->real neuron (parrot neurons - # ignore their input synapses, but output synapses are respected) - device = super(MUSICPyNNCommunicationAdapter, self). \ - register_spike_source(proxies, spike_generator_type, **params) - - # notify the remote brain processes that they need to setup the other side of this proxy - self.__notify_brain_processes(populations, proxies) - - # return the new generator device - return device - - def register_spike_sink(self, populations, spike_detector_type, **params): - """ - Requests a communication object with the given spike detector type - for the given set of neurons - - :param populations: A reference to the populations which should be connected - to the spike detector - :param spike_detector_type: A spike detector type (see documentation - for a list of allowed values) - :param params: A dictionary of configuration parameters - :return: A Communication object or a group of objects - """ - populations = self.__get_population_proxy(populations, 'sink') - return super(MUSICPyNNCommunicationAdapter, self). \ - register_spike_sink(populations, spike_detector_type, **params) - - @staticmethod - def __notify_brain_processes(populations, proxies): - """ - Notify remote MPI Brain Processes that they must complete this transfer function - connection by duplicating the parameters for this device connection with the output - proxy neurons. This is the only way to ensure a TF is actually connected with the - right parameters. - - :param populations The target population to connect to on the other side. - :param proxies The proxy/parrot neurons that the device is actually connected to. - """ - - # nest is the only supported simulator in the hbp_nrp_music packages, but assert here - # in case this changes, import here to avoid starting nest by accident earlier - assert sim.simulator.name == "NEST", "NEST is currently required to reconfigure MUSIC ports" - import nest - - # synapse details to pass to other MPI clients, the synapse parameters should all be - # the same, but in the future a device may have variable/randomly parameterized - # synapses so just support them now - synapse_params = [] - - # for each proxy/reference pair, extract input connectivity from the device, the real - # reference output targets, and finally duplicate the input connectivity to the targets - for p in map(int, proxies.all_cells): - - # the reference connection from the parrot neuron to proxy out, this contains music - # channel information - ref_c = nest.GetStatus(nest.GetConnections(source=[p]))[0] - channel = ref_c['receptor'] - - # the connection from device to parrot neuron, our desired synapse - dev_c = nest.GetStatus(nest.GetConnections(target=[p]))[0] - model = str(dev_c['synapse_model']) - - # remove specific connection information, only leave synapse params since - # otherwise nest will complain about unused values - for k in ['receptor', 'source', 'target', 'synapse_label', 'synapse_model', 'sizeof']: - if k in dev_c: - dev_c.pop(k) - - # override the original dummy weighted parrot->proxy synapse, we can't create a - # new synapse because MUSIC will complain about duplicate use of music_channels - nest.SetStatus(nest.GetConnections(source=[p]), dev_c) - - # store the connection parameters for remote clients - dev_c['model'] = model - dev_c['music_channel'] = channel - synapse_params.append(dev_c) - - # population information to send to the remote MPI nodes, we can't pickle Populations - # directly and those references wouldn't be valid on the remote nodes anyway - label = populations.parent.label if populations.parent else populations.label - - # [NRRPLT-4722] workaround, if there is no population mask, then we need to use the size - # of the proxies to target the real size of the neuron population instead of the inflated - # proxy size - mask = populations.mask if populations.mask else slice(0, len(proxies), 1) - - # propagate the synapse creation parameters to all remote notes, they will create the - # other side of the connections for this type - for rank in xrange(MPI.COMM_WORLD.Get_size()): - if rank == MPI.COMM_WORLD.Get_rank(): - continue - - MPI.COMM_WORLD.send({'command': 'ConnectTF', 'label': label, 'mask': mask, - 'synapses': synapse_params}, - dest=rank, tag=NestBrainProcess.MPI_MSG_TAG) - - def __get_population_proxy(self, population, proxy_type): - """ - Retrieves the first <size> free proxy neurons of the specified population proxy type - for a given population. - - :param population The population to find/create a proxy for. - :param proxy_type string The type of proxy device to retrieve. - :return: An equivalend population list or view containing proxies. - """ - if proxy_type not in ['sink', 'source']: - raise TypeError("Cannot retrieve unknown population proxy type: {}" % proxy_type) - - # lists are explicitly allowed by __register_device, support even if they are unused - if isinstance(population, list): - return [self.__get_population_proxy(p, proxy_type) for p in population] - - assert isinstance(population, sim.PopulationView) - try: - - # for sinks we must use the same few neurons that are allocated at MUSIC launch - # otherwise the frontend will not properly fill out the neuron monitor and things - if proxy_type == 'sink': - # top level population view with no subslicing (e.g. sensors, actors, etc.) - if isinstance(population.parent, sim.Population): - # tf_config.music_proxies is set in - # hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICBrainLoader.py - # and not in hbp_nrp_cle.tf_framework.config - # which confuses pylint - # pylint: disable=no-member - return tf_config.music_proxies[population.label][proxy_type] - # pylint: enable=no-member - - # otherwise, this is a view of a top level named population view - # pylint: disable=no-member - parent = tf_config.music_proxies[population.parent.label][proxy_type] - # pylint: enable=no-member - return sim.PopulationView(parent, population.mask, population.label) - - # [NRRPLT-4722] workaround, simply get the first <size> proxy neurons that are - # frozen for a population, unfreeze and return them for connection, for full - # population requests only get the real population size - import nest - # top level population view with no subslicing (e.g. sensors, actors, etc.) - # pylint: disable=no-member - if isinstance(population.parent, sim.Population): - proxies = tf_config.music_proxies[population.label][proxy_type] - size = proxies.size / MUSICConfiguration.FAUX_DYNAMIC_FUDGE_FACTOR - - # otherwise, this is a view of a top level named population view - else: - proxies = tf_config.music_proxies[population.parent.label][proxy_type] - size = population.size - # pylint: disable=no-member - # find all of the free/frozen proxy neurons - mask = [] - for i, p in enumerate(map(int, proxies.all_cells)): - - # if the neuron is frozen, unfreeze it and add to our list - if nest.GetStatus([p], 'frozen')[0]: - nest.SetStatus([p], 'frozen', False) - mask.append(i) - - # stop looping when we have enough free neurons - if len(mask) == size: - break - - # make sure we have enough free proxy neurons - if len(mask) != size: - raise Exception("Not enough free proxy neurons to connect transfer functions!\n" - "Please contact neurorobotics@humanbrainproject.eu with details of " - "this experiment and associated BIBI file if you require support.") - - # return a view of the free proxy neurons for connection - return sim.PopulationView(proxies, mask, population.label) - - except KeyError: - raise Exception("Unable to locate distriuted MUSIC neuron population proxies for {}.\n" - "This likely means that a transfer function is utilizing a neuron " - "population that is not specified at the top of the BIBI file or is" - "attempting to directly access the underlying \"circuit\" population." - "Please contact neurorobotics@humanbrainproject.eu with details of " - "this experiment and associated BIBI file if you require support." - .format(population)) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNControlAdapter.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNControlAdapter.py deleted file mode 100644 index 2d003a6d17433b8df776c1a59d434775e16bf972..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/MUSICPyNNControlAdapter.py +++ /dev/null @@ -1,74 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Extensions of the base CLE PyNNControlAdapter to use MUSIC specific proxies -instead of direct population access. Maxmimum code reuse and minimal duplication -where possible. -""" -from hbp_nrp_distributed_nest.cle.DistributedPyNNControlAdapter import DistributedPyNNControlAdapter -from hbp_nrp_music_interface.cle import MUSICBrainLoader - -import music -import logging -import os - -logger = logging.getLogger(__name__) - - -class MUSICPyNNControlAdapter(DistributedPyNNControlAdapter): - """ - Represents a MUSIC/PyNN proxy controller object for the neuronal simulator - """ - - def load_brain(self, network_file, **populations): - """ - Load MUSIC/PyNN brain proxy populations rather than loading and instantiating - the brain - overrides functionality for both python and h5 brains. - - :param network_file: The path to the python file containing the network - :param populations: A named list of populations to create - """ - self.__load_music_brain_proxies(**populations) - - # load the brain source for the frontend to display, copied from parent class - logger.info("Saving brain source") - import hbp_nrp_cle.tf_framework.config as tf_config - with open(network_file) as source: - tf_config.brain_source = source.read() - - @staticmethod - def __load_music_brain_proxies(**populations): - """ - Load MUSIC proxy devices for the given brain network specification and create - mappings from populations to input/output proxy devices. - - :param populations: A named list of populations to create - """ - - # initialize MUSIC and load proxies from the MUSIC proxy xml - logger.info("Loading MUSIC proxy brain devices.") - music.Setup() - music_path = os.environ.get('NRP_MUSIC_DIRECTORY') - proxy_file = os.path.join(music_path, 'proxy.xml') - MUSICBrainLoader.load_proxies_from_xml(proxy_file, **populations) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/__init__.py deleted file mode 100644 index fb359f2794eb655a536b7573e1c68cc20bbef467..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/cle/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -This package contains an extended implementation of the CLE PyNN Brain Control Adapter -and Brain Loader that use MUSIC proxy interfaces rather than direct access. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICBrainProcess.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICBrainProcess.py deleted file mode 100644 index 1def9d868b1e79a07514ade2135e8ce86bf50e81..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICBrainProcess.py +++ /dev/null @@ -1,166 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -A distributed MUSIC brain process that can be launched standalone on remote hosts. -""" -import hbp_nrp_cle.brainsim.pynn_nest # pylint: disable=unused-import - -from hbp_nrp_distributed_nest.launch.NestBrainProcess import NestBrainProcess - -import pyNN.nest as sim -import hbp_nrp_cle.tf_framework.config as tf_config - -from hbp_nrp_music_xml.pynn.factory import PyNNProxyFactory -from hbp_nrp_music_xml.pynn.connector_factory import PyNNConnectorFactory -from hbp_nrp_music_xml.pynn.xml_factory import XmlFactory - -import argparse -import os -import music - -from mpi4py import MPI -import traceback - - -class MUSICBrainProcess(NestBrainProcess): - """ - A distributed MUSIC brain process that can be launched standalone on remote hosts. - """ - - def __init__(self, bibi_file, rng_seed): - """ - Load the distributed brain and construct MUSIC proxies for communication - to/from the CLE. Nest will automatically allocate the brain in a round-robin - fashion under the hood, we do not need to do anything explicitly. - - :param bibi_file The absolute path to the BIBI file for this experiment. - """ - - # setup MUSIC before any brain loading attempt - self._music_setup = music.Setup() - - # load the brain and set parameters - super(MUSICBrainProcess, self).__init__(bibi_file, rng_seed) - - # load the MUSIC proxies for the spawned brain - music_path = os.environ.get('NRP_MUSIC_DIRECTORY') - proxy_file = os.path.join(music_path, 'proxy.xml') - with open(proxy_file, 'r') as f: - music_xml = f.read() - - proxy_model_factory = PyNNProxyFactory(sim) - connector_factory = PyNNConnectorFactory(sim) - xml_factory = XmlFactory("BRAIN", - connector_factory, - proxy_model_factory, - tf_config.brain_root.__dict__) - - self._proxies = xml_factory.create_proxies(music_xml) - - def _connect_tf(self, params): - """ - Reflect a transfer function connection made on the CLE side by connecting proxy neurons - to real brain neurons using the same parameters and connectivity as the CLE. This is the - only way to guarantee both sides share the same connectivity using static port allocation. - - :param params The connectivity/synapse parameters passed by the CLE. - """ - - # connections only supported during simulation construction - if self._ready: - raise Exception("The distributed MUSIC-Nest implementation does not dynamic TFs!") - - # get the population of neurons from our dictionary, we can guarantee this is a valid - # population that has been declared in the BIBI at this point as the CLE will validate - # before sending us the create message - brain_pop = sim.PopulationView(tf_config.brain_root.__dict__[params['label']], - selector=params['mask']) - - # get the whole population of proxy neurons for this port - port_name = '%s_to_brain' % params['label'] - proxies = self._proxies[port_name] - - # this is Nest specific code, but so is the rest of the pipeline - assert sim.simulator.name == "NEST", "Currently only NEST is supported" - import nest - - # iterate through synapses and connect the specific proxy neuron (via music channel) to real - # brain neuron with given parameters - for synapse, brain_neuron in zip(params['synapses'], map(int, brain_pop.all_cells)): - - # get the proxy neuron at the channel index - proxy = proxies[synapse['music_channel']] - synapse.pop('music_channel') - - # thaw the proxy neuron so we actually get data - nest.SetStatus([proxy], 'frozen', False) - - # for a source, we only need to connect the input proxy to the real neuron - nest.Connect([proxy], [brain_neuron], syn_spec=synapse) - - def _delete_tf(self, params): - """ - Currently unsupported, unable to dynamically create or destroy MUSIC ports. - """ - - # ignore any commands during simulation construction - if not self._ready: - return - - raise Exception("The distributed MUSIC-Nest implementation does not support TF deletion!") - - def _load_brain(self, params): - """ - Currently unsupported, unable to dynamically create or destroy MUSIC ports. - """ - - # ignore any commands during simulation construction - if not self._ready: - return - - raise Exception("The distributed MUSIC-Nest implementation does not support brain changes!") - - -if __name__ == '__main__': # pragma: no cover - - try: - parser = argparse.ArgumentParser() - parser.add_argument('--bibi-file', dest='bibi_file', - help='the bibi file path to load', required=True) - parser.add_argument('--rng-seed', dest='rng_seed', - help='the global experiment RNG seed', required=True) - args = parser.parse_args() - - # construct brain and proxies (expand environment variables in paths) - brain = MUSICBrainProcess(os.path.expandvars(args.bibi_file), args.rng_seed) - - # run the brain until terminated, this is a blocking call - brain.run() - - except Exception: # pylint: disable=broad-except - # print the traceback which should go back to the remote logger - traceback.print_exc() - - # for any failures, terminate all other brain processes and the CLE - MPI.COMM_WORLD.Abort(-1) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICCLEProcess.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICCLEProcess.py deleted file mode 100644 index cb149af5a46f61fe009dbf55cf58534889f8c0d3..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICCLEProcess.py +++ /dev/null @@ -1,86 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -This module contains the CLE process logic for the simulation assembly using MUSIC -""" - -import logging -import sys - -from hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly import CLEGazeboSimulationAssembly -from hbp_nrp_cleserver.server.ServerConfigurations import robot_gazebo_ros_adapters -from hbp_nrp_music_interface.cle.MUSICPyNNCommunicationAdapter import MUSICPyNNCommunicationAdapter -from hbp_nrp_music_interface.cle.MUSICPyNNControlAdapter import MUSICPyNNControlAdapter - -from hbp_nrp_distributed_nest.launch.DistributedCLEProcess import launch_cle - -# maintain this import order and both must be done before mpi4py -import hbp_nrp_cle.brainsim.pynn_nest # pylint: disable=unused-import -import pyNN.nest as nestsim -import music - -logger = logging.getLogger(__name__) - - -class MusicCLESimulationAssembly(CLEGazeboSimulationAssembly): - """ - Defines the assembly of a simulation using MUSIC - """ - - def __init__(self, sim_id, exc, bibi_model, **par): - """ - Creates a new simulation assembly to simulate an experiment using the CLE and Gazebo - :param sim_id: The simulation id - :param exc: The experiment configuration - :param bibi_model: The BIBI configuration - """ - super(MusicCLESimulationAssembly, self).__init__(sim_id, exc, bibi_model, **par) - - def _create_robot_adapters(self): - """ - Creates the adapter components for the robot side - - :return: A tuple of the communication and control adapter for the robot side - """ - return robot_gazebo_ros_adapters() - - def _create_brain_adapters(self): - """ - Creates the adapter components for the neural simulator - - :return: A tuple of the communication and control adapter for the neural simulator - """ - logger.info('Using MUSIC configuration and adapters for CLE') - - # initialize music and set the CLE to use MUSIC adapters - music.Setup() - - braincomm = MUSICPyNNCommunicationAdapter() - braincontrol = MUSICPyNNControlAdapter(nestsim) - return braincomm, braincontrol - -if __name__ == '__main__': # pragma: no cover - - # guaranteed to only be launched in one process by MUSIC, launch the CLE with defined assembly - launch_cle(sys.argv[1:], MusicCLESimulationAssembly) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICLauncher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICLauncher.py deleted file mode 100644 index 5da6eada36cc12acf21bda094737721a35a576e4..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICLauncher.py +++ /dev/null @@ -1,118 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Setup, build, and launch a distributed MUSIC instance that will spawn the CLE and -requested brain processes. -""" -from hbp_nrp_distributed_nest.launch.NestLauncher import NestLauncher - -from hbp_nrp_music_interface.bibi import bibi_music_config -from hbp_nrp_music_interface.launch.MUSICMPILauncher import MUSICMPILauncher -from hbp_nrp_music_interface.launch.host.LocalLauncher import LocalLauncher -from hbp_nrp_music_interface.launch.host.LuganoLauncher import LuganoLauncher - -import os - - -# This class intentionally does not inherit SimulationServer (even though it is an implementation of -# it) in order to avoid duplicate notificators -class MUSICLauncher(NestLauncher): - """ - Setup, build, and launch a distributed MUSIC instance that will spawn the CLE and - requested brain processes. - """ - - def __init__(self, sim_id, exc, bibi, **par): - """ - Store all experiment configuration parameters so that they can be propagated - to the remote hosts. - - :param exc: the experiment configuration - :param bibi: the BIBI configuration. - :param server_host Target Gazebo/brain process host (e.g. local or lugano) - :param reservation Reservation string for cluster backend (None is a valid option) - :param sim_id The id of the simulation/experiment to be launched. - :param timeout The default simulation timeout (time initially allocated). - """ - super(MUSICLauncher, self).__init__(sim_id, exc, bibi, **par) - - # we should call the except_hook when something goes wrong in the simulation, but currently - # we don't - # pylint: disable=unused-argument - def initialize(self, environment_file, except_hook): - """ - Construct the MUSIC launch configuration that will spawn CLE + brain processes - on distributed hosts. - """ - - # extract the environment file path - nrp_models_path = os.environ.get('NRP_MODELS_DIRECTORY').rstrip('/') - self._env_file = environment_file.replace(nrp_models_path, '$NRP_MODELS_DIRECTORY') - - # create a host specific launcher - if self._server_host == 'local': - self._launcher = LocalLauncher() - elif self._server_host == 'lugano': - self._launcher = LuganoLauncher(self._exc.bibiConf.processes + 1, - self._timeout, - self._reservation) - else: - raise Exception('Unknown server host {}, cannot configure and launch MUSIC!' - .format(self._server_host)) - - # create launch scripts for the CLE and brain processes - cle_launcher, brain_launcher = self._launcher.create_launch_scripts() - - # command line argument friendly versions of timeout and reservation arguments - # the receiving processes must understand how to convert these back - reservation_str = self._reservation if self._reservation else '' - timeout_str = str(self._timeout).replace(' ', '_') - - # build a MUSIC configuration script with correct brain ports, launchers and arugments - # save it to the host launcher temp directory, this is the same for every host - music_conf = bibi_music_config.MUSICConfiguration(self._bibi) - music_conf.add_application('CLE', - cle_launcher, - ['--exdconf={}'.format(self._exd_file), - '--bibi={}'.format(self._bibi_file), - '--environment={}'.format(self._env_file), - '--experiment-path={}'.format(self._exp_path), - '--gzserver-host={}'.format(self._server_host), - '--reservation={}'.format(reservation_str), - '--sim-id={}'.format(self._sim_id), - '--timeout={}'.format(timeout_str), - '--rng-seed={}'.format(self._rng_seed)], - 1) - music_conf.add_application('BRAIN', - brain_launcher, - ['--bibi-file={}'.format(self._bibi_file), - '--rng-seed={}'.format(self._rng_seed)], - self._exc.bibiConf.processes) - music_conf.save(self._launcher.local_tmpdir) - - # construct the actual MPI launcher - self.mpilauncher = MUSICMPILauncher('music cle.music') - - # build and deploy configuration - self._build() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICMPILauncher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICMPILauncher.py deleted file mode 100644 index 0bc240f58ce3e6e8dfa3462130c69bab314f4fee..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/MUSICMPILauncher.py +++ /dev/null @@ -1,53 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END - -""" -Helper class to build and execute a formatted mpirun command for music in the format: - - mpirun -envlist <vars> -np <proc> -host <hostname/ip> -wdir <temporary work dir> <command> : ... - -where each of the hosts has a specific working directory with necessary config files already -in place. Also passes environment variables required for NRP/CLE execution. -""" -from hbp_nrp_distributed_nest.launch.MPILauncher import MPILauncher - - -class MUSICMPILauncher(MPILauncher): - """ - Class constructs and executes the MUSIC mpi launch command. - """ - - def __init__(self, executable): - super(MUSICMPILauncher, self).__init__(executable) - - def add_host(self, hostname, tmpdir, processes=1): - """ - Add a target host to the mpi launch configuration with MUSIC working directory set. - - :param hostname The remote host name or ip. - :param tmpdir A valid temporary directory on the remote host to launch in. - :param processes The number of processes for this host. - """ - self._hosts.append('-np {p} -host {h} -wdir {t} -genv NRP_MUSIC_DIRECTORY {t}' - .format(p=processes, h=hostname, t=tmpdir)) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/__init__.py deleted file mode 100644 index e0b1e74bbc18480ae7de5d7997a351b67414eaf9..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -This package contains classes related to launching a distributed -MUSIC/PyNN/NEST simulation within the NRP. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LocalLauncher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LocalLauncher.py deleted file mode 100644 index c383c02af04ec9bf3e71ebcc6196140c5258ceee..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LocalLauncher.py +++ /dev/null @@ -1,88 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -localhost launch target configuration. -""" - -from hbp_nrp_distributed_nest.launch.host.LocalLauncher import LocalLauncher as ILocalLauncher - -import os -import stat -import sys - - -class LocalLauncher(ILocalLauncher): - """ - This launch configuration targets the localhost for all processes and is suitable for local - installs or deployed installs where the newly spawned processes can run on the same host - as the REST backend. - """ - - def __init__(self): - """ - Create a local launcher to target localhost and create a local temporary directory to - write MUSIC configuration files. - """ - super(LocalLauncher, self).__init__() - - def create_launch_scripts(self): - """ - Create a set of launch scripts for the CLE and individual brain processes with specific - implementations required for each host. Write the launch scripts to the temporary directory - for this launcher. - - Returns a tuple (path to CLE launch script, path to BrainProcess launc script). - """ - # create .sh launcher scripts for the CLE and brain processes - cle_launcher = self._create_launch_script('music_cle_launcher.sh', - 'hbp_nrp_music_interface.launch.MUSICCLEProcess') - brain_launcher = self._create_launch_script('music_brain_launcher.sh', - 'hbp_nrp_music_interface.launch.' + - 'MUSICBrainProcess') - return (cle_launcher, brain_launcher) - - def _create_launch_script(self, name, module): - """ - Create an executable script in the working temporary folder to launch the specified - Python module. These will be used by the MUSIC runtime on each of the hosts since there - are some quirks in launching "python -m <module> with <args>" directly throug MUSIC. - - :param name The name for the launch script to create. - :param module The python module to launch with this script. - :return The absolute path to this launch script. - """ - - # absolute path to script in tmpdir - path = os.path.join(self._local_tmpdir, name) - - # use the absolute path of the Python interpreter for our current process, this current - # process will not be executed through uwsgi, so this will be the correct interpreter - with open(path, 'w') as f: - f.write('#!/bin/bash\n') - f.write('{python} -m {module}\n'.format(python=sys.executable, module=module)) - - os.chmod(path, stat.S_IRWXU) - - # return a relative path to the script, it's guaranteed to be run in the tmpdir - return './%s' % name diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LuganoLauncher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LuganoLauncher.py deleted file mode 100644 index 86e603288a0dfc502cfd0a3a208546d52af8e9d1..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/LuganoLauncher.py +++ /dev/null @@ -1,170 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Lugano vizcluster launch target configuration. -""" - -from hbp_nrp_music_interface.launch.host.LocalLauncher import LocalLauncher - -from hbp_nrp_commons.cluster.LuganoVizCluster import LuganoVizCluster - -from hbp_nrp_cle.cle import config - -import netifaces -import os -import stat - - -class LuganoLauncher(LuganoVizCluster, LocalLauncher): - """ - This launch configuration targets the Lugano vizcluster and handles brain/CLE process - allocation and distribution. This is executed before the CLE is launched, so launching will - immediately terminate if there are not enough cluster resources. - """ - - def __init__(self, processes, timeout, reservation): - """ - Immediately attempt to allocate cluster resources for the brain processes. If this fails - or causes Exceptions, it will be propagated up to the user appropriately. - - :param processes The total number of processes (brain + CLE) to reserve. - :param timeout The simulation timeout required by the vizcluster launcher. - :param reservation Resource reservation string to access reserved nodes. - """ - - # ensure both constructors are called, raise Exception if allocation fails - try: - super(LuganoLauncher, self).__init__(processes, 0, timeout.tzinfo, reservation) - self._allocate_job(reuse_nodes=True) # multiple brains can run on the same node - finally: - LocalLauncher.__init__(self) - - # override hostname with allocated node, remote tmp does not exist until written - self._hostname = self._node - self._host_tmpdir = None - - def _create_launch_script(self, name, module): - """ - Create an executable script in the working temporary folder to launch the specified - Python module. These will be used by the MUSIC runtime on each of the hosts since there - are some quirks in launching "python -m <module> with <args>" directly throug MUSIC. - - Handle specific vizcluster configuration (modules and environment). - - :param name The name for the launch script to create. - :param module The python module to launch with this script. - :return The absolute path to this launch script on the remote host. - """ - - # absolute path to script in local tmpdir - path = os.path.join(self._local_tmpdir, name) - - # determine if we are running on a dev or staging environment - environment = os.environ.get('ENVIRONMENT') - - # set the ROS master uri to use an actual IP instead of localhost - ifaddress = netifaces.ifaddresses(config.config.get('network', 'main-interface')) - local_ip = ifaddress[netifaces.AF_INET][0]['addr'] - ros_master_uri = os.environ.get("ROS_MASTER_URI").replace('localhost', local_ip) - - # create a launch script that configures the vizcluster environment properly - with open(path, 'w') as f: - f.write('#!/bin/bash\n') - f.write('source /opt/rh/python27/enable\n') - - # set the terminal type to ensure we get the same behavior as from a backend VM - # this is also required in the Docker images - f.write('export TERM=linux\n') - - # set the environment version and any specific module versions to be used, then - # override the environment variable to the deployed location on the remote host - f.write('source $NRP_MUSIC_DIRECTORY/nrp-variables\n') - f.write('export NRP_VARIABLES_PATH=$NRP_MUSIC_DIRECTORY/nrp-variables\n') - - # load the environment modules based on the above configuration - proj_path = '/gpfs/bbp.cscs.ch/project/proj30/neurorobotics/%s/' % environment - f.write('source %s/server-scripts/nrp-services-modules.sh\n' % proj_path) - - # set paths to models/experiments directory on gpfs - f.write('export NRP_MODELS_DIRECTORY=%s/models\n' % proj_path) - f.write('export NRP_EXPERIMENTS_DIRECTORY=%s/experiments\n' % proj_path) - - # set the PYTHONPATH to add NRP modules on gpfs - venv_path = '%s/platform_venv/lib/python2.7/site-packages' % proj_path - f.write('export PYTHONPATH=%s:$PYTHONPATH\n' % venv_path) - - # configure ROS and source the ros_venv before launching - f.write('export ROS_MASTER_URI=%s\n' % ros_master_uri) - f.write('source $ROS_PYTHON_VENV/bin/activate\n') - - # actually launch the module - f.write('python -m {module}\n'.format(module=module)) - - # ensure the script is executable - os.chmod(path, stat.S_IRWXU) - - # return a relative path to the script, it's guaranteed to be run in the tmpdir - return './%s' % name - - def deploy(self): - """ - Copy all configuration files to a temp directory on the remote host. The remote directory - is created here, so use it to set the launcher interface host tmpdir value. - """ - - # generated configuration files - for f in os.listdir(self._local_tmpdir): - self._copy_to_remote(os.path.join(self._local_tmpdir, f)) - - # deploy any NRP specific variable/module version configuration - self._copy_to_remote(os.environ.get('NRP_VARIABLES_PATH')) - - # set the host tmpdir, slightly different naming convention between interfaces - self._host_tmpdir = self._tmp_dir - - def shutdown(self): - """ - Shutdown by trying to kill any running processes and deleting the temporary directory on the - remote allocated node and localhost. Both are guaranteed to exist by the constructor. - """ - - # try to terminate any processes running on the allocated node, they should already be - # terminated before we get here, catch any Exceptions and ensure we cleanup below - if self._host_tmpdir: - try: - # terminate any processes, remote directory will be deleted by parent cleanup - clean_process = self._spawn_ssh_node() - clean_process.sendline('for L in %s/*.lock ; do kill -9 `basename $L .lock`; done' % - self._host_tmpdir) - clean_process.terminate() - except Exception: # pylint: disable=broad-except - pass - finally: - self._host_tmpdir = None - - # delete the remote temp directory and deallocate the node - LuganoVizCluster.stop(self) - - # cleanup any local processes and delete the remote temp directory - LocalLauncher.shutdown(self) diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/__init__.py deleted file mode 100644 index 51aa846aea3a0f9b4eef897d920cd5b5252a503a..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/launch/host/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This package contains host specific implementations for distributed MUSIC targets. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/__init__.py deleted file mode 100644 index ec4a4d00bbdea0e1258944d3c093a89c0cf067d9..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This package contains all tests for the MUSIC interface package. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/__init__.py deleted file mode 100644 index 7366ab6055d5532576bbe86566a43568a0e63f14..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This package contains all tests for the MUSIC BIBI interface package. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/bibi.xml b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/bibi.xml deleted file mode 100644 index 7416897e6a882121d02befa309b7a3148965a509..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/bibi.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<bibi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.humanbrainproject.eu/SP10/2014/BIBI" xsi:schemaLocation="http://schemas.humanbrainproject.eu/SP10/2014/BIBI bibi_configuration.xsd"> - <brainModel> - <file>fake_brain.py</file> - <populations population="range" xsi:type="Range" from="0" to="2"/> - <populations population="list" xsi:type="List"> - <element>3</element> - <element>4</element> - <element>5</element> - </populations> - <populations population="population" xsi:type="Population" count="10"/> - </brainModel> - <bodyModel>fake_model.sdf</bodyModel> -</bibi> diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.music b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.music deleted file mode 100644 index c3235d0cce0bf890c9353965f28929fe276dddc4..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.music +++ /dev/null @@ -1,16 +0,0 @@ -[CLE] -np = 4 -binary = cle_binary -args = - -[BRAIN] -np = 2 -binary = brain_binary -args = "--brain --args" - -CLE.range_to_brain -> BRAIN.range_to_brain [10] -BRAIN.range_to_cle -> CLE.range_to_cle [2] -CLE.list_to_brain -> BRAIN.list_to_brain [15] -BRAIN.list_to_cle -> CLE.list_to_cle [3] -CLE.population_to_brain -> BRAIN.population_to_brain [50] -BRAIN.population_to_cle -> CLE.population_to_cle [10] diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.xml b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.xml deleted file mode 100644 index 89b9261bcbd1ede68f0b2e5690294548006f788c..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/config.xml +++ /dev/null @@ -1,137 +0,0 @@ -<?xml version="1.0"?> -<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <port> - <type>Event</type> - <name>range_to_brain</name> - <width>10</width> - <sender> - <name>CLE</name> - </sender> - <receiver> - <name>BRAIN</name> - <synapse> - <target>range</target> - <type>one_to_one</type> - <selector xsi:type="SliceSelector"> - <start>0</start> - <stop>2</stop> - <step>1</step> - </selector> - </synapse> - </receiver> - </port> - <port> - <type>Event</type> - <name>range_to_cle</name> - <width>2</width> - <sender> - <name>BRAIN</name> - </sender> - <receiver> - <name>CLE</name> - <synapse> - <target>range</target> - <type>one_to_one</type> - <selector xsi:type="SliceSelector"> - <start>0</start> - <stop>2</stop> - <step>1</step> - </selector> - </synapse> - </receiver> - </port> - <port> - <type>Event</type> - <name>list_to_brain</name> - <width>15</width> - <sender> - <name>CLE</name> - </sender> - <receiver> - <name>BRAIN</name> - <synapse> - <target>list</target> - <type>one_to_one</type> - <selector xsi:type="ListSelector"> - <element>3</element> - <element>4</element> - <element>5</element> - </selector> - </synapse> - </receiver> - </port> - <port> - <type>Event</type> - <name>list_to_cle</name> - <width>3</width> - <sender> - <name>BRAIN</name> - </sender> - <receiver> - <name>CLE</name> - <synapse> - <target>list</target> - <type>one_to_one</type> - <selector xsi:type="ListSelector"> - <element>3</element> - <element>4</element> - <element>5</element> - </selector> - </synapse> - </receiver> - </port> - <port> - <type>Event</type> - <name>population_to_brain</name> - <width>50</width> - <sender> - <name>CLE</name> - </sender> - <receiver> - <name>BRAIN</name> - <synapse> - <target>population</target> - <type>one_to_one</type> - <selector xsi:type="ListSelector"> - <element>0</element> - <element>1</element> - <element>2</element> - <element>3</element> - <element>4</element> - <element>5</element> - <element>6</element> - <element>7</element> - <element>8</element> - <element>9</element> - </selector> - </synapse> - </receiver> - </port> - <port> - <type>Event</type> - <name>population_to_cle</name> - <width>10</width> - <sender> - <name>BRAIN</name> - </sender> - <receiver> - <name>CLE</name> - <synapse> - <target>population</target> - <type>one_to_one</type> - <selector xsi:type="ListSelector"> - <element>0</element> - <element>1</element> - <element>2</element> - <element>3</element> - <element>4</element> - <element>5</element> - <element>6</element> - <element>7</element> - <element>8</element> - <element>9</element> - </selector> - </synapse> - </receiver> - </port> -</root> diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/test_bibi_music_config.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/test_bibi_music_config.py deleted file mode 100644 index 55bf4fc026dc9deb707d3be5fc9d78c4824b950d..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/bibi/test_bibi_music_config.py +++ /dev/null @@ -1,91 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.bibi.bibi_music_config import MUSICConfiguration -import hbp_nrp_commons.generated.bibi_api_gen as api - -from mock import Mock, patch -import os - - -class TestMusicConfiguration(unittest.TestCase): - - def setUp(self): - self._path = os.path.dirname(os.path.realpath(__file__)) - - # valid bibi with all supported population types - bibi_file = os.path.join(self._path, "bibi.xml") - with open(bibi_file) as f: - self._bibi = api.CreateFromDocument(f.read()) - - # expected xml generated - xml_file = os.path.join(self._path, "config.xml") - with open(xml_file) as f: - self._xml = "".join(f.read().split()) - - # expected script generated - script_file = os.path.join(self._path, "config.music") - with open(script_file) as f: - self._script = f.read() - - def test_invalid_bibi(self): - # not a BIBI file - self.assertRaises(Exception, MUSICConfiguration, 'foo') - - # brain populations set to none or empty - brain_file = "foo.py" - empty_bibi = api.BIBIConfiguration() - empty_bibi.brainModel = api.BrainModelWithPath(file=api.PythonFilename(brain_file), - populations=None) - self.assertRaises(Exception, MUSICConfiguration, empty_bibi) - empty_bibi.brainModel = api.BrainModelWithPath(file=api.PythonFilename(brain_file), - populations=[]) - self.assertRaises(Exception, MUSICConfiguration, empty_bibi) - - def test_xml(self): - conf = MUSICConfiguration(self._bibi) - self.assertEqual("".join(conf.xml().split()), self._xml) - - @patch('__builtin__.open', spec=open) - def test_str(self, mocked_open): - conf = MUSICConfiguration(self._bibi) - conf.add_application('CLE', 'cle_binary', None, 4) - - # missing BRAIN definition - self.assertRaises(Exception, conf.save, "") - - # invalid application name - self.assertRaises(Exception, conf.add_application, 'FOO', 'bar', None, 1) - - # add brain, invalid if added twice - conf.add_application('BRAIN', 'brain_binary', ['--brain', '--args'], 2) - self.assertRaises(Exception, conf.add_application, 'BRAIN', 'bar', None, 1) - - # compare generated music script - conf.save("") - self.assertEqual(str(conf), self._script) - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/__init__.py deleted file mode 100644 index 244bd597b35f715523e85fd2d2e4af8a40b3f116..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This package contains all tests for the MUSIC CLE interface package. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_brain_loader.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_brain_loader.py deleted file mode 100644 index 7b51fb9ee39b5fac99abb5c9c659f91f51321583..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_brain_loader.py +++ /dev/null @@ -1,67 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.cle.MUSICBrainLoader import load_proxies_from_xml -import hbp_nrp_cle.tf_framework.config as tf_config -import pyNN.nest as sim - -from mock import Mock, patch -import os - - -class TestBrainLoader(unittest.TestCase): - - def test_invalid_setup(self): - tf_config.brain_root = 'foo' - self.assertRaises(Exception, load_proxies_from_xml, 'foo.xml') - tf_config.brain_root = None - - def test_invalid_xml_file(self): - self.assertRaises(Exception, load_proxies_from_xml, 'foo.xml') - - @patch('__builtin__.open', spec=open) - def test_invalid_simulator(self, mock_open): - sim.simulator.name = 'FOO' - self.assertRaises(Exception, load_proxies_from_xml, 'foo.xml') - sim.simulator.name = 'NEST' - - @patch('__builtin__.open', spec=open) - @patch('hbp_nrp_music_xml.pynn.xml_factory.XmlFactory.create_proxies', new=Mock(return_value={})) - def test_proxy_dict_missing(self, mock_open): - self.assertRaises(Exception, load_proxies_from_xml, 'foo.xml', bar='foo') - - @patch('__builtin__.open', spec=open) - @patch('pyNN.nest.PopulationView', new=Mock(return_value='fake')) - @patch('hbp_nrp_music_xml.pynn.xml_factory.XmlFactory.create_proxies', - new=Mock(return_value={'bar_to_brain': 'foo', 'bar_to_cle': 'bar'})) - def test_proxy_dict_valid(self, mock_open): - tf_config.brain_root = None - load_proxies_from_xml('foo.xml', bar='foo') - self.assertEqual(tf_config.brain_root.__dict__['bar'], 'fake') - self.assertEqual(tf_config.music_proxies['bar'], {'source': 'fake', 'sink': 'fake'}) - - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_communication_adapter.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_communication_adapter.py deleted file mode 100644 index 14e345e472efe0dd6a090860664f85882d429ce6..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_communication_adapter.py +++ /dev/null @@ -1,89 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.cle.MUSICPyNNCommunicationAdapter import MUSICPyNNCommunicationAdapter - -import hbp_nrp_cle.tf_framework.config as tf_config - -from mock import Mock, patch -import os - - -class MockPopulation(object): - - def __init__(self, label): - self.label = label - - -class MockPopulationView(object): - - def __init__(self, parent, label, mask): - self.parent = parent - self.label = label - self.mask = mask - self.size = 0 - self.all_cells = [] - - -@patch('hbp_nrp_cle.brainsim.pynn_nest.PyNNNestCommunicationAdapter.PyNNNestCommunicationAdapter.initialize') -@patch('hbp_nrp_cle.brainsim.pynn_nest.PyNNNestCommunicationAdapter.PyNNNestCommunicationAdapter.register_spike_source') -@patch('hbp_nrp_cle.brainsim.pynn_nest.PyNNNestCommunicationAdapter.PyNNNestCommunicationAdapter.register_spike_sink') -@patch('pyNN.nest.PopulationView', MockPopulationView) -@patch('pyNN.nest.Population', MockPopulation) -class TestCommunicationAdapter(unittest.TestCase): - - def setUp(self): - self._adapter = MUSICPyNNCommunicationAdapter() - - def test_initialize(self, mock_initialize, mock_source, mock_sink): - self._adapter.initialize() - - def test_invalid_population_type(self, mock_initialize, mock_source, mock_sink): - self.assertRaises(Exception, self._adapter.register_spike_sink, 'foo', 'bar') - - def test_parent_population(self, mock_initialize, mock_source, mock_sink): - pop = MockPopulationView(MockPopulation('parent'), 'population', 'mask') - tf_config.music_proxies = {'population':{'source':pop}} - self._adapter.register_spike_source(pop, 'foo') - - def test_parent_population_view(self, mock_initialize, mock_source, mock_sink): - pop = MockPopulationView(MockPopulationView(MockPopulation('grandparent'), 'parent', 'mask'), 'population', 'mask') - tf_config.music_proxies = {'parent':{'sink':pop}} - self._adapter.register_spike_sink(pop, 'foo') - - ''' - def test_population_list(self, mock_initialize, mock_source, mock_sink): - pop = MockPopulationView(MockPopulation('parent'), 'population', 'mask') - tf_config.music_proxies = {'population':{'source':pop}} - self._adapter.register_spike_source([pop, pop, pop], 'foo') - ''' - - def test_invalid_population(self, mock_initialize, mock_source, mock_sink): - pop = MockPopulationView(MockPopulation('parent'), 'population', 'mask') - tf_config.music_proxies = {} - self.assertRaises(Exception, self._adapter.register_spike_source, pop, 'foo') - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_control_adapter.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_control_adapter.py deleted file mode 100644 index 3d054fc3a52afa3c58e72b2abe831dc9b6b23548..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/cle/test_control_adapter.py +++ /dev/null @@ -1,62 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.cle.MUSICPyNNControlAdapter import MUSICPyNNControlAdapter -import hbp_nrp_cle.tf_framework.config as tf_config - -from mock import Mock, patch, mock_open -import os - - -class MockedMUSICSetup(object): - - def config(self, key): - return 'mocked.xml' - - -class TestControlAdapter(unittest.TestCase): - - def test_missing_xml(self): - mc = MUSICPyNNControlAdapter(Mock()) - self.assertRaises(Exception, mc.load_brain, 'foo.xml') - - @patch('music.Setup', name=MockedMUSICSetup()) - @patch('os.environ.get', return_value='') - @patch('hbp_nrp_music_interface.cle.MUSICBrainLoader.load_proxies_from_xml') - def test_valid_xml(self, mocked_setup, mocked_environ, mocked_load): - - m = mock_open() - m.return_value.read.return_value = 'mock brain source' - - with patch('__builtin__.open', m, create=True): - mc = MUSICPyNNControlAdapter(Mock()) - mc.load_brain('foo.xml') - - mocked_environ.assert_called_once_with('NRP_MUSIC_DIRECTORY') - m.assert_called_once_with('foo.xml') - self.assertEquals(tf_config.brain_source, 'mock brain source') - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/__init__.py deleted file mode 100644 index 77cd9a0716bddba8cd3c17d2355785d7b60503d1..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -This package contains all tests for the MUSIC interface launch package. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/__init__.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/__init__.py deleted file mode 100644 index d6a3227dc89cdb6baf0e289d4b5ce8d404348002..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -This package contains all tests for the MUSIC interface launch.host package for host specific -launch configurations. -""" diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_interface.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_interface.py deleted file mode 100644 index 36525a6d535c94b853c7c5bc82c9f4095b9546f8..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_interface.py +++ /dev/null @@ -1,65 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_distributed_nest.launch.host import IHostLauncher - -from mock import Mock, patch -import os - - -class TestHostLauncherInterface(unittest.TestCase): - - def setUp(self): - self.__launcher = IHostLauncher() - - def test_initial_values(self): - self.assertEqual(self.__launcher._hostname, None) - self.assertEqual(self.__launcher._local_tmpdir, None) - self.assertEqual(self.__launcher._host_tmpdir, None) - - def test_properties(self): - - # default values raise implementation errors - self.assertRaises(NotImplementedError, getattr, self.__launcher, 'hostname') - self.assertRaises(NotImplementedError, getattr, self.__launcher, 'local_tmpdir') - self.assertRaises(NotImplementedError, getattr, self.__launcher, 'host_tmpdir') - - # set some values to simulate an implementation - self.__launcher._hostname = 'foo' - self.__launcher._local_tmpdir = 'local' - self.__launcher._host_tmpdir = 'host' - self.assertEqual(self.__launcher.hostname, 'foo') - self.assertEqual(self.__launcher.local_tmpdir, 'local') - self.assertEqual(self.__launcher.host_tmpdir, 'host') - - def test_functions(self): - - # all functions raise implementation errors in the interface - self.assertRaises(NotImplementedError, self.__launcher.create_launch_scripts) - self.assertRaises(NotImplementedError, self.__launcher.deploy) - self.assertRaises(NotImplementedError, self.__launcher.shutdown) - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_local.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_local.py deleted file mode 100644 index 0615167e53d86e5592728c60dc61f5fcedd5c272..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_local.py +++ /dev/null @@ -1,105 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.launch.host.LocalLauncher import LocalLauncher - -from mock import Mock, patch, mock_open, call -import os -import sys -import stat -import signal - - -class TestLocalLauncherInterface(unittest.TestCase): - - def setUp(self): - with patch('tempfile.mkdtemp') as mkdtemp_mock: - mkdtemp_mock.return_value = '/mock_tmp' - self.__launcher = LocalLauncher() - - def test_properties(self): - - # implementation should set all property values - self.assertEqual(self.__launcher.hostname, 'localhost') - self.assertEqual(self.__launcher.local_tmpdir, '/mock_tmp') - self.assertEqual(self.__launcher.host_tmpdir, '/mock_tmp') - - def test_create_launch_scripts(self): - - # ensure that the calls to create the cle and brain launch scripts are made - def mock_creator(name, module): - return name - - with patch.object(self.__launcher, '_create_launch_script', mock_creator): - self.assertEqual(self.__launcher.create_launch_scripts(), - ('music_cle_launcher.sh', 'music_brain_launcher.sh')) - - @patch('os.chmod') - def test_internal_create_launch_script(self, mock_chmod): - - # mock the script open and write commands - m = mock_open() - with patch('__builtin__.open', m, create=True): - self.assertEqual(self.__launcher._create_launch_script('name.sh', 'module'), - './name.sh') - - # the open call - m.assert_called_once_with('/mock_tmp/name.sh', 'w') - - # the write calls for the actual script - handle = m() - self.assertEqual(handle.write.call_args_list, - [call('#!/bin/bash\n'), - call('{python} -m module\n'.format(python=sys.executable))]) - - # ensure the chmod was called to make the script executable - mock_chmod.assert_called_once_with('/mock_tmp/name.sh', stat.S_IRWXU) - - def test_deploy(self): - - # should just call pass, exception means failure - self.__launcher.deploy() - - @patch('os.path.exists', return_value=True) - @patch('glob.iglob', return_value=['1234.lock']) - @patch('os.kill') - @patch('shutil.rmtree') - def test_shutdown(self, mock_rmtree, mock_kill, mock_iglob, mock_exists): - - # mock the lockfile open/readline command - m = mock_open() - m.return_value.readline.return_value = '1234' - with patch('__builtin__.open', m, create=True): - self.__launcher.shutdown() - - # verify the rmtree is called to delete the tmpdir - mock_rmtree.assert_called_once_with('/mock_tmp') - - # verify the tmp dirs are unset - self.assertEqual(self.__launcher._local_tmpdir, None) - self.assertEqual(self.__launcher._host_tmpdir, None) - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_lugano.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_lugano.py deleted file mode 100644 index c548b3557824c5f25ca58b7e5ff1857e5be1229c..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/host/test_lugano.py +++ /dev/null @@ -1,129 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.launch.host.LuganoLauncher import LuganoLauncher - -from mock import Mock, patch, mock_open, call -import os -import sys -import stat -import signal -import netifaces - - -class TestLuganoLauncherInterface(unittest.TestCase): - - def setUp(self): - - # mock the Lugano specific calls made in the constructor - def mock_init(self, processes, gpus, timeout, reservation): - self._node = 'mock_node' - - with patch('tempfile.mkdtemp', return_value='/mock_tmp') as mkdtemp_mock,\ - patch('hbp_nrp_commons.cluster.LuganoVizCluster.LuganoVizCluster.__init__', mock_init) as init_mock,\ - patch('hbp_nrp_commons.cluster.LuganoVizCluster.LuganoVizCluster._allocate_job') as allocate_mock: - - self.__launcher = LuganoLauncher(4, Mock(), None) - - def test_properties(self): - - # implementation should set all property values - self.assertEqual(self.__launcher.hostname, 'mock_node') - self.assertEqual(self.__launcher.local_tmpdir, '/mock_tmp') - - @patch('hbp_nrp_cle.cle.config.config.get') - @patch('netifaces.ifaddresses', return_value={netifaces.AF_INET: [{'addr': '1.2.3.4'}]}) - @patch('os.chmod') - def test_internal_create_launch_script(self, mock_chmod, mock_ifaddresses, mock_config): - - def mock_environ_get(key): - if key == 'ENVIRONMENT': - return 'dev' - elif key == 'ROS_MASTER_URI': - return 'http://localhost:11311' - - # mock the script open and write commands - m = mock_open() - with patch('__builtin__.open', m, create=True), patch('os.environ.get', mock_environ_get): - self.assertEqual(self.__launcher._create_launch_script('name.sh', 'module'), - './name.sh') - - # the open call - m.assert_called_once_with('/mock_tmp/name.sh', 'w') - - # the write calls for the actual script - handle = m() - self.assertEqual(handle.write.call_args_list, - [call('#!/bin/bash\n'), - call('source /opt/rh/python27/enable\n'), - call('export TERM=linux\n'), - call('source $NRP_MUSIC_DIRECTORY/nrp-variables\n'), - call('export NRP_VARIABLES_PATH=$NRP_MUSIC_DIRECTORY/nrp-variables\n'), - call('source /gpfs/bbp.cscs.ch/project/proj30/neurorobotics/dev//server-scripts/nrp-services-modules.sh\n'), - call('export NRP_MODELS_DIRECTORY=/gpfs/bbp.cscs.ch/project/proj30/neurorobotics/dev//models\n'), - call('export NRP_EXPERIMENTS_DIRECTORY=/gpfs/bbp.cscs.ch/project/proj30/neurorobotics/dev//experiments\n'), - call('export PYTHONPATH=/gpfs/bbp.cscs.ch/project/proj30/neurorobotics/dev//platform_venv/lib/python2.7/site-packages:$PYTHONPATH\n'), - call('export ROS_MASTER_URI=http://1.2.3.4:11311\n'), - call('source $ROS_PYTHON_VENV/bin/activate\n'), - call('python -m module\n')]) - - # ensure the chmod was called to make the script executable - mock_chmod.assert_called_once_with('/mock_tmp/name.sh', stat.S_IRWXU) - - def test_deploy(self): - - # set the remote temp dir name that is created by the copy command - def mock_copy(self, source): - self._tmp_dir = '/mock_remote_tmp' - - with patch('hbp_nrp_commons.cluster.LuganoVizCluster.LuganoVizCluster._copy_to_remote', mock_copy),\ - patch('os.listdir', return_value=['foo']): - # should just call pass, exception means failure - self.__launcher.deploy() - - # make sure the remote tmp variable is set correctly - self.assertEqual(self.__launcher.host_tmpdir, '/mock_remote_tmp') - - @patch('hbp_nrp_commons.cluster.LuganoVizCluster.LuganoVizCluster._spawn_ssh_node') - @patch('hbp_nrp_commons.cluster.LuganoVizCluster.LuganoVizCluster.stop') - @patch('hbp_nrp_music_interface.launch.host.LocalLauncher.LocalLauncher.shutdown') - def test_shutdown(self, mock_shutdown, mock_stop, mock_spawn): - - mock_ssh = Mock() - mock_spawn.return_value = mock_ssh - - # ensure deploy has been called first even if the test hasn't run - self.__launcher._host_tmpdir = '/mock_remote_tmp' - self.__launcher.shutdown() - - # verify the parent class shutdowns are called - mock_stop.assert_called_once() - mock_shutdown.assert_called_once() - - # verify the tmp dirs are unset - self.assertEqual(self.__launcher._host_tmpdir, None) - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_mpi_launcher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_mpi_launcher.py deleted file mode 100644 index 8b55e82724adce98b34bd42a763761032f91bc7f..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_mpi_launcher.py +++ /dev/null @@ -1,197 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.launch.MUSICMPILauncher import MUSICMPILauncher - -from mock import Mock, patch -import os -import json - -from std_msgs.msg import String - - -class MockProcessIO(object): - - def write(self, message): - pass - - def flush(self): - pass - - -class MockProcess(object): - - def __init__(self, cmd, preexec_fn, stdin, env): - self.stdin=MockProcessIO() - - def poll(self): - return None - - def wait(self): - return 0 - - def kill(self): - raise OSError('testing error') - - -class MockFailedProcess(MockProcess): - - def poll(self): - return 255 - - def wait(self): - return 255 - - -class TestControlAdapter(unittest.TestCase): - - def setUp(self): - self.__launcher = MUSICMPILauncher('music cle.music') - - def test_add_hosts(self): - self.__launcher.add_host('foo', '/tmp/foo') - self.__launcher.add_host('bar', '/tmp/bar', 3) - self.assertEqual(self.__launcher._hosts, - ['-np 1 -host foo -wdir /tmp/foo -genv NRP_MUSIC_DIRECTORY /tmp/foo', - '-np 3 -host bar -wdir /tmp/bar -genv NRP_MUSIC_DIRECTORY /tmp/bar']) - - @patch('os.environ.get', new=Mock(return_value='foo')) - def test_build(self): - self.__launcher._hosts = [] - self.assertRaises(Exception, self.__launcher.build) - - self.__launcher.add_host('foo', '/tmp/foo') - self.__launcher.add_host('bar', '/tmp/bar', 3) - self.__launcher.build() - self.assertEqual(self.__launcher._cmd, - 'mpirun -np 1 -host foo -wdir /tmp/foo -genv NRP_MUSIC_DIRECTORY /tmp/foo music cle.music : ' + - '-np 3 -host bar -wdir /tmp/bar -genv NRP_MUSIC_DIRECTORY /tmp/bar music cle.music') - - def test_on_status(self): - - # reset launched flag if another test was run prior - self.__launcher._launched = False - - # not a progress message, no update to launched - msg = String() - msg.data = json.dumps({'progress': {'task': 'Neurorobotics Closed Loop Engine'}}) - self.__launcher._on_status(msg) - self.assertEqual(self.__launcher._launched, False) - - # progress completion message - msg.data = json.dumps({'simulation': 'status'}) - self.__launcher._on_status(msg) - self.assertEqual(self.__launcher._launched, True) - - @patch('rosnode.get_api_uri') - @patch('rospy.get_master', return_value='foo') - @patch('os.environ', return_value={}) - @patch('hbp_nrp_cle.config.config.get', return_value='mock_gzbridge_cmd') - @patch('os.system') - def test_check_gzbridge(self, system_mock, config_mock, environ_mock, rospy_mock, rosnode_mock): - - # simulate a call when uri has already been set - self.__launcher._gazebo_master_uri = 'something' - self.__launcher._check_gzbridge() - self.assertEqual(rosnode_mock.call_count, 0) - self.assertEqual(environ_mock.call_count, 0) - self.assertEqual(system_mock.call_count, 0) - - # simulate node not yet started - self.__launcher._gazebo_master_uri = None - rosnode_mock.return_value = (-1, '', '') - self.__launcher._check_gzbridge() - rosnode_mock.assert_called_with('foo', '/gazebo', True) - self.assertEqual(environ_mock.call_count, 0) - self.assertEqual(system_mock.call_count, 0) - - # simulate started on localhost - self.__launcher._gazebo_master_uri = None - rosnode_mock.return_value = (1, '', 'http://127.0.0.1:54321') - self.__launcher._check_gzbridge() - rosnode_mock.assert_called_with('foo', '/gazebo', True) - self.assertEqual(self.__launcher._gazebo_master_uri, 'http://127.0.0.1:11345') - self.assertEqual(environ_mock.call_count, 0) - self.assertEqual(system_mock.call_count, 0) - - # simulate started on remote host - self.__launcher._gazebo_master_uri = None - rosnode_mock.return_value = (1, '', 'http://1.2.3.4:54321') - self.__launcher._check_gzbridge() - rosnode_mock.assert_called_with('foo', '/gazebo', True) - self.assertEqual(self.__launcher._gazebo_master_uri, 'http://1.2.3.4:11345') - system_mock.assert_called_once_with('mock_gzbridge_cmd') - - - @patch('rospy.Subscriber') - def test_launch(self, rospy_mock): - - # unset any variables from other tests - self.__launcher._cmd = None - self.__launcher._launched = None - - # not initialized, cannot run without a command - self.assertRaises(Exception, self.__launcher.launch) - - # patch gzbridge launch function to be tested separately - with patch.object(self.__launcher, '_check_gzbridge', Mock()): - - # initialize with a valid process - self.__launcher._cmd = 'foo' - with patch('subprocess.Popen', MockProcess): - self.__launcher._launched = True - self.__launcher.launch() - - # initialize with an invalid process - with patch('subprocess.Popen', MockFailedProcess): - self.__launcher._launched = False - self.assertRaises(Exception, self.__launcher.launch) - - def test_run(self): - - # not initialized or launched, failure expected - self.__launcher._process = None - self.__launcher._launched = False - self.assertRaises(Exception, self.__launcher.run) - - # successfully launched and completed - self.__launcher._launched = True - self.__launcher._process = MockProcess(None, None, None, None) - self.__launcher.run() - - # failed process run - self.__launcher._process = MockFailedProcess(None, None, None, None) - self.assertRaises(Exception, self.__launcher.run) - - @patch('hbp_nrp_cle.config.config.get', return_value='mock_gzbridge_cmd') - @patch('os.system') - def test_shutdown(self, system_mock, config_mock): - self.__launcher._process = MockProcess(None, None, None, None) - self.__launcher._gazebo_master_uri = 'http://1.2.3.4:11345' - self.__launcher.shutdown() - system_mock.assert_called_once_with('mock_gzbridge_cmd') - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_music_launcher.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_music_launcher.py deleted file mode 100644 index c94af48fd0423c5cca430f5e6b6f90712996af09..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/tests/launch/test_music_launcher.py +++ /dev/null @@ -1,109 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest - -from hbp_nrp_music_interface.launch.MUSICLauncher import MUSICLauncher - -from mock import Mock, patch -import os - - -class MockLocalLauncher(Mock): - - @property - def hostname(self): - return 'localhost' - - @property - def local_tmpdir(self): - return '/mock_tmpdir' - - @property - def host_tmpdir(self): - return '/mock_host_tmpdir' - - def create_launch_scripts(self): - return ('cle.sh', 'brain.sh') - - -class TestMUSICLauncher(unittest.TestCase): - - @patch('os.environ.get', return_value='') - def setUp(self, mock_environ_get): - exc_mock = Mock() - exc_mock.path = 'exd_conf' - exc_mock.dir = '/exp_path' - exc_mock.rngSeed = 123456 - exc_mock.bibiConf.processes = 10 - bibi_mock = Mock() - bibi_mock.path = 'bibi_file' - self.__launcher = MUSICLauncher(1, exc_mock, bibi_mock, - gzserver_host='local', - reservation=None, - timeout=None) - - @patch('hbp_nrp_music_interface.launch.MUSICLauncher.LocalLauncher', MockLocalLauncher) - @patch('hbp_nrp_music_interface.launch.MUSICLauncher.bibi_music_config.MUSICConfiguration') - @patch('hbp_nrp_music_interface.launch.MUSICLauncher.MUSICMPILauncher') - def test_init(self, mock_mpi, mock_conf): - # mock all of the local launcher functionality - with patch('hbp_nrp_music_interface.launch.MUSICLauncher.os.environ.get', - return_value='/somewhere/over/the/rainbow'): - self.__launcher.initialize('env_file', None) - - # call to generate launch scripts - self.__launcher._launcher.deploy.assert_called_once() - - # assert that all of the MPI configuration/launch commands were called - self.__launcher.mpilauncher.add_host.assert_called_once_with('localhost', '/mock_host_tmpdir', 11) - self.__launcher.mpilauncher.build.assert_called_once() - self.__launcher.mpilauncher.launch.assert_called_once() - - @patch('os.system') - def test_shutdown(self, system_mock): - - # mock the cleserver and launcher - mock_cle_server = Mock() - mock_cle_server.shutdown = Mock() - mock_launcher = Mock() - mock_launcher.shutdown = Mock() - - # set values like in init() and shutdown - self.__launcher.mpilauncher = mock_cle_server - self.__launcher._launcher = mock_launcher - self.__launcher.shutdown() - - # make sure the mocked shutdowns are called - mock_cle_server.shutdown.assert_called_once() - mock_launcher.shutdown.assert_called_once() - - # verify the local variables are unset - self.assertEqual(self.__launcher.mpilauncher, None) - self.assertEqual(self.__launcher._launcher, None) - - # verify the ros cleanup command has been called - system_mock.assert_called_once() - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_interface/hbp_nrp_music_interface/version.py b/hbp_nrp_music_interface/hbp_nrp_music_interface/version.py deleted file mode 100644 index cff3ffe78f84bd6b7a67779ef89754d7be4f8d83..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/hbp_nrp_music_interface/version.py +++ /dev/null @@ -1,2 +0,0 @@ -'''version string - generated by setVersion.sh''' -VERSION = '2.3.0' diff --git a/hbp_nrp_music_interface/requirements.txt b/hbp_nrp_music_interface/requirements.txt deleted file mode 100644 index fb7fe6f6ddb0b6c3cf98aebc1333cec983558c3f..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -# third party requirements -mpi4py==2.0.0 -netifaces==0.8 diff --git a/hbp_nrp_music_interface/requirements_extension_tests.txt b/hbp_nrp_music_interface/requirements_extension_tests.txt deleted file mode 100644 index 031ce958f7c92f34b5aebfd200ba995fa2a54b88..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/requirements_extension_tests.txt +++ /dev/null @@ -1,3 +0,0 @@ -#the following is required for the unit testing -mock==1.0.1 -testfixtures==3.0.2 diff --git a/hbp_nrp_music_interface/setup.py b/hbp_nrp_music_interface/setup.py deleted file mode 100644 index a164b229a863a9b1b65738825a08525464dbe182..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_interface/setup.py +++ /dev/null @@ -1,68 +0,0 @@ -'''setup.py''' - -from setuptools import setup - -import hbp_nrp_music_interface -import pip - -from optparse import Option -options = Option('--workaround') -options.skip_requirements_regex = None -reqs_file = './requirements.txt' -if pip.__version__.startswith('10.'): - # Versions greater or equal to 10.x don't rely on pip.req.parse_requirements - install_reqs = list(val.strip() for val in open(reqs_file)) - reqs = install_reqs -elif pip.__version__.startswith('1.'): - # Versions 1.x rely on pip.req.parse_requirements - # but don't require a "session" parameter - from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error - install_reqs = parse_requirements(reqs_file, options=options) - reqs = [str(ir.req) for ir in install_reqs] -else: - # Versions greater than 1.x but smaller than 10.x rely on pip.req.parse_requirements - # and requires a "session" parameter - from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error - from pip.download import PipSession # pylint:disable=no-name-in-module, import-error - options.isolated_mode = False - install_reqs = parse_requirements( # pylint:disable=unexpected-keyword-arg - reqs_file, - session=PipSession, - options=options - ) - reqs = [str(ir.req) for ir in install_reqs] - -# ensure we install numpy before the main list of requirements, ignore -# failures if numpy/cython are not requirements and just proceed (future proof) -try: - cython_req = next(r for r in reqs if r.startswith('cython')) - numpy_req = next(r for r in reqs if r.startswith('numpy')) - if pip.__version__.startswith('10.'): - import subprocess - subprocess.check_call( - ["python", '-m', 'pip', 'install', "--no-clean", "--user", cython_req, numpy_req] - ) - else: - pip.main(['install', '--no-clean', cython_req, numpy_req]) # pylint:disable=no-member -# pylint: disable=bare-except -except: - pass - -config = { - 'description': 'MUSIC interface support for CLE/ExDBackend for HBP SP10', - 'author': 'HBP Neurorobotics', - 'url': 'http://neurorobotics.net', - 'author_email': 'neurorobotics@humanbrainproject.eu', - 'version': hbp_nrp_music_interface.__version__, - 'install_requires': reqs, - 'packages': ['hbp_nrp_music_interface', - 'hbp_nrp_music_interface.bibi', - 'hbp_nrp_music_interface.cle', - 'hbp_nrp_music_interface.launch', - 'hbp_nrp_music_interface.launch.host'], - 'scripts': [], - 'name': 'hbp-nrp-music-interface', - 'include_package_data': True, -} - -setup(**config) diff --git a/hbp_nrp_music_interface_deprec.tar.gz b/hbp_nrp_music_interface_deprec.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..ebc23b26413abeef4eff06dbf95f40bbb0f70044 Binary files /dev/null and b/hbp_nrp_music_interface_deprec.tar.gz differ diff --git a/hbp_nrp_music_xml/MANIFEST.in b/hbp_nrp_music_xml/MANIFEST.in deleted file mode 100644 index 540b72040df162428003e7ff8fc4d46a80823bca..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include requirements.txt \ No newline at end of file diff --git a/hbp_nrp_music_xml/README.txt b/hbp_nrp_music_xml/README.txt deleted file mode 100644 index 4133956be23f765615fcef392dab28faa9c3c701..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -This package provides an interface for creating and interacting with MUSIC XML configuration -files - including reading/writing to a neuron/synapse XML format, generating a MUSIC script -that can be used to instantiate MUSIC, and conversions to and from PyNN interfaces. - -This package does not depend on any other hbp_nrp dependencies and is loigically independent. diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/__init__.py deleted file mode 100644 index 762853e919dfa1f9093d9f4511aef2dd5aa38456..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -This package contains a XML schema and corresponding factories as well as -utilities in order to programatically create MUSIC ports and connect them to -PyNN populations. -""" - -from hbp_nrp_music_xml.version import VERSION as __version__ # pylint: disable=W0611 - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/config/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/config/__init__.py deleted file mode 100644 index 9f1d4cc4cd23be69d0b7f74de83e296ca1121596..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/config/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -This package provides a programatic interface to assemble a MUSIC-XML and -MUSIC-config file -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/config/music_config.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/config/music_config.py deleted file mode 100644 index a77db57326dda26967896c3f7bec09a964718f7d..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/config/music_config.py +++ /dev/null @@ -1,154 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Programmatic interfaces to assemble MUSIC XML and config files. -""" -from hbp_nrp_music_xml.schema.generated import music_xml - -from ConfigParser import ConfigParser -from types import NoneType -import StringIO - - -class Application(object): - """ - Class to represent an application in the MUSIC context - """ - - def __init__(self, name, binary, args=None, num_processes=1): - """ - :param name: A string to specify the application name - :param binary: A string specifiying the binary to execute for this - application process - :param args: An ordered list of arguments for the binary. - :param num_processes: The integer number of MPI instances for this process - """ - assert isinstance(name, str) - assert isinstance(binary, str) - assert isinstance(args, (NoneType, list)) - assert isinstance(num_processes, int) - - self.name = name - self.binary = binary - self.args = '"{}"'.format(' '.join(args)) if args is not None else '' - self.num_processes = num_processes - - -class MusicConfigWriter(object): - """ - This class helps to write a MUSIC-Config file - """ - - def __init__(self, header=None, applications=None, ports=None): - """ - :param header: A dictionary object - :param applications: A list of music_config.Application objects - :param ports: A list of music_config.MusicConfigPort objects - """ - assert isinstance(header, (NoneType, dict)) - assert isinstance(applications, (NoneType, list, tuple)) - assert isinstance(ports, (NoneType, list, tuple)) - - self.header = header - self.applications = applications - self.ports = ports - - def write(self, file_handle): - """ - Writes a string representing the MUSIC-Config to a file-like object - :param file_handle: A file-like object - """ - if self.header and len(self.header) > 0: - for key, val in self.header.items(): - file_handle.write(u'{key} = "{val}"\n'.format(key=key, val=val)) - file_handle.write(u'\n') - - if self.applications: - config = ConfigParser() - for application in self.applications: - config.add_section(application.name) - config.set(application.name, 'np', application.num_processes) - config.set(application.name, 'binary', application.binary) - config.set(application.name, 'args', application.args) - - config.write(file_handle) - - if self.ports: - for port in self.ports: - file_handle.write(u'{port}\n'.format(port=port)) - - def __str__(self): - """ - Returns the MUSIC-Config as a python string - """ - - try: - conf_io = StringIO.StringIO() - self.write(conf_io) - conf_str = conf_io.getvalue() - except (UnicodeError, ValueError): - raise Exception("Unable to encode MUSIC Configuration Script to String!") - finally: - conf_io.close() - - return conf_str - - -class MusicConfigPort(object): - """ - This class converts a MUSIC-XML Port object into a string - representation in order to assemble the MUSIC config file - """ - - def __init__(self, music_xml_port): - """ - :param music_xml_port: A music_xml.Port object - """ - assert isinstance(music_xml_port, music_xml.Port) - self.music_xml_port = music_xml_port - - def get_connection_strings(self): - """ - Returns a list of port connectivity representations. The format complies - with the format that is being used in the MUSIC-config files. - """ - connection_strs = [] - for receiver in self.music_xml_port.receiver: - connection_strs.append("{sender_name}.{port_name} -> " - "{receiver_name}.{port_name} [{port_width}]".format( - sender_name=self.music_xml_port.sender.name, - port_name=self.music_xml_port.name, - receiver_name=receiver.name, - port_width=self.music_xml_port.width)) - return connection_strs - - def __str__(self): - """ - Returns all connectivity representation strings as given by - MusicConfigPort.get_connection_strings() but in a concatenated - form. Different connectivity strings are seperated by new-line breaks. - """ - - connection_strs = self.get_connection_strings() - return "\n".join(connection_strs) diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/__init__.py deleted file mode 100644 index 679b1da381ac21e443036293747586054aa07b6d..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -""" -This package provides a programmatic interface to create MUSIC PyNN proxy devices -from a MUSIC-XML specification. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/cell_types.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/cell_types.py deleted file mode 100644 index 3af30bd0e575395091b50cce9e47515150d43aad..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/cell_types.py +++ /dev/null @@ -1,58 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Provides utility functions for native cell types. -""" - -__author__ = 'Martin Schulze' - - -def load_cell_types(simulator): - """ - This function provides a map containing PyNN wrappers around the simulator - specific MUSIC proxy implementations - - :param simulator : The PyNN simulator (e.g. pyNN.nest) - """ - cell_type_dict = {} - - if simulator.simulator.name == "NEST": - - music_event_out_proxy = simulator.native_cell_type('music_event_out_proxy') - music_event_in_proxy = simulator.native_cell_type('music_event_in_proxy') - parrot_neuron_type = simulator.native_cell_type('parrot_neuron') - - for model in [music_event_out_proxy, music_event_in_proxy, parrot_neuron_type]: - model.default_initial_values = {} - model.default_parameters = {} - - cell_type_dict['out'] = {'Event': music_event_out_proxy} - cell_type_dict['in'] = {'Event': music_event_in_proxy} - cell_type_dict['parrot'] = parrot_neuron_type - - else: - raise Exception("Implementation for {simulator_name} not found" - .format(simulator_name=simulator.name)) - - return cell_type_dict diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/connector_factory.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/connector_factory.py deleted file mode 100644 index cb4f47cd3c4521ccd8e4706902ce9072638dd82a..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/connector_factory.py +++ /dev/null @@ -1,114 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -PyNN factory for PyNN projections between PyNN MUSIC proxy objects and other PyNN populations -""" -from hbp_nrp_music_xml.pynn.utils import desc_pynn_pop, pprint_pynn_pop, get_min_delay - -import logging - -__author__ = 'Martin Schulze' - -logger = logging.getLogger(__name__) - - -class PyNNConnectorFactory(object): - """ - PyNN factory for PyNN projections between PyNN MUSIC proxy objects and other PyNN populations - """ - - def __init__(self, simulator): - """ - :param simulator: The PyNN simulator (e.g. pyNN.nest) - """ - self.simulator = simulator - self.connector_types = {'one_to_one': simulator.OneToOneConnector, - 'all_to_all': simulator.AllToAllConnector} - - def create_and_connect_synapse(self, proxy, port_name, connection_rule, population_slice, - target_population, is_output_proxy, synapse=None): - """ - :param proxy: PyNN population that wraps the simulator specific MUSIC port implementation - :param port_name: The name of the port - :param connection_rule: {'one_to_one', 'all_to_all'} to connect proxy->target_population - or target_population->proxy - :param population_slice: Apply synapse only on subset (slice) of given target_population - :param target_population: The target/source population - :param is_output_proxy: A boolean which indicates whether the proxy to create represents an - ingoing or outgoing connection - :param synapse: Uses this PyNN synapse instead of 'StaticSynapse', default None - """ - - # only create default synapses to the cle ports since we will dynamically configure - # device connectivity <-> proxies from the cle (e.g. spike generators or recorders) - # but we need connectivity in the remote brain processes from parrot -> proxy so that - # spikes are propagated - if not port_name.endswith('to_cle'): - return - - try: - connector = self.connector_types[connection_rule] - except KeyError, e: - message = "Unsupported PyNN connector type: {connector_factory} does not support \ - '{synaptic_rule}' connectors."\ - .format(connector_factory=self.__class__, synaptic_rule=connection_rule) - logger.error(message, exc_info=True) - raise Exception(message) - - if population_slice: - logger.debug("Applying slice {population_slice} on population {population_name}" - .format(population_slice=population_slice, - population_name=desc_pynn_pop(target_population))) - target_population = self.simulator.PopulationView(target_population, population_slice) - - if is_output_proxy: - presynaptic_population = target_population - postsynaptic_population = proxy - else: - presynaptic_population = proxy - postsynaptic_population = target_population - - direction_arrow = '-->' if not is_output_proxy else '<--' - message = "Connecting port {port_name} {direction_arrow} PyNNPopulation \ - {postsynaptic_population}. Interface population for the proxy is\ - {presynaptic_population}"\ - .format(port_name=port_name, direction_arrow=direction_arrow, - postsynaptic_population=desc_pynn_pop(postsynaptic_population), - presynaptic_population=desc_pynn_pop(presynaptic_population)) - logger.debug(message) - - try: - if not synapse: - synaptic_delay = get_min_delay() - synapse = self.simulator.StaticSynapse(weight=1.0, delay=synaptic_delay) - self.simulator.Projection(presynaptic_population, postsynaptic_population, - connector(), synapse) - except Exception, e: - logging.error(e, exc_info=True) - logging.error('Debug information: \nStatus dictionaries of the \ - populations: \npresynaptic population: {presynaptic_population}\n\ - postsynaptic population: {postsynaptic_population}'. - format(presynaptic_population=pprint_pynn_pop(presynaptic_population), - postsynaptic_population=pprint_pynn_pop(postsynaptic_population))) - raise Exception("Failure creating PyNN/MUSIC synapse: {}" % message) diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/factory.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/factory.py deleted file mode 100644 index 080e94123679c39a28d0c0086854d423813745bd..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/factory.py +++ /dev/null @@ -1,188 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Factory class for PyNN MUSIC-proxy objects -""" - - -from hbp_nrp_music_xml.pynn.cell_types import load_cell_types -from hbp_nrp_music_xml.pynn.utils import get_min_delay - -import nest -import logging - -logger = logging.getLogger(__name__) - -__author__ = 'Martin Schulze' - - -def create_proxy_via_native_cell_types(simulator, proxy_width, cell_type, port_name, proxy_type, - acc_latency, is_output_proxy): - """ - Creates the PyNN proxy representation of a MUSIC port - - :param simulator: The PyNN simulator (e.g. pyNN.nest) - :param proxy_width: The number of proxies required to represent the port - :param cell_type: The PyNN celltype that encapsulates the proxy mechanism of - the underlying PyNN simulator - :param port_name: The port name - :param acc_latency: The maximum allowed latency in milisecond (ignored on output proxies) - :param is_output_proxy: A boolean which indicates whether the proxy to create represents - an ingoing or outgoing connection - """ - assert simulator.simulator.name == "NEST", "Currently only NEST is supported" - - if not acc_latency: - acc_latency = get_min_delay() - - proxy_label = "Port: {name}\nWidth: {width}".format(name=port_name, width=proxy_width) - proxy = simulator.Population(proxy_width, cell_type, {}, label=proxy_label) - - proxy_ids = map(int, proxy.all_cells) - nest.SetStatus(proxy_ids, 'port_name', port_name) - - # Acc. latency actually only matters for input ports - if not is_output_proxy: - nest.SetAcceptableLatency(port_name, acc_latency) - logger.debug("Created {proxy_width} {port_direction} {port_type} proxy neurons with " - "accLatency={port_acc_latency} for port {port_name} " - .format(proxy_width=proxy_width, port_direction="input", - port_type=proxy_type, port_acc_latency=acc_latency, - port_name=port_name)) - else: - logger.debug("Created {proxy_width} {port_direction} {port_type} proxy neurons for " - "port {port_name}" - .format(proxy_width=proxy_width, port_direction="output", - port_type=proxy_type, port_name=port_name)) - - if proxy_type == "Event" and not is_output_proxy: - for i, proxy_id in enumerate(proxy_ids): - nest.SetStatus([proxy_id], 'music_channel', i) - - return proxy - - -def export_proxy(simulator, presynaptic_population, proxy, synaptic_delay=get_min_delay()): - """ - This helper function connects a population to an output proxy. - - :param simulator: The PyNN simulator (e.g. pyNN.nest) - :param presynaptic_population: A PyNN population that is to be connected to the - desired output proxy - :param proxy: The PyNN proxy population - """ - assert simulator.simulator.name == "NEST", "Currently only NEST is supported" - - if not synaptic_delay: - synaptic_delay = get_min_delay() - - presynaptic_neuron_ids = map(int, presynaptic_population.all_cells) - proxy_ids = map(int, proxy.all_cells) - connection_params = {'delay': synaptic_delay, 'weight': 1.0} - - for i, pre_id in enumerate(presynaptic_neuron_ids): - connection_params.update(music_channel=i) - nest.Connect([pre_id], proxy_ids, 'one_to_one', connection_params) - - logger.debug("Connected presynaptic population {population_name} to output proxy " - "{proxy_name}" - .format(population_name=presynaptic_population, proxy_name=proxy)) - - -class PyNNProxyFactory(object): - """ - Factory class for PyNN MUSIC-proxy objects - """ - - def __init__(self, simulator, acc_latency=None, max_buffered=1): - """ - :param simulator: The PyNN simulator (e.g. pyNN.nest) - :param acc_latency: The maximum allowed latency in miliseconds - :param max_buffered: TODO - """ - assert simulator.simulator.name == "NEST", "Currently only NEST is supported" - - self.acc_latency = acc_latency - self.max_buffered = max_buffered - self.simulator = simulator - self.cell_types = load_cell_types(simulator) - - def create_proxy(self, port_name, proxy_type, port_width, is_output_proxy, synaptic_delay=None): - """ - Creates the actual PyNN MUSIC proxy object - - :param port_name: The name of the port - :param proxy_type: {'Event', 'Message', 'Continuous'} - :param port_width: The number of MUSIC connections for this port - :param is_output_proxy: A boolean which indicates whether the proxy to create represents an - ingoing or outgoing connection - :param synaptic_delay: Sets the synaptic delay of the connection, defaults to simulator - minimum synaptic delay - """ - - assert proxy_type == "Event", '{proxy_type} ports are currently not supported for PyNN.'\ - .format(proxy_type=proxy_type) - - if is_output_proxy: - cell_type = self.cell_types['out'][proxy_type] - # We only do need one output proxy (for spike_out_proxy and continuous_out_proxy) - proxy_width = 1 - else: - cell_type = self.cell_types['in'][proxy_type] - proxy_width = port_width - - # Currently NEST specific, will be replaced by a MUSIC branch of PyNN - proxy = create_proxy_via_native_cell_types(self.simulator, proxy_width, cell_type, - port_name, proxy_type, self.acc_latency, - is_output_proxy) - - if proxy_type == 'Event': - if is_output_proxy: - label = "Parrots for Port: {name}\nWidth: {width}"\ - .format(name=port_name, width=proxy_width) - parrots = self.simulator.Population(port_width, - self.cell_types['parrot'], - {}, - label=label) - - export_proxy(self.simulator, parrots, proxy, synaptic_delay) - logger.debug("Created {port_width} parrot neurons and connected it to outgoing " - "port {port_name}" - .format(port_width=port_width, port_name=port_name)) - - # [NRRPLT-4722] workaround for lack of dynamic MUSIC ports, since we have many - # more parrot neurons than required, freeze them. this means they will not be - # updated until we explicitly thaw them during connection. - if port_name.endswith('to_brain'): - nest.SetStatus(map(int, parrots.all_cells), 'frozen', True) - - return parrots - else: - # [NRRPLT-4722] workaround for lack of dynamic MUSIC ports, since we have many - # more parrot neurons than required, freeze them. this means they will not be - # updated until we explicitly thaw them during connection. - if port_name.endswith('to_brain'): - nest.SetStatus(map(int, proxy.all_cells), 'frozen', True) - - return proxy diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/utils.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/utils.py deleted file mode 100644 index 5999fcc0145110369e154d0ba85ca3ce35b0fdda..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/utils.py +++ /dev/null @@ -1,70 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Common Nest/PyNN helper utility functions. -""" - -import pprint -import nest - -__author__ = 'Martin Schulze' - -pp = pprint.PrettyPrinter(indent=4) - - -def desc_pynn_pop(pop): - """ - Return a string with a high-level description of a PyNN population. - - :param pop: The PyNN population to describe. - """ - return "<Type: {cell_type}, Width: {population_width}, Label: {population_label}>"\ - .format(cell_type=pop.celltype, population_width=pop.size, population_label=pop.label) - - -def desc_nest_pop(ids): - """ - Return a string with a high-level description of a Nest population. - - :param pop: The Nest population to describe. - """ - return "<Model: {nest_model_name}, Width: {population_width}>"\ - .format(nest_model_name=nest.GetStatus(list(ids), 'model'), - population_width=len(list(ids))) - - -def pprint_pynn_pop(pop): - """ - Return a string with a detailed population level description of a PyNN population. - - :param pop: The PyNN population to describe. - """ - return pp.pformat(nest.GetStatus(map(int, pop.all_cells))) - - -def get_min_delay(): - """ - Returns the minimum delay of the simulator. - """ - return nest.GetKernelStatus()['min_delay'] diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/xml_factory.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/xml_factory.py deleted file mode 100644 index 340c181583b79a97aee89a13a1fa66ff716b4a12..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/pynn/xml_factory.py +++ /dev/null @@ -1,249 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -""" -Provides a high level interface to convert a MUSIC XML file into MUSIC proxies. -""" - -from hbp_nrp_music_xml.schema.generated import music_xml - -from collections import OrderedDict -from prettytable import PrettyTable -from operator import attrgetter - -import logging - -logger = logging.getLogger(__name__) - -__author__ = 'Martin Schulze' - - -def extract_kwargs(xml_parameter_list): - """ - Extracts keyword arguments from a music_xml.ParameterList object - - :param xml_parameter_list: music_xml.ParameterList object - """ - - if not xml_parameter_list: - return {} - kwargs = {} - for elem in xml_parameter_list.orderedContent(): - kwargs[elem.value.name] = elem.value.content() - return kwargs - - -def is_application_receiver(application_name, xml_port): - """ - Returns 'True' if the application with 'application_name' is a receiver with - respect to the provided xml_port. Returns 'False' else - - :param application_name: The application name - :param xml_port: music_xml.Port object - """ - - xml_receivers = xml_port.receiver - receiver_names = map(attrgetter('name'), xml_receivers) - if application_name in receiver_names: - return True - return False - - -def build_port_overview_table(xml_ports, application_name): - """ - Constructs a tabular overview in string representation for logging purposes - - :param xml_ports: A list of music_xml.Port objects - :param application_name: The name of the current application (will be shown - in the table header) - """ - - overview_table = PrettyTable(['Portname', 'Type', 'Width', 'Direction']) - for xml_port in xml_ports: - xml_sender = xml_port.sender - direction = "Outgoing" if xml_sender.name == application_name else \ - "Ingoing" - port_name = xml_port.name - port_type = xml_port.type - width = int(xml_port.width) - if xml_sender.name == application_name or \ - is_application_receiver(application_name, xml_port): - overview_table.add_row([port_name, port_type, width, direction]) - return overview_table - - -def create_pop_slice(xml_selector): - """ - Returns either a python-slice or a list, depending on the type of xml_selector - - :param xml_selector: music_xml.SelectorType - """ - if isinstance(xml_selector, music_xml.SliceSelector): - return slice(xml_selector.start, xml_selector.stop, xml_selector.step) - elif isinstance(xml_selector, music_xml.ListSelector): - elements = [x for x in xml_selector.element] - return elements - else: - raise Exception("Can not convert object {xml_selector} to a " - "slice-like object. Unknown selector type" - .format(xml_selector=xml_selector)) - - -def create_selector(xml_synapse): - """ - Returns a python-slice or list if a synaptic selector has been specified - in the xml_synapse - - :param xml_synapse: music_xml.SynapticConnectionType - """ - - xml_selector = getattr(xml_synapse, 'selector', None) - if xml_selector: - selector = create_pop_slice(xml_selector) - else: - selector = None - return selector - - -class XmlFactory(object): - """ - This class helps unpacking the MUSIC-XML and makes subsequent calls to the - desired proxy/connector factories - """ - - def __init__(self, application_name, connector_factory, proxy_factory, - population_dict): - """ - :param application_name: The name of the application (process) where - this factory is instantiated on - :param connector_factory: A factory class to create PyNN ports - :param proxy_factory: A factory class to create PyNN wrappers around - simulator specific MUSIC proxy objects - :param population_dict: A dictionary containing population names as keys - and PyNN population objects as values. If the XML specifies synaptic - connections between proxies and populations then this dictionary - provides the respective mapping - """ - self.application_name = application_name - self.connector_factory = connector_factory - self.proxy_factory = proxy_factory - self.population_dict = population_dict - - def _get_synaptic_target_population(self, xml_synapse): - """ - Returns the target/source population as specified in the xml_synapse - object provided the population has been passed along with the - population dictionary in the constructor - - :param xml_synapse: music_xml.SynapticConnectionType object - """ - - population_name = getattr(xml_synapse, 'target') - try: - target_population = self.population_dict[population_name] - except KeyError: - raise Exception("Population with dictionary key {population_name} " - "has not been found in the provided " - "population-dictionary." - .format(population_name=population_name)) - return target_population - - def _create_and_connect_proxy(self, xml_port, xml_peer, is_output_proxy): - """ - Creates a PyNN proxy for a specific MUSIC port and connects it to a - source/target population as long this is specified in the - xml_port. - - :param xml_port: music_xml.Port object - :param xml_peer: music_xml.PeerType object, represents a sender or - receiver application - :param is_output_proxy: A boolean to indicate whether the proxy is - inbound or outbound - """ - port_name = xml_port.name - port_type = xml_port.type - width = int(xml_port.width) - - proxy = self.proxy_factory.create_proxy(port_name, port_type, width, - is_output_proxy) - xml_synapses = getattr(xml_peer, 'synapse', None) - if not xml_synapses: - raise Exception("No synapse connectivity specified for port {}, invalid " - "configuration!".format(port_name)) - - if self.population_dict and len(self.population_dict) > 0: - for xml_synapse in xml_synapses: - population_slice = create_selector(xml_synapse) - connection_rule = xml_synapse.type - synaptic_target = self._get_synaptic_target_population(xml_synapse) - if hasattr(synaptic_target, 'mask'): # prevent duplicate slicing - population_slice = None - self.connector_factory.create_and_connect_synapse(proxy, - port_name, - connection_rule, - population_slice, - synaptic_target, - is_output_proxy) - return proxy - - def _assemble_proxy(self, xml_port): - """ - Assembles and connects all PyNN proxy objects for a specific port. - Returns a population to interface the MUSIC ports - - :param xml_port: music_xml.Port - """ - - xml_sender = xml_port.sender - xml_receivers = xml_port.receiver - - if xml_sender.name == self.application_name: - for xml_receiver in list(xml_receivers): - return self._create_and_connect_proxy(xml_port, xml_receiver, True) - else: - for xml_receiver in list(xml_receivers): - if xml_receiver.name == self.application_name: - return self._create_and_connect_proxy(xml_port, - xml_receiver, False) - - def create_proxies(self, xml_string): - """ - This method parses, reads and creates and connects all MUSIC proxy - objects and returns a dictionary with keys: port_name and value: PyNN - populations that represent the MUSIC ports). - - :param xml_string: A raw string containing valid MUSIC-XML content - """ - - logger.debug("Parsing XML File") - xml_root = music_xml.CreateFromDocument(xml_string) - xml_ports = xml_root.port - proxy_dict = OrderedDict() - port_overview_table = build_port_overview_table(xml_ports, - self.application_name) - logger.debug("\nPort overview of application: " - "{}\n{}".format(self.application_name, port_overview_table)) - for xml_port in xml_ports: - proxy = self._assemble_proxy(xml_port) - proxy_dict[xml_port.name] = proxy - return proxy_dict diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/__init__.py deleted file mode 100644 index 1610e006d0316a2251bae256b127c27c264bae21..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -XML Schema and generated pyxb file for MUSIC configuration file. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/__init__.py deleted file mode 100644 index e79ff7afeb820f0214397a9a2ffca5b22821d5f2..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -Generated pyxb file for MUSIC schema. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/music_xml.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/music_xml.py deleted file mode 100644 index b5c25e0edfb7ae4fcc049c03f71b4c6a887e8208..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated/music_xml.py +++ /dev/null @@ -1,743 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -# ./music_xml.py -# -*- coding: utf-8 -*- -# PyXB bindings for NM:e92452c8d3e28a9e27abfc9994d2007779e7f4c9 -# Generated 2016-09-16 13:06:43.146805 by PyXB version 1.2.4 using Python 2.7.6.final.0 -# Namespace AbsentNamespace0 - -from __future__ import unicode_literals -import pyxb -import pyxb.binding -import pyxb.binding.saxer -import io -import pyxb.utils.utility -import pyxb.utils.domutils -import sys -import pyxb.utils.six as _six - -# Unique identifier for bindings created at the same time -_GenerationUID = pyxb.utils.utility.UniqueIdentifier('urn:uuid:398b796a-7d06-11e6-91a7-e4b318398898') - -# Version of PyXB used to generate the bindings -_PyXBVersion = '1.2.4' -# Generated bindings are not compatible across PyXB versions -if pyxb.__version__ != _PyXBVersion: - raise pyxb.PyXBVersionError(_PyXBVersion) - -# Import bindings for namespaces imported into schema -import pyxb.binding.datatypes - -# NOTE: All namespace declarations are reserved within the binding -Namespace = pyxb.namespace.CreateAbsentNamespace() -Namespace.configureCategories(['typeBinding', 'elementBinding']) - -def CreateFromDocument (xml_text, default_namespace=None, location_base=None): - """Parse the given XML and use the document element to create a - Python instance. - - @param xml_text An XML document. This should be data (Python 2 - str or Python 3 bytes), or a text (Python 2 unicode or Python 3 - str) in the L{pyxb._InputEncoding} encoding. - - @keyword default_namespace The L{pyxb.Namespace} instance to use as the - default namespace where there is no default namespace in scope. - If unspecified or C{None}, the namespace of the module containing - this function will be used. - - @keyword location_base: An object to be recorded as the base of all - L{pyxb.utils.utility.Location} instances associated with events and - objects handled by the parser. You might pass the URI from which - the document was obtained. - """ - - if pyxb.XMLStyle_saxer != pyxb._XMLStyle: - dom = pyxb.utils.domutils.StringToDOM(xml_text) - return CreateFromDOM(dom.documentElement, default_namespace=default_namespace) - if default_namespace is None: - default_namespace = Namespace.fallbackNamespace() - saxer = pyxb.binding.saxer.make_parser(fallback_namespace=default_namespace, location_base=location_base) - handler = saxer.getContentHandler() - xmld = xml_text - if isinstance(xmld, _six.text_type): - xmld = xmld.encode(pyxb._InputEncoding) - saxer.parse(io.BytesIO(xmld)) - instance = handler.rootObject() - return instance - -def CreateFromDOM (node, default_namespace=None): - """Create a Python instance from the given DOM node. - The node tag must correspond to an element declaration in this module. - - @deprecated: Forcing use of DOM interface is unnecessary; use L{CreateFromDocument}.""" - if default_namespace is None: - default_namespace = Namespace.fallbackNamespace() - return pyxb.binding.basis.element.AnyCreateFromDOM(node, default_namespace) - - -# Atomic simple type: PortType -class PortType (pyxb.binding.datatypes.string, pyxb.binding.basis.enumeration_mixin): - - """An atomic simple type.""" - - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'PortType') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 40, 2) - _Documentation = None -PortType._CF_enumeration = pyxb.binding.facets.CF_enumeration(value_datatype=PortType, enum_prefix=None) -PortType.Event = PortType._CF_enumeration.addEnumeration(unicode_value='Event', tag='Event') -PortType.Continuous = PortType._CF_enumeration.addEnumeration(unicode_value='Continuous', tag='Continuous') -PortType.Message = PortType._CF_enumeration.addEnumeration(unicode_value='Message', tag='Message') -PortType._InitializeFacetMap(PortType._CF_enumeration) -Namespace.addCategoryObject('typeBinding', 'PortType', PortType) - -# Atomic simple type: ConnectionType -class ConnectionType (pyxb.binding.datatypes.string, pyxb.binding.basis.enumeration_mixin): - - """An atomic simple type.""" - - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'ConnectionType') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 64, 2) - _Documentation = None -ConnectionType._CF_enumeration = pyxb.binding.facets.CF_enumeration(value_datatype=ConnectionType, enum_prefix=None) -ConnectionType.one_to_one = ConnectionType._CF_enumeration.addEnumeration(unicode_value='one_to_one', tag='one_to_one') -ConnectionType.all_to_all = ConnectionType._CF_enumeration.addEnumeration(unicode_value='all_to_all', tag='all_to_all') -ConnectionType._InitializeFacetMap(ConnectionType._CF_enumeration) -Namespace.addCategoryObject('typeBinding', 'ConnectionType', ConnectionType) - -# Complex type [anonymous] with content type ELEMENT_ONLY -class CTD_ANON (pyxb.binding.basis.complexTypeDefinition): - """Complex type [anonymous] with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = None - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 10, 4) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - - # Element port uses Python identifier port - __port = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'port'), 'port', '__AbsentNamespace0_CTD_ANON_port', True, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 12, 8), ) - - - port = property(__port.value, __port.set, None, None) - - _ElementMap.update({ - __port.name() : __port - }) - _AttributeMap.update({ - - }) - - - -# Complex type Port with content type ELEMENT_ONLY -class Port (pyxb.binding.basis.complexTypeDefinition): - """Complex type Port with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Port') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 25, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - - # Element type uses Python identifier type - __type = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'type'), 'type', '__AbsentNamespace0_Port_type', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 27, 6), ) - - - type = property(__type.value, __type.set, None, None) - - - # Element name uses Python identifier name - __name = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'name'), 'name', '__AbsentNamespace0_Port_name', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 28, 6), ) - - - name = property(__name.value, __name.set, None, None) - - - # Element width uses Python identifier width - __width = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'width'), 'width', '__AbsentNamespace0_Port_width', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 29, 6), ) - - - width = property(__width.value, __width.set, None, None) - - - # Element sender uses Python identifier sender - __sender = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'sender'), 'sender', '__AbsentNamespace0_Port_sender', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 30, 6), ) - - - sender = property(__sender.value, __sender.set, None, None) - - - # Element receiver uses Python identifier receiver - __receiver = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'receiver'), 'receiver', '__AbsentNamespace0_Port_receiver', True, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 31, 6), ) - - - receiver = property(__receiver.value, __receiver.set, None, None) - - _ElementMap.update({ - __type.name() : __type, - __name.name() : __name, - __width.name() : __width, - __sender.name() : __sender, - __receiver.name() : __receiver - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'Port', Port) - - -# Complex type Peer with content type ELEMENT_ONLY -class Peer (pyxb.binding.basis.complexTypeDefinition): - """Complex type Peer with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Peer') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 49, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - - # Element name uses Python identifier name - __name = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'name'), 'name', '__AbsentNamespace0_Peer_name', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 51, 6), ) - - - name = property(__name.value, __name.set, None, None) - - - # Element synapse uses Python identifier synapse - __synapse = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'synapse'), 'synapse', '__AbsentNamespace0_Peer_synapse', True, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 52, 6), ) - - - synapse = property(__synapse.value, __synapse.set, None, None) - - - # Element parameters uses Python identifier parameters - __parameters = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'parameters'), 'parameters', '__AbsentNamespace0_Peer_parameters', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 53, 6), ) - - - parameters = property(__parameters.value, __parameters.set, None, None) - - _ElementMap.update({ - __name.name() : __name, - __synapse.name() : __synapse, - __parameters.name() : __parameters - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'Peer', Peer) - - -# Complex type SynapticConnection with content type ELEMENT_ONLY -class SynapticConnection (pyxb.binding.basis.complexTypeDefinition): - """Complex type SynapticConnection with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'SynapticConnection') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 56, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - - # Element target uses Python identifier target - __target = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'target'), 'target', '__AbsentNamespace0_SynapticConnection_target', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 58, 6), ) - - - target = property(__target.value, __target.set, None, None) - - - # Element type uses Python identifier type - __type = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'type'), 'type', '__AbsentNamespace0_SynapticConnection_type', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 59, 6), ) - - - type = property(__type.value, __type.set, None, None) - - - # Element selector uses Python identifier selector - __selector = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'selector'), 'selector', '__AbsentNamespace0_SynapticConnection_selector', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 60, 6), ) - - - selector = property(__selector.value, __selector.set, None, None) - - - # Element parameters uses Python identifier parameters - __parameters = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'parameters'), 'parameters', '__AbsentNamespace0_SynapticConnection_parameters', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 61, 6), ) - - - parameters = property(__parameters.value, __parameters.set, None, None) - - _ElementMap.update({ - __target.name() : __target, - __type.name() : __type, - __selector.name() : __selector, - __parameters.name() : __parameters - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'SynapticConnection', SynapticConnection) - - -# Complex type SynapticSelector with content type EMPTY -class SynapticSelector (pyxb.binding.basis.complexTypeDefinition): - """Complex type SynapticSelector with content type EMPTY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_EMPTY - _Abstract = True - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'SynapticSelector') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 72, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - _ElementMap.update({ - - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'SynapticSelector', SynapticSelector) - - -# Complex type ParameterList with content type ELEMENT_ONLY -class ParameterList (pyxb.binding.basis.complexTypeDefinition): - """Complex type ParameterList with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'ParameterList') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 95, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.anyType - - # Element parameter uses Python identifier parameter - __parameter = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'parameter'), 'parameter', '__AbsentNamespace0_ParameterList_parameter', True, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 97, 6), ) - - - parameter = property(__parameter.value, __parameter.set, None, None) - - _ElementMap.update({ - __parameter.name() : __parameter - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'ParameterList', ParameterList) - - -# Complex type Parameter with content type SIMPLE -class Parameter (pyxb.binding.basis.complexTypeDefinition): - """Complex type Parameter with content type SIMPLE""" - _TypeDefinition = pyxb.binding.datatypes.string - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_SIMPLE - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Parameter') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 100, 2) - _ElementMap = {} - _AttributeMap = {} - # Base type is pyxb.binding.datatypes.string - - # Attribute name uses Python identifier name - __name = pyxb.binding.content.AttributeUse(pyxb.namespace.ExpandedName(None, 'name'), 'name', '__AbsentNamespace0_Parameter_name', pyxb.binding.datatypes.string, required=True) - __name._DeclarationLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 103, 8) - __name._UseLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 103, 8) - - name = property(__name.value, __name.set, None, None) - - _ElementMap.update({ - - }) - _AttributeMap.update({ - __name.name() : __name - }) -Namespace.addCategoryObject('typeBinding', 'Parameter', Parameter) - - -# Complex type SliceSelector with content type ELEMENT_ONLY -class SliceSelector (SynapticSelector): - """Complex type SliceSelector with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'SliceSelector') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 73, 2) - _ElementMap = SynapticSelector._ElementMap.copy() - _AttributeMap = SynapticSelector._AttributeMap.copy() - # Base type is SynapticSelector - - # Element start uses Python identifier start - __start = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'start'), 'start', '__AbsentNamespace0_SliceSelector_start', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 77, 10), ) - - - start = property(__start.value, __start.set, None, None) - - - # Element stop uses Python identifier stop - __stop = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'stop'), 'stop', '__AbsentNamespace0_SliceSelector_stop', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 78, 10), ) - - - stop = property(__stop.value, __stop.set, None, None) - - - # Element step uses Python identifier step - __step = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'step'), 'step', '__AbsentNamespace0_SliceSelector_step', False, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 79, 10), ) - - - step = property(__step.value, __step.set, None, None) - - _ElementMap.update({ - __start.name() : __start, - __stop.name() : __stop, - __step.name() : __step - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'SliceSelector', SliceSelector) - - -# Complex type ListSelector with content type ELEMENT_ONLY -class ListSelector (SynapticSelector): - """Complex type ListSelector with content type ELEMENT_ONLY""" - _TypeDefinition = None - _ContentTypeTag = pyxb.binding.basis.complexTypeDefinition._CT_ELEMENT_ONLY - _Abstract = False - _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'ListSelector') - _XSDLocation = pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 84, 2) - _ElementMap = SynapticSelector._ElementMap.copy() - _AttributeMap = SynapticSelector._AttributeMap.copy() - # Base type is SynapticSelector - - # Element element uses Python identifier element - __element = pyxb.binding.content.ElementDeclaration(pyxb.namespace.ExpandedName(None, 'element'), 'element', '__AbsentNamespace0_ListSelector_element', True, pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 88, 10), ) - - - element = property(__element.value, __element.set, None, None) - - _ElementMap.update({ - __element.name() : __element - }) - _AttributeMap.update({ - - }) -Namespace.addCategoryObject('typeBinding', 'ListSelector', ListSelector) - - -root = pyxb.binding.basis.element(pyxb.namespace.ExpandedName(Namespace, 'root'), CTD_ANON, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 9, 2)) -Namespace.addCategoryObject('elementBinding', root.name().localName(), root) - - - -CTD_ANON._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'port'), Port, scope=CTD_ANON, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 12, 8))) - -def _BuildAutomaton (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton - del _BuildAutomaton - import pyxb.utils.fac as fac - - counters = set() - states = [] - final_update = set() - symbol = pyxb.binding.content.ElementUse(CTD_ANON._UseForTag(pyxb.namespace.ExpandedName(None, 'port')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 12, 8)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - transitions = [] - transitions.append(fac.Transition(st_0, [ - ])) - st_0._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -CTD_ANON._Automaton = _BuildAutomaton() - - - - -Port._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'type'), PortType, scope=Port, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 27, 6))) - -Port._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'name'), pyxb.binding.datatypes.string, scope=Port, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 28, 6))) - -Port._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'width'), pyxb.binding.datatypes.positiveInteger, scope=Port, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 29, 6))) - -Port._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'sender'), Peer, scope=Port, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 30, 6))) - -Port._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'receiver'), Peer, scope=Port, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 31, 6))) - -def _BuildAutomaton_ (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_ - del _BuildAutomaton_ - import pyxb.utils.fac as fac - - counters = set() - states = [] - final_update = None - symbol = pyxb.binding.content.ElementUse(Port._UseForTag(pyxb.namespace.ExpandedName(None, 'type')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 27, 6)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - final_update = None - symbol = pyxb.binding.content.ElementUse(Port._UseForTag(pyxb.namespace.ExpandedName(None, 'name')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 28, 6)) - st_1 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_1) - final_update = None - symbol = pyxb.binding.content.ElementUse(Port._UseForTag(pyxb.namespace.ExpandedName(None, 'width')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 29, 6)) - st_2 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_2) - final_update = None - symbol = pyxb.binding.content.ElementUse(Port._UseForTag(pyxb.namespace.ExpandedName(None, 'sender')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 30, 6)) - st_3 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_3) - final_update = set() - symbol = pyxb.binding.content.ElementUse(Port._UseForTag(pyxb.namespace.ExpandedName(None, 'receiver')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 31, 6)) - st_4 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_4) - transitions = [] - transitions.append(fac.Transition(st_1, [ - ])) - st_0._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_2, [ - ])) - st_1._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_3, [ - ])) - st_2._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_4, [ - ])) - st_3._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_4, [ - ])) - st_4._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -Port._Automaton = _BuildAutomaton_() - - - - -Peer._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'name'), pyxb.binding.datatypes.string, scope=Peer, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 51, 6))) - -Peer._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'synapse'), SynapticConnection, scope=Peer, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 52, 6))) - -Peer._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'parameters'), ParameterList, scope=Peer, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 53, 6))) - -def _BuildAutomaton_2 (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_2 - del _BuildAutomaton_2 - import pyxb.utils.fac as fac - - counters = set() - cc_0 = fac.CounterCondition(min=0, max=None, metadata=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 52, 6)) - counters.add(cc_0) - cc_1 = fac.CounterCondition(min=0, max=1, metadata=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 53, 6)) - counters.add(cc_1) - states = [] - final_update = set() - symbol = pyxb.binding.content.ElementUse(Peer._UseForTag(pyxb.namespace.ExpandedName(None, 'name')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 51, 6)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - final_update = set() - final_update.add(fac.UpdateInstruction(cc_0, False)) - symbol = pyxb.binding.content.ElementUse(Peer._UseForTag(pyxb.namespace.ExpandedName(None, 'synapse')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 52, 6)) - st_1 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_1) - final_update = set() - final_update.add(fac.UpdateInstruction(cc_1, False)) - symbol = pyxb.binding.content.ElementUse(Peer._UseForTag(pyxb.namespace.ExpandedName(None, 'parameters')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 53, 6)) - st_2 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_2) - transitions = [] - transitions.append(fac.Transition(st_1, [ - ])) - transitions.append(fac.Transition(st_2, [ - ])) - st_0._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_1, [ - fac.UpdateInstruction(cc_0, True) ])) - transitions.append(fac.Transition(st_2, [ - fac.UpdateInstruction(cc_0, False) ])) - st_1._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_2, [ - fac.UpdateInstruction(cc_1, True) ])) - st_2._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -Peer._Automaton = _BuildAutomaton_2() - - - - -SynapticConnection._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'target'), pyxb.binding.datatypes.string, scope=SynapticConnection, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 58, 6))) - -SynapticConnection._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'type'), ConnectionType, scope=SynapticConnection, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 59, 6))) - -SynapticConnection._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'selector'), SynapticSelector, scope=SynapticConnection, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 60, 6))) - -SynapticConnection._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'parameters'), ParameterList, scope=SynapticConnection, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 61, 6))) - -def _BuildAutomaton_3 (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_3 - del _BuildAutomaton_3 - import pyxb.utils.fac as fac - - counters = set() - cc_0 = fac.CounterCondition(min=0, max=1, metadata=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 61, 6)) - counters.add(cc_0) - states = [] - final_update = None - symbol = pyxb.binding.content.ElementUse(SynapticConnection._UseForTag(pyxb.namespace.ExpandedName(None, 'target')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 58, 6)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - final_update = None - symbol = pyxb.binding.content.ElementUse(SynapticConnection._UseForTag(pyxb.namespace.ExpandedName(None, 'type')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 59, 6)) - st_1 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_1) - final_update = set() - symbol = pyxb.binding.content.ElementUse(SynapticConnection._UseForTag(pyxb.namespace.ExpandedName(None, 'selector')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 60, 6)) - st_2 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_2) - final_update = set() - final_update.add(fac.UpdateInstruction(cc_0, False)) - symbol = pyxb.binding.content.ElementUse(SynapticConnection._UseForTag(pyxb.namespace.ExpandedName(None, 'parameters')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 61, 6)) - st_3 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_3) - transitions = [] - transitions.append(fac.Transition(st_1, [ - ])) - st_0._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_2, [ - ])) - st_1._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_3, [ - ])) - st_2._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_3, [ - fac.UpdateInstruction(cc_0, True) ])) - st_3._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -SynapticConnection._Automaton = _BuildAutomaton_3() - - - - -ParameterList._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'parameter'), Parameter, scope=ParameterList, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 97, 6))) - -def _BuildAutomaton_4 (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_4 - del _BuildAutomaton_4 - import pyxb.utils.fac as fac - - counters = set() - states = [] - final_update = set() - symbol = pyxb.binding.content.ElementUse(ParameterList._UseForTag(pyxb.namespace.ExpandedName(None, 'parameter')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 97, 6)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - transitions = [] - transitions.append(fac.Transition(st_0, [ - ])) - st_0._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -ParameterList._Automaton = _BuildAutomaton_4() - - - - -SliceSelector._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'start'), pyxb.binding.datatypes.nonNegativeInteger, scope=SliceSelector, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 77, 10))) - -SliceSelector._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'stop'), pyxb.binding.datatypes.positiveInteger, scope=SliceSelector, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 78, 10))) - -SliceSelector._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'step'), pyxb.binding.datatypes.positiveInteger, scope=SliceSelector, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 79, 10))) - -def _BuildAutomaton_5 (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_5 - del _BuildAutomaton_5 - import pyxb.utils.fac as fac - - counters = set() - states = [] - final_update = None - symbol = pyxb.binding.content.ElementUse(SliceSelector._UseForTag(pyxb.namespace.ExpandedName(None, 'start')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 77, 10)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - final_update = None - symbol = pyxb.binding.content.ElementUse(SliceSelector._UseForTag(pyxb.namespace.ExpandedName(None, 'stop')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 78, 10)) - st_1 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_1) - final_update = set() - symbol = pyxb.binding.content.ElementUse(SliceSelector._UseForTag(pyxb.namespace.ExpandedName(None, 'step')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 79, 10)) - st_2 = fac.State(symbol, is_initial=False, final_update=final_update, is_unordered_catenation=False) - states.append(st_2) - transitions = [] - transitions.append(fac.Transition(st_1, [ - ])) - st_0._set_transitionSet(transitions) - transitions = [] - transitions.append(fac.Transition(st_2, [ - ])) - st_1._set_transitionSet(transitions) - transitions = [] - st_2._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -SliceSelector._Automaton = _BuildAutomaton_5() - - - - -ListSelector._AddElement(pyxb.binding.basis.element(pyxb.namespace.ExpandedName(None, 'element'), pyxb.binding.datatypes.nonNegativeInteger, scope=ListSelector, location=pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 88, 10))) - -def _BuildAutomaton_6 (): - # Remove this helper function from the namespace after it is invoked - global _BuildAutomaton_6 - del _BuildAutomaton_6 - import pyxb.utils.fac as fac - - counters = set() - states = [] - final_update = set() - symbol = pyxb.binding.content.ElementUse(ListSelector._UseForTag(pyxb.namespace.ExpandedName(None, 'element')), pyxb.utils.utility.Location('/home/kenny/Desktop/HBP/BrainSimulation/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd', 88, 10)) - st_0 = fac.State(symbol, is_initial=True, final_update=final_update, is_unordered_catenation=False) - states.append(st_0) - transitions = [] - transitions.append(fac.Transition(st_0, [ - ])) - st_0._set_transitionSet(transitions) - return fac.Automaton(states, counters, False, containing_state=None) -ListSelector._Automaton = _BuildAutomaton_6() - diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd b/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd deleted file mode 100644 index 5e28f1305abf43d2283326d955a34af54bb5b4bb..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/schema/music.xsd +++ /dev/null @@ -1,108 +0,0 @@ -<?xml version="1.0"?> -<!-- MUSIC Documentation is available at: http://http://software.incf.org/software/music/home - - Descriptions provided inline below are from the reference documentation. ---> -<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> - - <!-- root element is a list of port connections between music applications --> - <xs:element name="root"> - <xs:complexType> - <xs:sequence> - <xs:element name="port" type="Port" minOccurs="1" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <!-- Communication between applications is handled by ports. Ports are named - sources (output ports) or sinks (input ports) of data flows. The data to be - communicated may be differently organized in process memory on the receiver - side compared to the sender side. - - The width of a port, that is the number of data elements transferred in parallel - from a cont port or the largest possible id of an event port + 1. - --> - <xs:complexType name="Port"> - <xs:sequence> - <xs:element name="type" type="PortType"/> - <xs:element name="name" type="xs:string"/> - <xs:element name="width" type="xs:positiveInteger"/> - <xs:element name="sender" type="Peer" minOccurs="1" maxOccurs="1"/> - <xs:element name="receiver" type="Peer" minOccurs="1" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - - <!-- Each application declares its ability to produce and consume data by - publishing ports. Ports are named by the application and provided with - information about the datatype (continuous data, spike events, messages) - and mapping onto different processors. - --> - <xs:simpleType name="PortType"> - <xs:restriction base="xs:string"> - <xs:enumeration value="Event"/> - <xs:enumeration value="Continuous"/> - <xs:enumeration value="Message"/> - </xs:restriction> - </xs:simpleType> - - <!-- A named peer (sender/receiver) for a port, describes the neurons/synapses to connect to/from --> - <xs:complexType name="Peer"> - <xs:sequence> - <xs:element name="name" type="xs:string"/> - <xs:element name="synapse" type="SynapticConnection" minOccurs="0" maxOccurs="unbounded"/> - <xs:element name="parameters" type="ParameterList" minOccurs="0" maxOccurs="1"/> - </xs:sequence> - </xs:complexType> - <xs:complexType name="SynapticConnection"> - <xs:sequence> - <xs:element name="target" type="xs:string"/> - <xs:element name="type" type="ConnectionType"/> - <xs:element name="selector" type="SynapticSelector" minOccurs="1" maxOccurs="1"/> - <xs:element name="parameters" type="ParameterList" minOccurs="0" maxOccurs="1"/> - </xs:sequence> - </xs:complexType> - <xs:simpleType name="ConnectionType"> - <xs:restriction base="xs:string"> - <xs:enumeration value="one_to_one"/> - <xs:enumeration value="all_to_all"/> - </xs:restriction> - </xs:simpleType> - - <!-- neuron/synapse selection, similar to the abstract selectors in the BIBI --> - <xs:complexType name="SynapticSelector" abstract="true"/> - <xs:complexType name="SliceSelector"> - <xs:complexContent> - <xs:extension base="SynapticSelector"> - <xs:sequence> - <xs:element name="start" type="xs:nonNegativeInteger"/> - <xs:element name="stop" type="xs:positiveInteger"/> - <xs:element name="step" type="xs:positiveInteger"/> - </xs:sequence> - </xs:extension> - </xs:complexContent> - </xs:complexType> - <xs:complexType name="ListSelector"> - <xs:complexContent> - <xs:extension base="SynapticSelector"> - <xs:sequence> - <xs:element name="element" type="xs:nonNegativeInteger" maxOccurs="unbounded"/> - </xs:sequence> - </xs:extension> - </xs:complexContent> - </xs:complexType> - - <!-- A list of parameters with attribute name and key value (string) --> - <xs:complexType name="ParameterList"> - <xs:sequence> - <xs:element name="parameter" type="Parameter" minOccurs="1" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - <xs:complexType name="Parameter"> - <xs:simpleContent> - <xs:extension base="xs:string"> - <xs:attribute name="name" type="xs:string" use="required"/> - </xs:extension> - </xs:simpleContent> - </xs:complexType> - -</xs:schema> diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/__init__.py deleted file mode 100644 index fcfe222a11988ebfc1b64c29cd3623d1aed6e018..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This package contains all tests for the MUSIC-XML package -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/__init__.py deleted file mode 100644 index 1e62c493f2226569fcefa4645ca9ce1d4b86b105..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This package contains all tests for the MUSIC config package. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/test_music_config.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/test_music_config.py deleted file mode 100644 index 67d9ca1582d1962017d9dfa97c8ec6e150e7a7e2..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/config/test_music_config.py +++ /dev/null @@ -1,75 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest -import io - -from mock import patch -import hbp_nrp_music_xml.config.music_config as config - -__author__ = 'Martin Schulze, Kenny Sharma' - - -class MockedPortReceiver(object): - def __init__(self, name): - self.name = name - - -class MockedXMLPort(object): - sender = MockedPortReceiver('sender') - name = "port" - receiver = [MockedPortReceiver('receiver1')] - width = 42 - - def __str__(self): - return 'port' - - -class TestMusicConfig(unittest.TestCase): - - # application tests - def test_application(self): - ma = config.Application('foo', 'bar', ['arg1', 'arg2'], 3) - self.assertEqual(ma.name, 'foo') - self.assertEqual(ma.binary, 'bar') - self.assertEqual(ma.args, '"arg1 arg2"') - self.assertEqual(ma.num_processes, 3) - - # config writer tests - def test_config_writer(self): - header = {'foo': 'bar'} - apps = [config.Application('foo', 'bar', None, 3)] - projs = [MockedXMLPort()] - mcw = config.MusicConfigWriter(header, apps, projs) - self.assertEqual(str(mcw), - 'foo = "bar"\n\n[foo]\nnp = 3\nbinary = bar\n' +\ - 'args = \n\nport\n') - - # music config port mock test - @patch("hbp_nrp_music_xml.schema.generated.music_xml.Port", new=MockedXMLPort) - def test_config_port(self): - proj = config.MusicConfigPort(MockedXMLPort()) - self.assertEqual(str(proj), 'sender.port -> receiver1.port [42]') - -if __name__ == "__main__": - unittest.main() diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/__init__.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/__init__.py deleted file mode 100644 index 30b6db464b6216853961df35de6a39ac6aae9afc..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -Unit tests for the MUSIC XML -> PyNN Proxy factories. -""" - -__author__ = 'Martin Schulze' diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_factory.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_factory.py deleted file mode 100644 index 76b34640a43759500314f80ddbab3f076606ff2c..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_factory.py +++ /dev/null @@ -1,169 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest -from mock import MagicMock - -from hbp_nrp_music_xml.pynn.factory import PyNNProxyFactory, export_proxy, create_proxy_via_native_cell_types -from hbp_nrp_music_xml.pynn.connector_factory import PyNNConnectorFactory -from hbp_nrp_music_xml.pynn.cell_types import load_cell_types -from hbp_nrp_music_xml.schema.generated import music_xml - -import pyNN.nest as sim -import nest - -__author__ = 'Martin Schulze' - -class TestPyNNConnectorFactory(unittest.TestCase): - - def test_create_and_connect_synapse(self): - nest.ResetKernel() - connector_factory = PyNNConnectorFactory(sim) - - def check_all_to_all(source_ids, target_ids): - for target_id in target_ids: - for source_id in source_ids: - connections = nest.GetConnections(source=[source_id], - target=[target_id]) - self.assertTrue(connections) - self.assertTrue(len(connections) == 1) - - def check_one_to_one(source_ids, target_ids): - for (source_id, target_id) in zip(source_ids, target_ids): - connections = nest.GetConnections(source=[source_id], - target=[target_id]) - self.assertTrue(connections) - self.assertTrue(len(connections) == 1) - - def test_case(connection_rule, population_slice, is_output_proxy): - sim.setup(min_delay=0.1, max_delay=20.0, threads=1) - connection_check_func = {'all_to_all': check_all_to_all, - 'one_to_one': check_one_to_one} - - if is_output_proxy: - proxy = sim.Population(1, sim.IF_cond_alpha()) - else: - proxy = sim.Population(10, sim.IF_cond_alpha()) - - target_population = sim.Population(10, sim.IF_cond_alpha()) - connector_factory.create_and_connect_synapse(proxy, "test_to_cle", - connection_rule, - population_slice, - target_population, - is_output_proxy) - connections = nest.GetConnections() - proxy_ids = map(int, proxy.all_cells) - target_ids = map(int, target_population.all_cells) - if population_slice: - target_ids = target_ids[population_slice] - if is_output_proxy: - connection_check_func[connection_rule](target_ids, proxy_ids) - else: - connection_check_func[connection_rule](proxy_ids, target_ids) - sim.end() - nest.ResetKernel() - - # Output proxy tests - test_case('all_to_all', None, True) - test_case('all_to_all', slice(0, 5, 1), True) - test_case('one_to_one', None, True) - test_case('one_to_one', slice(0, 5, 1), True) - - # Input proxy tests - test_case('all_to_all', None, False) - test_case('all_to_all', slice(0, 5, 1), False) - test_case('one_to_one', None, False) - test_case('one_to_one', slice(0, 5, 1), False) - test_case('all_to_all', slice(0,11,1), False) - - # Invalid test cases - with self.assertRaises(Exception): - test_case('foo', None, False) - -class TestPyNNProxyFactory(unittest.TestCase): - - def setUp(self): - sim.setup(min_delay=0.1, max_delay=20.0, threads=1) - self._music_cell_types = load_cell_types(sim) - self._music_event_in_cell = self._music_cell_types['in']['Event'] - self._music_event_out_cell = self._music_cell_types['out']['Event'] - self._parrot_cell = self._music_cell_types['parrot'] - - def tearDown(self): - sim.end() - nest.ResetKernel() - - def test_create_proxy_via_native_cell_types(self): - - def setup_nest_mocks(): - # nest.SetStatus = MagicMock(return_value=False) - nest.SetAcceptableLatency = MagicMock(return_value=False) - - def check_nest_calls(proxy, port_name, acc_latency, is_output_proxy): - proxy_ids = map(int, proxy.all_cells) - self.assertEqual(nest.GetStatus(proxy_ids, 'port_name'), (port_name,)*len(proxy_ids)) - if not is_output_proxy: - for i, proxy_id in enumerate(proxy_ids): - self.assertEqual(nest.GetStatus([proxy_id], 'music_channel')[0], i) - - set_acc_latency_call_args = nest.SetAcceptableLatency.call_args_list - self.assertEqual(set_acc_latency_call_args[0][0][:], (port_name, acc_latency)) - - # Input proxy test - setup_nest_mocks() - proxy = create_proxy_via_native_cell_types(sim, 2, self._music_event_in_cell, "test", "Event", 10.0, False) - check_nest_calls(proxy, "test", 10.0, False) - - setup_nest_mocks() - proxy = create_proxy_via_native_cell_types(sim, 2, self._music_event_in_cell, "test", "Event", None, False) - check_nest_calls(proxy, "test", sim.get_min_delay(), False) - - # Output proxy test - proxy = create_proxy_via_native_cell_types(sim, 2, self._music_event_out_cell, "test", "Event", 10.0, True) - check_nest_calls(proxy, "test", 10.0, True) - - def test_export_proxy(self): - presyn_pop = sim.Population(2, sim.IF_cond_alpha()) - proxy = create_proxy_via_native_cell_types(sim, 1, self._music_event_out_cell, "test", "Event", None, True) - proxy_ids = map(int, proxy.all_cells) - export_proxy(sim, presyn_pop, proxy, 3.0) - connections = nest.GetConnections(target=proxy_ids) - delays = nest.GetStatus(connections, 'delay') - music_channels = nest.GetStatus(connections, 'receptor') - self.assertTrue(delays, (3.0,)*len(proxy_ids)) - self.assertTrue(music_channels, range(len(proxy_ids))) - - def test_create_proxy(self): - proxy_factory = PyNNProxyFactory(sim) - proxy_parrots = proxy_factory.create_proxy("test", "Event", 2, True) - self.assertEqual(proxy_parrots.celltype.nest_name['on_grid'], 'parrot_neuron') - self.assertEqual(proxy_parrots.size, 2) - - -if __name__ == "__main__": - unittest.main() - - - - - diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_xml_factory.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_xml_factory.py deleted file mode 100644 index 8c7074084e7745a2c7e5df85a27f9256457b3b55..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/tests/pynn/test_xml_factory.py +++ /dev/null @@ -1,178 +0,0 @@ -# ---LICENSE-BEGIN - DO NOT CHANGE OR MOVE THIS HEADER -# This file is part of the Neurorobotics Platform software -# Copyright (C) 2014,2015,2016,2017 Human Brain Project -# https://www.humanbrainproject.eu -# -# The Human Brain Project is a European Commission funded project -# in the frame of the Horizon2020 FET Flagship plan. -# http://ec.europa.eu/programmes/horizon2020/en/h2020-section/fet-flagships -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# ---LICENSE-END -import unittest -from mock import Mock, patch, MagicMock - -from hbp_nrp_music_xml.pynn.xml_factory import XmlFactory, create_selector, create_pop_slice -from hbp_nrp_music_xml.pynn.xml_factory import extract_kwargs, is_application_receiver, build_port_overview_table -from hbp_nrp_music_xml.schema.generated import music_xml - -import pyNN.nest as sim -import nest - -__author__ = 'Martin Schulze' - - -class TestPyNNXMLFactory(unittest.TestCase): - - def setUp(self): - self._population_dict = {'Pop1': sim.Population(10, sim.IF_cond_alpha()), - 'Pop2': sim.Population(5, sim.IF_cond_alpha())} - self._connector_factory = None - def create_proxy(port_name, proxy_type, port_width, - is_output_proxy, synaptic_delay=None): - if is_output_proxy: - return sim.Population(1, sim.IF_cond_alpha()) - else: - return sim.Population(10, sim.IF_cond_alpha()) - - self._proxy_factory = MagicMock() - self._proxy_factory.create_proxy = MagicMock(side_effect=create_proxy) - self._xml_factory = XmlFactory("TestApp", self._connector_factory, - self._proxy_factory, self._population_dict) - - def test_create_pop_slice(self): - slice_selector = music_xml.SliceSelector() - slice_selector.start = 0 - slice_selector.stop = 9 - slice_selector.step = 2 - population_slice = create_pop_slice(slice_selector) - self.assertEqual(slice(0, 9, 2), population_slice) - - list_selector = music_xml.ListSelector() - list_selector.element = [0,2,4,6] - population_slice_list = create_pop_slice(list_selector) - self.assertEqual([0,2,4,6], population_slice_list) - with self.assertRaises(Exception): - create_pop_slice(None) - - def test_create_selector(self): - xml_synapse = music_xml.SynapticConnection() - selector = create_selector(xml_synapse) - self.assertIsNone(selector) - - xml_synapse.selector = music_xml.SliceSelector() - xml_synapse.selector.start = 0 - xml_synapse.selector.stop = 9 - xml_synapse.selector.step = 1 - selector = create_selector(xml_synapse) - self.assertEqual(selector, slice(0, 9, 1)) - - def test_get_synaptic_target_population(self): - xml_synapse = music_xml.SynapticConnection() - with self.assertRaises(Exception): - self._xml_factory._get_synaptic_target_population(xml_synapse) - - with self.assertRaises(Exception): - xml_synapse.target = 'Pop3' - self._xml_factory._get_synaptic_target_population(xml_synapse) - - xml_synapse.target = 'Pop1' - self.assertEqual(self._xml_factory. - _get_synaptic_target_population(xml_synapse), - self._population_dict['Pop1']) - - def test_create_and_connect_proxy(self): - - def check_create_proxy_args(xml_projection, is_output_proxy): - call_args_list = self._proxy_factory.create_proxy.call_args_list - self.assertEqual(call_args_list[0][0][0], xml_projection.name) - self.assertEqual(call_args_list[0][0][1], xml_projection.type) - self.assertEqual(call_args_list[0][0][2], xml_projection.width) - self.assertEqual(call_args_list[0][0][3], True) - - xml_projection = music_xml.Port() - xml_projection.type = "Event" - xml_projection.name = "Port1" - xml_projection.connector = "Static" - xml_projection.width = 10 - xml_peer = music_xml.Peer() - xml_peer.synapse = None - xml_peer.name = "App1" - - # Without synapses - with self.assertRaises(Exception): - proxy = self._xml_factory._create_and_connect_proxy(xml_projection, - xml_peer, True) - - with self.assertRaises(Exception): - proxy = self._xml_factory._create_and_connect_proxy(xml_projection, - xml_peer, False) - - # With synapses - xml_synapse = music_xml.SynapticConnection() - xml_synapse.target = "Pop1" - xml_synapse.type = "one_to_one" - xml_projection.synapse = xml_synapse - xml_peer.synapse = 'foo' - self.assertRaises(Exception, self._xml_factory._create_and_connect_proxy, - xml_projection, xml_peer, True) - - def test_assemble_proxy(self): - xml_projection = music_xml.Port() - xml_sender = music_xml.Peer() - xml_sender.name = "Sender1" - xml_receiver = music_xml.Peer() - xml_receiver.name = "Receiver1" - xml_projection.sender = xml_sender - xml_projection.receiver = [xml_receiver, xml_sender] - xml_factory_sender = XmlFactory("Sender1", - self._connector_factory, - self._proxy_factory, - self._population_dict) - xml_factory_receiver = XmlFactory("Receiver1", - self._connector_factory, - self._proxy_factory, - self._population_dict) - xml_factory_sender._create_and_connect_proxy = MagicMock() - xml_factory_receiver._create_and_connect_proxy = MagicMock() - - self._xml_factory._assemble_proxy(xml_projection) - - def test_extract_kwargs(self): - self.assertEquals(extract_kwargs(None), {}) - - def test_application_receiver(self): - xml_port = music_xml.Port() - xml_port.receiver = [] - self.assertEqual(is_application_receiver('foo', xml_port), False) - - xml_receiver = music_xml.Peer() - xml_receiver.name = 'foo' - xml_port.receiver = [xml_receiver] - self.assertEqual(is_application_receiver('foo', xml_port), True) - - def test_build_port_overview_table(self): - xml_port = music_xml.Port(name='bar.port', type='Event', width=42, sender=music_xml.Peer(name='foo')) - self.assertEqual(str(build_port_overview_table([xml_port], 'foo')), - '+----------+-------+-------+-----------+\n' + - '| Portname | Type | Width | Direction |\n' + - '+----------+-------+-------+-----------+\n' + - '| bar.port | Event | 42 | Outgoing |\n' + - '+----------+-------+-------+-----------+') - -if __name__ == "__main__": - unittest.main() - - diff --git a/hbp_nrp_music_xml/hbp_nrp_music_xml/version.py b/hbp_nrp_music_xml/hbp_nrp_music_xml/version.py deleted file mode 100644 index cff3ffe78f84bd6b7a67779ef89754d7be4f8d83..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/hbp_nrp_music_xml/version.py +++ /dev/null @@ -1,2 +0,0 @@ -'''version string - generated by setVersion.sh''' -VERSION = '2.3.0' diff --git a/hbp_nrp_music_xml/requirements.txt b/hbp_nrp_music_xml/requirements.txt deleted file mode 100644 index bb56fe37267b41bcc172e2f323c2f3bf8e31ef95..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -# third party requirements -configparser==3.5.0 -prettytable==0.7.2 -pyxb==1.2.4 diff --git a/hbp_nrp_music_xml/requirements_extension_tests.txt b/hbp_nrp_music_xml/requirements_extension_tests.txt deleted file mode 100644 index 031ce958f7c92f34b5aebfd200ba995fa2a54b88..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/requirements_extension_tests.txt +++ /dev/null @@ -1,3 +0,0 @@ -#the following is required for the unit testing -mock==1.0.1 -testfixtures==3.0.2 diff --git a/hbp_nrp_music_xml/setup.py b/hbp_nrp_music_xml/setup.py deleted file mode 100644 index ba19ca8ceafa8ff3aca221baa4590f11c2a714d2..0000000000000000000000000000000000000000 --- a/hbp_nrp_music_xml/setup.py +++ /dev/null @@ -1,71 +0,0 @@ -'''setup.py''' - -from setuptools import setup - -import hbp_nrp_music_xml -import pip - -from optparse import Option -options = Option('--workaround') -options.skip_requirements_regex = None -reqs_file = './requirements.txt' -options = Option("--workaround") -options.skip_requirements_regex = None -# Hack for old pip versions -if pip.__version__.startswith('10.'): - # Versions greater or equal to 10.x don't rely on pip.req.parse_requirements - install_reqs = list(val.strip() for val in open(reqs_file)) - reqs = install_reqs -elif pip.__version__.startswith('1.'): - # Versions 1.x rely on pip.req.parse_requirements - # but don't require a "session" parameter - from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error - install_reqs = parse_requirements(reqs_file, options=options) - reqs = [str(ir.req) for ir in install_reqs] -else: - # Versions greater than 1.x but smaller than 10.x rely on pip.req.parse_requirements - # and requires a "session" parameter - from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error - from pip.download import PipSession # pylint:disable=no-name-in-module, import-error - options.isolated_mode = False - install_reqs = parse_requirements( # pylint:disable=unexpected-keyword-arg - reqs_file, - session=PipSession, - options=options - ) - reqs = [str(ir.req) for ir in install_reqs] - -# ensure we install numpy before the main list of requirements, ignore -# failures if numpy/cython are not requirements and just proceed (future proof) -try: - cython_req = next(r for r in reqs if r.startswith('cython')) - numpy_req = next(r for r in reqs if r.startswith('numpy')) - if pip.__version__.startswith('10.'): - import subprocess - subprocess.check_call( - ["python", '-m', 'pip', 'install', "--no-clean", "--user", cython_req, numpy_req] - ) - else: - pip.main(['install', '--no-clean', cython_req, numpy_req]) # pylint:disable=no-member -# pylint: disable=bare-except -except: - pass - -config = { - 'description': 'MUSIC XML support for pyNN/NEST for HBP SP10', - 'author': 'HBP Neurorobotics', - 'url': 'http://neurorobotics.net', - 'author_email': 'neurorobotics@humanbrainproject.eu', - 'version': hbp_nrp_music_xml.__version__, - 'install_requires': reqs, - 'packages': ['hbp_nrp_music_xml', - 'hbp_nrp_music_xml.config', - 'hbp_nrp_music_xml.pynn', - 'hbp_nrp_music_xml.schema', - 'hbp_nrp_music_xml.schema.generated'], - 'scripts': [], - 'name': 'hbp-nrp-music-xml', - 'include_package_data': True, -} - -setup(**config) diff --git a/hbp_nrp_music_xml_deprec.tar.gz b/hbp_nrp_music_xml_deprec.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..4c2fd8943ca9c6237dae4d4833a0147ab9ea7e17 Binary files /dev/null and b/hbp_nrp_music_xml_deprec.tar.gz differ diff --git a/verify.sh b/verify.sh index 662e0df46e68e6a4037336f3de812cda248b3781..ec2889c4f23fda6d2beeb7f312e073c636d64681 100755 --- a/verify.sh +++ b/verify.sh @@ -2,10 +2,10 @@ # This script is designed for local usage. # Ignore generated files -# export IGNORE_LINT="platform_venv|hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated" +# export IGNORE_LINT="platform_venv|" -# Ignore generated and music related files -export IGNORE_LINT='platform_venv|hbp_nrp_music_xml|hbp_nrp_music_interface|hbp_nrp_music_xml/hbp_nrp_music_xml/schema/generated|migrations|nest' +# Ignore generated related files +export IGNORE_LINT='platform_venv|migrations|nest' export VIRTUAL_ENV=$NRP_VIRTUAL_ENV # This script only runs static code analysis, the tests can be run separately using run_tests.sh