Skip to content

Commit 84511d4

Browse files
committed
Merge branch 'master' of https://github.com/brainpy/BrainPy
2 parents a1e0e15 + 532dafb commit 84511d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1368
-194
lines changed

.github/workflows/CI.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ jobs:
3939
flake8 brainpy/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4040
- name: Test with pytest
4141
run: |
42-
cd examples
43-
pytest ../brainpy/
42+
cd brainpy
43+
pytest _src/
44+
4445
4546
# test_linux_py37:
4647
# runs-on: ubuntu-latest
@@ -75,6 +76,7 @@ jobs:
7576
# cd examples
7677
# pytest ../brainpy/
7778
#
79+
7880
test_macos:
7981
runs-on: macos-latest
8082
strategy:
@@ -103,8 +105,8 @@ jobs:
103105
flake8 brainpy/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
104106
- name: Test with pytest
105107
run: |
106-
cd examples
107-
pytest ../brainpy/
108+
cd brainpy
109+
pytest _src/
108110
109111
# test_macos_py37:
110112
# runs-on: macos-latest
@@ -140,6 +142,7 @@ jobs:
140142
# pytest ../brainpy/
141143
#
142144

145+
143146
test_windows:
144147
runs-on: windows-latest
145148
strategy:
@@ -172,8 +175,9 @@ jobs:
172175
flake8 brainpy/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
173176
- name: Test with pytest
174177
run: |
175-
cd examples
176-
pytest ../brainpy/
178+
cd brainpy
179+
pytest _src/
180+
177181
178182
# test_windows_py37:
179183
# runs-on: windows-latest
@@ -208,4 +212,4 @@ jobs:
208212
# - name: Test with pytest
209213
# run: |
210214
# cd examples
211-
# pytest ../brainpy/
215+
# pytest ../brainpy/

.github/workflows/docs.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Make documentation
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
13+
jobs:
14+
make_docs:
15+
runs-on:
16+
group: Default
17+
labels: self-hosted
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- uses: conda-incubator/setup-miniconda@v2
22+
with:
23+
auto-update-conda: true
24+
python-version: "3.10"
25+
miniconda-version: "latest"
26+
- name: Conda info
27+
shell: bash -el {0}
28+
run: conda info
29+
- name: Install dependencies
30+
shell: bash -el {0}
31+
run: |
32+
conda activate
33+
python -m pip install --upgrade pip
34+
python -m pip install flake8 pytest
35+
if [ -f requirements-doc.txt ]; then pip install -r requirements-doc.txt; fi
36+
pip uninstall brainpy -y
37+
python setup.py install
38+
- name: Make docs
39+
shell: bash -el {0}
40+
run: |
41+
conda activate
42+
cd ~/brainpy_docs/docs
43+
make html

brainpy/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@
179179

180180
dyn.__deprecations = {
181181
# module
182-
'channels': ('brainpy.dyn.channels', 'brainpy.channels', channels),
183-
'neurons': ('brainpy.dyn.neurons', 'brainpy.neurons', neurons),
182+
# 'channels': ('brainpy.dyn.channels', 'brainpy.channels', channels),
183+
# 'neurons': ('brainpy.dyn.neurons', 'brainpy.neurons', neurons),
184184
'rates': ('brainpy.dyn.rates', 'brainpy.rates', rates),
185-
'synapses': ('brainpy.dyn.synapses', 'brainpy.synapses', synapses),
185+
# 'synapses': ('brainpy.dyn.synapses', 'brainpy.synapses', synapses),
186186
'synouts': ('brainpy.dyn.synouts', 'brainpy.synapses', synouts),
187187
'synplast': ('brainpy.dyn.synplast', 'brainpy.synapses', synplast),
188188

@@ -193,7 +193,7 @@
193193
'Network': ('brainpy.dyn.Network', 'brainpy.Network', Network),
194194
'NeuGroup': ('brainpy.dyn.NeuGroup', 'brainpy.NeuGroup', NeuGroup),
195195
'SynConn': ('brainpy.dyn.SynConn', 'brainpy.SynConn', SynConn),
196-
'SynOut': ('brainpy.dyn.SynOut', 'brainpy.SynOut', SynOut),
196+
# 'SynOut': ('brainpy.dyn.SynOut', 'brainpy.SynOut', SynOut),
197197
'SynLTP': ('brainpy.dyn.SynLTP', 'brainpy.SynLTP', SynLTP),
198198
'SynSTP': ('brainpy.dyn.SynSTP', 'brainpy.SynSTP', SynSTP),
199199
'TwoEndConn': ('brainpy.dyn.TwoEndConn', 'brainpy.TwoEndConn', TwoEndConn),
@@ -231,7 +231,7 @@
231231
'DualExpCOBA': ('brainpy.dyn.DualExpCOBA', 'brainpy.synapses.DualExponential', compat.DualExpCOBA),
232232
'AlphaCUBA': ('brainpy.dyn.AlphaCUBA', 'brainpy.synapses.Alpha', compat.AlphaCUBA),
233233
'AlphaCOBA': ('brainpy.dyn.AlphaCOBA', 'brainpy.synapses.Alpha', compat.AlphaCOBA),
234-
'NMDA': ('brainpy.dyn.NMDA', 'brainpy.synapses.NMDA', compat.NMDA),
234+
# 'NMDA': ('brainpy.dyn.NMDA', 'brainpy.synapses.NMDA', compat.NMDA),
235235
}
236236
dyn.__getattr__ = deprecation_getattr2('brainpy.dyn', dyn.__deprecations)
237237

