Source code for hbp_nrp_cleserver.server.ServerConfigurations

# ---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 existing server configuration. Each configuration is represented
by a class that adopts the SimulationAssembly API.
"""

from hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly import CLEGazeboSimulationAssembly
import logging
logger = logging.getLogger(__name__)


[docs]def unused(_): """ Marks an argument as unused """ pass
[docs]def robot_gazebo_ros_adapters(): """ Creates the adapter components for the robot side, configuration with Gazebo :return: A tuple of the communication and control adapter for the robot side """ from hbp_nrp_cle.robotsim.RosControlAdapter import RosControlAdapter from hbp_nrp_cle.robotsim.RosCommunicationAdapter import RosCommunicationAdapter # control adapter robotcontrol = RosControlAdapter() # communication adapter robotcomm = RosCommunicationAdapter() return robotcomm, robotcontrol
[docs]def robot_ros_adapters(): """ Creates the adapter components for the robot side, configuration with the real robot :return: A tuple of the communication and control adapter for the robot side """ from hbp_nrp_cle.robotsim.RosRobotControlAdapter import RosRobotControlAdapter from hbp_nrp_cle.robotsim.RosCommunicationAdapter import RosCommunicationAdapter # control adapter robotcontrol = RosRobotControlAdapter() # communication adapter robotcomm = RosCommunicationAdapter() return robotcomm, robotcontrol
[docs]def brain_nest_adapters(): """ Creates the adapter components for the neural simulator, configuration with NEST :return: A tuple of the communication and control adapter for the neural simulator """ import pyNN.nest as nestsim from hbp_nrp_cle.brainsim.pynn.PyNNControlAdapter import PyNNControlAdapter from hbp_nrp_cle.brainsim.pynn_nest.PyNNNestCommunicationAdapter import \ PyNNNestCommunicationAdapter braincontrol = PyNNControlAdapter(nestsim) braincomm = PyNNNestCommunicationAdapter() return braincomm, braincontrol
[docs]def brain_direct_nest_adapters(): """ Creates the adapter components for the neural simulator, configuration with direct NEST :return: A tuple of the communication and control adapter for the neural simulator """ import nest from hbp_nrp_cle.brainsim.nest.NestControlAdapter import NestControlAdapter from hbp_nrp_cle.brainsim.nest.NestCommunicationAdapter import \ NestCommunicationAdapter braincontrol = NestControlAdapter(nest) braincomm = NestCommunicationAdapter() return braincomm, braincontrol
[docs]def brain_nengo_adapters(loihi=False): """ Creates the adapter components for the neural simulator, configuration with Nengo :param: loihi: Indicates whether the backend is loihi :return: A tuple of the communication and control adapter for the neural simulator """ # pylint: disable=unused-variable try: if loihi: ex_msg = ("nengo_loihi does not seem to be installed on this machine. " "Please install nengo_loihi in order to use it in the NRP. " "Make sure that the loihi board is connected and works.") import nengo_loihi # pylint: disable=unused-import logger.warn("Warning! " "If no loihi board is found by Nengo, " "the simulation will use the CPU as a backend." "Please make sure that your loihi board is connected and works.") else: ex_msg = ("Nengo does not seem to be installed on this machine. " "Please install Nengo in order to use it in the NRP " "or use a different server.") import nengo # pylint: disable=unused-import except ImportError: raise Exception(ex_msg) from hbp_nrp_cle.brainsim.nengo.NengoSimulationState import NengoSimulationState from hbp_nrp_cle.brainsim.nengo.NengoControlAdapter import NengoControlAdapter from hbp_nrp_cle.brainsim.nengo.NengoCommunicationAdapter import NengoCommunicationAdapter sim_state = NengoSimulationState(loihi) brain_control = NengoControlAdapter(sim_state, loihi) brain_comm = NengoCommunicationAdapter(sim_state) return brain_comm, brain_control
[docs]def brain_spinnaker_adapters(): # pragma: no cover """ Creates the adapter components for the neural simulator, configuration with SpiNNaker :return: A tuple of the communication and control adapter for the neural simulator """ # pylint: disable=import-error, no-name-in-module try: import pyNN.spiNNaker as spinnaker except ImportError: try: import spynnaker8 as spinnaker except ImportError: raise Exception("Spinnaker does not seem to be installed on this machine. " "Please install Spinnaker in order to use it in the NRP " "or use a different server.") from hbp_nrp_cle.brainsim.pynn_spiNNaker.PyNNSpiNNakerCommunicationAdapter import \ PyNNSpiNNakerCommunicationAdapter from hbp_nrp_cle.brainsim.pynn_spiNNaker.PyNNSpiNNakerControlAdapter import \ PySpiNNakerControlAdapter return PyNNSpiNNakerCommunicationAdapter(), PySpiNNakerControlAdapter(spinnaker)
[docs]class SynchronousNestSimulation(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using Nest as the neural simulator synchronous to Gazebo """ 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 """ return brain_nest_adapters()
[docs]class SynchronousDirectNestSimulation(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using NEST as the neural simulator synchronous to Gazebo """ 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 """ return brain_direct_nest_adapters()
[docs]class SynchronousSpinnakerSimulation(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using SpiNNaker as the neural simulator """ def _create_robot_adapters(self): # pragma: no cover """ 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): # pragma: no cover """ Creates the adapter components for the neural simulator :return: A tuple of the communication and control adapter for the neural simulator """ return brain_spinnaker_adapters()
[docs]class SynchronousRobotRosNest(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using Nest as the neural simulator and a real robotic platform that uses ROS """ def _load_environment(self, world_file_abs_path): """ Loads the environment in Gazebo :param world_file: Backwards compatibility for world file specified through webpage """ unused(world_file_abs_path) return None, None def _load_robot(self): """ Loads the robot in Gazebo """ return None 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_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 """ return brain_nest_adapters()
[docs]class SynchronousNengoLoihiSimulation(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using Nengo as the neural simulator synchronous to Gazebo and loihi as a hardware backend """ 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 """ return brain_nengo_adapters(loihi=True)
[docs]class SynchronousNengoSimulation(CLEGazeboSimulationAssembly): """ This class represents a synchronous simulation assembly using Nengo as the neural simulator synchronous to Gazebo """ 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 """ return brain_nengo_adapters()