Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dyn] fix warning of reset_state #587

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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