bsb-nest 4.2.1__py2.py3-none-any.whl → 4.3.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bsb-nest might be problematic. Click here for more details.

bsb_nest/__init__.py CHANGED
@@ -9,4 +9,4 @@ from .adapter import NestAdapter
9
9
  from .simulation import NestSimulation
10
10
 
11
11
  __plugin__ = SimulationBackendPlugin(Simulation=NestSimulation, Adapter=NestAdapter)
12
- __version__ = "4.2.1"
12
+ __version__ = "4.3.1"
bsb_nest/device.py CHANGED
@@ -1,7 +1,12 @@
1
+ import typing
1
2
  import warnings
2
3
 
3
4
  import nest
4
- from bsb import DeviceModel, Targetting, config, refs, types
5
+ from bsb import DeviceModel, SimulationData, Targetting, config, refs, types
6
+
7
+ if typing.TYPE_CHECKING:
8
+ from .adapter import NestAdapter
9
+ from .simulation import NestSimulation
5
10
 
6
11
 
7
12
  @config.node
@@ -21,19 +26,59 @@ class NestDevice(DeviceModel):
21
26
  type=types.or_(Targetting, NestRule), default=dict, call_default=True
22
27
  )
23
28
  """Targets of the device, which should be either a population or a nest rule"""
29
+ receptor_type = config.attr(type=int, required=False, default=0)
30
+ """Integer ID of the postsynaptic target receptor"""
31
+
32
+ def get_dict_targets(
33
+ self,
34
+ adapter: "NestAdapter",
35
+ simulation: "NestSimulation",
36
+ simdata: "SimulationData",
37
+ ) -> dict:
38
+ """
39
+ Get a dictionary from a target group to its NEST Collection
40
+ for each target group of the device.
24
41
 
25
- def get_target_nodes(self, adapter, simulation, simdata):
42
+ :param bsb_nest.NestAdapter adapter:
43
+ :param bsb_nest.NestSimulation simulation: Nest simulation instance
44
+ :param bsb.SimulationData simdata: Simulation data instance
45
+ :return: dictionary of device target group to NEST Collection
46
+ :rtype: dict
47
+ """
26
48
  if isinstance(self.targetting, Targetting):
27
- node_collector = self.targetting.get_targets(
28
- adapter, simulation, simdata
29
- ).values()
49
+ node_collector = self.targetting.get_targets(adapter, simulation, simdata)
30
50
  else:
31
- node_collector = (
32
- simdata.populations[model][targets]
51
+ node_collector = {
52
+ model: simdata.populations[model][targets]
33
53
  for model, targets in simdata.populations.items()
34
54
  if not self.targetting.cell_models or model in self.targetting.cell_models
35
- )
36
- return sum(node_collector, start=nest.NodeCollection())
55
+ }
56
+ return node_collector
57
+
58
+ @staticmethod
59
+ def _flatten_nodes_ids(dict_targets):
60
+ return sum(dict_targets.values(), start=nest.NodeCollection())
61
+
62
+ @staticmethod
63
+ def _invert_targets_dict(dict_targets):
64
+ return {elem: k.name for k, v in dict_targets.items() for elem in v.tolist()}
65
+
66
+ def get_target_nodes(
67
+ self,
68
+ adapter: "NestAdapter",
69
+ simulation: "NestSimulation",
70
+ simdata: "SimulationData",
71
+ ):
72
+ """
73
+ Get the NEST Collection of the targets of the device.
74
+
75
+ :param bsb_nest.NestAdapter adapter:
76
+ :param bsb_nest.NestSimulation simulation: Nest simulation instance
77
+ :param bsb.SimulationData simdata: Simulation data instance
78
+ :return: Flattened NEST collection with all the targets of the device
79
+ """
80
+ targets_dict = self.get_dict_targets(adapter, simulation, simdata)
81
+ return self._flatten_nodes_ids(targets_dict)
37
82
 
38
83
  def connect_to_nodes(self, device, nodes):
39
84
  if len(nodes) == 0:
@@ -43,8 +88,13 @@ class NestDevice(DeviceModel):
43
88
  nest.Connect(
44
89
  device,
45
90
  nodes,
46
- syn_spec={"weight": self.weight, "delay": self.delay},
91
+ syn_spec={
92
+ "weight": self.weight,
93
+ "delay": self.delay,
94
+ "receptor_type": self.receptor_type,
95
+ },
47
96
  )
