Skip to content

Commit 95a9560

Browse files
committed
refactor: Remove clear_buffer_memory calls from various test files
1 parent 1e7ed83 commit 95a9560

48 files changed

Lines changed: 241 additions & 389 deletions

Some content is hidden

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

.github/workflows/CI-models.yml

Lines changed: 33 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
python-version: [ "3.10", "3.11", "3.12"]
25+
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
2626

2727
steps:
2828
- uses: actions/checkout@v4
@@ -40,128 +40,50 @@ jobs:
4040
run: |
4141
pytest tests/
4242
43-
# test_linux_py37:
44-
# runs-on: ubuntu-latest
45-
# if: github.event.pull_request.merged == true
46-
# strategy:
47-
# fail-fast: false
48-
# matrix:
49-
# python-version: ["3.7"]
50-
#
51-
# steps:
52-
# - uses: actions/checkout@v4
53-
# - name: Set up Python ${{ matrix.python-version }}
54-
# uses: actions/setup-python@v5
55-
# with:
56-
# python-version: ${{ matrix.python-version }}
57-
# - name: Install dependencies
58-
# run: |
59-
# if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
60-
# pip install jax==0.3.25
61-
# pip install jaxlib==0.3.25
62-
# pip uninstall brainpy -y
63-
# python setup.py install
64-
# - name: Test with pytest
65-
# run: |
66-
# pytest tests/
67-
6843
test_macos:
6944
runs-on: macos-latest
7045
strategy:
7146
fail-fast: false
7247
matrix:
73-
python-version: [ "3.10", "3.11", "3.12"]
48+
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
7449

7550
steps:
76-
- uses: actions/checkout@v4
77-
- name: Set up Python ${{ matrix.python-version }}
78-
uses: actions/setup-python@v5
79-
with:
80-
python-version: ${{ matrix.python-version }}
81-
- name: Install dependencies
82-
run: |
83-
python -m pip install --upgrade pip
84-
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
85-
pip uninstall brainpy -y
86-
python setup.py install
87-
- name: Test with pytest
88-
run: |
89-
pytest tests/
90-
91-
# test_macos_py37:
92-
# runs-on: macos-latest
93-
# if: github.event.pull_request.merged == true
94-
# strategy:
95-
# fail-fast: false
96-
# matrix:
97-
# python-version: [ "3.7" ]
98-
#
99-
# steps:
100-
# - uses: actions/checkout@v4
101-
# - name: Set up Python ${{ matrix.python-version }}
102-
# uses: actions/setup-python@v5
103-
# with:
104-
# python-version: ${{ matrix.python-version }}
105-
# - name: Install dependencies
106-
# run: |
107-
# if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
108-
# pip install jax==0.3.25
109-
# pip install jaxlib==0.3.25
110-
# pip uninstall brainpy -y
111-
# python setup.py install
112-
# - name: Test with pytest
113-
# run: |
114-
# pytest tests/
115-
51+
- uses: actions/checkout@v4
52+
- name: Set up Python ${{ matrix.python-version }}
53+
uses: actions/setup-python@v5
54+
with:
55+
python-version: ${{ matrix.python-version }}
56+
- name: Install dependencies
57+
run: |
58+
python -m pip install --upgrade pip
59+
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
60+
pip uninstall brainpy -y
61+
python setup.py install
62+
- name: Test with pytest
63+
run: |
64+
pytest tests/
11665
11766
test_windows:
11867
runs-on: windows-latest
11968
strategy:
12069
fail-fast: false
12170
matrix:
122-
python-version: ["3.10", "3.11", "3.12"]
71+
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
12372

