Skip to content
Snippets Groups Projects
Commit 3c03f682 authored by Manos Angelidis's avatar Manos Angelidis Committed by Ugo Albanese
Browse files

Merged in nengo_loihi (pull request #137)

[NUIT-225] Added nengo_loihi implementation

Approved-by: Ugo Albanese
parent f40d3074
No related branches found
No related tags found
No related merge requests found
...@@ -328,7 +328,6 @@ class ROSCLEServer(SimulationServer): ...@@ -328,7 +328,6 @@ class ROSCLEServer(SimulationServer):
tf_framework.TransferFunction.excepthook = self.__tf_except_hook tf_framework.TransferFunction.excepthook = self.__tf_except_hook
tf_framework.TF_API.set_ros_cle_server(self) tf_framework.TF_API.set_ros_cle_server(self)
if self.timeout_type == TimeoutType.SIMULATION: if self.timeout_type == TimeoutType.SIMULATION:
......
...@@ -188,6 +188,8 @@ class ROSCLESimulationFactory(object): ...@@ -188,6 +188,8 @@ class ROSCLESimulationFactory(object):
assembly = ServerConfigurations.SynchronousSpinnakerSimulation assembly = ServerConfigurations.SynchronousSpinnakerSimulation
elif sim_config.simulation_type is SimulationType.NENGO_SYNC: elif sim_config.simulation_type is SimulationType.NENGO_SYNC:
assembly = ServerConfigurations.SynchronousNengoSimulation assembly = ServerConfigurations.SynchronousNengoSimulation
elif sim_config.simulation_type is SimulationType.NENGO_LOIHI_SYNC:
assembly = ServerConfigurations.SynchronousNengoLoihiSimulation
elif sim_config.simulation_type is SimulationType.ROBOT_ROS_SYNC: elif sim_config.simulation_type is SimulationType.ROBOT_ROS_SYNC:
assembly = ServerConfigurations.SynchronousRobotRosNest assembly = ServerConfigurations.SynchronousRobotRosNest
elif sim_config.simulation_type is SimulationType.NEST_DIRECT_SYNC: elif sim_config.simulation_type is SimulationType.NEST_DIRECT_SYNC:
......
...@@ -27,6 +27,8 @@ by a class that adopts the SimulationAssembly API. ...@@ -27,6 +27,8 @@ by a class that adopts the SimulationAssembly API.
""" """
from hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly import CLEGazeboSimulationAssembly from hbp_nrp_cleserver.server.CLEGazeboSimulationAssembly import CLEGazeboSimulationAssembly
import logging
logger = logging.getLogger(__name__)
def unused(_): def unused(_):
...@@ -96,25 +98,38 @@ def brain_direct_nest_adapters(): ...@@ -96,25 +98,38 @@ def brain_direct_nest_adapters():
return braincomm, braincontrol return braincomm, braincontrol
def brain_nengo_adapters(): def brain_nengo_adapters(loihi=False):
""" """
Creates the adapter components for the neural simulator, configuration with Nengo 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 :return: A tuple of the communication and control adapter for the neural simulator
""" """
# pylint: disable=unused-variable # pylint: disable=unused-variable
try: try:
import nengo # pylint: disable=unused-import 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: except ImportError:
raise Exception("Nengo does not seem to be installed on this machine. " raise Exception(ex_msg)
"Please install Nengo in order to use it in the NRP "
"or use a different server.")
from hbp_nrp_cle.brainsim.nengo.NengoSimulationState import NengoSimulationState from hbp_nrp_cle.brainsim.nengo.NengoSimulationState import NengoSimulationState
from hbp_nrp_cle.brainsim.nengo.NengoControlAdapter import NengoControlAdapter from hbp_nrp_cle.brainsim.nengo.NengoControlAdapter import NengoControlAdapter
from hbp_nrp_cle.brainsim.nengo.NengoCommunicationAdapter import NengoCommunicationAdapter from hbp_nrp_cle.brainsim.nengo.NengoCommunicationAdapter import NengoCommunicationAdapter
sim_state = NengoSimulationState() sim_state = NengoSimulationState(loihi)
brain_control = NengoControlAdapter(sim_state) brain_control = NengoControlAdapter(sim_state, loihi)
brain_comm = NengoCommunicationAdapter(sim_state) brain_comm = NengoCommunicationAdapter(sim_state)
return brain_comm, brain_control return brain_comm, brain_control
...@@ -248,6 +263,29 @@ class SynchronousRobotRosNest(CLEGazeboSimulationAssembly): ...@@ -248,6 +263,29 @@ class SynchronousRobotRosNest(CLEGazeboSimulationAssembly):
return brain_nest_adapters() return brain_nest_adapters()
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)
class SynchronousNengoSimulation(CLEGazeboSimulationAssembly): class SynchronousNengoSimulation(CLEGazeboSimulationAssembly):
""" """
This class represents a synchronous simulation assembly using Nengo as the neural simulator This class represents a synchronous simulation assembly using Nengo as the neural simulator
......
...@@ -6,7 +6,9 @@ hbp-nrp-backend ...@@ -6,7 +6,9 @@ hbp-nrp-backend
pyxb==1.2.6 pyxb==1.2.6
Jinja2>=2.11.2 Jinja2>=2.11.2
defusedxml==0.6.0 defusedxml==0.6.0
nengo==2.8.0 nengo==3.1.0
# the version of nengo_loihi compatible with nxsdk 1.0.0
nengo-loihi @ git+https://github.com/nengo/nengo-loihi.git@00ef8e3c8309cf347a8e02d6367bba583ee33932
future future
RestrictedPython==3.6.0; python_version=="2.7" RestrictedPython==3.6.0; python_version=="2.7"
RestrictedPython>=4.0; python_version >= "3.0" RestrictedPython>=4.0; python_version >= "3.0"
\ No newline at end of file
...@@ -64,6 +64,7 @@ class SimulationType(Enum): # pragma: no cover ...@@ -64,6 +64,7 @@ class SimulationType(Enum): # pragma: no cover
NEST_DIST = 0x11000002 NEST_DIST = 0x11000002
SPINNAKER_SYNC = 0x11000003 SPINNAKER_SYNC = 0x11000003
NENGO_SYNC = 0x11000004 NENGO_SYNC = 0x11000004
NENGO_LOIHI_SYNC = 0x11000005
ROBOT_ROS_SYNC = 0x11000006 ROBOT_ROS_SYNC = 0x11000006
NEST_DIRECT_SYNC = 0x11000007 NEST_DIRECT_SYNC = 0x11000007
...@@ -316,6 +317,8 @@ class SimConfig(object): ...@@ -316,6 +317,8 @@ class SimConfig(object):
bibi_parser.SimulationMode.SynchronousSpinnakerSimulation: bibi_parser.SimulationMode.SynchronousSpinnakerSimulation:
SimulationType.SPINNAKER_SYNC, SimulationType.SPINNAKER_SYNC,
bibi_parser.SimulationMode.SynchronousNengoSimulation: SimulationType.NENGO_SYNC, bibi_parser.SimulationMode.SynchronousNengoSimulation: SimulationType.NENGO_SYNC,
bibi_parser.SimulationMode.SynchronousNengoLoihiSimulation: \
SimulationType.NENGO_LOIHI_SYNC,
bibi_parser.SimulationMode.SynchronousRobotRosNest: SimulationType.ROBOT_ROS_SYNC, bibi_parser.SimulationMode.SynchronousRobotRosNest: SimulationType.ROBOT_ROS_SYNC,
bibi_parser.SimulationMode.SynchronousDirectNestSimulation: bibi_parser.SimulationMode.SynchronousDirectNestSimulation:
SimulationType.NEST_DIRECT_SYNC, SimulationType.NEST_DIRECT_SYNC,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment