Hi,
I have a question and kindly need your help, How i can run a new and separate instance of current simulator at a specific state ?
It should be noted that, I have examined the following methods, but i haven’t succeed !!
1. copy.deepcopy has been tested and i have got errors about not having a Signal or Probe in Dict
simcopy=copy.deepcopy(sim)
simcopy.run_steps(5*1000)
t = simcopy.trange()
plot(simcopy)
Hi!
It is possible to pickle a closed Simulator object and unpickle it later on. However, once a simulator is closed, it can’t be reopened to resume the simulation (for some information on this topic, the following documentation might be useful: https://www.nengo.ai/nengo/backend-api.html#nengo.Simulator).
Depending on your use case, there are a couple of ways to simulate multiple copies of the same model. The most straightforward approach would involve setting a fixed seed to ensure deterministic behaviour across simulations. A more complicated approach would involve running a simulation to a current a given state, storing all of the state information, and then constructing a new network that uses this state information to initialize all of the e.g. neuron voltages, synaptic filters, etc. I wouldn’t recommend this unless there’s something specific you’re trying to do that isn’t handled by fixing the seed.
To demonstrate pickling and unpickling, the following script provides a short example:
import nengo
import numpy as np
with nengo.Network() as model:
inp = nengo.Node(np.cos)
ens = nengo.Ensemble(100, dimensions=1)
nengo.Connection(inp, ens)
probe = nengo.Probe(ens)
sim = nengo.Simulator(model)
with sim:
sim.run(1)
with open('sim.pkl', 'wb') as pfile:
pickle.dump(sim, pfile)
with open('sim.pkl', 'rb') as pfile:
sim_copy = pickle.load(pfile)
Anyway, I hope this is helpful, but let us know if you have any followup questions!