brainpy/_src/channels/IH.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ def dP1(self, P1, t, C_Ca):
220220
return self.k1 * C_Ca ** 4 * (1 - P1) - self.k2 * P1
221221

222222
def update(self, tdi, V, C_Ca, E_Ca):
223-
self.O.value = self.integral(self.O.value, self.OL.value, self.P1.value,
224-
tdi['t'], V=V, C_Ca=C_Ca, dt=tdi['dt'])
223+
self.O.value, self.OL.value, self.P1.value = self.integral(self.O.value, self.OL.value, self.P1.value,
224+
tdi['t'], V=V, C_Ca=C_Ca, dt=tdi['dt'])
225225

226226
def current(self, V, C_Ca, E_Ca):
227227
return self.g_max * (self.O + self.g_inc * self.OL) * (self.E - V)

brainpy/_src/channels/K.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,17 +812,17 @@ def __init__(
812812
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
813813

814814
def f_p_inf(self, V):
815-
raise 1. / (1. + bm.exp(-(V - self.V_sh + 43.) / 17.))
815+
return 1. / (1. + bm.exp(-(V - self.V_sh + 43.) / 17.))
816816

817817
def f_p_tau(self, V):
818818
return 1. / (bm.exp((V - self.V_sh - 81.) / 25.6) +
819819
bm.exp(-(V - self.V_sh + 132) / 18.)) + 9.9
820820

821821
def f_q_inf(self, V):
822-
raise 1. / (1. + bm.exp((V - self.V_sh + 58.) / 10.6))
822+
return 1. / (1. + bm.exp((V - self.V_sh + 58.) / 10.6))
823823

824824
def f_q_tau(self, V):
825-
raise 1. / (bm.exp((V - self.V_sh - 1329.) / 200.) +
825+
return 1. / (bm.exp((V - self.V_sh - 1329.) / 200.) +
826826
bm.exp(-(V - self.V_sh + 130.) / 7.1))
827827

828828

@@ -903,17 +903,17 @@ def __init__(
903903
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
904904

905905
def f_p_inf(self, V):
906-
raise 1. / (1. + bm.exp(-(V - self.V_sh + 43.) / 17.))
906+
return 1. / (1. + bm.exp(-(V - self.V_sh + 43.) / 17.))
907907

908908
def f_p_tau(self, V):
909909
return 1. / (bm.exp((V - self.V_sh - 81.) / 25.6) +
910910
bm.exp(-(V - self.V_sh + 132) / 18.)) + 9.9
911911

912912
def f_q_inf(self, V):
913-
raise 1. / (1. + bm.exp((V - self.V_sh + 58.) / 10.6))
913+
return 1. / (1. + bm.exp((V - self.V_sh + 58.) / 10.6))
914914

915915
def f_q_tau(self, V):
916-
raise bm.where(V < -70 + self.V_sh,
916+
return bm.where(V < -70 + self.V_sh,
917917
1. / (bm.exp((V - self.V_sh - 1329.) / 200.) +
918918
bm.exp(-(V - self.V_sh + 130.) / 7.1)),
919919
8.9)
@@ -1010,8 +1010,8 @@ def reset_state(self, V, batch_size=None):
10101010
assert self.p.shape[0] == batch_size
10111011

10121012
def f_p_inf(self, V):
1013-
raise 1. / (1. + bm.exp(-(V - self.V_sh + 35.) / 10.))
1013+
return 1. / (1. + bm.exp(-(V - self.V_sh + 35.) / 10.))
10141014

10151015
def f_p_tau(self, V):
10161016
temp = V - self.V_sh + 35.
1017-
raise self.tau_max / (3.3 * bm.exp(temp / 20.) + bm.exp(-temp / 20.))
1017+
return self.tau_max / (3.3 * bm.exp(temp / 20.) + bm.exp(-temp / 20.))
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
import brainpy as bp
5+
import brainpy.math as bm
6+
from absl.testing import parameterized
7+
from brainpy._src.channels import Ca
8+
9+
class Test_Ca(parameterized.TestCase):
10+
def test_Ca(self):
11+
bm.random.seed(1234)
12+
class Neuron(bp.CondNeuGroup):
13+
def __init__(self, size):
14+
super(Neuron, self).__init__(size)
15+
self.Ca1 = Ca.CalciumFixed(size)
16+
self.Ca2 = Ca.CalciumDetailed(size)
17+
self.Ca3 = Ca.CalciumFirstOrder(size)
18+
19+
model = Neuron(1)
20+
runner = bp.DSRunner(model,
21+
monitors=['V', 'Ca2.C', 'Ca3.C'],
22+
progress_bar=False)
23+
runner.run(10.)
24+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
25+
self.assertTupleEqual(runner.mon['Ca2.C'].shape, (100, 1))
26+
self.assertTupleEqual(runner.mon['Ca3.C'].shape, (100, 1))
27+
28+
def test_ICaN_IS2008(self):
29+
bm.random.seed(1234)
30+
class Neuron(bp.CondNeuGroup):
31+
def __init__(self, size):
32+
super(Neuron, self).__init__(size)
33+
self.Ca = Ca.CalciumDetailed(size,
34+
ICa=Ca.ICaN_IS2008(size),
35+
)
36+
37+
model = Neuron(1)
38+
runner = bp.DSRunner(model,
39+
monitors=['V', 'Ca.ICa.p'],
40+
progress_bar=False)
41+
runner.run(10.)
42+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
43+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
44+
45+
def test_ICaT_HM1992(self):
46+
bm.random.seed(1234)
47+
class Neuron(bp.CondNeuGroup):
48+
def __init__(self, size):
49+
super(Neuron, self).__init__(size)
50+
self.Ca = Ca.CalciumDetailed(size,
51+
ICa=Ca.ICaT_HM1992(size),
52+
)
53+
54+
model = Neuron(1)
55+
runner = bp.DSRunner(model,
56+
monitors=['V',
57+
'Ca.ICa.p',
58+
],
59+
progress_bar=False)
60+
runner.run(10.)
61+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
62+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
63+
64+
def test_ICaT_HP1992(self):
65+
bm.random.seed(1234)
66+
class Neuron(bp.CondNeuGroup):
67+
def __init__(self, size):
68+
super(Neuron, self).__init__(size)
69+
self.Ca = Ca.CalciumDetailed(size,
70+
ICa=Ca.ICaT_HP1992(size),
71+
)
72+
73+
model = Neuron(1)
74+
runner = bp.DSRunner(model,
75+
monitors=['V',
76+
'Ca.ICa.p',
77+
],
78+
progress_bar=False)
79+
runner.run(10.)
80+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
81+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
82+
83+
def test_ICaHT_HM1992(self):
84+
bm.random.seed(1234)
85+
class Neuron(bp.CondNeuGroup):
86+
def __init__(self, size):
87+
super(Neuron, self).__init__(size)
88+
self.Ca = Ca.CalciumDetailed(size,
89+
ICa=Ca.ICaHT_HM1992(size),
90+
)
91+
92+
model = Neuron(1)
93+
runner = bp.DSRunner(model,
94+
monitors=['V',
95+
'Ca.ICa.p',
96+
],
97+
progress_bar=False)
98+
runner.run(10.)
99+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
100+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
101+
102+
def test_ICaHT_Re1993(self):
103+
bm.random.seed(1234)
104+
class Neuron(bp.CondNeuGroup):
105+
def __init__(self, size):
106+
super(Neuron, self).__init__(size)
107+
self.Ca = Ca.CalciumDetailed(size,
108+
ICa=Ca.ICaHT_Re1993(size),
109+
)
110+
111+
model = Neuron(1)
112+
runner = bp.DSRunner(model,
113+
monitors=['V',
114+
'Ca.ICa.p',
115+
],
116+
progress_bar=False)
117+
runner.run(10.)
118+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
119+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
120+
121+
def test_ICaL_IS2008(self):
122+
bm.random.seed(1234)
123+
class Neuron(bp.CondNeuGroup):
124+
def __init__(self, size):
125+
super(Neuron, self).__init__(size)
126+
self.Ca = Ca.CalciumDetailed(size,
127+
ICa=Ca.ICaL_IS2008(size),
128+
)
129+
130+
model = Neuron(1)
131+
runner = bp.DSRunner(model,
132+
monitors=['V',
133+
'Ca.ICa.p',
134+
],
135+
progress_bar=False)
136+
runner.run(10.)
137+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
138+
self.assertTupleEqual(runner.mon['Ca.ICa.p'].shape, (100, 1))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
import brainpy as bp
5+
import brainpy.math as bm
6+
from absl.testing import parameterized
7+
from brainpy._src.channels import IH, Ca
8+
9+
10+
class Test_IH(parameterized.TestCase):
11+
bm.random.seed(1234)
12+
def test_IH(self):
13+
class Neuron(bp.CondNeuGroup):
14+
def __init__(self, size):
15+
super(Neuron, self).__init__(size)
16+
self.IH = IH.Ih_HM1992(size)
17+
self.Ca = Ca.CalciumDetailed(size, IH=IH.Ih_De1996(size))
18+
19+
model = Neuron(1)
20+
runner = bp.DSRunner(model,
21+
monitors=['V', 'IH.p', 'Ca.IH.O'],
22+
progress_bar=False)
23+
runner.run(10.)
24+
self.assertTupleEqual(runner.mon['V'].shape, (100, 1))
25+
self.assertTupleEqual(runner.mon['IH.p'].shape, (100, 1))
26+
self.assertTupleEqual(runner.mon['Ca.IH.O'].shape, (100, 1))

0 commit comments

Comments
 (0)