bsb-nest 0.0.0b0__py2.py3-none-any.whl → 0.0.0b2__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
@@ -2,11 +2,11 @@
2
2
  NEST simulation adapter for the BSB framework.
3
3
  """
4
4
 
5
- from bsb.simulation import SimulationBackendPlugin
5
+ from bsb import SimulationBackendPlugin
6
+
7
+ from . import devices
6
8
  from .adapter import NestAdapter
7
9
  from .simulation import NestSimulation
8
- from . import devices
9
-
10
10
 
11
11
  __plugin__ = SimulationBackendPlugin(Simulation=NestSimulation, Adapter=NestAdapter)
12
- __version__ = "0.0.0b0"
12
+ __version__ = "0.0.0-b2"
bsb_nest/adapter.py CHANGED
@@ -1,31 +1,30 @@
1
1
  import sys
2
- from neo import SpikeTrain
3
2
  import typing
4
- import time
5
- import functools
6
- from tqdm import tqdm
7
3
 
8
- from bsb.simulation.adapter import SimulatorAdapter, SimulationData
9
- from bsb.simulation.results import SimulationResult
10
- from bsb.reporting import report, warn
11
- from bsb.exceptions import (
12
- KernelWarning,
13
- NestModuleError,
14
- NestModelError,
15
- NestConnectError,
4
+ import nest
5
+ from bsb import (
6
+ MPI,
7
+ AdapterError,
8
+ AdapterProgress,
9
+ SimulationData,
10
+ SimulationResult,
11
+ SimulatorAdapter,
12
+ report,
13
+ warn,
16
14
  )
17
- from bsb.services import MPI
15
+ from neo import SpikeTrain
16
+ from tqdm import tqdm
17
+
18
+ from .exceptions import NestConnectError, NestModelError, NestModuleError
18
19
 
19
20
  if typing.TYPE_CHECKING:
20
- from bsb.simulation import Simulation
21
+ from bsb import Simulation
21
22
 
22
23
 
23
24
  class NestResult(SimulationResult):
24
25
  def record(self, nc, **annotations):
25
- import bsb_nest
26
-
27
- recorder = bsb_nest.Create("spike_recorder", params={"record_to": "memory"})
28
- bsb_nest.Connect(nc, recorder)
26
+ recorder = nest.Create("spike_recorder", params={"record_to": "memory"})
27
+ nest.Connect(nc, recorder)
29
28
 
30
29
  def flush(segment):
31
30
  events = recorder.events[0]
@@ -34,7 +33,7 @@ class NestResult(SimulationResult):
34
33
  SpikeTrain(
35
34
  events["times"],
36
35
  waveforms=events["senders"],
37
- t_stop=bsb_nest.biological_time,
36
+ t_stop=nest.biological_time,
38
37
  units="ms",
39
38
  **annotations,
40
39
  )
@@ -48,16 +47,6 @@ class NestAdapter(SimulatorAdapter):
48
47
  self.simdata = dict()
49
48
  self.loaded_modules = set()
50
49
 
51
- @property
52
- @functools.cache
53
- def nest(self):
54
- report("Importing NEST...", level=2)
55
- import bsb_nest
56
-
57
- self.check_comm()
58
-
59
- return bsb_nest
60
-
61
50
  def simulate(self, simulation):
62
51
  try:
63
52
  self.reset_kernel()
@@ -85,32 +74,35 @@ class NestAdapter(SimulatorAdapter):
85
74
  raise
86
75
 
87
76
  def reset_kernel(self):
88
- self.nest.ResetKernel()
77
+ nest.ResetKernel()
89
78
  # Reset which modules we should consider explicitly loaded by the user
90
79
  # to appropriately warn them when they load them twice.
91
80
  self.loaded_modules = set()
92
81
 
93
- def run(self, simulation):
94
- if simulation not in self.simdata:
95
- raise RuntimeError("Can't run unprepared simulation")
82
+ def run(self, *simulations, comm=None):
83
+ unprepared = [sim for sim in simulations if sim not in self.simdata]
84
+ if unprepared:
85
+ raise AdapterError(f"Unprepared for simulations: {', '.join(unprepared)}")
96
86
  report("Simulating...", level=2)
97
- tick = time.time()
98
- simulation.start_progress(simulation.duration)
87
+ duration = max(sim.duration for sim in simulations)
88
+ progress = AdapterProgress(duration)
99
89
  try:
100
- with self.nest.RunManager():
101
- for oi, i in simulation.step_progress(simulation.duration, step=1):
102
- self.nest.Run(i - oi)
103
- simulation.progress(i)
90
+ with nest.RunManager():
91
+ for oi, i in progress.steps(step=1):
92
+ nest.Run(i - oi)
93
+ progress.tick(i)
104
94
  finally:
105
- result = self.simdata[simulation].result
106
- del self.simdata[simulation]
107
- report(f"Simulation done. {time.time() - tick:.2f}s elapsed.", level=2)
108
- return result
95
+ results = [self.simdata[sim].result for sim in simulations]
96
+ for sim in simulations:
97
+ del self.simdata[sim]
98
+ progress.complete()
99
+ report(f"Simulation done.", level=2)
100
+ return results
109
101
 
110
102
  def load_modules(self, simulation):
111
103
  for module in simulation.modules:
112
104
  try:
113
- self.nest.Install(module)
105
+ nest.Install(module)
114
106
  self.loaded_modules.add(module)
115
107
  except Exception as e:
116
108
  if e.errorname == "DynamicModuleManagementError":
@@ -162,10 +154,10 @@ class NestAdapter(SimulatorAdapter):
162
154
  except KeyError:
163
155
  raise NestModelError(f"No model found for {cs.post_type}")
164
156
  try:
165
- simdata.connections[
166
- connection_model
167
- ] = connection_model.create_connections(
168
- simdata, pre_nodes, post_nodes, cs
157
+ simdata.connections[connection_model] = (
158
+ connection_model.create_connections(
159
+ simdata, pre_nodes, post_nodes, cs
160
+ )
169
161
  )
170
162
  except Exception as e:
171
163
  raise NestConnectError(f"{connection_model} error during connect.")
@@ -176,15 +168,13 @@ class NestAdapter(SimulatorAdapter):
176
168
  device_model.implement(self, simulation, simdata)
177
169
 
178
170
  def set_settings(self, simulation: "Simulation"):
179
- self.nest.set_verbosity(simulation.verbosity)
180
- self.nest.resolution = simulation.resolution
181
- self.nest.overwrite_files = True
171
+ nest.set_verbosity(simulation.verbosity)
172
+ nest.resolution = simulation.resolution
173
+ nest.overwrite_files = True
182
174
 
183
175
  def check_comm(self):
184
- import bsb_nest
185
-
186
- if bsb_nest.NumProcesses() != MPI.get_size():
176
+ if nest.NumProcesses() != MPI.get_size():
187
177
  raise RuntimeError(
188
- f"NEST is managing {bsb_nest.NumProcesses()} processes, but {MPI.get_size()}"
178
+ f"NEST is managing {nest.NumProcesses()} processes, but {MPI.get_size()}"
189
179
  " were detected. Please check your MPI setup."
190
180
  )
bsb_nest/cell.py CHANGED
@@ -1,6 +1,5 @@
1
- from bsb import config
2
- from bsb.config import types
3
- from bsb.simulation.cell import CellModel
1
+ import nest
2
+ from bsb import CellModel, config, types
4
3
 
5
4
 
6
5
  @config.node
@@ -9,10 +8,8 @@ class NestCell(CellModel):
9
8
  constants = config.dict(type=types.any_())
10
9
 
11
10
  def create_population(self, simdata):
12
- import bsb_nest
13
-
14
11
  n = len(simdata.placement[self])
15
- population = bsb_nest.Create(self.model, n) if n else bsb_nest.NodeCollection([])
12
+ population = nest.Create(self.model, n) if n else nest.NodeCollection([])
16
13
  self.set_constants(population)
17
14
  self.set_parameters(population, simdata)
18
15
  return population
bsb_nest/connection.py CHANGED
@@ -1,15 +1,13 @@
1
1
  import functools
2
2
  import sys
3
3
 
4
+ import nest
4
5
  import numpy as np
5
6
  import psutil
7
+ from bsb import MPI, ConnectionModel, compose_nodes, config, types
6
8
  from tqdm import tqdm
7
9
 
8
- from bsb import config
9
- from bsb.config import types, compose_nodes
10
- from bsb.services import MPI
11
- from bsb.simulation.connection import ConnectionModel
12
- from bsb.exceptions import NestConnectError
10
+ from .exceptions import NestConnectError
13
11
 
14
12
 
15
13
  @config.node
@@ -46,9 +44,7 @@ class LazySynapseCollection:
46
44
 
47
45
  @functools.cached_property
48
46
  def collection(self):
49
- import bsb_nest
50
-
51
- return bsb_nest.GetConnections(self._pre, self._post)
47
+ return nest.GetConnections(self._pre, self._post)
52
48
 
53
49
 
54
50
  @config.dynamic(attr_name="model_strategy", required=False)
@@ -57,15 +53,15 @@ class NestConnection(compose_nodes(NestConnectionSettings, ConnectionModel)):
57
53
  synapse = config.attr(type=NestSynapseSettings, required=True)
58
54
 
59
55
  def create_connections(self, simdata, pre_nodes, post_nodes, cs):
60
- import bsb_nest
56
+ import nest
61
57
 
62
58
  syn_spec = self.get_syn_spec()
63
- if syn_spec["synapse_model"] not in bsb_nest.synapse_models:
59
+ if syn_spec["synapse_model"] not in nest.Models(mtype="synapses"):
64
60
  raise NestConnectError(
65
61
  f"Unknown synapse model '{syn_spec['synapse_model']}'."
66
62
  )
67
63
  if self.rule is not None:
68
- bsb_nest.Connect(pre_nodes, post_nodes, self.get_conn_spec(), syn_spec)
64
+ nest.Connect(pre_nodes, post_nodes, self.get_conn_spec(), syn_spec)
69
65
  else:
70
66
  MPI.barrier()
71
67
  for pre_locs, post_locs in self.predict_mem_iterator(
@@ -83,7 +79,7 @@ class NestConnection(compose_nodes(NestConnectionSettings, ConnectionModel)):
83
79
  bw = syn_spec["weight"]
84
80
  ssw["weight"] = [bw * m for m in multiplicity]
85
81
  ssw["delay"] = [syn_spec["delay"]] * len(ssw["weight"])
86
- bsb_nest.Connect(
82
+ nest.Connect(
87
83
  [prel[x] for x in cell_pairs[:, 0]],
88
84
  [postl[x] for x in cell_pairs[:, 1]],
89
85
  "one_to_one",
@@ -96,7 +92,9 @@ class NestConnection(compose_nodes(NestConnectionSettings, ConnectionModel)):
96
92
  def predict_mem_iterator(self, pre_nodes, post_nodes, cs):
97
93
  avmem = psutil.virtual_memory().available
98
94
  predicted_all_mem = (
99
- len(pre_nodes) * 8 * 2 + len(post_nodes) * 8 * 2 + len(cs) * 6 * 8 * (16 + 2)
95
+ len(pre_nodes) * 8 * 2
96
+ + len(post_nodes) * 8 * 2
97
+ + len(cs) * 6 * 8 * (16 + 2)
100
98
  ) * MPI.get_size()
101
99
  predicted_local_mem = predicted_all_mem / len(cs.get_local_chunks("out"))
102
100
  if predicted_local_mem > avmem / 2:
bsb_nest/device.py CHANGED
@@ -1,9 +1,7 @@
1
1
  import warnings
2
2
 
3
- from bsb import config
4
- from bsb.config import types, refs
5
- from bsb.simulation.device import DeviceModel
6
- from bsb.simulation.targetting import Targetting
3
+ import nest
4
+ from bsb import DeviceModel, Targetting, config, refs, types
7
5
 
8
6
 
9
7
  @config.node
@@ -30,18 +28,17 @@ class NestDevice(DeviceModel):
30
28
  node_collector = (
31
29
  simdata.populations[model][targets]
32
30
  for model, targets in simdata.populations.items()
33
- if not self.targetting.cell_models or model in self.targetting.cell_models
31
+ if not self.targetting.cell_models
32
+ or model in self.targetting.cell_models
34
33
  )
35
- return sum(node_collector, start=adapter.nest.NodeCollection())
34
+ return sum(node_collector, start=nest.NodeCollection())
36
35
 
37
36
  def connect_to_nodes(self, device, nodes):
38
- import bsb_nest
39
-
40
37
  if len(nodes) == 0:
41
38
  warnings.warn(f"{self.name} has no targets")
42
39
  else:
43
40
  try:
44
- bsb_nest.Connect(
41
+ nest.Connect(
45
42
  device,
46
43
  nodes,
47
44
  syn_spec={"weight": self.weight, "delay": self.delay},
@@ -49,7 +46,7 @@ class NestDevice(DeviceModel):
49
46
  except Exception as e:
50
47
  if "does not send output" not in str(e):
51
48
  raise
52
- bsb_nest.Connect(
49
+ nest.Connect(
53
50
  nodes,
54
51
  device,
55
52
  syn_spec={"weight": self.weight, "delay": self.delay},
@@ -66,7 +63,7 @@ class ExtNestDevice(NestDevice, classmap_entry="external"):
66
63
  constants = config.dict(type=types.or_(types.number(), str))
67
64
 
68
65
  def implement(self, adapter, simulation, simdata):
69
- simdata.devices[self] = device = adapter.nest.Create(
66
+ simdata.devices[self] = device = nest.Create(
70
67
  self.nest_model, params=self.constants
71
68
  )
72
69
  nodes = self.get_target_nodes(adapter, simdata)
@@ -1,2 +1,2 @@
1
- from .spike_recorder import SpikeRecorder
2
1
  from .poisson_generator import PoissonGenerator
2
+ from .spike_recorder import SpikeRecorder
@@ -1,6 +1,8 @@
1
+ import nest
2
+ from bsb import config
1
3
  from neo import SpikeTrain
4
+
2
5
  from ..device import NestDevice
3
- from bsb import config
4
6
 
5
7
 
6
8
  @config.node
@@ -8,14 +10,12 @@ class PoissonGenerator(NestDevice, classmap_entry="poisson_generator"):
8
10
  rate = config.attr(type=float, required=True)
9
11
 
10
12
  def implement(self, adapter, simulation, simdata):
11
- import bsb_nest
12
-
13
13
  nodes = self.get_target_nodes(adapter, simulation, simdata)
14
14
  device = self.register_device(
15
- simdata, bsb_nest.Create("poisson_generator", params={"rate": self.rate})
15
+ simdata, nest.Create("poisson_generator", params={"rate": self.rate})
16
16
  )
17
- sr = bsb_nest.Create("spike_recorder")
18
- bsb_nest.Connect(device, sr)
17
+ sr = nest.Create("spike_recorder")
18
+ nest.Connect(device, sr)
19
19
  self.connect_to_nodes(device, nodes)
20
20
 
21
21
  def recorder(segment):
@@ -1,7 +1,8 @@
1
+ import nest
2
+ from bsb import config
1
3
  from neo import SpikeTrain
2
4
 
3
5
  from ..device import NestDevice
4
- from bsb import config
5
6
 
6
7
 
7
8
  @config.node
@@ -9,10 +10,9 @@ class SpikeRecorder(NestDevice, classmap_entry="spike_recorder"):
9
10
  weight = config.provide(1)
10
11
 
11
12
  def implement(self, adapter, simulation, simdata):
12
- import bsb_nest
13
13
 
14
14
  nodes = self.get_target_nodes(adapter, simulation, simdata)
15
- device = self.register_device(simdata, bsb_nest.Create("spike_recorder"))
15
+ device = self.register_device(simdata, nest.Create("spike_recorder"))
16
16
  self.connect_to_nodes(device, nodes)
17
17
 
18
18
  def recorder(segment):
bsb_nest/exceptions.py ADDED
@@ -0,0 +1,18 @@
1
+ class KernelWarning(Warning):
2
+ pass
3
+
4
+
5
+ class NestError(Exception):
6
+ pass
7
+
8
+ class NestKernelError(NestError):
9
+ pass
10
+
11
+ class NestModuleError(NestKernelError):
12
+ pass
13
+
14
+ class NestModelError(NestError):
15
+ pass
16
+
17
+ class NestConnectError(NestError):
18
+ pass
bsb_nest/simulation.py CHANGED
@@ -1,6 +1,5 @@
1
- from bsb import config
2
- from bsb.config import types
3
- from bsb.simulation.simulation import Simulation
1
+ from bsb import Simulation, config, types
2
+
4
3
  from .cell import NestCell
5
4
  from .connection import NestConnection
6
5
  from .device import NestDevice
@@ -20,10 +19,3 @@ class NestSimulation(Simulation):
20
19
  cell_models = config.dict(type=NestCell, required=True)
21
20
  connection_models = config.dict(type=NestConnection, required=True)
22
21
  devices = config.dict(type=NestDevice, required=True)
23
-
24
- def boot(self):
25
- self.is_prepared = False
26
- self.suffix = ""
27
- self.multi = False
28
- self.has_lock = False
29
- self.global_identifier_map = {}
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.1
2
+ Name: bsb-nest
3
+ Version: 0.0.0b2
4
+ Summary: NEST simulation adapter for the BSB framework.
5
+ Author-email: Robin De Schepper <robingilbert.deschepper@unipv.it>
6
+ Description-Content-Type: text/markdown
7
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
8
+ Requires-Dist: bsb-core>=4.0.0b4,<=4.0.0b9999
9
+ Requires-Dist: pre-commit~=3.5 ; extra == "dev"
10
+ Requires-Dist: black~=24.1.1 ; extra == "dev"
11
+ Requires-Dist: isort~=5.12 ; extra == "dev"
12
+ Requires-Dist: bump-my-version~=0.18 ; extra == "dev"
13
+ Requires-Dist: bsb-core[parallel] ; extra == "parallel"
14
+ Requires-Dist: bsb-test>=0.0.0b9,<=0.0.0b9999 ; extra == "test"
15
+ Requires-Dist: coverage~=7.0 ; extra == "test"
16
+ Requires-Dist: bsb-hdf5>=1.0.0b0 ; extra == "test"
17
+ Requires-Dist: bsb-arbor==0.0.0b1 ; extra == "test"
18
+ Provides-Extra: dev
19
+ Provides-Extra: parallel
20
+ Provides-Extra: test
21
+
22
+ # bsb-nest
23
+
@@ -0,0 +1,15 @@
1
+ bsb_nest/__init__.py,sha256=s8CFh-2LZQ5V-lSSh47o2r7-Rsuhdw_wslWIey5VYPw,314
2
+ bsb_nest/adapter.py,sha256=Zlt0QuV-3UtFoHrSF_sdPb4O1u0OVTEzBsEqjj0M3QQ,6733
3
+ bsb_nest/cell.py,sha256=hYuCp-60RlGO5lO7SdJsYadoyFjKgiqBqP9aLOpTxcc,772
4
+ bsb_nest/connection.py,sha256=sdFiTSCyM0u8gcE5rpMjn29bX3bmhcRPyLBc7L7KFXc,5568
5
+ bsb_nest/device.py,sha256=Hw2bIzMmUAWHlrOi-fn72riyiFFmT338YKlkh2KNCaU,2478
6
+ bsb_nest/exceptions.py,sha256=c0_-DqSXNm0pHP-v_pQqUcC2uhFhDUAb5TVAw6QW-P8,276
7
+ bsb_nest/simulation.py,sha256=09P7u78z6ruYD24RWDroiBypSix_RPzRHoS6MZELer0,707
8
+ bsb_nest/devices/__init__.py,sha256=ecfuof-qH8WdPYnbmn4iMZPjXn1WIzxzAZPa6_iPYLI,92
9
+ bsb_nest/devices/poisson_generator.py,sha256=Dr7jtoHk7HCYoGcqCqpX4FVHVUkWx1RI3GHIRq538Fk,1030
10
+ bsb_nest/devices/spike_recorder.py,sha256=W2xuoKNEYkdYNfNPdPCJe7snc-ff3PB1miX8Eqrix7I,924
11
+ bsb_nest-0.0.0b2.dist-info/entry_points.txt,sha256=uJlX9h2VeYfAumav18IM2PTJ3FssfwDUnUmfSFdR2SA,41
12
+ bsb_nest-0.0.0b2.dist-info/LICENSE,sha256=0SAgqCl8RI6Vm7Rv5YC6CPyLA2MXedQM9tq17WMXl-o,33041
13
+ bsb_nest-0.0.0b2.dist-info/WHEEL,sha256=Sgu64hAMa6g5FdzHxXv9Xdse9yxpGGMeagVtPMWpJQY,99
14
+ bsb_nest-0.0.0b2.dist-info/METADATA,sha256=HbIuYpS8qHZ873WY-Nd3lC0_JSw2V5fJO_piDFXXm0M,891
15
+ bsb_nest-0.0.0b2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.7.1
2
+ Generator: flit 3.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any
@@ -1,11 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: bsb-nest
3
- Version: 0.0.0b0
4
- Summary: NEST simulation adapter for the BSB framework.
5
- Author-email: Robin De Schepper <robingilbert.deschepper@unipv.it>
6
- Description-Content-Type: text/markdown
7
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
8
- Requires-Dist: bsb-core>=4.0.0b0,<=4.0.0b9999
9
-
10
- # bsb-nest
11
-
@@ -1,14 +0,0 @@
1
- bsb_nest/__init__.py,sha256=ZUs7SkZEBanqgUY-s8gTtgpnSgkyrp7IcBKKUsXk_nQ,322
2
- bsb_nest/adapter.py,sha256=KfFG2TuMxHDOfO0QEgEYWYrScXWydM0k30kTKNGCYP4,6993
3
- bsb_nest/cell.py,sha256=dx5t-4IY-ognwbbWPDtfZ9itm6DZ0_bb_kfy-eqs5p8,849
4
- bsb_nest/connection.py,sha256=B5atlJJBjocq5INNxnWfe3MrMZ2Rsos_iXSa-8X58Rk,5655
5
- bsb_nest/device.py,sha256=cWe9nTZmT8tNnh4jyv5VUvI9pR8YmuhJhg5qVGBzmAY,2594
6
- bsb_nest/simulation.py,sha256=cYWgbHKHm23ef27_4m-Nd_ENP6fgRHd86WJZ8buveEU,949
7
- bsb_nest/devices/__init__.py,sha256=4fnD4S_O0rBajd8bkPhlbq5xM_tV6ui7pdb8bmSzoG0,92
8
- bsb_nest/devices/poisson_generator.py,sha256=Ad7L8U1fdtgOyKybvg-3FydNqyFgBOee9mKUWV4sWC8,1054
9
- bsb_nest/devices/spike_recorder.py,sha256=JlCYjZqrkApGcHWBe6vNfP9xaYWKTDJsmZxGkBxlDds,940
10
- bsb_nest-0.0.0b0.dist-info/entry_points.txt,sha256=uJlX9h2VeYfAumav18IM2PTJ3FssfwDUnUmfSFdR2SA,41
11
- bsb_nest-0.0.0b0.dist-info/LICENSE,sha256=0SAgqCl8RI6Vm7Rv5YC6CPyLA2MXedQM9tq17WMXl-o,33041
12
- bsb_nest-0.0.0b0.dist-info/WHEEL,sha256=96_DCfscDnVj9fVNwi1rfifiRwfpxLjwXWglVksjj_E,99
13
- bsb_nest-0.0.0b0.dist-info/METADATA,sha256=yfCNiLz4M7kGXaJ9b22YUBc4QvbDZjgU6ZUZzT_A1MI,363
14
- bsb_nest-0.0.0b0.dist-info/RECORD,,