NotImplementedError: The store/restore mechanism is not supported in the C++ standalone

Description of problem

Dear all, I am new to Brian2. It’s really a wonderful simulator. Yet I encounter a problem when using the C++ standalone mode. To maximize the simulation speed, I used the following code to set the C++ standalone mode:
set_device(‘cpp_standalone’, build_on_run=False)
cache_dir = os.path.expanduser(f’~/.cython/brian-pid-{os.getpid()}')
prefs.codegen.runtime.cython.cache_dir = cache_dir
prefs.devices.cpp_standalone.openmp_threads = os.cpu_count() - 1

After building the network, I used the following code to start simulation:
device.build(run=False)
device.run()
Then I used model.net.store to store the model:
model.net.store(‘train’, ‘train.b2’)
Yet it comes with the following error:
NotImplementedError: The store/restore mechanism is not supported in the C++ standalone

How could I solve this problem, thank you in advance.

Hi @Imperialpiggy. As the error message states, you cannot use store/restore in C++ standalone mode. It wouldn’t be that hard to make this functionality available, but someone would have to work on this (happy to help, but I don’t have the capacity to do this myself in the near future).
However, note that the store/restore mechanism is maybe more powerful than what you need : it creates a snapshot of the entire network state and allows you to “go back in time”. If all you want is to save and re-use synaptic weights, you can do this directly, i.e. store syn.w[:] after a simulation in a variable or to disk, and then use syn.w[:] = stored_values before running a new simulation. If the connections are random, you’d also have to store syn.i[:] and syn.j[:] and use them in syn.connect(i=stored_i, j=stored_j) to restore the same connections.

Hope that helps!

PS: Note that the setting for the cython cache directory is not used in C++ standalone mode

Dear Mstimberg,

Thank you so much for your clear explanation and informative response. It’s very helpful. Thanks again for your time and help!

1 Like