97
+
48
98
  except Exception as e:
49
99
  if "does not send output" not in str(e):
50
100
  raise
@@ -68,5 +118,5 @@ class ExtNestDevice(NestDevice, classmap_entry="external"):
68
118
  simdata.devices[self] = device = nest.Create(
69
119
  self.nest_model, params=self.constants
70
120
  )
71
- nodes = self.get_target_nodes(adapter, simdata)
121
+ nodes = self.get_target_nodes(adapter, simulation, simdata)
72
122
  self.connect_to_nodes(device, nodes)
@@ -1,4 +1,5 @@
1
1
  from .dc_generator import DCGenerator
2
2
  from .multimeter import Multimeter
3
3
  from .poisson_generator import PoissonGenerator
4
+ from .sinusoidal_poisson_generator import SinusoidalPoissonGenerator
4
5
  from .spike_recorder import SpikeRecorder
@@ -1,4 +1,5 @@
1
1
  import nest
2
+ import numpy as np
2
3
  import quantities as pq
3
4
  from bsb import ConfigurationError, _util, config, types
4
5
  from neo import AnalogSignal
@@ -24,7 +25,9 @@ class Multimeter(NestDevice, classmap_entry="multimeter"):
24
25
 
25
26
  def implement(self, adapter, simulation, simdata):
26
27
 
