Skip to content

Commit

Permalink
Merge pull request #40 from PKU-NIP-Lab/develop
Browse files Browse the repository at this point in the history
V1.0.0rc1
  • Loading branch information
chaoming0625 committed Apr 11, 2021
2 parents 824299c + fe0f0a8 commit 7541a03
Show file tree
Hide file tree
Showing 100 changed files with 6,918 additions and 4,071 deletions.
101 changes: 27 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@



**Note**: *BrainPy is a project under development. More features are coming soon. Contributions are welcome.*
# Why to use BrainPy

``BrainPy`` is an integrative framework for computational neuroscience and brain-inspired computation. Three core functions are provided in BrainPy:

- *General numerical solvers* for ODEs and SDEs (support for DDEs and FDEs will come soon).
- *Neurodynamics simulation tools* for brain objects, such like neurons, synapses and networks (support for soma and dendrites will come soon).
- *Neurodynamics analysis tools* for differential equations, including phase plane analysis and bifurcation analysis (support for continuation analysis and sensitive analysis will come soon).

## Why to use BrainPy

``BrainPy`` is an integrative framework for computational neuroscience and brain-inspired computation. Three core functions are provided in `BrainPy`:

- *General numerical solvers* for ODEs and SDEs (future will support DDEs and FDEs).
- *Neurodynamics simulation tools* for brain objects, such like neurons, synapses and networks (future will support soma and dendrites).
- *Neurodynamics analysis tools* for differential equations, including phase plane analysis and bifurcation analysis (future will support continuation analysis and sensitive analysis).

Moreover, `BrainPy` can effectively satisfy your basic requirements: 1. *Easy to learn and use*, because it is only based on Python language and has little dependency requirements; 2. *Highly flexible and transparent*, because it endows the users with the fully data/logic flow control; 3. *Simulation can be guided with the analysis*, because the same code in BrainPy can not only be used for simulation, but also for dynamics analysis; 4. *Efficient running speed*, because BrainPy is compatitable with the latest JIT compilers (or any other computing backend you prefer).

Moreover, `BrainPy` is designed to effectively satisfy your basic requirements:

- *Easy to learn and use*, because BrainPy is only based on Python language and has little dependency requirements;
- *Highly flexible and transparent*, because BrainPy endows the users with the fully data/logic flow control;
- *Simulation can be guided with the analysis*, because the same code in BrainPy can not only be used for simulation, but also for dynamics analysis;
- *Efficient running speed*, because BrainPy is compatible with the latest JIT compilers or any other accelerating framework you prefer (below we list the speed comparison based on Numba JIT).


![Speed Comparison](docs/images/speed.png)

