3.14. Saving / Loading¶
3.14.1. Saving / loading the state of the network¶
To save or load the network state you can use the following methods:
-
ANNarchy.
save
(filename, populations=True, projections=True, net_id=0)[source]¶ Save the current network state (parameters and variables) to a file.
- If the extension is ‘.npz’, the data will be saved and compressed using np.savez_compressed (recommended).
- If the extension is ‘.mat’, the data will be saved as a Matlab 7.2 file. Scipy must be installed.
- If the extension ends with ‘.gz’, the data will be pickled into a binary file and compressed using gzip.
- Otherwise, the data will be pickled into a simple binary text file using cPickle.
Parameters: - filename – filename, may contain relative or absolute path.
- populations – if True, population data will be saved (by default True)
- projections – if True, projection data will be saved (by default True)
Warning
The ‘.mat’ data will not be loadable by ANNarchy, it is only for external analysis purpose.
Example:
save('results/init.npz') save('results/init.data') save('results/init.txt.gz') save('1000_trials.mat')
-
ANNarchy.
load
(filename, populations=True, projections=True, net_id=0)[source]¶ Loads a saved state of the network.
Warning: Matlab data can not be loaded.
Parameters: - filename – the filename with relative or absolute path.
- populations – if True, population data will be loaded (by default True)
- projections – if True, projection data will be loaded (by default True)
Example:
load('results/network.npz')
Please note that these functions are only usable after the call to ANNarchy.compile()
.
3.14.2. Saving / loading the parameters of the network¶
-
ANNarchy.
save_parameters
(filename, net_id=0)[source]¶ Saves the global parameters of a network (flag
population
for neurons,projection
for synapses) to a JSON file.Parameters: - filename – path to the JSON file.
- net_id – ID of the network (default: 0, the global network).
-
ANNarchy.
load_parameters
(filename, global_only=True, verbose=False, net_id=0)[source]¶ Loads the global parameters of a network (flag
population
for neurons,projection
for synapses) from a JSON file.Parameters: - filename – path to the JSON file.
- global_only – True if only global parameters (flags
population
andprojection
) should be loaded, the other values are ignored. (default: True) - verbose – True if the old and new values of the parameters should be printed (default: False).
- net_id – ID of the network (default: 0, the global network).
Returns: a dictionary of additional parameters not related to populations or projections (keyword
network
in the JSON file).It is advised to generate the JSON file first with
save_parameters()
and later edit it manually.A strong restriction is that population/projection names cannot change between saving and loading. By default, they take names such as
pop0
orproj2
, we advise setting explicitly a name in their constructor for readability.If you add a parameter name to the JSON file but it does not exist in te neuron/synapse, it will be silently skipped. Enable
verbose=True
to see which parameters are effectively changed.If you set
global_only
to True, you will be able to set values for non-global parameters (e.g. synapse-specific), but a single value will be loaded for all. The JSON file cannot contain arrays.If you want to save/load the value of variables after a simulation, please refer to
save()
orload()
.