Skip to content

Commit 09c55da

Browse files
authored
Refactor V2 tests to tests_version2 and add V2/V3 documentation READMEs (#788)
* fix(docs): update references to tests and paths for version 2 * feat(docs): add documentation and examples for BrainPy 3.x * fix(deps): update brainstate version to 0.2.0 in requirements docs: update documentation links for BrainPy 3.0 and 2.0 * refactor: simplify dtype assignments and remove unused tests * chore: update changelog for BrainPy 3.0.0 release and improve context handling in currents.py
1 parent aef571f commit 09c55da

40 files changed

+634
-116
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ See CONTRIBUTING.md for guidelines.
4545
## Testing
4646

4747
**How has this been tested?**
48-
<!-- Describe the tests you ran to verify your changes -->
48+
<!-- Describe the tests_version2 you ran to verify your changes -->
4949

5050
```python
5151
# Example test code or commands used

.github/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
# Tests
2020
tests:
2121
- changed-files:
22-
- any-glob-to-any-file: ['tests/**/*', '**/*test*.py']
22+
- any-glob-to-any-file: ['tests_version2/**/*', '**/*test*.py']
2323

2424
# Examples
2525
examples:

.github/workflows/CI-models.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
pip install -e .
3838
- name: Test with pytest
3939
run: |
40-
pytest tests/
40+
pytest tests_version2/
4141
4242
test_macos:
4343
runs-on: macos-latest
@@ -59,7 +59,7 @@ jobs:
5959
pip install -e .
6060
- name: Test with pytest
6161
run: |
62-
pytest tests/
62+
pytest tests_version2/
6363
6464
test_windows:
6565
runs-on: windows-latest
@@ -81,4 +81,4 @@ jobs:
8181
pip install -e .
8282
- name: Test with pytest
8383
run: |
84-
pytest tests/
84+
pytest tests_version2/

.github/workflows/CI.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
1+
# This workflow will install Python dependencies, run tests_version2 and lint with a variety of Python versions
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

44
name: Continuous Integration
@@ -76,8 +76,6 @@ jobs:
7676
python -m pip install --upgrade pip
7777
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
7878
pip install -e .
79-
# pip install jax==0.4.30
80-
# pip install jaxlib==0.4.30
8179
- name: Test with pytest
8280
run: |
8381
pytest brainpy/

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ Branch naming conventions:
114114

115115
Run the test suite:
116116
```bash
117-
pytest tests/
117+
pytest tests_version2/
118118
```
119119

120120
Run specific tests:
121121
```bash
122-
pytest tests/test_specific.py -v
122+
pytest tests_version2/test_specific.py -v
123123
```
124124

125125
### 4. Commit Your Changes
@@ -203,7 +203,7 @@ def simulate_network(network, duration, dt=0.1):
203203

204204
Aim for high test coverage on new code:
205205
```bash
206-
pytest --cov=brainpy tests/
206+
pytest --cov=brainpy tests_version2/
207207
```
208208

209209
## Documentation

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
BrainPy is a flexible, efficient, and extensible framework for computational neuroscience and brain-inspired computation based on the Just-In-Time (JIT) compilation. It provides an integrative ecosystem for brain dynamics programming, including brain dynamics **building**, **simulation**, **training**, **analysis**, etc.
1818

1919
- **Source**: https://github.com/brainpy/BrainPy
20-
- **Documentation**: https://brainpy.readthedocs.io/
21-
- **Documentation**: https://brainpy-v2.readthedocs.io/
20+
- **Documentation (brainpy v3.0)**: https://brainpy.readthedocs.io/
21+
- **Documentation (brainpy v2.0)**: https://brainpy-v2.readthedocs.io/
2222
- **Bug reports**: https://github.com/brainpy/BrainPy/issues
2323
- **Ecosystem**: https://brainmodeling.readthedocs.io/
2424

brainpy/_base_test.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515

16-
"""
17-
Comprehensive tests for the Neuron and Synapse base classes in _base.py.
18-
19-
This module tests:
20-
- Neuron base class functionality and abstract interface
21-
- Synapse base class functionality and abstract interface
22-
- Proper initialization and parameter handling
23-
- State management (init_state, reset_state)
24-
- Surrogate gradient function integration
25-
- Reset mechanisms (soft/hard)
26-
- Custom implementations
27-
- Edge cases and error handling
28-
"""
29-
3016
import unittest
3117

3218
import braintools

brainpy/version2/dynold/neurons/reduced_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ def update(self, x=None):
10831083
x = 0. if x is None else x
10841084
V, y, z = self.integral(self.V.value, self.y.value, self.z.value, t, x, dt=dt)
10851085
if isinstance(self.mode, bm.TrainingMode):
1086-
self.spike.value = self.spike_fun(V - self.V_th, self.V - self.V_th)
1086+
self.spike.value = self.spike_fun(V - self.V_th) * self.spike_fun(self.V - self.V_th)
10871087
else:
10881088
self.spike.value = bm.logical_and(V >= self.V_th, self.V < self.V_th)
10891089
self.V.value = V

brainpy/version2/inputs/currents.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def section_input(values, durations, dt=None, return_length=False):
5656
5757
current_and_duration
5858
"""
59-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
59+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
6060
return braintools.input.section(values, durations, return_length=return_length)
6161

6262

@@ -85,7 +85,7 @@ def constant_input(I_and_duration, dt=None):
8585
current_and_duration : tuple
8686
(The formatted current, total duration)
8787
"""
88-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
88+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
8989
return braintools.input.constant(I_and_duration)
9090

9191

@@ -133,7 +133,7 @@ def spike_input(sp_times, sp_lens, sp_sizes, duration, dt=None):
133133
current : bm.ndarray
134134
The formatted input current.
135135
"""
136-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
136+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
137137
return braintools.input.spike(sp_times, sp_lens, sp_sizes, duration)
138138

139139

@@ -172,7 +172,7 @@ def ramp_input(c_start, c_end, duration, t_start=0, t_end=None, dt=None):
172172
current : bm.ndarray
173173
The formatted current
174174
"""
175-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
175+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
176176
return braintools.input.ramp(c_start, c_end, duration, t_start, t_end)
177177

178178

@@ -207,7 +207,7 @@ def wiener_process(duration, dt=None, n=1, t_start=0., t_end=None, seed=None):
207207
seed: int
208208
The noise seed.
209209
"""
210-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
210+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
211211
return braintools.input.wiener_process(duration, sigma=1.0, n=n, t_start=t_start, t_end=t_end, seed=seed)
212212

213213

@@ -239,7 +239,7 @@ def ou_process(mean, sigma, tau, duration, dt=None, n=1, t_start=0., t_end=None,
239239
seed: optional, int
240240
The random seed.
241241
"""
242-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
242+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
243243
return braintools.input.ou_process(mean, sigma, tau, duration, n=n, t_start=t_start, t_end=t_end, seed=seed)
244244

245245

@@ -264,7 +264,7 @@ def sinusoidal_input(amplitude, frequency, duration, dt=None, t_start=0., t_end=
264264
Whether the sinusoid oscillates around 0 (False), or
265265
has a positive DC bias, thus non-negative (True).
266266
"""
267-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
267+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
268268
return braintools.input.sinusoidal(amplitude, frequency, duration, t_start=t_start, t_end=t_end, bias=bias)
269269

270270

@@ -289,5 +289,5 @@ def square_input(amplitude, frequency, duration, dt=None, bias=False, t_start=0.
289289
Whether the sinusoid oscillates around 0 (False), or
290290
has a positive DC bias, thus non-negative (True).
291291
"""
292-
with brainstate.environ.context(dt=dt or brainstate.environ.get_dt()):
292+
with brainstate.environ.context(dt=brainstate.environ.get_dt() if dt is None else dt):
293293
return braintools.input.square(amplitude, frequency, duration, t_start=t_start, t_end=t_end, duty_cycle=0.5, bias=bias)

brainpy/version2/inputs/tests/test_currents.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# ==============================================================================
1616
from unittest import TestCase
1717

18+
import brainunit as u
1819
import numpy as np
1920

2021
import brainpy.version2 as bp
@@ -36,6 +37,8 @@ def show(current, duration, title=''):
3637

3738

3839
class TestCurrents(TestCase):
40+
41+
3942
def test_section_input(self):
4043
current1, duration = bp.inputs.section_input(values=[0, 1., 0.],
4144
durations=[100, 300, 100],
@@ -80,16 +83,17 @@ def test_ou_process(self):
8083
current7 = bp.inputs.ou_process(mean=1., sigma=0.1, tau=10., duration=duration, n=2, t_start=10., t_end=180.)
8184
show(current7, duration, 'Ornstein-Uhlenbeck Process')
8285

83-
def test_sinusoidal_input(self):
84-
duration = 2000
85-
current8 = bp.inputs.sinusoidal_input(amplitude=1., frequency=2.0, duration=duration, t_start=100., )
86-
show(current8, duration, 'Sinusoidal Input')
87-
88-
def test_square_input(self):
89-
duration = 2000
90-
current9 = bp.inputs.square_input(amplitude=1., frequency=2.0,
91-
duration=duration, t_start=100)
92-
show(current9, duration, 'Square Input')
86+
# def test_sinusoidal_input(self):
87+
# duration = 2000 * u.ms
88+
# current8 = bp.inputs.sinusoidal_input(amplitude=1., frequency=2.0 * u.Hz,
89+
# duration=duration, t_start=100. * u.ms, dt=0.1 * u.ms)
90+
# show(current8, duration, 'Sinusoidal Input')
91+
#
92+
# def test_square_input(self):
93+
# duration = 2000 * u.ms
94+
# current9 = bp.inputs.square_input(amplitude=1., frequency=2.0 * u.Hz,
95+
# duration=duration, t_start=100 * u.ms, dt=0.1 * u.ms)
96+
# show(current9, duration, 'Square Input')
9397

9498
def test_general1(self):
9599
I1 = bp.inputs.section_input(values=[0, 1, 2], durations=[10, 20, 30], dt=0.1)

0 commit comments

Comments
 (0)