`BrainPy` is a backend-independent neural simulator. Users can define models with any backend they prefer. Intrinsically, BrainPy supports the array/tensor-oriented backends such like [NumPy](https://numpy.org/), [PyTorch](https://pytorch.org/), and [TensorFlow](https://www.tensorflow.org/), it also supports the JIT compilers such as [Numba](https://numba.pydata.org/) on CPU or CUDA devices. Extending BrainPy to support other backend frameworks you prefer is very easy. The details please see documents coming soon.



## Installation
# Installation

Install ``BrainPy`` by using ``pip``:

```bash
> pip install brainpy-simulator>=1.0.0b1
> pip install brainpy-simulator>=1.0.0rc1
```

Install ``BrainPy`` by using ``conda``:
Expand All @@ -53,12 +54,18 @@ Install ``BrainPy`` from source:
``BrainPy`` is based on Python (>=3.7), and the following packages are required to be installed to use ``BrainPy``:

- NumPy >= 1.13
- Matplotlib >= 3.2
- Matplotlib >= 3.3



# Let's start

## Neurodynamics simulation
- **Website (including documentations):** https://brainpy.readthedocs.io/
- **Source code:** https://github.com/PKU-NIP-Lab/BrainPy or https://git.openi.org.cn/OpenI/BrainPy
- **Bug reports:** https://github.com/PKU-NIP-Lab/BrainPy/issues or Email to adaduo@outlook.com
- **Examples from papers**: https://brainmodels.readthedocs.io/en/latest/from_papers.html

Here list several simple examples for neurodynamics simulation and analysis. Comprehensive examples and tutorials please see [BrainModels](https://brainmodels.readthedocs.io).

<table border="0">
<tr>
Expand All @@ -69,11 +76,7 @@ Install ``BrainPy`` from source:
</td>
<td border="0" valign="top">
<h3><a href="https://github.com/PKU-NIP-Lab/BrainModels/blob/main/brainmodels/tensor_backend/neurons/HodgkinHuxley_model.py">HH Neuron Model</a></h3>
<p>The Hodgkin–Huxley model, or conductance-based model,
is a mathematical model that describes how action potentials
in neurons are initiated and propagated. It is a set of nonlinear
differential equations that approximates the electrical characteristics
of excitable cells such as neurons and cardiac myocytes.</p>
<p>The Hodgkin–Huxley neuron model.</p>
</td>
</tr>
<tr>
Expand All @@ -84,7 +87,7 @@ Install ``BrainPy`` from source:
</td>
<td border="0" valign="top">
<h3><a href="https://github.com/PKU-NIP-Lab/BrainModels/blob/main/brainmodels/tensor_backend/synapses/AMPA_synapse.py">AMPA Synapse Model</a></h3>
<p>AMPA synapse model.</p>
<p>The AMPA synapse model.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -112,7 +115,7 @@ Install ``BrainPy`` from source:
<p>Implementation of the paper: <i>Van Vreeswijk, Carl, and Haim Sompolinsky.
“Chaos in neuronal networks with balanced excitatory and inhibitory activity.”
Science 274.5293 (1996): 1724-1726.</i></p>
</td>
</td>
</tr>
<tr>
<td border="0" width="30%">
Expand All @@ -128,21 +131,6 @@ Install ``BrainPy`` from source:
</p>
</td>
</tr>
</table>


More neuron examples please see [BrainPy-Models/neurons](https://github.com/PKU-NIP-Lab/BrainModels/tree/main/brainmodels/tensor_backend/neurons);

More synapse examples please see [BrainPy-Models/synapses](https://github.com/PKU-NIP-Lab/BrainModels/tree/main/brainmodels/tensor_backend/synapses);

More network examples please see [BrainPy-Models/from_papers](https://brainmodels.readthedocs.io/en/latest/from_papers.html).




## Neurodynamics analysis

<table border="0">
<tr>
<td border="0" width="30%">
<a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/NaK_model_analysis.html">
Expand All @@ -155,33 +143,6 @@ More network examples please see [BrainPy-Models/from_papers](https://brainmodel
"input" is 50., and "Vn_half" is -45..</p>
</td>
</tr>
<tr>
<td border="0" width="30%">
<a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/NaK_model_analysis.html#Codimension-1-bifurcation-analysis">
<img src="docs/images/NaK_model_codimension1.png">
</a>
</td>
<td border="0" valign="top">
<h3><a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/NaK_model_analysis.html#Codimension-1-bifurcation-analysis">
Codimension 1 Bifurcation Analysis (1)</a></h3>
<p>Codimension 1 bifurcation analysis of the I<sub>Na,p+</sub>-I<sub>K</sub> model,
in which "input" is varied in [0., 50.].</p>
</td>
</tr>
<tr>
<td border="0" width="30%">
<a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/NaK_model_analysis.html#Codimension-2-bifurcation-analysis">
<img src="docs/images/NaK_model_codimension2.png">
</a>
</td>
<td border="0" valign="top">
<h3><a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/NaK_model_analysis.html#Codimension-2-bifurcation-analysis">
Codimension 2 Bifurcation Analysis (1)</a></h3>
<p>Codimension 2 bifurcation analysis of a two-variable neuron model:
the I<sub>Na,p+</sub>-I<sub>K</sub> model, in which "input" is varied
in [0., 50.], and "Vn_half" is varied in [-50, -40].</p>
</td>
</tr>
<tr>
<td border="0" width="30%">
<a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/FitzHugh_Nagumo_analysis.html">
Expand All @@ -190,7 +151,7 @@ More network examples please see [BrainPy-Models/from_papers](https://brainmodel
</td>
<td border="0" valign="top">
<h3><a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/FitzHugh_Nagumo_analysis.html">
Codimension 1 Bifurcation Analysis (2)</a></h3>
Codimension 1 Bifurcation Analysis</a></h3>
<p>Codimension 1 bifurcation analysis of FitzHugh Nagumo model, in which
"a" is equal to 0.7, and "Iext" is varied in [0., 1.].</p>
</td>
Expand All @@ -203,19 +164,11 @@ More network examples please see [BrainPy-Models/from_papers](https://brainmodel
</td>
<td border="0" valign="top">
<h3><a href="https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis/FitzHugh_Nagumo_analysis.html#Codimension-2-bifurcation-analysis">
Codimension 2 Bifurcation Analysis (2)</a></h3>
Codimension 2 Bifurcation Analysis</a></h3>
<p>Codimension 2 bifurcation analysis of FitzHugh Nagumo model, in which "a"
is varied in [0.5, 1.0], and "Iext" is varied in [0., 1.].</p>
</td>
</tr>
</table>



More examples please see [BrainPy-Models/dynamics_analysis](https://brainmodels.readthedocs.io/en/latest/tutorials/dynamics_analysis.html).






9 changes: 6 additions & 3 deletions brainpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-

__version__ = "1.0.0-beta"
__version__ = "1.0.0rc1"

# "backend" module
from . import backend
from .backend import ops
from .backend import drivers

# "analysis" module
from . import analysis
Expand All @@ -12,7 +14,7 @@
from . import simulation
from .simulation import connectivity as connect
from .simulation.dynamic_system import *
from .simulation.brain_objects import *
from .simulation.brainobjects import *
from .simulation.utils import size2len

# "integrators" module
Expand All @@ -26,7 +28,8 @@
from . import visualization as visualize

# other modules
from . import tools
from . import errors
from . import inputs
from . import measure
from . import running
from . import tools
16 changes: 3 additions & 13 deletions brainpy/analysis/solver.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-

from collections import namedtuple
from importlib import import_module

import numpy as np

try:
numba = import_module('numba')
except ModuleNotFoundError:
numba = None
from brainpy import tools

__all__ = [
'brentq',
Expand All @@ -22,6 +18,7 @@
results = namedtuple('results', ['root', 'function_calls', 'iterations', 'converged'])


@tools.numba_jit
def brentq(f, a, b, args=(), xtol=2e-14, maxiter=200, rtol=4 * np.finfo(float).eps):
"""
Find a root of a function in a bracketing interval using Brent's method
Expand Down Expand Up @@ -153,10 +150,7 @@ def brentq(f, a, b, args=(), xtol=2e-14, maxiter=200, rtol=4 * np.finfo(float).e
return root, funcalls, itr


if numba is not None:
brentq = numba.njit(brentq)


@tools.numba_jit
def find_root_of_1d(f, f_points, args=(), tol=1e-8):
"""Find the roots of the given function by numerical methods.
Expand Down Expand Up @@ -203,10 +197,6 @@ def find_root_of_1d(f, f_points, args=(), tol=1e-8):
return roots


if numba is not None:
find_root_of_1d = numba.njit(find_root_of_1d)


def find_root_of_2d(f, x_bound, y_bound, args=(), shgo_args=None,
fl_tol=1e-6, xl_tol=1e-4, verbose=False):
"""Find the root of a two dimensional function.
Expand Down

0 comments on commit 7541a03

Please sign in to comment.