Skip to content

Commit

Permalink
Merge pull request #393 from lukasgd/arbor_integration
Browse files Browse the repository at this point in the history
Arbor cable cell exporter and backend
  • Loading branch information
wvangeit authored Jan 17, 2023
2 parents 38ba649 + 70fddf8 commit af06928
Show file tree
Hide file tree
Showing 76 changed files with 51,402 additions and 258 deletions.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
include versioneer.py
include bluepyopt/_version.py
include bluepyopt/ephys/static/arbor_mechanisms.json
include bluepyopt/ephys/templates/cell_template.jinja2
include bluepyopt/ephys/templates/acc/_json_template.jinja2
include bluepyopt/ephys/templates/acc/decor_acc_template.jinja2
include bluepyopt/ephys/templates/acc/label_dict_acc_template.jinja2

include.txt
include AUTHORS.txt
Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ l5pc_nbconvert: jupyter
cd examples/l5pc && \
jupyter nbconvert --to python L5PC.ipynb && \
sed '/get_ipython/d;/plt\./d;/plot_responses/d;/import matplotlib/d;/neurom/d;/axes/d;/fig/d;/for index/d' L5PC.py >L5PC.tmp && \
mv L5PC.tmp L5PC.py
mv L5PC.tmp L5PC.py && \
python l5pc_validate_neuron_arbor_pm.py --prepare-only --regions somatic --param-values ../../bluepyopt/tests/testdata/l5pc_validate_neuron_arbor/param_values.json && \
jupyter nbconvert --to python l5pc_validate_neuron_arbor_somatic.ipynb && \
sed '/get_ipython/d;/plt\./d;/import matplotlib/d;/from IPython.display/d;/multiprocessing/d;s/pool.map/map/g;s/# test_l5pc: insert //g;/# test_l5pc: skip/d' l5pc_validate_neuron_arbor_somatic.py >l5pc_validate_neuron_arbor_somatic.tmp && \
mv l5pc_validate_neuron_arbor_somatic.tmp l5pc_validate_neuron_arbor_somatic.py
l5pc_nrnivmodl:
cd examples/l5pc && nrnivmodl mechanisms
l5pc_zip:
Expand All @@ -28,7 +32,11 @@ sc_prepare: jupyter
cd examples/simplecell && \
jupyter nbconvert --to python simplecell.ipynb && \
sed '/get_ipython/d;/plt\./d;/plot_responses/d;/import matplotlib/d' simplecell.py >simplecell.tmp && \
mv simplecell.tmp simplecell.py
mv simplecell.tmp simplecell.py && \
jupyter nbconvert --to python simplecell_arbor.ipynb && \
sed '/get_ipython/d;/plt\./d;/plot_responses/d;/import matplotlib/d' simplecell_arbor.py >simplecell_arbor.tmp && \
mv simplecell_arbor.tmp simplecell_arbor.py