12473
steps:
125-
- uses: actions/checkout@v4
126-
- name: Set up Python ${{ matrix.python-version }}
127-
uses: actions/setup-python@v5
128-
with:
129-
python-version: ${{ matrix.python-version }}
130-
- name: Install dependencies
131-
run: |
132-
python -m pip install --upgrade pip
133-
python -m pip install numpy>=1.21.0
134-
python -m pip install -r requirements-dev.txt
135-
python -m pip install tqdm
136-
pip uninstall brainpy -y
137-
python setup.py install
138-
- name: Test with pytest
139-
run: |
140-
pytest tests/
141-
142-
# test_windows_py37:
143-
# runs-on: windows-latest
144-
# if: github.event.pull_request.merged == true
145-
# strategy:
146-
# fail-fast: false
147-
# matrix:
148-
# python-version: ["3.7"]
149-
#
150-
# steps:
151-
# - uses: actions/checkout@v4
152-
# - name: Set up Python ${{ matrix.python-version }}
153-
# uses: actions/setup-python@v5
154-
# with:
155-
# python-version: ${{ matrix.python-version }}
156-
# - name: Install dependencies
157-
# run: |
158-
# python -m pip install numpy>=1.21.0
159-
# python -m pip install "jaxlib==0.3.25" -f https://whls.blob.core.windows.net/unstable/index.html --use-deprecated legacy-resolver
160-
# python -m pip install https://github.com/google/jax/archive/refs/tags/jax-v0.3.25.tar.gz
161-
# python -m pip install -r requirements-dev.txt
162-
# python -m pip install tqdm brainpylib
163-
# pip uninstall brainpy -y
164-
# python setup.py install
165-
# - name: Test with pytest
166-
# run: |
167-
# pytest tests/
74+
- uses: actions/checkout@v4
75+
- name: Set up Python ${{ matrix.python-version }}
76+
uses: actions/setup-python@v5
77+
with:
78+
python-version: ${{ matrix.python-version }}
79+
- name: Install dependencies
80+
run: |
81+
python -m pip install --upgrade pip
82+
python -m pip install numpy>=1.21.0
83+
python -m pip install -r requirements-dev.txt
84+
python -m pip install tqdm
85+
pip uninstall brainpy -y
86+
python setup.py install
87+
- name: Test with pytest
88+
run: |
89+
pytest tests/

brainpy/_src/analysis/highdim/tests/test_slow_points.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
import brainpy as bp
43
import unittest
4+
5+
import brainpy as bp
56
import brainpy.math as bm
67

78

@@ -61,10 +62,10 @@ def dV(self, V, t, m, h, n, Iext):
6162

6263
def update(self, tdi):
6364
t, dt = tdi.t, tdi.dt
64-
m = self.int_m(self.m, t, self.V, dt=dt)
65-
h = self.int_h(self.h, t, self.V, dt=dt)
66-
n = self.int_n(self.n, t, self.V, dt=dt)
67-
V = self.int_V(self.V, t, self.m, self.h, self.n, self.input, dt=dt)
65+
m = self.int_m(self.m.value, t, self.V.value, dt=dt)
66+
h = self.int_h(self.h.value, t, self.V.value, dt=dt)
67+
n = self.int_n(self.n.value, t, self.V.value, dt=dt)
68+
V = self.int_V(self.V.value, t, self.m.value, self.h.value, self.n.value, self.input.value, dt=dt)
6869
self.spike.value = bm.logical_and(self.V < self.V_th, V >= self.V_th)
6970
self.V.value = V
7071
self.h.value = h
@@ -106,7 +107,6 @@ def step(s):
106107
rng = bm.random.RandomState(123)
107108
finder = bp.analysis.SlowPointFinder(f_cell=step, f_type=bp.analysis.CONTINUOUS)
108109
finder.find_fps_with_opt_solver(rng.random((100, 2)))
109-
bm.clear_buffer_memory()
110110

111111
def test_opt_solver_for_ds1(self):
112112
hh = HH(1)
@@ -120,7 +120,6 @@ def test_opt_solver_for_ds1(self):
120120
'm': rng.random((100, 1)),
121121
'h': rng.random((100, 1)),
122122
'n': rng.random((100, 1))})
123-
bm.clear_buffer_memory()
124123

125124
def test_gd_method_for_func1(self):
126125
gamma = 0.641 # Saturation factor for gating variable
@@ -154,7 +153,6 @@ def step(s):
154153
rng = bm.random.RandomState(123)
155154
finder = bp.analysis.SlowPointFinder(f_cell=step, f_type=bp.analysis.CONTINUOUS)
156155
finder.find_fps_with_gd_method(rng.random((100, 2)), num_opt=100)
157-
bm.clear_buffer_memory()
158156

