SynapseLauncher.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from core.ConfigurationManager.BrainLoader import BrainLoader
  2. from core.NeuroneLauncher import NeuroneLauncher
  3. class SynapseNameNotFound(Exception):
  4. pass
  5. class SynapseLauncher(object):
  6. def __init__(self):
  7. pass
  8. @classmethod
  9. def start_synapse(cls, name, brain=None):
  10. """
  11. Start a synapse by it's name
  12. :param name: Name (Unique ID) of the synapse to launch
  13. :param brain: Brain instance
  14. """
  15. synapse_name_launch = name
  16. # get the brain
  17. cls.brain = brain
  18. # check if we have found and launched the synapse
  19. synapse_launched = False
  20. for synapse in cls.brain.synapses:
  21. if synapse.name == synapse_name_launch:
  22. cls._run_synapse(synapse)
  23. synapse_launched = True
  24. # we found the synapse, we don't need to check the rest of the list
  25. break
  26. if not synapse_launched:
  27. raise SynapseNameNotFound("The synapse name \"%s\" does not exist in the brain file" % name)
  28. @classmethod
  29. def _run_synapse(cls, synapse):
  30. """
  31. Start all neurons in the synapse
  32. :param synapse: Synapse for which we run neurons
  33. :return:
  34. """
  35. for neuron in synapse.neurons:
  36. NeuroneLauncher.start_neurone(neuron)
  37. return True