Saving / Loading#
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)
#
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.
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')
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)
Source code in ANNarchy/core/IO.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
ANNarchy.load(filename, populations=True, projections=True, pickle_encoding=None, net_id=0)
#
Loads a saved state of the network.
Warning: Matlab data can not be loaded.
Example:
load('results/network.npz')
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)
-
pickle_encoding
–optional parameter provided to the pickle.load() method. If set to None the default is used.
Source code in ANNarchy/core/IO.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
Please note that these functions are only usable after the call to ANNarchy.compile()
.
Saving / loading the parameters of the network#
ANNarchy.save_parameters(filename, net_id=0)
#
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).
Source code in ANNarchy/core/IO.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
ANNarchy.load_parameters(filename, global_only=True, verbose=False, net_id=0)
#
Loads the global parameters of a network (flag population
for neurons, projection
for synapses) from a 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
or proj2
, 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()
or load()
.
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).
Source code in ANNarchy/core/IO.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|