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

[docs] Update custom saving and loading #439

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions docs/tutorial_toolbox/saving_and_loading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,23 @@
}
},
"source": [
"You can make your own saving and loading functions easily. Beacause all variables in the model can be easily collected through ``.vars()``. Therefore, saving variables is just transforming these variables to numpy.ndarray and then storing them into the disk. Similarly, to load variables, you just need read the numpy arrays from the disk and then transform these arrays as instances of [Variables](../tutorial_math/variables.ipynb). \n",
"You can make your own saving and loading functions easily. Beacause all variables in the model can be easily collected through ``.vars()``.\n",
"\n",
"The only gotcha to pay attention to is to avoid saving duplicated variables. "
"For customizing the saving, users can use:\n",
"\n",
"```python\n",
"class YourClass(bp.BrainPyObject):\n",
" def __save_state__(self):\n",
" ...\n",
"```\n",
"\n",
"For customizing the loading, users can use:\n",
"\n",
"```python\n",
"class YourClass(bp.BrainPyObject):\n",
" def __load_state__(self, state_dict):\n",
" ...\n",
"```"
]
}
],
Expand Down