Skip to content

Commit

Permalink
[dyn] fix warning of reset_state (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed Jan 5, 2024
1 parent 5871c9c commit c6c96fb
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions brainpy/_src/dynsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def reset(self, *args, **kwargs):
from brainpy._src.helpers import reset_state
reset_state(self, *args, **kwargs)

@not_implemented
def reset_state(self, *args, **kwargs):
"""Reset function which resets local states in this model.
Expand Down Expand Up @@ -332,22 +333,25 @@ def _compatible_reset_state(self, *args, **kwargs):
global the_top_layer_reset_state
the_top_layer_reset_state = False
try:
self.reset(*args, **kwargs)
if hasattr(self.reset_state, '_not_implemented'):
self.reset(*args, **kwargs)
warnings.warn(
'''
From version >= 2.4.6, the policy of ``.reset_state()`` has been changed. See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_saving_and_loading.html for details.
1. If you are resetting all states in a network by calling "net.reset_state(*args, **kwargs)", please use
"bp.reset_state(net, *args, **kwargs)" function, or "net.reset(*args, **kwargs)".
".reset_state()" only defines the resetting of local states in a local node (excluded its children nodes).
2. If you does not customize "reset_state()" function for a local node, please implement it in your subclass.
''',
DeprecationWarning
)
else:
self.reset_state(*args, **kwargs)
finally:
the_top_layer_reset_state = True
warnings.warn(
'''
From version >= 2.4.6, the policy of ``.reset_state()`` has been changed. See https://brainpy.readthedocs.io/en/latest/tutorial_toolbox/state_saving_and_loading.html for details.
1. If you are resetting all states in a network by calling "net.reset_state(*args, **kwargs)", please use
"bp.reset_state(net, *args, **kwargs)" function, or "net.reset(*args, **kwargs)".
".reset_state()" only defines the resetting of local states in a local node (excluded its children nodes).
2. If you does not customize "reset_state()" function for a local node, please implement it in your subclass.
''',
DeprecationWarning
)

def _get_update_fun(self):
return object.__getattribute__(self, 'update')
Expand Down

0 comments on commit c6c96fb

Please sign in to comment.