meta_prepare: jupyter
cd examples/metaparameters && \
jupyter nbconvert --to python metaparameters.ipynb && \
Expand All @@ -41,6 +49,8 @@ coverage_test: test
jupyter:
pip install jupyter
pip install ipython --upgrade
pip install papermill
pip install scipy
install_test_requirements:
pip install -q $(TEST_REQUIREMENTS) --upgrade
test: clean unit functional
Expand All @@ -65,6 +75,8 @@ clean:
rm -rf bluepyopt/tests/coverage.xml
rm -rf bluepyopt/tests/coverage_html
rm -rf examples/l5pc/L5PC.py
rm -rf examples/l5pc/l5pc_validate_neuron_arbor_somatic.ipynb
rm -rf examples/l5pc/l5pc_validate_neuron_arbor_somatic.py
rm -rf examples/l5pc/x86_64
rm -rf examples/stochkv/x86_64
rm -rf x86_64
Expand Down
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ We are providing support using a chat channel on `Gitter <https://gitter.im/Blue

News
====
- 2023/01: BluePyOpt now supports the Arbor simulator.
- 2022/12: Support for LFPy models merged into master. Examples and preprint: https://github.com/alejoe91/multimodalfitting, https://www.biorxiv.org/content/10.1101/2022.08.03.502468v1.full
- 2022/12: BluePyOpt now has the ability to write out NeuroML files: https://github.com/BlueBrain/BluePyOpt/tree/master/bluepyopt/neuroml
- 2021/08/30: BluePyOpt dropped Python 2.7 support.
Expand Down Expand Up @@ -141,6 +142,11 @@ And then bluepyopt itself:
pip install bluepyopt
Support for simulators other than NEURON is optional and not installed by default. If you want to use [Arbor](https://arbor-sim.org/) to run your models, use the following line instead to install bluepyopt.

.. code-block:: bash
pip install bluepyopt[arbor]
Cloud infrastructure
====================
Expand All @@ -158,7 +164,8 @@ Single compartmental model
An iPython notebook with an introductory optimisation of a one compartmental
model with 2 HH channels can be found at

https://github.com/BlueBrain/BluePyOpt/blob/master/examples/simplecell/simplecell.ipynb
https://github.com/BlueBrain/BluePyOpt/blob/master/examples/simplecell/simplecell.ipynb (NEURON)
https://github.com/BlueBrain/BluePyOpt/blob/master/examples/simplecell/simplecell_arbor.ipynb (Arbor)


|landscape_example|
Expand All @@ -173,7 +180,8 @@ Scripts for a more complex neocortical L5PC are in

With a notebook:

https://github.com/BlueBrain/BluePyOpt/blob/master/examples/l5pc/L5PC.ipynb
https://github.com/BlueBrain/BluePyOpt/blob/master/examples/l5pc/L5PC.ipynb (NEURON)
https://github.com/BlueBrain/BluePyOpt/blob/master/examples/l5pc/L5PC_arbor.ipynb (Arbor)

Thalamocortical Cells
---------------------
Expand Down
2 changes: 1 addition & 1 deletion bluepyopt/deapext/optimisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def setup_deap(self):
# import deap_efel_eval1
self.toolbox.register(
"evaluate",
self.evaluator.set_neuron_variables_and_evaluate_with_lists
self.evaluator.init_simulator_and_evaluate_with_lists
)

# Register the mate operator
Expand Down
2 changes: 1 addition & 1 deletion bluepyopt/deapext/optimisationsCMA.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def setup_deap(self):
# Register the evaluation function for the individuals
self.toolbox.register(
"evaluate",
self.evaluator.set_neuron_variables_and_evaluate_with_lists
self.evaluator.init_simulator_and_evaluate_with_lists
)

import copyreg
Expand Down
57 changes: 57 additions & 0 deletions bluepyopt/ephys/acc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''Dependencies of Arbor simulator backend'''

try:
import arbor
except ImportError as e:
class arbor:
def __getattribute__(self, _):
raise ImportError("Exporting cell models to ACC/JSON, loading"
" them or optimizing them with the Arbor"
" simulator requires missing dependency arbor."
" To install BluePyOpt with arbor,"
" run 'pip install bluepyopt[arbor]'.")


class ArbLabel:
"""Arbor label"""

def __init__(self, type, name, s_expr):
if type not in ['locset', 'region', 'iexpr']:
raise ValueError('Invalid Arbor label type %s' % type)
self._type = type
self._name = name
self._s_expr = s_expr

@property
def defn(self):
"""Label definition for label-dict"""
return '(%s-def "%s" %s)' % (self._type, self._name, self._s_expr)

@property
def ref(self):
"""Reference to label defined in label-dict"""
return '(%s "%s")' % (self._type, self._name)

@property
def name(self):
"""Name of the label"""
return self._name

@property
def loc(self):
"""S-expression defining the location of the label"""
return self._s_expr

def __eq__(self, other):
if other is None:
return False
elif not isinstance(other, ArbLabel):
raise TypeError('%s is not an ArbLabel' % str(other))
else:
return self._s_expr == other._s_expr

def __hash__(self):
return hash(self._s_expr)

def __repr__(self):
return self.defn
Loading

0 comments on commit af06928

Please sign in to comment.