159157
def test_gd_method_for_func2(self):
160158
hh = HH(1)
@@ -164,10 +162,10 @@ def test_gd_method_for_func2(self):
164162
with self.assertRaises(ValueError):
165163
finder.find_fps_with_opt_solver(rng.random((100, 4)))
166164

167-
finder.find_fps_with_gd_method({'V': rng.random((100, 1)),
165+
finder.find_fps_with_gd_method(
166+
{'V': rng.random((100, 1)),
168167
'm': rng.random((100, 1)),
169168
'h': rng.random((100, 1)),
170169
'n': rng.random((100, 1))},
171-
num_opt=100)
172-
bm.clear_buffer_memory()
173-
170+
num_opt=100
171+
)

brainpy/_src/context.py

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
from typing import Any, Union
88

9-
from brainpy._src.math.environment import get_dt
9+
import brainstate
10+
1011
from brainpy._src.tools.dicts import DotDict
1112

1213
__all__ = [
@@ -26,17 +27,14 @@ def __init__(self):
2627

2728
@property
2829
def dt(self):
29-
if 'dt' in self._arguments:
30-
return self._arguments['dt']
31-
else:
32-
return get_dt()
30+
return brainstate.environ.get_dt()
3331

3432
@dt.setter
3533
def dt(self, dt):
3634
self.set_dt(dt)
3735

3836
def set_dt(self, dt: Union[int, float]):
39-
self._arguments['dt'] = dt
37+
brainstate.environ.set(dt=dt)
4038

4139
def load(self, key, value: Any = None, desc: str = None):
4240
"""Load the shared data by the ``key``.
@@ -46,28 +44,16 @@ def load(self, key, value: Any = None, desc: str = None):
4644
value (Any): the default value when ``key`` is not defined in the shared.
4745
desc: (str): the description of the key.
4846
"""
49-
if key == 'dt':
50-
return self.dt
51-
if key in self._arguments:
52-
return self._arguments[key]
53-
if value is None:
54-
warn = f'Cannot found shared data of {key}. \n'
55-
if desc is not None:
56-
warn += f'{key}: {desc}\n'
57-
warn += f'Please define it with "brainpy.share.save({key}=<your data>)". '
58-
raise KeyError(warn)
59-
else:
60-
return value
47+
return brainstate.environ.get(key, value, desc)
6148

6249
def save(self, *args, **kwargs) -> None:
6350
"""Save shared arguments in the global context."""
6451
assert len(args) % 2 == 0
6552
for i in range(0, len(args), 2):
6653
identifier = args[i]
6754
data = args[i + 1]
68-
self._arguments[identifier] = data
69-
for identifier, data in kwargs.items():
70-
self._arguments[identifier] = data
55+
brainstate.environ.set(**{identifier: data})
56+
brainstate.environ.set(**kwargs)
7157

7258
def __setitem__(self, key, value):
7359
"""Enable setting the shared item by ``bp.share[key] = value``."""
@@ -79,36 +65,7 @@ def __getitem__(self, item):
7965

8066
def get_shargs(self) -> DotDict:
8167
"""Get all shared arguments in the global context."""
82-
shs = self._arguments.copy()
83-
if 'dt' not in shs:
84-
shs['dt'] = self.dt
85-
return shs
86-
87-
def clear_shargs(self, *args) -> None:
88-
"""Clear all shared arguments in the global context."""
89-
if len(args) > 0:
90-
for a in args:
91-
self._arguments.pop(a)
92-
else:
93-
self._arguments.clear()
94-
95-
def clear(self) -> None:
96-
"""Clear all shared data in this computation context."""
97-
self._arguments.clear()
98-
99-
def save_category(self, category, **kwargs):
100-
if category not in self._category:
101-
self._category[category] = dict()
102-
self._category[category].update(**kwargs)
103-
104-
def clear_category(self, category=None):
105-
if category is None:
106-
self._category.clear()
107-
else:
108-
self._category.pop(category)
109-
110-
def get_category(self, category):
111-
return self._category[category]
68+
return DotDict(brainstate.environ.all())
11269

11370

11471
share = _ShareContext()

0 commit comments

Comments
 (0)