Code Monkey home page Code Monkey logo

bluecellulab's Introduction

banner

BlueCelluLab

Latest Release latest release
Documentation latest documentation
License license
Build Status CI
Coverage coverage
Gitter Join the chat at https://gitter.im/BlueBrain/BlueCelluLab
Paper JOSS
Zenodo zenodo

The Blue Brain Cellular Laboratory is designed for simulations and experiments on individual cells or groups of cells. Suitable use cases for BlueCelluLab include:

  • Scripting and statistical analysis for single cells or cell pairs.
  • Lightweight, detailed reporting on specific state variables after simulation.
  • Developing synaptic plasticity rules.
  • Validating dynamics of synaptic properties.
  • Automating in-silico whole-cell patching experiments.
  • Debugging, both scientifically and computationally.

Citation

When using the BlueCelluLab software for your research, please cite the following paper (including for poster presentations): BlueCelluLab: Biologically Detailed Neural Network Experimentation API

@article{Tuncel2024,
    doi = {10.21105/joss.07026},
    url = {https://doi.org/10.21105/joss.07026},
    year = {2024},
    publisher = {The Open Journal},
    volume = {9},
    number = {100},
    pages = {7026},
    author = {Anıl Tuncel and Werner Van Geit and Mike Gevaert and Benjamin Torben-Nielsen and Darshan Mandge and İlkan Kılıç and Aurélien Jaquier and Eilif Muller and Lida Kanari and Henry Markram},
    title = {BlueCelluLab: Biologically Detailed Neural Network Experimentation API},
    journal = {Journal of Open Source Software}
}

If you need to cite a specific version, please use the DOI provided by Zenodo, which you can access via the "Cite this repository" button at the top of the repository page.

Support

We are providing support on Gitter. We suggest you create tickets on the Github issue tracker in case you encounter problems while using the software or if you have some suggestions.

Main dependencies

Installation

BlueCelluLab can be pip installed with the following command:

pip install bluecellulab

Quick Start

The following example shows how to create a cell, add a stimulus and run a simulation:

from bluecellulab.cell import create_ball_stick
from bluecellulab import Simulation

cell = create_ball_stick()
sim = Simulation()
sim.add_cell(cell)
stimulus = cell.add_step(start_time=5.0, stop_time=20.0, level=0.5)

sim.run(25, cvode=False)
time, voltage = cell.get_time(), cell.get_soma_voltage()
# plotting time and voltage ...

Voltage plot

Tutorial

A more detailed explanation on how to use BlueCelluLab, as well as other examples can be found on the examples page.

API Documentation

The API documentation can be found on ReadTheDocs.

Running the tests

Testing is set up using tox:

pip install tox

tox -e py3  # runs the tests
tox -e lint  # runs the format checks

Contributing

We welcome contributions to BlueCelluLab! Please see the CONTRIBUTING.rst for guidelines on how to contribute.

Funding & Acknowledgements

The development and maintenance of this code is supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government's ETH Board of the Swiss Federal Institutes of Technology.

Copyright

Copyright (c) 2023-2024 Blue Brain Project/EPFL

This work is licensed under Apache 2.0

For MOD files for which the original source is available on ModelDB, any specific licenses on mentioned on ModelDB, or the generic License of ModelDB apply.

The licenses of the morphology files used in this repository are available on: https://zenodo.org/record/5909613

bluecellulab's People

Contributors

anilbey avatar arnaudon avatar asvg avatar aurelienjaquier avatar darshanmandge avatar dependabot[bot] avatar edasubert avatar ejayromero avatar ilkilic avatar mgeplf avatar wvangeit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluecellulab's Issues

StimulusFactory: enable amplitude based versions of the protocols

At the moment the following protocols are only threshold-based.

  • neg_cheops
  • pos_cheops
  • fire_pattern
  • iv
  • idrest
  • ap_waveform

Some of the non-bbp models however are amplitude based.

The StimulusFactory should be extended to support the amplitude based methods as well.
The amplitude based implementation can be reused by the threshold based implementation.

Such as the following:

amplitude = threshold_current * threshold_percentage / 100
res = cls.amplitude_based(
dt,
pre_delay=pre_delay,
duration=duration,
post_delay=post_delay,
amplitude=amplitude,
)
return res

Keep main Apache software license intact and mention the modelDB and Zenodo in the examples directory

This is mentioned by the AEiC of JOSS
openjournals/joss-reviews#7026 (comment)

BlueCelluLab does not depend on any of those licensed morphology or MOD files to be installed and run.

The MOD and morphologies are not even part of the package resources.
https://github.com/BlueBrain/BlueCelluLab/blob/fe4baed5db1cd3df85012e22e3625fb0646c5b5b/MANIFEST.in

Only the example directories and test directories show its applicability using those files.

So I suggest this commit can be reverted so that the software will have the original Apache license text
baebfcb

And then 2 LICENSE files can be created inside the /examples and /tests to acknowledge where the test and examples data/code (morph and MOD) comes from.

Issue with Synaptic and Somatic Voltage traces using synapse_replay feature

Hi @anilbey,

I've encountered an issue where both the synaptic and somatic voltage traces are turning out empty after utilizing the synapse_replay feature. I have attached the code that I used to run the simulation below.

Could you please review it and let me know if I've initialized the synapses correctly or if there's anything I might have missed or done incorrectly?

Thank you in advance for your time and assistance!

Script:

import neuron
from bluecellulab import SSim

neuron.load_mechanisms("./circuit_sonata/")

cfg_json = "/project/ctb-emuller/projects/proj01/dhuruva_sims/2_cpre_cpost/simulation_config.json"
sim = SSim(cfg_json,print_cellstate=True)

cell_id = 170923
pre_gid = ('S1nonbarrel_neurons', 170983)

# Working snippet - without synapse_replay
# sim.instantiate_gids([('S1nonbarrel_neurons',cell_id)])

# With synapse replay
sim.instantiate_gids([('S1nonbarrel_neurons',cell_id)], add_synapses=True,
                          pre_spike_trains={pre_gid: [1000.]}, add_projections = False, add_minis = False)

duration = 200
dt = 0.025
sim.run(duration, cvode=False, v_init=-70, celsius=34, dt=dt)
Somatic Voltage trace Empty Somatic Voltage trace
image image

Simulation Config:

{
    "manifest": {
        "$CURRENT_DIR": "."
    },
    "run": {
        "dt": 0.025,
        "tstop": 2000.0,
        "random_seed": 12345,
        "using_cvode": 0
    },
    "conditions": {
        "extracellular_calcium": 2.0,
        "v_init": -80.0,
        "spike_location": "AIS",
        "mechanisms": {
            "ProbAMPANMDA_EMS": {
                "init_depleted": true,
                "minis_single_vesicle": true
            },
            "ProbGABAAB_EMS": {
                "init_depleted": true,
                "minis_single_vesicle": true
            },
            "GluSynapse": {
                "init_depleted": false,
                "minis_single_vesicle": true,
                "cao_CR": 2.0
            }
            }
    },
    "target_simulator": "CORENEURON",
    "network": "---/circuit_config.json",
    "node_sets_file": "./node_sets.json",
    "node_set": "test_circuit",
    "output": {
        "output_dir": "./reporting",
        "spikes_file": "out.h5"
    },
    "reports": {
        "soma": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "compartment",
            "variable_name": "v",
            "unit": "mV",
            "dt": 1.0,
            "start_time": 0.0,
            "end_time": 122500.0
        },
        "rho": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "synapse",
            "sections": "all",
            "variable_name": "GluSynapse.rho_GB",
            "unit": "nd",
            "dt": 0.025,
            "start_time": 0.0,
            "end_time": 122500.0
        },
        "effcai_GB": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "synapse",
            "sections": "all",
            "variable_name": "GluSynapse.effcai_GB",
            "unit": "mM",
            "dt": 0.025,
            "start_time": 0.0,
            "end_time": 122500.0
        }
    },
    "inputs": {
        "s1_syns_spikes": {
            "node_set": "hex_O1ExcitatoryPlastic",
            "input_type": "spikes",
            "delay": 0.0,
            "duration": 2000.0,
            "module": "synapse_replay",
            "spike_file": "./input_spikes/s1_syn_spikes.dat",
            "source": "hex_O1"
            }
    },
    "connection_overrides": [
        {
            "name": "plasticity",
            "source": "hex_O1Excitatory",
            "target": "hex_O1Excitatory",
            "modoverride": "GluSynapse",
            "weight": 1.0
        },
        {
            "name": "init",
            "source": "hex_O1",
            "target": "hex_O1",
	    "spont_minis": 0.0,
            "weight": 1.0
        },
        {
            "name": "VPM_init",
            "source": "proj_Thalamocortical_VPM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        },
        {
            "name": "POm_init",
            "source": "proj_Thalamocortical_POM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        }
    ]
}

stimulus duration of add_noise_step is longer than informed

Here is what I gave to BlueCelluLab:

cell.add_noise_step(cell.soma, 0.5, delay=1000.0, duration=43.0, mean=0.2, variance=0.0, seed=20)
sim.run(1600, cvode=False, dt=0.025, v_init=-55, celsius=35)

but here is the output I got:

hoc_run_BCL

Even though I gave a short duration (43 ms), BlueCelluLab make it last until the end of the simulation.

Allow custom section names in hoc files for Cell object

Hi,
The Cell object intialisation does not support hoc files with custom section names:

bluecellulab/psection.py:89, in PSection.__init__(self, hsection, isec)
     87     self.section_type = 'myelin'
     88 else:
---> 89     raise Exception(
     90         "PSection: Section of unknown type: %s" %
     91         self.name)
     93 self.psegments: list[PSegment] = []
     94 self.maxsegdiam = 0.0

Exception: PSection: Section of unknown type: MOBopl_mTC_bSTUT_bluecellulab_0x7fff01743ad0[0].hillock

Warning needed on serialised sections?

This warning

BlueCelluLab/bluecellulab/cell/serialized_sections.py:40: UserWarning: [Warning] SerializedSections: v(0.0001) < 0. index=1 v()=-65.0

is a pain when we use non-bbp mod files, is it really necessary to have it always printed, not in debug mode or so?

bug when morphology is not in a subfolder

When morphology is not in a subfolder and we give, e.g.

morph_file = "./soma_10c.asc"
cell = Cell(hoc_file, morph_file, template_format="v6", emodel_properties=emodel_properties)

the cell can be run as expected, but if we give

morph_file = "soma_10c.asc"
cell = Cell(hoc_file, morph_file, template_format="v6", emodel_properties=emodel_properties)

then we have the following error:

could not open /soma_10c.asc
NEURON: /soma_10c.asc :file is not open
 near line 0
 
 ^
        File[0].eof()
      Import3d_Neurolucida3[0].rdfile("/soma_10c.asc")
    Import3d_Neurolucida3[0].input("/soma_10c.asc")
  cell_bluecellulab_0x7fffe5c34a90[0].load_morphology("", "soma_10c.asc")

It would be nice if we were allowed to give the morphology path without ./ in front of it.

This is not an urgent issue though.

Have an alternative template naming

The current way of appending _x to the template name can be confusing while debugging. If 2 cells are loaded using the same hoc, the order of loading matters and the more cells share the same hoc the less readable things become.

E.g.

Screenshot from 2023-06-16 13-47-59

One possible solution is to use the same memory address python uses. This will also help in debugging between python and hoc.
E.g. <bluecellulab.cell.Cell at 0x7f096d72afd0>

cADpyr_L2TPC_bluecellulab_0x7f096d72afd0[0].apic[62]

We will know which python object will refer to which hoc object without counting the order of creation or the number of _x's in it

map SONATA spec's LINEAR input

The implementation exists as add_step the hoc implementation is in TStim.hoc. The mapping is missing. When sonata config contains LINEAR, it should be read and the underlying implementation called.

Add default segx to add_voltage_recording

I'm trying to use the function add_voltage_recording and get_voltage_recording
https://github.com/BlueBrain/BlueCelluLab/blob/main/bluecellulab/cell/core.py#L387

Maybe in the documentation we should include more details about what that segx is. Like it is described in Neuron documentation

... specify a value between 0 and 1, where 0 is typically the end closest to the soma and 1 is the distal end

Also I've seen that you set a default value for segx like in here:

def add_allsections_voltagerecordings(self):
   """Add a voltage recording to every section of the cell."""
   all_sections = public_hoc_cell(self.cell).all
   for section in all_sections:
      self.add_voltage_recording(section, segx=0.5, dt=self.record_dt)

https://github.com/BlueBrain/BlueCelluLab/blob/main/bluecellulab/cell/core.py#L422

And I'm wondering if maybe we can also add this default value for the add_voltage_recording and get_voltage_recording functions

Discrepancy in Synapse-Replay Simulation Outputs between Neurodamus and BlueCelluLab

Hi @anilbey,

I would like to report a discrepancy between the two codebases when using the synapse replay feature. I attempted to simulate synapses of a cell using SScx dataset, specifically focusing on the edge population labeled "S1_nonbarrel_neurons__S1_nonbarrel_neurons." The somatic voltage traces obtained from BlueCelluLab do not align with those from Neurodamus. Interestingly, when the release probability is set to 1, the traces do match, suggesting that the issue may lie in my random seed settings. I have attached my simulation_config, spikes files, and results for your review. Please let me know if you need additional details to help resolve this issue. Thank you in advance!

image

Matching Results for Use = 1:
image

My simulation_config.json:

{

  "run": {
    "dt": 0.025,
    "tstop": 2000,
    "random_seed": 12345
  },

  "conditions": {
    "extracellular_calcium": 1.05,
    "v_init": -80.0,
    "spike_location": "AIS",
    "mechanisms": {
        "ProbAMPANMDA_EMS": {
            "init_depleted": false,
            "minis_single_vesicle": false
        },
        "ProbGABAAB_EMS": {
            "init_depleted": false,
            "minis_single_vesicle": false
        }
    }
  },

  "target_simulator": "CORENEURON",
  "network": "./circuit_config.json",
  "node_sets_file": "./node_sets.json",
    "node_set": "my_circuit",
  "output": {
    "output_dir": "./reporting",
    "spikes_file": "spikes.h5"
  },
  
  "inputs":{ 
	"s1_syns_spikes": {
            "node_set": "hex_O1",
            "input_type": "spikes",
            "delay": 0.0,
            "duration": 2000.0,
            "module": "synapse_replay",
            "spike_file": "./input_spikes/s1_syn_spikes.dat",
            "source": "hex_O1"
            }
},
    "connection_overrides": [
        {
            "name": "init",
            "source": "hex_O1",
            "target": "hex_O1",
            "spont_minis":0.0,
            "weight": 1.0
        },
        {
            "name": "VPM_init",
            "source": "proj_Thalamocortical_VPM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        },
        {
            "name": "VPM-L5E_meanE",
            "source": "proj_Thalamocortical_VPM_Source",
            "target": "Layer5Excitatory",
            "spont_minis": 1.0,
            "weight": 0.733
        },
        {
            "name": "POm_init",
            "source": "proj_Thalamocortical_POM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        }
    ],
    "reports": {
        "soma_report": {
            "type": "compartment",
            "cells": "my_circuit",
            "variable_name": "v",
            "dt": 0.25,
            "start_time": 0.0,
            "end_time": 11000.0
        }
    }    

    
}

My spikes data:

/scatter
200 375
400 413
800 744
1000 3228
1400 3869
1800 12503

Thanks,
Dhuruva Priyan G M

logging info in importer

Could you move the logging.info in import.py to debug?
Running this code in parallel pollutes my logs:

2024-02-20 22:13:28,409 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,410 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,411 INFO bluecellulab.importer: Loading the mod files.
2024-02-20 22:13:28,412 INFO bluecellulab.importer: Loading the hoc files.
2024-02-20 22:13:28,428 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,429 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,436 INFO bluecellulab.importer: Loading the mod files.
2024-02-20 22:13:28,436 INFO bluecellulab.importer: Loading the hoc files.
2024-02-20 22:13:28,445 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,445 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,456 INFO bluecellulab.importer: Loading the mod files.
2024-02-20 22:13:28,457 INFO bluecellulab.importer: Loading the hoc files.
2024-02-20 22:13:28,468 INFO bluecellulab.importer: Loading the mod files.
2024-02-20 22:13:28,469 INFO bluecellulab.importer: Loading the hoc files.
2024-02-20 22:13:28,486 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,486 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,491 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,491 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,501 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,501 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,524 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,525 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,556 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,556 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64
2024-02-20 22:13:28,580 INFO bluecellulab.importer: Imported NEURON from: /gpfs/bbp.cscs.ch/home/arnaudon/base/lib/python3.11/site-packages/neuron/__init__.py
2024-02-20 22:13:28,580 INFO bluecellulab.importer: Mod lib: /gpfs/bbp.cscs.ch/data/scratch/proj148/circuits/test_emodel/x86_64

replace neuron.h.nrn_load_dll call with the high level load_mechanisms function

Source of the issue:

neuron.h.nrn_load_dll(libnrnmech_path)

and

neuron.h.nrn_load_dll(mod_lib)

Problem: nrn_load_dll is a very low level module call. It may terminate with C or hoc exceptions. E.g. a segfault.

(Pdb) c
NEURON: The user defined name already exists: cacum
near line 0
{bACnoljp_bluecellulab[0].dend[47] gbar_na3(0.970588) = exp((-452.52733948473912)/50)*0.03991157933283921}
^
nrn_load_dll("x86_64/lib...")
NEURON: kdr is not a MECHANISM
near line 115
insert kdr
^
make: *** [initial-opt-results] Segmentation fault

Solution:
NEURON has a high level python function to handle loading of mechanisms. We should use that.
https://github.com/neuronsimulator/nrn/blob/e0290762790622291c4867dee25a7c13e0c2d326/share/lib/python/neuron/__init__.py#L298

having consistent sampling options across ssim methods

Description

One use-case of bluecellulab is to rerun a neurodamus simulation with some changed properties. For that purpose, SSim class has get_mainsim_voltage_trace, get_mainsim_time_trace methods to retrieve the results of neurodamus simulation. Similarly SSim has get_voltage_trace and get_time_trace methods to retrieve the results of bluecellulab simulation.

The time step between data points may differ in the simulations. It is due to the sampling involved in the simulation.
The scientist decides the sampling rate, hence the time step.

bluecellulab's API should support sampling.

Implementation

Currently some methods of bluecellulab support sampling, some don't. All 4 methods should support sampling consistently.

  • SSim::get_mainsim_voltage_trace supports sampling.
    SSim::get_voltage_trace does not.

  • get_mainsim_time_trace does not pass the t_step parameter to simulation_access.get_soma_time_trace().

  • get_time_trace does not support sampling.

TODO 1: make all get_mainsim_voltage_trace, get_voltage_trace, get_mainsim_time_trace, get_time_trace support sampling.
After the implementation get_mainsim_voltage_trace and get_voltage_trace should have the same arguments.
After the implementation get_mainsim_time_trace and get_time_trace should have the same arguments.

The _sample_array function currently takes 2 t_step parameters.

def _sample_array(arr: Sequence, t_step: float, sim_t_step: float) -> Sequence:

Then it computes a ratio via
ratio = t_step / sim_t_step

This is confusing. The function should only take ratio as an argument. The calling functions should be responsible of computing it.
TODO 2: sampling function should only take the ratio

Once this is implemented the tests below no longer have to sample explicitly

TODO 3: the test code in test_ssim_sonata.py should be simplified (with this, user's code will also be simplified).

Add unit test for EuclideanSectionDistance

The EuclideanSectionDistance is an old code that remains untested.

Todo:

bug in the assignment of AIS_scaler/soma_scaler

Hi @arnaudon this should be the soma_scaler, no?

emodel_properties.AIS_scaler = float(self.get_cell_properties(

Like in the code below:

        if "@dynamics:AIS_scaler" in self.available_cell_properties:
            emodel_properties.AIS_scaler = float(self.get_cell_properties(
                cell_id, properties=["@dynamics:AIS_scaler"])["@dynamics:AIS_scaler"])

        if "@dynamics:soma_scaler" in self.available_cell_properties:
            emodel_properties.AIS_scaler = float(self.get_cell_properties(
                cell_id, properties=["@dynamics:soma_scaler"])["@dynamics:soma_scaler"])

Is there a simulation (in our gpfs) using blueconfig that we can use?

Discrepancy in Results Between Neurodamus and BlueCelluLab on Zenodo SSCX Circuit

Thanks for implementing spike replay! This is very useful for us!
One question: A great usecase is to "re-run" single cell simulations in the context of a former neurodamus circuit run.
I recall the legacy bglibpy had essentially perfect agreement with neurodamus voltage traces.
Is this currently the case with BluweCelluLab? We're trying it out now on our end, but can't seem to get it to work.
I would seem like the OU process rng seeds are not the same ... Could you offer some insight as to this is a known issue or if its expected to work? Thanks!

Originally posted by @markovg in #55 (comment)

Feature request: ability to check for node sets in the simulation node sets file

It seems that bluecellulab is currently only finding node sets in the circuit config's node sets file, which means using any of the node sets defined in the simulation config's node sets file would raise an exception.

It would be nice if it could also look into the simulation config's node sets file and prioritise that file over the circuit config's node sets file as the simulation config is what CircuitSimulation takes as an argument.

If you are interested in implementing this, I'm happy to help should you need help with bluepysnap.

SSim API needs simplifications

The following needs to be addressed:

  • add_X_stimulus, add_Y_stimulus, add_Z_stimulus can be expressed simpler
  • not every feature plays well with every other feature
  • some features do redundant work, duplicated work

add unit test for get_allsections_voltagerecordings

It is an important function to enable recording from every section of the morphology. The unit test is missing.

The function to be tested: bluecellulab/cell/core.py/Cell::get_allsections_voltagerecordings

Steps:

  1. rename test_cell/test_cell.py -> test_cell/test_core.py
  2. add the unit test to test_cell/test_core.py

Issues while initializing Excitatory Plastic cells

Hi @anilbey,

I've encountered some challenges while stimulating Excitatory Plastic cells with the GluSynapse mechanism on the SSCx_plasticity circuit. Specifically, I selected a L5_TPC cell and transitioned its synapses to GluSynapse using the modoverride function. However, during the cell initialization process, I was met with an error indicating a missing parameter within the GluSynapse mechanism.

Could you kindly assist me in addressing this issue?

For your reference, I've attached the simulation configuration and a snippet of the node_set to this ticket. Your assistance would be greatly appreciated. Thank you in advance!

Python snippet:

import neuron
neuron.h.nrnunit_use_legacy(True)
neuron.load_mechanisms("./circuit_sonata/")
from bluecellulab import SSim

cfg_json = "/path-to-cfg/simulation_config.json"
sim = SSim(cfg_json,print_cellstate=True)

cell_id = 170923
pre_gid = ('S1nonbarrel_neurons', 170983)
sim.instantiate_gids([('S1nonbarrel_neurons',cell_id)], add_synapses=True,  pre_spike_trains={pre_gid: [1000.]}, intersect_pre_gids=[pre_gid])
t_stop = 2000.0
sim.run(t_stop)

Bug Trace:

---------------------------------------------------------------------------
BluepySnapError                           Traceback (most recent call last)
(ssim_bluecellulab_L5.ipynb) Cell 1 line 3
---> [35](L5TTPC_L5TTPC/138728-158705/ssim_bluecellulab_L5.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=34) sim.instantiate_gids([('S1nonbarrel_neurons',cell_id)], add_synapses=True,
     [36](ssim_bluecellulab_L5.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=35)                           pre_spike_trains={pre_gid: [1000.]},
     [37](ssim_bluecellulab_L5.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=36)                           intersect_pre_gids=[pre_gid])
     [38](ssim_bluecellulab_L5.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=37) t_stop = 2000.0
     [39](ssim_bluecellulab_L5.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=38) sim.run(t_stop)

File [---/BlueCelluLab/bluecellulab/ssim.py:255), in SSim.instantiate_gids(self, cells, add_replay, add_stimuli, add_synapses, add_minis, add_noise_stimuli, add_hyperpolarizing_stimuli, add_relativelinear_stimuli, add_pulse_stimuli, add_projections, intersect_pre_gids, interconnect_cells, pre_spike_trains, add_shotnoise_stimuli, add_ornstein_uhlenbeck_stimuli)
    253 self._add_cells(cell_ids)
    254 if add_synapses:
--> 255     self._add_synapses(
    256         pre_gids=pre_gids,
    257         add_minis=add_minis,
    258         projections=projections)
    259 if add_replay or interconnect_cells or pre_spike_trains:
    260     if add_replay and not add_synapses:

File [---/BlueCelluLab/bluecellulab/ssim.py:368), in SSim._add_synapses(self, pre_gids, add_minis, projections)
    366 """Instantiate all the synapses."""
    367 for cell_id in self.cells:
--> 368     self._add_cell_synapses(
    369         cell_id, pre_gids=pre_gids,
    370         add_minis=add_minis,
    371         projections=projections)

File [---/BlueCelluLab/bluecellulab/ssim.py:376), in SSim._add_cell_synapses(self, cell_id, pre_gids, add_minis, projections)
    373 def _add_cell_synapses(
    374     self, cell_id: CellId, pre_gids=None, add_minis=False, projections=None
    375 ) -> None:
--> 376     syn_descriptions = self.get_syn_descriptions(
    377         cell_id, projections=projections)
    379     if pre_gids is not None:
    380         if self.circuit_format == CircuitFormat.SONATA:

File [---/BlueCelluLab/bluecellulab/ssim.py:429), in SSim.get_syn_descriptions(self, cell_id, projections)
    427 syn_description_builder = bluecellulab.synapse.SynDescription()
    428 if self.circuit_access.config.is_glusynapse_used:
--> 429     return syn_description_builder.glusynapse_syn_description(
    430         self.circuit_access,
    431         cell_id,
    432         projections,
    433     )
    434 else:
    435     return syn_description_builder.gabaab_ampanmda_syn_description(
    436         self.circuit_access,
    437         cell_id,
    438         projections,
    439     )

File [---/BlueCelluLab/bluecellulab/synapse/synapse_params.py:54), in SynDescription.glusynapse_syn_description(self, circuit, gid, projections)
     50 glusynapse_only_properties = [
     51     "volume_CR", "rho0_GB", "Use_d_TM", "Use_p_TM", "gmax_d_AMPA",
     52     "gmax_p_AMPA", "theta_d", "theta_p"]
     53 all_properties = self.common_properties + glusynapse_only_properties
---> 54 return circuit.extract_synapses(gid, all_properties, projections)

File [---/BlueCelluLab/bluecellulab/circuit/circuit_access.py:664), in SonataCircuitAccess.extract_synapses(self, cell_id, properties, projections)
    662 print(snap_properties)
    663 print(afferent_edges)
--> 664 synapses: pd.DataFrame = edge.get(afferent_edges, snap_properties)
    665 column_names = list(synapses.columns)
    666 synapses.columns = pd.Index(properties_from_snap(column_names))

File [---/site-packages/bluepysnap/edges/edge_population.py:306), in EdgePopulation.get(self, edge_ids, properties)
    304 edge_ids = self.ids(edge_ids)
    305 selection = libsonata.Selection(edge_ids)
--> 306 return self._get(selection, properties)

File [---/site-packages/bluepysnap/edges/edge_population.py:195), in EdgePopulation._get(self, selection, properties)
    193         result = pd.DataFrame(index=edge_ids)
    194         for p in properties:
--> 195             result[p] = self._get_property(p, selection)
    196 else:
    197     if len(edge_ids) == 0:

File [---/site-packages/bluepysnap/edges/edge_population.py:176), in EdgePopulation._get_property(self, prop, selection)
    172     result = self._population.get_dynamics_attribute(
    173         prop.split(DYNAMICS_PREFIX)[1], selection
    174     )
    175 else:
--> 176     raise BluepySnapError(f"No such property: {prop}")
    177 return result

BluepySnapError: No such property: volume_CR

node_set snippet to add cells:

{
  "test_circuit": {
	  "node_id": [
	          170923,
            170982
	  ],
	  "population": "S1nonbarrel_neurons"
  },

Simulation_config.json

{
    "manifest": {
        "$CURRENT_DIR": "."
    },
    "run": {
        "dt": 0.025,
        "tstop": 2000.0,
        "random_seed": 12345
    },
    "conditions": {
        "extracellular_calcium": 2.0,
        "v_init": -80.0,
        "spike_location": "AIS",
        "mechanisms": {
            "ProbAMPANMDA_EMS": {
                "init_depleted": true,
                "minis_single_vesicle": true
            },
            "ProbGABAAB_EMS": {
                "init_depleted": true,
                "minis_single_vesicle": true
            },
            "GluSynapse": {
                "init_depleted": false,
                "minis_single_vesicle": true,
                "cao_CR": 2.0
            }
            }
    },
    "target_simulator": "CORENEURON",
    "network": "/path-to-cfg/circuit_config.json",
    "node_sets_file": "./node_sets.json",
    "node_set": "test_circuit",
    "output": {
        "output_dir": "./reporting",
        "spikes_file": "out.h5"
    },
    "reports": {
        "soma": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "compartment",
            "variable_name": "v",
            "unit": "mV",
            "dt": 1.0,
            "start_time": 0.0,
            "end_time": 122500.0
        },
        "rho": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "synapse",
            "sections": "all",
            "variable_name": "GluSynapse.rho_GB",
            "unit": "nd",
            "dt": 0.025,
            "start_time": 0.0,
            "end_time": 122500.0
        },
        "effcai_GB": {
            "cells": "hex_O1ExcitatoryPlastic",
            "type": "synapse",
            "sections": "all",
            "variable_name": "GluSynapse.effcai_GB",
            "unit": "mM",
            "dt": 0.025,
            "start_time": 0.0,
            "end_time": 122500.0
        }
    },
    "inputs": {
        "s1_syns_spikes": {
            "node_set": "hex_O1ExcitatoryPlastic",
            "input_type": "spikes",
            "delay": 0.0,
            "duration": 2000.0,
            "module": "synapse_replay",
            "spike_file": "./input_spikes/s1_syn_spikes.dat",
            "source": "hex_O1"
            }
    },
    "connection_overrides": [
        {
            "name": "plasticity",
            "source": "hex_O1Excitatory",
            "target": "hex_O1Excitatory",
            "modoverride": "GluSynapse",
            "weight": 1.0
        },
        {
            "name": "init",
            "source": "hex_O1",
            "target": "hex_O1",
	    "spont_minis": 0.0,
            "weight": 1.0
        },
        {
            "name": "VPM_init",
            "source": "proj_Thalamocortical_VPM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        },
        {
            "name": "POm_init",
            "source": "proj_Thalamocortical_POM_Source",
            "target": "hex_O1",
            "spont_minis": 0.0,
            "weight": 1.0
        },
        {
              "name": "Make_Use_1",
              "source": "hex_O1",
              "target": "hex_O1",
              "synapse_configure": "%s.Use = 1 %s.Use_GB = 1 %s.Use_p = 1 %s.gmax0_AMPA = gmax_p_AMPA %s.rho_GB = 1 %s.rho0_GB = 1 %s.gmax_AMPA = %s.gmax_p_AMPA"
        }
    ]
}

switch to pydantic2.0

There are breaking changes, the whole code base needs to be updated.

We need to make sure Extra.forbid still works.

@dataclass(frozen=True, config=dict(extra=Extra.forbid))

Use of ramp protocol for the calculation of steady state voltage

@AurelienJaquier and I are wondering why a ramp protocol with the same start and stop step levels is used here in the calculation of the steady state voltage.

cell.add_ramp(500, 5000, step_level, step_level)

Wouldn't the following achieve the same?

cell.add_step(500, 5000, step_level)

Do you know why ramp is preferred here @wvangeit ?

cell.add_ramp(500, 5000, step_level, step_level)

simplify RNGSettings logic for setting the seeds

Currently, Synapse objects are doing redundant work on checking and assigning RNGSettings values. See if the RNGSettings checking and assigning can be moved to the Simulator.

        if cell.rng_settings is None:
            self.rng_setting = bluecellulab.RNGSettings(
                mode='Compatibility',
                base_seed=base_seed)
        elif base_seed is not None:
            raise Exception('Synapse: base_seed and RNGSettings cant '
                            'be used together')
        else:
            self.rng_settings = cell.rng_settings

Address multiple neuron references pointing to same recording

self.soma(0.5)._ref_v': Vector[2551] is same as neuron.h.cADpyr_L2TPC_bluecellulab_0x7f77e58f8a10[0].soma[0](0.5)._ref_v

(Pdb) self.cell.recordings
{'self.soma(0.5)._ref_v': Vector[2551], 'neuron.h._ref_t': Vector[2552], 'neuron.h.cADpyr_L2TPC_bluecellulab_0x7f77e58f8a10[0].soma[0](0.5)._ref_v': Vector[2553]}

Components to be affected: core.py test_core.py

Restrict the use of add_recordings instead use add_voltage_recording that takes the NEURON object as argument instead of recording str.

Function cell.get_psection not working

When I load a cell and then I want to get the psection from the cell filtering by secname I get an error:

Screenshot 2024-02-08 at 14 49 08

Getting the psection from the section works fine

Screenshot 2024-02-08 at 14 50 47

drop py37 support

Its end-of-life is approaching. Libsonata dropped building the binaries for it, bluepysnap also dropped it.

Add missing unit tests for tools functions

The following functions are lacking the unit tests

  • search_threshold_current
  • detect_threshold_current
  • calculate_SS_voltage_replay
  • calculate_SS_voltage_replay_subprocess
  • search_hyp_current_replay
  • search_hyp_current_replay_gidlist

Isolate NEURON Simulations in Separate Processes

I've noticed that the tools module uses multiprocessing.pool to run NEURON. In other projects, this combination caused issues. When one simulation finishes, another gets started in the same process. This can give wrong results and may cause memory leaks if NEURON objects from the last simulation aren't fully removed.

Each independent simulation task should spawn a new process and that process should be terminated once the task is over.

class NestedPool(multiprocessing.pool.Pool):

during import, some neuron function returns 1 check if it is something important

The result 1 gets printed to the console. Although it's harmless, handling it can be beneficial.

Assuming that in this function's context, 1 signifies success and 0 indicates failure, it would be beneficial to handle the failure scenario within Python. This adjustment would spare users from deciphering potentially confusing error messages coming from the C/C++ implementation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.