Skip to content

Commit

Permalink
consistent arg names&types in replay minis&synapses
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Oct 4, 2023
1 parent 68ffef2 commit f249ad3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
49 changes: 27 additions & 22 deletions bluecellulab/cell/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def __init__(self, template_path: str | Path, morphology_path: str | Path,
self.synapses: dict[tuple[str, int], Synapse] = {}
self.connections: dict[tuple[str, int], bluecellulab.Connection] = {}

self.ips: dict[int, HocObjectType] = {}
self.syn_mini_netcons: dict[int, HocObjectType] = {}
self.ips: dict[tuple[str, int], HocObjectType] = {}
self.syn_mini_netcons: dict[tuple[str, int], HocObjectType] = {}
self.serialized = None

# Be careful when removing this,
Expand Down Expand Up @@ -503,7 +503,8 @@ def get_recording(self, var_name: str) -> np.ndarray:
"""Get recorded values."""
return np.array(self.recordings[var_name].to_python())

def add_replay_synapse(self, synapse_id: tuple[str, int],
def add_replay_synapse(self,
synapse_id: tuple[str, int],
syn_description: pd.Series,
connection_modifiers: dict,
condition_parameters: Conditions,
Expand Down Expand Up @@ -638,13 +639,17 @@ def get_recorded_spikes(self, location: str, threshold: float = -30) -> list[flo
result = self.recordings[f"spike_detector_{location}_{threshold}"]
return result.to_python()

def add_replay_minis(self, syn_id, syn_description, connection_parameters,
base_seed=None, popids=(0, 0), mini_frequencies=None):
def add_replay_minis(self,
synapse_id: tuple[str, int],
syn_description: pd.Series,
connection_modifiers: dict,
base_seed: int | None,
popids: tuple[int, int],
mini_frequencies: tuple[float | None, float | None]) -> None:
"""Add minis from the replay."""

source_popid, target_popid = popids

sid = syn_id[1]
sid = synapse_id[1]

if base_seed is None:
base_seed = self.rng_settings.base_seed
Expand All @@ -659,19 +664,19 @@ def add_replay_minis(self, syn_id, syn_description, connection_parameters,
synlocation_to_segx(post_sec_id, post_seg_id,
post_seg_distance)
# todo: False
if 'Weight' in connection_parameters:
weight_scalar = connection_parameters['Weight']
if 'Weight' in connection_modifiers:
weight_scalar = connection_modifiers['Weight']
else:
weight_scalar = 1.0

exc_mini_frequency, inh_mini_frequency = mini_frequencies \
if mini_frequencies is not None else (None, None)

synapse = self.synapses[syn_id]
synapse = self.synapses[synapse_id]

# SpontMinis in sim config takes precedence of values in nodes file
if 'SpontMinis' in connection_parameters:
spont_minis_rate = connection_parameters['SpontMinis']
if 'SpontMinis' in connection_modifiers:
spont_minis_rate = connection_modifiers['SpontMinis']
else:
if synapse.mech_name in ["GluSynapse", "ProbAMPANMDA_EMS"]:
spont_minis_rate = exc_mini_frequency
Expand All @@ -681,25 +686,25 @@ def add_replay_minis(self, syn_id, syn_description, connection_parameters,
if spont_minis_rate is not None and spont_minis_rate > 0:
sec = self.get_hsection(post_sec_id)
# add the *minis*: spontaneous synaptic events
self.ips[syn_id] = bluecellulab.neuron.h.\
self.ips[synapse_id] = bluecellulab.neuron.h.\
InhPoissonStim(location, sec=sec)

self.syn_mini_netcons[syn_id] = bluecellulab.neuron.h.\
NetCon(self.ips[syn_id], synapse.hsynapse, sec=sec)
self.syn_mini_netcons[syn_id].delay = 0.1
self.syn_mini_netcons[syn_id].weight[0] = weight * weight_scalar
self.syn_mini_netcons[synapse_id] = bluecellulab.neuron.h.\
NetCon(self.ips[synapse_id], synapse.hsynapse, sec=sec)
self.syn_mini_netcons[synapse_id].delay = 0.1
self.syn_mini_netcons[synapse_id].weight[0] = weight * weight_scalar
# set netcon type
nc_param_name = 'nc_type_param_{}'.format(
synapse.hsynapse).split('[')[0]
if hasattr(bluecellulab.neuron.h, nc_param_name):
nc_type_param = int(getattr(bluecellulab.neuron.h, nc_param_name))
# NC_SPONTMINI
self.syn_mini_netcons[syn_id].weight[nc_type_param] = 1
self.syn_mini_netcons[synapse_id].weight[nc_type_param] = 1

if self.rng_settings.mode == 'Random123':
seed2 = source_popid * 65536 + target_popid \
+ self.rng_settings.minis_seed
self.ips[syn_id].setRNGs(
self.ips[synapse_id].setRNGs(
sid + 200,
self.gid + 250,
seed2 + 300,
Expand Down Expand Up @@ -739,16 +744,16 @@ def add_replay_minis(self, syn_id, syn_description, connection_parameters,
uniformrng.MCellRan4(uniform_seed1, uniform_seed2)
uniformrng.uniform(0.0, 1.0)

self.ips[syn_id].setRNGs(exprng, uniformrng)
self.ips[synapse_id].setRNGs(exprng, uniformrng)

tbins_vec = bluecellulab.neuron.h.Vector(1)
tbins_vec.x[0] = 0.0
rate_vec = bluecellulab.neuron.h.Vector(1)
rate_vec.x[0] = spont_minis_rate
self.persistent.append(tbins_vec)
self.persistent.append(rate_vec)
self.ips[syn_id].setTbins(tbins_vec)
self.ips[syn_id].setRate(rate_vec)
self.ips[synapse_id].setTbins(tbins_vec)
self.ips[synapse_id].setRate(rate_vec)

def locate_bapsite(self, seclist_name, distance):
"""Return the location of the BAP site.
Expand Down
6 changes: 3 additions & 3 deletions bluecellulab/circuit/circuit_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_target_cell_ids(self, target: str) -> set[CellId]:
def fetch_cell_info(self, cell_id: CellId) -> pd.Series:
raise NotImplementedError

def fetch_mini_frequencies(self, cell_id: CellId) -> tuple:
def fetch_mini_frequencies(self, cell_id: CellId) -> tuple[float | None, float | None]:
raise NotImplementedError

@property
Expand Down Expand Up @@ -432,7 +432,7 @@ def _fetch_emodel_name(self, cell_id: CellId) -> str:

return emodel_name

def fetch_mini_frequencies(self, cell_id: CellId) -> tuple:
def fetch_mini_frequencies(self, cell_id: CellId) -> tuple[float | None, float | None]:
"""Get inhibitory frequency of gid."""
cell_info = self.fetch_cell_info(cell_id)
# mvd uses inh_mini_frequency, sonata uses inh-mini_frequency
Expand Down Expand Up @@ -650,7 +650,7 @@ def get_target_cell_ids(self, target: str) -> set[CellId]:
def fetch_cell_info(self, cell_id: CellId) -> pd.Series:
return self._circuit.nodes[cell_id.population_name].get(cell_id.id)

def fetch_mini_frequencies(self, cell_id: CellId) -> tuple:
def fetch_mini_frequencies(self, cell_id: CellId) -> tuple[float | None, float | None]:
cell_info = self.fetch_cell_info(cell_id)
exc_mini_frequency = cell_info['exc-mini_frequency'] \
if 'exc-mini_frequency' in cell_info else None
Expand Down
4 changes: 3 additions & 1 deletion bluecellulab/ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ def _instantiate_synapse(self, cell_id: CellId, syn_id: tuple[str, int], syn_des
syn_description,
syn_connection_parameters,
popids=popids,
mini_frequencies=mini_frequencies)
mini_frequencies=mini_frequencies,
base_seed=None
)

def run(
self,
Expand Down

0 comments on commit f249ad3

Please sign in to comment.