Skip to content

Commit

Permalink
Fix the incorrect verbose of clear_name_cache() (#681)
Browse files Browse the repository at this point in the history
* fix the incorrect verbose of `clear_name_cache()`

* add the test for naming
  • Loading branch information
chaoming0625 authored Jun 20, 2024
1 parent d04839d commit 5e75f78
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion brainpy/_src/math/object_transform/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def check_name_uniqueness(name, obj):
f'In BrainPy, each object should have a unique name. '
f'However, we detect that {obj} has a used name "{name}". \n'
f'If you try to run multiple trials, you may need \n\n'
f'>>> brainpy.brainpy_object.clear_name_cache() \n\n'
f'>>> brainpy.math.clear_name_cache() \n\n'
f'to clear all cached names. '
)
else:
Expand Down
31 changes: 31 additions & 0 deletions brainpy/_src/math/object_transform/tests/test_naming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 BDP Ecosystem Limited. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================


import brainpy as bp
import brainpy.math as bm
import unittest


class TestNaming(unittest.TestCase):

def test_clear_name_cache(self):
lif = bp.dyn.LifRef(1, name='a')
with self.assertRaises(bp.errors.UniqueNameError):
lif = bp.dyn.LifRef(1, name='a')
bm.clear_name_cache(ignore_warn=True)
lif = bp.dyn.LifRef(1, name='a')
bm.clear_name_cache()
bm.clear_buffer_memory(array=True, compilation=True)
2 changes: 1 addition & 1 deletion docs/tutorial_building/customize_dynamical_systems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@
}
],
"source": [
"runner = bp.dyn.DSRunner(fhn_net,\n",
"runner = bp.DSRunner(fhn_net,\n",
" monitors=['f1.v', 'X.v'], \n",
" inputs=[('f1.I', 1.5), # relative access to variable \"I\" in 'fhn1'\n",
" ('X.I', 1.0),]) # absolute access to variable \"I\" in 'fhn2'\n",
Expand Down

0 comments on commit 5e75f78

Please sign in to comment.