27
- nodes = self.get_target_nodes(adapter, simulation, simdata)
28
+ targets_dict = self.get_dict_targets(adapter, simulation, simdata)
29
+ nodes = self._flatten_nodes_ids(targets_dict)
30
+ inv_targets = self._invert_targets_dict(targets_dict)
28
31
  device = self.register_device(
29
32
  simdata,
30
33
  nest.Create(
@@ -38,15 +41,20 @@ class Multimeter(NestDevice, classmap_entry="multimeter"):
38
41
  self.connect_to_nodes(device, nodes)
39
42
 
40
43
  def recorder(segment):
41
- for prop, unit in zip(self.properties, self.units):
42
- segment.analogsignals.append(
43
- AnalogSignal(
44
- device.events[prop],
45
- units=pq.units.__dict__[unit],
46
- sampling_period=self.simulation.resolution * pq.ms,
47
- name=self.name,
48
- senders=device.events["senders"],
44
+ senders = device.events["senders"]
45
+ for sender in np.unique(senders):
46
+ sender_filter = senders == sender
47
+ for prop, unit in zip(self.properties, self.units):
48
+ segment.analogsignals.append(
49
+ AnalogSignal(
50
+ device.events[prop][sender_filter],
51
+ units=pq.units.__dict__[unit],
52
+ sampling_period=self.simulation.resolution * pq.ms,
53
+ name=self.name,
54
+ cell_type=inv_targets[sender],
55
+ cell_id=sender,
56
+ prop_recorded=prop,
57
+ )
49
58
  )
50
- )
51
59
 
52
60
  simdata.result.create_recorder(recorder)
@@ -35,6 +35,7 @@ class PoissonGenerator(NestDevice, classmap_entry="poisson_generator"):
35
35
  senders=sr.events["senders"],
36
36
  t_stop=simulation.duration,
37
37
  device=self.name,
38
+ pop_size=len(nodes),
38
39
  )
39
40
  )
40
41
 
@@ -0,0 +1,63 @@
1
+ import nest
2
+ from bsb import ConfigurationError, config
3
+ from neo import SpikeTrain
4
+
5
+ from ..device import NestDevice
6
+
7
+
8
+ @config.node
9
+ class SinusoidalPoissonGenerator(
10
+ NestDevice, classmap_entry="sinusoidal_poisson_generator"
11
+ ):
12
+ rate = config.attr(type=float, required=True)
13
+ """Rate of the poisson generator"""
14
+ amplitude = config.attr(type=float, required=True)
15
+ """Amplitude of the sinusoidal signal"""
16
+ frequency = config.attr(type=float, required=True)
17
+ """Frequency of the sinusoidal signal"""
18
+ phase = config.attr(type=float, required=False, default=0.0)
19
+ """Phase of the sinusoidal signal"""
20
+ start = config.attr(type=float, required=False, default=0.0)
21
+ """Activation time in ms"""
22
+ stop = config.attr(type=float, required=False, default=None)
23
+ """Deactivation time in ms.
24
+ If not specified, generator will last until the end of the simulation."""
25
+
26
+ def boot(self):
27
+ if self.stop is not None:
28
+ if self.stop <= self.start:
29
+ raise ConfigurationError(
30
+ f"Stop time (given: {self.stop}) must be greater than start time (given: {self.start})."
31
+ )
32
+
33
+ def implement(self, adapter, simulation, simdata):
34
+ nodes = self.get_target_nodes(adapter, simulation, simdata)
35
+ params = {
36
+ "rate": self.rate,
37
+ "start": self.start,
38
+ "amplitude": self.amplitude,
39
+ "frequency": self.frequency,
40
+ "phase": self.phase,
41
+ }
42
+ if self.stop is not None:
43
+ params["stop"] = self.stop
44
+ device = self.register_device(
45
+ simdata, nest.Create("sinusoidal_poisson_generator", params=params)
46
+ )
47
+ sr = nest.Create("spike_recorder")
48
+ nest.Connect(device, sr)
49
+ self.connect_to_nodes(device, nodes)
50
+
51
+ def recorder(segment):
52
+ segment.spiketrains.append(
53
+ SpikeTrain(
54
+ sr.events["times"],
55
+ units="ms",
56
+ senders=sr.events["senders"],
57
+ t_stop=simulation.duration,
58
+ device=self.name,
59
+ pop_size=len(nodes),
60
+ )
61
+ )
62
+
63
+ simdata.result.create_recorder(recorder)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: bsb-nest
3
- Version: 4.2.1
3
+ Version: 4.3.1
4
4
  Summary: NEST simulation adapter for the BSB framework.
5
5
  Author-email: Robin De Schepper <robingilbert.deschepper@unipv.it>
6
6
  Description-Content-Type: text/markdown
@@ -24,7 +24,7 @@ Provides-Extra: dev
24
24
  Provides-Extra: parallel
25
25
  Provides-Extra: test
26
26
 
27
- [![Build Status](https://github.com/dbbs-lab/bsb-nest/actions/workflows/build.yml/badge.svg)](https://github.com/dbbs-lab/bsb-nest/actions/workflows/build.yml)
27
+ [![Build Status](https://github.com/dbbs-lab/bsb-nest/actions/workflows/main.yml/badge.svg)](https://github.com/dbbs-lab/bsb-nest/actions/workflows/main.yml)
28
28
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
29
29
 
30
30
  # bsb-nest
@@ -0,0 +1,19 @@
1
+ bsb_nest/__init__.py,sha256=jmNzWzEx2ygwXCcVTy7eWawQcalhBxceHFo2nAlHhd4,311
2
+ bsb_nest/adapter.py,sha256=uwFdicGOx7mRyYlfRY89zw7re0dnv9qumli1llJ0Rok,6668
3
+ bsb_nest/cell.py,sha256=AauERRJd5OkKVSIxbx6LO2D9L7LDA6iMFfYjxu59e4c,960
4
+ bsb_nest/connection.py,sha256=KFMXRvSR-tN7E52Mpo7dgWjXVQQSOd1VdryRPx-NfHQ,5571
5
+ bsb_nest/device.py,sha256=s-cIgR2-6J1k9WqhYdZv2FfMUVnnIdmCG-lXNNPgfj8,4388
6
+ bsb_nest/distributions.py,sha256=qAYaHJkMwaCfbTh_efoJT1hMoDHWsfQo_3SNLoD8WeA,1950
7
+ bsb_nest/exceptions.py,sha256=NX4oiGWIshrLG1DCak_nTfI8cQI7GTdewR71qNzsXGM,264
8
+ bsb_nest/simulation.py,sha256=MCfEhwhbl_S1WNyY-EAzW8SmVKk-nLui71jK9M3lGKw,985
9
+ bsb_nest/devices/__init__.py,sha256=AgiHteAtWd5jhl_xB_V60oeM31fGb-DGi3WjoLZLL_E,232
10
+ bsb_nest/devices/dc_generator.py,sha256=g-jRZorCl2yYhr5bx2I00ZlxYrblDcqVbtk0XYZzmdI,953
11
+ bsb_nest/devices/multimeter.py,sha256=pM35gSCbjuAMOtj9m4r4eGusc5tnLXA0k2ZKtJMiMOc,2240
12
+ bsb_nest/devices/poisson_generator.py,sha256=7knwxFmJbV_RCg18H4wizot23fKUrvr6IhIye0BeOfA,1506
13
+ bsb_nest/devices/sinusoidal_poisson_generator.py,sha256=MEV5yJ5laKYLIy8T1W9cDbnAhFB7OPZAfaqH8ffqDwc,2252
14
+ bsb_nest/devices/spike_recorder.py,sha256=vJ9FQqmrcF0HdLl5Jy_bt_ABCUIgF-PLVI23E76JkhY,894
15
+ bsb_nest-4.3.1.dist-info/entry_points.txt,sha256=uJlX9h2VeYfAumav18IM2PTJ3FssfwDUnUmfSFdR2SA,41
16
+ bsb_nest-4.3.1.dist-info/LICENSE,sha256=ljOS4DjXvqEo5VzGfdaRwgRZPbNScGBmfwyC8PChvmQ,32422
17
+ bsb_nest-4.3.1.dist-info/WHEEL,sha256=ssQ84EZ5gH1pCOujd3iW7HClo_O_aDaClUbX4B8bjKY,100
18
+ bsb_nest-4.3.1.dist-info/METADATA,sha256=QfslnPnYKys8N2puto1YZcIBoMEkJILcHEabaWz4AVY,1600
19
+ bsb_nest-4.3.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.9.0
2
+ Generator: flit 3.10.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -1,18 +0,0 @@
1
- bsb_nest/__init__.py,sha256=IL-VNOohSjl__4e5bfduv46iMjfLhZqT6G9xJdsfTHA,311
2
- bsb_nest/adapter.py,sha256=uwFdicGOx7mRyYlfRY89zw7re0dnv9qumli1llJ0Rok,6668
3
- bsb_nest/cell.py,sha256=AauERRJd5OkKVSIxbx6LO2D9L7LDA6iMFfYjxu59e4c,960
4
- bsb_nest/connection.py,sha256=KFMXRvSR-tN7E52Mpo7dgWjXVQQSOd1VdryRPx-NfHQ,5571
5
- bsb_nest/device.py,sha256=w6jeGSOzqd8iTtw6HxsWS0TuYTxf6iO9eqAseaFC3W8,2615
6
- bsb_nest/distributions.py,sha256=qAYaHJkMwaCfbTh_efoJT1hMoDHWsfQo_3SNLoD8WeA,1950
7
- bsb_nest/exceptions.py,sha256=NX4oiGWIshrLG1DCak_nTfI8cQI7GTdewR71qNzsXGM,264
8
- bsb_nest/simulation.py,sha256=MCfEhwhbl_S1WNyY-EAzW8SmVKk-nLui71jK9M3lGKw,985
9
- bsb_nest/devices/__init__.py,sha256=0-zwJ8jdvBdTFetU-q87OfyZYpKl_JVcVDrsLNn7yHQ,163
10
- bsb_nest/devices/dc_generator.py,sha256=g-jRZorCl2yYhr5bx2I00ZlxYrblDcqVbtk0XYZzmdI,953
11
- bsb_nest/devices/multimeter.py,sha256=dLBDNCJuFIgxOZ0ssEoir7d65EW7ORS1jFNsvmU2wJ0,1811
12
- bsb_nest/devices/poisson_generator.py,sha256=SGo4jhq_rbIoB38OM5FTTYlyShxGAwWqCqAncWVB3qg,1465
13
- bsb_nest/devices/spike_recorder.py,sha256=vJ9FQqmrcF0HdLl5Jy_bt_ABCUIgF-PLVI23E76JkhY,894
14
- bsb_nest-4.2.1.dist-info/entry_points.txt,sha256=uJlX9h2VeYfAumav18IM2PTJ3FssfwDUnUmfSFdR2SA,41
15
- bsb_nest-4.2.1.dist-info/LICENSE,sha256=ljOS4DjXvqEo5VzGfdaRwgRZPbNScGBmfwyC8PChvmQ,32422
16
- bsb_nest-4.2.1.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
17
- bsb_nest-4.2.1.dist-info/METADATA,sha256=gm8BOcXCq1xdqi6oFDS3bUynPxa4BdvNaq_tiN0qnvk,1602
18
- bsb_nest-4.2.1.dist-info/RECORD,,