CARLsim  5.0.0
CARLsim: a GPU-accelerated SNN simulator
Chapter 8: Saving and Loading
Author
Kristofor D. Carlson
Michael Beyeler

Once a network has reached SETUP_STATE or RUN_STATE, the network state can be stored in a file for later processing or for restoring a specific network using the CARLsim::saveSimulation function. The network state consists of all the synaptic connections, weights, delays, and whether the connections are plastic or fixed. The network state data can be analyzed with the MATLAB ConnectionMonitor.

Furthermore, the network state can be loaded from a file using the CARLsim::loadSimulation function call. However, this function can only be called in the CONFIG_STATE.

Saving and loading network state data can be especially time-saving when an SNN is extremely large or if it must be trained for a long period of time. After training for the first run is completed and saved to file, subsequent testing runs will be much faster.

8.1 Saving a Simulation File

A network can be saved at any time in SETUP_STATE or RUN_STATE, for as many times as desired, via CARLsim::saveSimulation:

#include <carlsim.h>
CARLsim sim("saveSim", CPU_MODE, USER);
// configure a network
int gOut = sim.createGroup("gOut", 10, EXCITATORY_NEURON);
int gIn = sim.createSpikeGeneratorGroup("gIn", 10, EXCITATORY_NEURON);
sim.connect(gIn, gOut, "one-to-one", RangeWeight(0.1f), 0.1f);
// .. etc.
// save initial network
sim.saveSimulation("networkA.dat", true); // fileName, saveSynapseInfo
// perform experiment, which might include synaptic plasticity and/or a training phase
// etc.
sim.runNetwork(1,0);
// store network at the end of training
sim.saveSimulation("networkZ.dat", true); // fileName, saveSynapseInfo

where the user specifies a filename (e.g., "networkA.dat") and a flag whether or not to store the synapse information. In this example, "networkA.dat" will contain the network state at the beginning of the experiment, and "networkZ.dat" will contain the network state at the end of the experiment (which might be different from the beginning if there is synaptic plasticity enabled). If the flag saveSynapseInfo is set to true, the method will store all the synaptic connections, weights, delays, and whether the connections are plastic or fixed. The value of this flag is true by default.

8.2 Loading a Simulation File

Past CARLsim networks can be loaded from file by setting up the same number of groups, connections, and neurons as was used to store the network via CARLsim::saveSimulation, and then calling CARLsim::loadSimulation to overwrite all corresponding synaptic weight and delay values from file.

The following code snippet configures a network and calls CARLsim::loadSimulation with a file pointer to "networkA.dat", which is a file that was created with CARLsim::saveSimulation and flag saveSynapseInfo set to true:

#include <carlsim.h>
CARLsim sim("loadSim", CPU_MODE, USER);
// configure the same network used with saveSimulation
int gOut = sim.createGroup("gOut", 10, EXCITATORY_NEURON);
int gIn = sim.createSpikeGeneratorGroup("gIn", 10, EXCITATORY_NEURON);
sim.connect(gIn, gOut, "one-to-one", RangeWeight(0.1f), 0.1f);
// .. etc.
// before calling setupNetwork, call loadSimulation
FILE* fId = NULL;
simFid = fopen("networkA.dat", "rb");
sim.loadSimulation(fId);
// don't fclose fId yet ...
// ... wait until after setupNetwork is called
fclose(fId);
// perform experiment, etc.
Note
In order for CARLsim::loadSimulation to work, the configured network must have the identical number of groups, connections, and neurons as the one stored with CARLsim::saveSimulation.
In addition, CARLsim::saveSimulation must have been called with flag saveSynapseInfo set to true.
Attention
Wait with calling fclose on the file pointer until SETUP_STATE!
CARLsim::createSpikeGeneratorGroup
int createSpikeGeneratorGroup(const std::string &grpName, int nNeur, int neurType, int preferredPartition=ANY, ComputingBackend preferredBackend=CPU_CORES)
creates a spike generator group
Definition: carlsim.cpp:1780
RangeWeight
a range struct for synaptic weight magnitudes
Definition: carlsim_datastructures.h:312
CARLsim::runNetwork
int runNetwork(int nSec, int nMsec=0, bool printRunSummary=true)
run the simulation for time=(nSec*seconds + nMsec*milliseconds)
Definition: carlsim.cpp:1910
CARLsim::saveSimulation
void saveSimulation(const std::string &fileName, bool saveSynapseInfo=true)
Saves important simulation and network infos to file.
Definition: carlsim.cpp:1923
EXCITATORY_NEURON
#define EXCITATORY_NEURON
Definition: carlsim_definitions.h:77
USER
@ USER
User mode, for experiment-oriented simulations.
Definition: carlsim_datastructures.h:92
CARLsim::setupNetwork
void setupNetwork()
build the network
Definition: carlsim.cpp:1915
CPU_MODE
@ CPU_MODE
model is run on CPU core(s)
Definition: carlsim_datastructures.h:115
CARLsim
CARLsim User Interface This class provides a user interface to the public sections of CARLsimCore sou...
Definition: carlsim.h:138
CARLsim::connect
short int connect(int grpId1, int grpId2, const std::string &connType, const RangeWeight &wt, float connProb, const RangeDelay &delay=RangeDelay(1), const RadiusRF &radRF=RadiusRF(-1.0), bool synWtType=SYN_FIXED, float mulSynFast=1.0f, float mulSynSlow=1.0f)
Connects a presynaptic to a postsynaptic group using fixed/plastic weights and a range of delay value...
Definition: carlsim.cpp:1740
carlsim.h
CARLsim::loadSimulation
void loadSimulation(FILE *fid)
Loads a simulation (and network state) from file. The file pointer fid must point to a valid CARLsim ...
Definition: carlsim.cpp:1942
CARLsim::createGroup
int createGroup(const std::string &grpName, int nNeur, int neurType, int preferredPartition=ANY, ComputingBackend preferredBackend=CPU_CORES)
creates a group of Izhikevich spiking neurons
Definition: carlsim.cpp:1764