Challenge Import/Export Probe Data with Numpy

I’m encountering a challenge with probes. In my setup, it’s easier to run a python script instead of running a Jupyter notebook. The probe data is saved using the np.save (Numpy), and then import it later and create plots by accessing the data with np.load.

I have no issues doing this with an SPA State module. Here is a small snippet of this.
p_inputOut = nengo.Probe(input0.output, synapse=0.01) np.save((logPath+fileName),spa.similarity(sim.data[p_inputOut], vocab))
p_inputOut = np.save(logPath+fileName) # load in another file`

To note, the logPath+fileName will create a unique filename stored in a Numpy format.

I’m having issues doing the same thing with a neuron ensemble. An example is the snippet below.
p_mtr_speed = nengo.Probe(motor, synapse=0.01) np.save((logPath+"mtrSpeed_turtlebotFull"),p_mtr_speed) p_mtr_speed = np.load(logPath+fileName) # load in another file

At first I received an error regarding allowing pickles. I changed p_mtr_speed = np.load(logPath+fileName) to p_mtr_speed = np.load(logPath+fileName, allow_pickle=True). This addressed the first issue.

I’m stuck on this error: AttributeError: Can't get attribute 'ScatteredHypersphere' on <module 'nengo.dists' from 'C:\\Program Files\\Python37\\lib\\site-packages\\nengo\\dists.py'> It appears to be related to the pickle as understand from the error tracking on return format.read_array(fid, allow_pickle=allow_pickle, pickle_kwargs=pickle_kwargs) found in **~\AppData\Roaming\Python\Python37\site-packages\numpy\lib\npyio.py** in load**(file, mmap_mode, allow_pickle, fix_imports, encoding)**

I’m not sure how to address this. Any suggestions?

Hi @MZeglen,

I’m not 100% sure, but I think your issue is that you are trying to do the np.save operation on a Nengo probe object, rather than on the data. From the code you have included, this works:

p_inputOut = nengo.Probe(input0.output, synapse=0.01)
np.save((logPath+fileName),spa.similarity(sim.data[p_inputOut], vocab))
p_inputOut = np.save(logPath+fileName) # load in another file

whereas this does not:

p_mtr_speed = nengo.Probe(motor, synapse=0.01) 
np.save((logPath+"mtrSpeed_turtlebotFull"), p_mtr_speed) 
p_mtr_speed = np.load(logPath+fileName) # load in another file

And the difference between the two pieces of code is that one is using sim.data, whereas one uses the nengo.Probe object directly. Rather, I believe what you want for the second piece of code is something like this:

p_mtr_speed = nengo.Probe(motor, synapse=0.01) 
np.save((logPath+"mtrSpeed_turtlebotFull"), sim.data[p_mtr_speed]) 
p_mtr_speed = np.load(logPath+fileName) # load in another file

Let me know if that works for you. :slight_smile:

Thanks, @xchoo.

I just found the omission of sim.data[] was the issue yesterday. Such a simple mistake. I got a good laugh. I had included it in other portions but failed to do this with the newly added probes.

1 Like