bluecellulab 2.4.0__py3-none-any.whl → 2.6.37__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 bluecellulab might be problematic. Click here for more details.
- bluecellulab/__init__.py +10 -3
- bluecellulab/analysis/__init__.py +0 -0
- bluecellulab/analysis/inject_sequence.py +165 -0
- bluecellulab/cell/cell_dict.py +1 -1
- bluecellulab/cell/core.py +95 -76
- bluecellulab/cell/injector.py +8 -10
- bluecellulab/cell/plotting.py +2 -1
- bluecellulab/cell/random.py +1 -1
- bluecellulab/cell/recording.py +8 -0
- bluecellulab/cell/section_distance.py +1 -1
- bluecellulab/cell/serialized_sections.py +4 -6
- bluecellulab/cell/sonata_proxy.py +1 -1
- bluecellulab/cell/stimuli_generator.py +26 -8
- bluecellulab/cell/template.py +12 -4
- bluecellulab/circuit/circuit_access/bluepy_circuit_access.py +12 -20
- bluecellulab/circuit/circuit_access/definition.py +1 -1
- bluecellulab/circuit/circuit_access/sonata_circuit_access.py +5 -4
- bluecellulab/circuit/config/bluepy_simulation_config.py +1 -1
- bluecellulab/circuit/config/definition.py +1 -1
- bluecellulab/circuit/config/sections.py +1 -1
- bluecellulab/circuit/config/sonata_simulation_config.py +1 -1
- bluecellulab/circuit/format.py +1 -1
- bluecellulab/circuit/iotools.py +2 -2
- bluecellulab/circuit/node_id.py +1 -1
- bluecellulab/circuit/simulation_access.py +11 -8
- bluecellulab/circuit/synapse_properties.py +25 -9
- bluecellulab/circuit/validate.py +1 -1
- bluecellulab/{ssim.py → circuit_simulation.py} +36 -34
- bluecellulab/connection.py +1 -1
- bluecellulab/dendrogram.py +1 -1
- bluecellulab/exceptions.py +1 -1
- bluecellulab/graph.py +1 -1
- bluecellulab/importer.py +6 -8
- bluecellulab/neuron_interpreter.py +1 -1
- bluecellulab/plotwindow.py +1 -1
- bluecellulab/psection.py +11 -16
- bluecellulab/psegment.py +4 -4
- bluecellulab/rngsettings.py +4 -4
- bluecellulab/simulation/__init__.py +0 -1
- bluecellulab/simulation/neuron_globals.py +48 -4
- bluecellulab/simulation/parallel.py +40 -0
- bluecellulab/simulation/simulation.py +28 -32
- bluecellulab/stimulus/circuit_stimulus_definitions.py +11 -6
- bluecellulab/stimulus/factory.py +537 -102
- bluecellulab/synapse/synapse_factory.py +8 -4
- bluecellulab/synapse/synapse_types.py +1 -1
- bluecellulab/tools.py +20 -13
- bluecellulab/type_aliases.py +4 -1
- bluecellulab/utils.py +20 -16
- {bluecellulab-2.4.0.dist-info → bluecellulab-2.6.37.dist-info}/LICENSE +0 -7
- {bluecellulab-2.4.0.dist-info → bluecellulab-2.6.37.dist-info}/METADATA +42 -25
- bluecellulab-2.6.37.dist-info/RECORD +70 -0
- {bluecellulab-2.4.0.dist-info → bluecellulab-2.6.37.dist-info}/WHEEL +1 -1
- bluecellulab-2.4.0.dist-info/RECORD +0 -66
- {bluecellulab-2.4.0.dist-info → bluecellulab-2.6.37.dist-info}/AUTHORS.txt +0 -0
- {bluecellulab-2.4.0.dist-info → bluecellulab-2.6.37.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -15,17 +15,14 @@
|
|
|
15
15
|
index."""
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
import logging
|
|
18
|
-
import warnings
|
|
19
18
|
import neuron
|
|
20
19
|
from bluecellulab.type_aliases import HocObjectType, NeuronSection
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
logger = logging.getLogger(__name__)
|
|
24
|
-
warnings.filterwarnings("once", category=UserWarning, module=__name__)
|
|
25
23
|
|
|
26
24
|
|
|
27
25
|
class SerializedSections:
|
|
28
|
-
|
|
29
26
|
def __init__(self, cell: HocObjectType) -> None:
|
|
30
27
|
self.isec2sec: dict[int, NeuronSection] = {}
|
|
31
28
|
n = cell.nSecAll
|
|
@@ -37,7 +34,8 @@ class SerializedSections:
|
|
|
37
34
|
raise ValueError("Error: failure in mk2_isec2sec()")
|
|
38
35
|
|
|
39
36
|
if v_value < 0:
|
|
40
|
-
|
|
41
|
-
f"[Warning] SerializedSections: v(0.0001) < 0. index={index} v()={v_value}"
|
|
37
|
+
logging.debug(
|
|
38
|
+
f"[Warning] SerializedSections: v(0.0001) < 0. index={index} v()={v_value}"
|
|
39
|
+
)
|
|
42
40
|
else:
|
|
43
41
|
self.isec2sec[int(v_value)] = neuron.h.SectionRef(sec=sec)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -114,17 +114,35 @@ def gen_shotnoise_signal(tau_D, tau_R, rate, amp_mean, amp_var,
|
|
|
114
114
|
return tvec, P
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
def get_relative_shotnoise_params(mean,
|
|
117
|
+
def get_relative_shotnoise_params(mean, sd, tau_D, tau_R, relative_skew):
|
|
118
118
|
"""Returns Rate, amp_mean and amp_var parameters."""
|
|
119
119
|
# bi-exponential time to peak [ms]
|
|
120
120
|
t_peak = math.log(tau_D / tau_R) / (1 / tau_R - 1 / tau_D)
|
|
121
121
|
# bi-exponential peak height [1]
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
F_peak = math.exp(-t_peak / tau_D) - math.exp(-t_peak / tau_R)
|
|
123
|
+
|
|
124
|
+
# utility constants
|
|
125
|
+
Xi = (tau_D - tau_R) / F_peak
|
|
126
|
+
A = 1 / (tau_D + tau_R)
|
|
127
|
+
B = 1 / ((tau_D + 2 * tau_R) * (2 * tau_D + tau_R))
|
|
128
|
+
|
|
129
|
+
# skewness
|
|
130
|
+
skew_bnd_min = (8 / 3) * (B / A ** 2) * (sd / mean)
|
|
131
|
+
skew = (1 + relative_skew) * skew_bnd_min
|
|
132
|
+
if skew < skew_bnd_min or skew > 2 * skew_bnd_min:
|
|
133
|
+
raise ValueError("skewness out of bounds")
|
|
134
|
+
|
|
135
|
+
# cumulants
|
|
136
|
+
lambda2_1 = sd ** 2 / mean # lambda2 over lambda1
|
|
137
|
+
lambda3_2 = sd * skew # lambda3 over lambda2
|
|
138
|
+
theta1pk = 2 / (A * Xi) * lambda2_1 # = (1 + k) * theta
|
|
139
|
+
theta2pk = (3 * A) / (4 * B * Xi) * lambda3_2 # = (2 + k) * theta
|
|
140
|
+
|
|
141
|
+
# derived parameters
|
|
142
|
+
amp_mean = 2 * theta1pk - theta2pk # mean amplitude [nA or uS]
|
|
143
|
+
amp_var = amp_mean * (theta2pk - theta1pk) # variance of amplitude [nA^2 or uS^2]
|
|
144
|
+
rate_ms = mean / (amp_mean * Xi) # event rate in 1 / ms
|
|
145
|
+
rate = rate_ms * 1000 # event rate in 1 / s [Hz]
|
|
128
146
|
|
|
129
147
|
return rate, amp_mean, amp_var
|
|
130
148
|
|
bluecellulab/cell/template.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -20,7 +20,8 @@ import os
|
|
|
20
20
|
from pathlib import Path
|
|
21
21
|
import re
|
|
22
22
|
import string
|
|
23
|
-
from typing import Optional
|
|
23
|
+
from typing import NamedTuple, Optional
|
|
24
|
+
import uuid
|
|
24
25
|
|
|
25
26
|
import neuron
|
|
26
27
|
|
|
@@ -44,6 +45,13 @@ def public_hoc_cell(cell: HocObjectType) -> HocObjectType:
|
|
|
44
45
|
from the hoc model. Either getCell() or CellRef needs to be provided""")
|
|
45
46
|
|
|
46
47
|
|
|
48
|
+
class TemplateParams(NamedTuple):
|
|
49
|
+
template_filepath: str | Path
|
|
50
|
+
morph_filepath: str | Path
|
|
51
|
+
template_format: str
|
|
52
|
+
emodel_properties: Optional[EmodelProperties]
|
|
53
|
+
|
|
54
|
+
|
|
47
55
|
class NeuronTemplate:
|
|
48
56
|
"""NeuronTemplate representation."""
|
|
49
57
|
|
|
@@ -119,8 +127,8 @@ class NeuronTemplate:
|
|
|
119
127
|
# templates load outside of bluecellulab
|
|
120
128
|
template_name = "%s_bluecellulab" % template_name
|
|
121
129
|
template_name = get_neuron_compliant_template_name(template_name)
|
|
122
|
-
|
|
123
|
-
template_name = f"{template_name}_{
|
|
130
|
+
unique_id = uuid.uuid4().hex
|
|
131
|
+
template_name = f"{template_name}_{unique_id}"
|
|
124
132
|
|
|
125
133
|
template_content = re.sub(
|
|
126
134
|
r"begintemplate\s*(\S*)",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -19,8 +19,9 @@ import os
|
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
from typing import Optional
|
|
21
21
|
|
|
22
|
+
import neuron
|
|
22
23
|
import pandas as pd
|
|
23
|
-
from bluecellulab import circuit
|
|
24
|
+
from bluecellulab import circuit
|
|
24
25
|
from bluecellulab.circuit.circuit_access import EmodelProperties
|
|
25
26
|
from bluecellulab.circuit.config import BluepySimulationConfig
|
|
26
27
|
from bluecellulab.circuit.config.definition import SimulationConfig
|
|
@@ -57,7 +58,6 @@ class BluepyCircuitAccess:
|
|
|
57
58
|
raise FileNotFoundError(
|
|
58
59
|
f"Circuit config file {simulation_config} not found.")
|
|
59
60
|
|
|
60
|
-
# to allow the usage of SimulationConfig outside of Ssim
|
|
61
61
|
if isinstance(simulation_config, BluepySimulationConfig):
|
|
62
62
|
simulation_config = simulation_config.impl
|
|
63
63
|
|
|
@@ -191,23 +191,15 @@ class BluepyCircuitAccess:
|
|
|
191
191
|
|
|
192
192
|
if isinstance(connectome._impl, SonataConnectome):
|
|
193
193
|
logger.debug('Using sonata style synapse file, not nrn.h5')
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
synapses.columns = properties_from_bluepy(synapses.columns)
|
|
205
|
-
else:
|
|
206
|
-
connectome_properties = properties_to_bluepy(connectome_properties)
|
|
207
|
-
synapses = connectome.afferent_synapses(
|
|
208
|
-
gid, properties=connectome_properties
|
|
209
|
-
)
|
|
210
|
-
synapses.columns = properties_from_bluepy(synapses.columns)
|
|
194
|
+
connectome_properties.remove(SynapseProperty.POST_SEGMENT_OFFSET)
|
|
195
|
+
else: # afferent section_pos will be computed via post_segment_offset
|
|
196
|
+
connectome_properties.remove(SynapseProperty.AFFERENT_SECTION_POS)
|
|
197
|
+
|
|
198
|
+
connectome_properties = properties_to_bluepy(connectome_properties)
|
|
199
|
+
synapses = connectome.afferent_synapses(
|
|
200
|
+
gid, properties=connectome_properties
|
|
201
|
+
)
|
|
202
|
+
synapses.columns = properties_from_bluepy(synapses.columns)
|
|
211
203
|
|
|
212
204
|
synapses = synapses.reset_index(drop=True)
|
|
213
205
|
synapses.index = pd.MultiIndex.from_tuples(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -22,8 +22,9 @@ from bluepysnap.bbp import Cell as SnapCell
|
|
|
22
22
|
from bluepysnap.circuit_ids import CircuitNodeId, CircuitEdgeIds
|
|
23
23
|
from bluepysnap.exceptions import BluepySnapError
|
|
24
24
|
from bluepysnap import Circuit as SnapCircuit
|
|
25
|
+
import neuron
|
|
25
26
|
import pandas as pd
|
|
26
|
-
from bluecellulab import circuit
|
|
27
|
+
from bluecellulab import circuit
|
|
27
28
|
from bluecellulab.circuit.circuit_access.definition import EmodelProperties
|
|
28
29
|
from bluecellulab.circuit import CellId, SynapseProperty
|
|
29
30
|
from bluecellulab.circuit.config import SimulationConfig
|
|
@@ -46,7 +47,7 @@ class SonataCircuitAccess:
|
|
|
46
47
|
raise FileNotFoundError(f"Circuit config file {simulation_config} not found.")
|
|
47
48
|
|
|
48
49
|
if isinstance(simulation_config, SonataSimulationConfig):
|
|
49
|
-
self.config
|
|
50
|
+
self.config = simulation_config
|
|
50
51
|
else:
|
|
51
52
|
self.config = SonataSimulationConfig(simulation_config)
|
|
52
53
|
circuit_config = self.config.impl.config["network"]
|
|
@@ -190,7 +191,7 @@ class SonataCircuitAccess:
|
|
|
190
191
|
|
|
191
192
|
@lru_cache(maxsize=16)
|
|
192
193
|
def get_target_cell_ids(self, target: str) -> set[CellId]:
|
|
193
|
-
ids = self._circuit.nodes.ids(target)
|
|
194
|
+
ids = self._circuit.nodes.ids(self.config.impl.node_sets[target])
|
|
194
195
|
return {CellId(x.population, x.id) for x in ids}
|
|
195
196
|
|
|
196
197
|
@lru_cache(maxsize=100)
|
bluecellulab/circuit/format.py
CHANGED
bluecellulab/circuit/iotools.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -32,7 +32,7 @@ def parse_outdat(path: str | Path) -> dict[CellId, np.ndarray]:
|
|
|
32
32
|
# convert Series to DataFrame with 2 columns for `groupby` operation
|
|
33
33
|
spike_df = spikes.to_frame().reset_index()
|
|
34
34
|
if (spike_df["t"] < 0).any():
|
|
35
|
-
logger.warning('
|
|
35
|
+
logger.warning('Found negative spike times in out.dat ! '
|
|
36
36
|
'Clipping them to 0')
|
|
37
37
|
spike_df["t"].clip(lower=0., inplace=True)
|
|
38
38
|
|
bluecellulab/circuit/node_id.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -18,6 +18,7 @@ import logging
|
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
from typing import Optional, Protocol
|
|
20
20
|
|
|
21
|
+
import h5py
|
|
21
22
|
import pandas as pd
|
|
22
23
|
|
|
23
24
|
from bluecellulab.circuit.config import SimulationConfig, SonataSimulationConfig
|
|
@@ -171,13 +172,15 @@ class SonataSimulationAccess:
|
|
|
171
172
|
|
|
172
173
|
|
|
173
174
|
def get_synapse_replay_spikes(f_name: str) -> dict:
|
|
174
|
-
"""Read the .
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
"""Read the .h5 file containing the spike replays."""
|
|
176
|
+
with h5py.File(f_name, 'r') as f:
|
|
177
|
+
# Access the timestamps and node_ids datasets
|
|
178
|
+
timestamps = f['/spikes/All/timestamps'][:]
|
|
179
|
+
node_ids = f['/spikes/All/node_ids'][:]
|
|
180
|
+
|
|
181
|
+
spikes = pd.DataFrame(data={'t': timestamps, 'node_id': node_ids})
|
|
182
|
+
spikes = spikes.astype({"node_id": int})
|
|
183
|
+
|
|
181
184
|
if (spikes["t"] < 0).any():
|
|
182
185
|
logger.warning("Found negative spike times... Clipping them to 0")
|
|
183
186
|
spikes["t"].clip(lower=0., inplace=True)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -40,6 +40,7 @@ class SynapseProperty(Enum):
|
|
|
40
40
|
NRRP = "NRRP"
|
|
41
41
|
U_HILL_COEFFICIENT = "u_hill_coefficient"
|
|
42
42
|
CONDUCTANCE_RATIO = "conductance_scale_factor"
|
|
43
|
+
AFFERENT_SECTION_POS = "afferent_section_pos"
|
|
43
44
|
|
|
44
45
|
@classmethod
|
|
45
46
|
def from_bluepy(cls, prop: BLPSynapse) -> SynapseProperty:
|
|
@@ -76,6 +77,7 @@ class SynapseProperties:
|
|
|
76
77
|
SynapseProperty.NRRP,
|
|
77
78
|
SynapseProperty.U_HILL_COEFFICIENT,
|
|
78
79
|
SynapseProperty.CONDUCTANCE_RATIO,
|
|
80
|
+
SynapseProperty.AFFERENT_SECTION_POS,
|
|
79
81
|
)
|
|
80
82
|
plasticity = (
|
|
81
83
|
"volume_CR", "rho0_GB", "Use_d_TM", "Use_p_TM", "gmax_d_AMPA",
|
|
@@ -98,6 +100,7 @@ snap_to_synproperty = MappingProxyType({
|
|
|
98
100
|
"n_rrp_vesicles": SynapseProperty.NRRP,
|
|
99
101
|
"u_hill_coefficient": SynapseProperty.U_HILL_COEFFICIENT,
|
|
100
102
|
"conductance_scale_factor": SynapseProperty.CONDUCTANCE_RATIO,
|
|
103
|
+
"afferent_section_pos": SynapseProperty.AFFERENT_SECTION_POS,
|
|
101
104
|
})
|
|
102
105
|
|
|
103
106
|
|
|
@@ -137,23 +140,36 @@ def properties_from_bluepy(
|
|
|
137
140
|
'str's."""
|
|
138
141
|
if not BLUEPY_AVAILABLE:
|
|
139
142
|
raise ExtraDependencyMissingError("bluepy")
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if isinstance(prop, BLPSynapse)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
res: list[SynapseProperty | str] = []
|
|
144
|
+
for prop in props:
|
|
145
|
+
if isinstance(prop, BLPSynapse):
|
|
146
|
+
res.append(SynapseProperty.from_bluepy(prop))
|
|
147
|
+
elif prop == "afferent_section_pos": # jira_url/project/issues/browse/NSETM-2313
|
|
148
|
+
res.append(SynapseProperty.AFFERENT_SECTION_POS)
|
|
149
|
+
else:
|
|
150
|
+
res.append(prop)
|
|
151
|
+
return res
|
|
146
152
|
|
|
147
153
|
|
|
148
154
|
def properties_to_bluepy(props: list[SynapseProperty | str]) -> list[BLPSynapse | str]:
|
|
149
155
|
"""Convert a list of SynapseProperty to bluepy Synapse properties, spare
|
|
150
156
|
'str's."""
|
|
151
|
-
|
|
157
|
+
# bluepy does not have AFFERENT_SECTION_POS atm.
|
|
158
|
+
# jira_url/project/issues/browse/NSETM-2313
|
|
159
|
+
bluepy_recognised_props = props.copy()
|
|
160
|
+
removed_afferent_section_pos = False
|
|
161
|
+
if SynapseProperty.AFFERENT_SECTION_POS in bluepy_recognised_props:
|
|
162
|
+
removed_afferent_section_pos = True
|
|
163
|
+
bluepy_recognised_props.remove(SynapseProperty.AFFERENT_SECTION_POS)
|
|
164
|
+
res = [
|
|
152
165
|
prop.to_bluepy()
|
|
153
166
|
if isinstance(prop, SynapseProperty)
|
|
154
167
|
else prop
|
|
155
|
-
for prop in
|
|
168
|
+
for prop in bluepy_recognised_props
|
|
156
169
|
]
|
|
170
|
+
if removed_afferent_section_pos:
|
|
171
|
+
res.append("afferent_section_pos")
|
|
172
|
+
return res
|
|
157
173
|
|
|
158
174
|
|
|
159
175
|
def synapse_property_encoder(dct: dict[SynapseProperty | str, Any]) -> dict[str, Any]:
|
bluecellulab/circuit/validate.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2023-2024 Blue Brain Project / EPFL
|
|
2
2
|
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -25,6 +25,9 @@ import neuron
|
|
|
25
25
|
import numpy as np
|
|
26
26
|
import pandas as pd
|
|
27
27
|
from pydantic.types import NonNegativeInt
|
|
28
|
+
from typing_extensions import deprecated
|
|
29
|
+
from typing import Optional
|
|
30
|
+
|
|
28
31
|
import bluecellulab
|
|
29
32
|
from bluecellulab.cell import CellDict
|
|
30
33
|
from bluecellulab.cell.sonata_proxy import SonataProxy
|
|
@@ -39,24 +42,29 @@ from bluecellulab.circuit.config import SimulationConfig
|
|
|
39
42
|
from bluecellulab.circuit.format import determine_circuit_format, CircuitFormat
|
|
40
43
|
from bluecellulab.circuit.node_id import create_cell_id, create_cell_ids
|
|
41
44
|
from bluecellulab.circuit.simulation_access import BluepySimulationAccess, SimulationAccess, SonataSimulationAccess, _sample_array
|
|
42
|
-
from bluecellulab.importer import
|
|
45
|
+
from bluecellulab.importer import load_mod_files
|
|
43
46
|
from bluecellulab.rngsettings import RNGSettings
|
|
47
|
+
from bluecellulab.simulation.neuron_globals import NeuronGlobals
|
|
44
48
|
from bluecellulab.stimulus.circuit_stimulus_definitions import Noise, OrnsteinUhlenbeck, RelativeOrnsteinUhlenbeck, RelativeShotNoise, ShotNoise
|
|
45
49
|
import bluecellulab.stimulus.circuit_stimulus_definitions as circuit_stimulus_definitions
|
|
46
50
|
from bluecellulab.exceptions import BluecellulabError
|
|
47
51
|
from bluecellulab.simulation import (
|
|
48
52
|
set_global_condition_parameters,
|
|
49
|
-
set_tstop_value
|
|
50
53
|
)
|
|
51
54
|
from bluecellulab.synapse.synapse_types import SynapseID
|
|
52
55
|
|
|
53
56
|
logger = logging.getLogger(__name__)
|
|
54
57
|
|
|
55
58
|
|
|
59
|
+
@deprecated("SSim will be removed, use CircuitSimulation instead.")
|
|
56
60
|
class SSim:
|
|
57
61
|
"""Class that loads a circuit simulation to do cell simulations."""
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
|
|
64
|
+
class CircuitSimulation:
|
|
65
|
+
"""Class that loads a circuit simulation to do cell simulations."""
|
|
66
|
+
|
|
67
|
+
@load_mod_files
|
|
60
68
|
def __init__(
|
|
61
69
|
self,
|
|
62
70
|
simulation_config: str | Path | SimulationConfig,
|
|
@@ -106,14 +114,11 @@ class SSim:
|
|
|
106
114
|
|
|
107
115
|
self.gids_instantiated = False
|
|
108
116
|
|
|
109
|
-
# Make sure tstop is set correctly, because it is used by the
|
|
110
|
-
# TStim noise stimulus
|
|
111
|
-
if self.circuit_access.config.duration is not None:
|
|
112
|
-
set_tstop_value(self.circuit_access.config.duration)
|
|
113
|
-
|
|
114
117
|
self.spike_threshold = self.circuit_access.config.spike_threshold
|
|
115
118
|
self.spike_location = self.circuit_access.config.spike_location
|
|
116
119
|
|
|
120
|
+
self.projections: list[str] = []
|
|
121
|
+
|
|
117
122
|
condition_parameters = self.circuit_access.config.condition_parameters()
|
|
118
123
|
set_global_condition_parameters(condition_parameters)
|
|
119
124
|
|
|
@@ -224,34 +229,34 @@ class SSim:
|
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
if self.gids_instantiated:
|
|
227
|
-
raise
|
|
228
|
-
|
|
232
|
+
raise BluecellulabError(
|
|
233
|
+
"instantiate_gids() is called twice on the "
|
|
234
|
+
"same CircuitSimumation, this is not supported")
|
|
229
235
|
else:
|
|
230
236
|
self.gids_instantiated = True
|
|
231
237
|
|
|
232
238
|
if pre_spike_trains or add_replay:
|
|
233
239
|
if add_synapses is False:
|
|
234
|
-
raise
|
|
235
|
-
|
|
236
|
-
|
|
240
|
+
raise BluecellulabError("You need to set add_synapses to True "
|
|
241
|
+
"if you want to specify use add_replay or "
|
|
242
|
+
"pre_spike_trains")
|
|
237
243
|
|
|
238
244
|
if add_projections is True:
|
|
239
|
-
projections = self.circuit_access.config.get_all_projection_names()
|
|
245
|
+
self.projections = self.circuit_access.config.get_all_projection_names()
|
|
240
246
|
elif add_projections is False:
|
|
241
|
-
projections = []
|
|
247
|
+
self.projections = []
|
|
242
248
|
else:
|
|
243
|
-
projections = add_projections
|
|
249
|
+
self.projections = add_projections
|
|
244
250
|
|
|
245
251
|
self._add_cells(cell_ids)
|
|
246
252
|
if add_synapses:
|
|
247
253
|
self._add_synapses(
|
|
248
254
|
pre_gids=pre_gids,
|
|
249
|
-
add_minis=add_minis
|
|
250
|
-
projections=projections)
|
|
255
|
+
add_minis=add_minis)
|
|
251
256
|
if add_replay or interconnect_cells or pre_spike_trains:
|
|
252
257
|
if add_replay and not add_synapses:
|
|
253
|
-
raise
|
|
254
|
-
|
|
258
|
+
raise BluecellulabError("add_replay option can not be used if "
|
|
259
|
+
"add_synapses is False")
|
|
255
260
|
self._add_connections(add_replay=add_replay,
|
|
256
261
|
interconnect_cells=interconnect_cells,
|
|
257
262
|
user_pre_spike_trains=pre_spike_trains) # type: ignore
|
|
@@ -354,18 +359,17 @@ class SSim:
|
|
|
354
359
|
ornstein_uhlenbeck_stim_count += 1
|
|
355
360
|
|
|
356
361
|
def _add_synapses(
|
|
357
|
-
self, pre_gids=None, add_minis=False
|
|
362
|
+
self, pre_gids=None, add_minis=False):
|
|
358
363
|
"""Instantiate all the synapses."""
|
|
359
364
|
for cell_id in self.cells:
|
|
360
365
|
self._add_cell_synapses(
|
|
361
366
|
cell_id, pre_gids=pre_gids,
|
|
362
|
-
add_minis=add_minis
|
|
363
|
-
projections=projections)
|
|
367
|
+
add_minis=add_minis)
|
|
364
368
|
|
|
365
369
|
def _add_cell_synapses(
|
|
366
|
-
self, cell_id: CellId, pre_gids=None, add_minis=False
|
|
370
|
+
self, cell_id: CellId, pre_gids=None, add_minis=False
|
|
367
371
|
) -> None:
|
|
368
|
-
syn_descriptions = self.get_syn_descriptions(cell_id
|
|
372
|
+
syn_descriptions = self.get_syn_descriptions(cell_id)
|
|
369
373
|
|
|
370
374
|
if pre_gids is not None:
|
|
371
375
|
if self.circuit_format == CircuitFormat.SONATA:
|
|
@@ -420,12 +424,10 @@ class SSim:
|
|
|
420
424
|
)
|
|
421
425
|
return syn_descriptions[filtered_rows]
|
|
422
426
|
|
|
423
|
-
def get_syn_descriptions(
|
|
424
|
-
self, cell_id: int | tuple[str, int], projections=None
|
|
425
|
-
) -> pd.DataFrame:
|
|
427
|
+
def get_syn_descriptions(self, cell_id: int | tuple[str, int]) -> pd.DataFrame:
|
|
426
428
|
"""Get synapse descriptions dataframe."""
|
|
427
429
|
cell_id = create_cell_id(cell_id)
|
|
428
|
-
return self.circuit_access.extract_synapses(cell_id, projections=projections)
|
|
430
|
+
return self.circuit_access.extract_synapses(cell_id, projections=self.projections)
|
|
429
431
|
|
|
430
432
|
@staticmethod
|
|
431
433
|
def merge_pre_spike_trains(*train_dicts) -> dict[CellId, np.ndarray]:
|
|
@@ -554,7 +556,7 @@ class SSim:
|
|
|
554
556
|
cvode: bool = False,
|
|
555
557
|
show_progress: bool = False,
|
|
556
558
|
):
|
|
557
|
-
"""Simulate the
|
|
559
|
+
"""Simulate the Circuit.
|
|
558
560
|
|
|
559
561
|
Parameters
|
|
560
562
|
----------
|
|
@@ -596,8 +598,10 @@ class SSim:
|
|
|
596
598
|
forward_skip_value = self.circuit_access.config.forward_skip
|
|
597
599
|
if celsius is None:
|
|
598
600
|
celsius = self.circuit_access.config.celsius
|
|
601
|
+
NeuronGlobals.get_instance().temperature = celsius
|
|
599
602
|
if v_init is None:
|
|
600
603
|
v_init = self.circuit_access.config.v_init
|
|
604
|
+
NeuronGlobals.get_instance().v_init = v_init
|
|
601
605
|
|
|
602
606
|
sim = bluecellulab.Simulation(self.pc)
|
|
603
607
|
for cell_id in self.cells:
|
|
@@ -612,8 +616,6 @@ class SSim:
|
|
|
612
616
|
t_stop,
|
|
613
617
|
cvode=cvode,
|
|
614
618
|
dt=dt,
|
|
615
|
-
celsius=celsius,
|
|
616
|
-
v_init=v_init,
|
|
617
619
|
forward_skip=forward_skip,
|
|
618
620
|
forward_skip_value=forward_skip_value,
|
|
619
621
|
show_progress=show_progress)
|
|
@@ -710,7 +712,7 @@ class SSim:
|
|
|
710
712
|
return voltage
|
|
711
713
|
|
|
712
714
|
def delete(self):
|
|
713
|
-
"""Delete
|
|
715
|
+
"""Delete CircuitSimulation and all of its attributes.
|
|
714
716
|
|
|
715
717
|
NEURON objects are explicitly needed to be deleted.
|
|
716
718
|
"""
|
bluecellulab/connection.py
CHANGED
bluecellulab/dendrogram.py
CHANGED
bluecellulab/exceptions.py
CHANGED
bluecellulab/graph.py
CHANGED