Save/load state

A Python package that facilitates development and use of models of biological neural networks

Moderator: tom_morse

Post Reply
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Save/load state

Post by salvadord »

Question received by email from Andrew Knox:

"One other question. Ideally I’d like to be able to run the model for ~10 seconds to let it come to steady state, then save that state and run a number of simulations with different parameters from that point in time. What’s the best way to do this?

I had written some code that essentially boils down to

Code: Select all

netParams = specs.NetParams() 
simConfig = specs.SimConfig()
 
if firstrun:
        {do a bunch of stuff to set up simulation}
        simConfig.filename = 'sim_data'
 
else:
        sim.load(‘sim_data.pkl’)
 
sim.simulate()
sim.analyze()
sim.gatherData()
sim.saveData()

However, its giving me this error on the second run (ie when it’s trying to load sim_data.pkl):

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "absence.py", line 88, in <module>
    sim.load('sim_data.pkl')
  File "C:\ProgramData\Anaconda2\lib\site-packages\netpyne\wrappers.py", line 82, in load
    sim.loadAll(filename)
  File "C:\ProgramData\Anaconda2\lib\site-packages\netpyne\simFuncs.py", line 244, in loadAll
    loadNet(filename, data=data)
  File "C:\ProgramData\Anaconda2\lib\site-packages\netpyne\simFuncs.py", line 187, in loadNet
    cell.createNEURONObj(prop)  # use same syntax as when creating based on high-level specs
  File "C:\ProgramData\Anaconda2\lib\site-packages\netpyne\cell.py", line 451, in createNEURONObj
    setattr(sec['pointps'][pointpName]['hPointp'], pointpParamName, pointpParamValue)
LookupError: 'hPointp' is not a defined hoc variable name.
 

I wasn’t sure whether this was a bug, something specific that I’m doing wrong, or a more general misunderstanding of how load and save are supposed to be used.

Also, I thought about posting to the board, but then I couldn’t remember my login and it just became too much work…

Thanks,
Andrew"
salvadord
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Save/load state

Post by salvadord »

Hi Andrew,

Unfortunately, the save/load state feature in netpyne is still in the TO DO list, see here: https://github.com/Neurosim-lab/netpyne/issues/172 -- if you have a nice code example from your model you can add it as a comment to the github issue and that might help with the implementation.

The netpyne save command is used to save the netParams, simConfig, net and [/i]simData[/i] objects, i.e. the high-level specifications, simulation configuration, instantiated network and output simulation data. You can use this to e.g. load an instantiated network, which is faster than recreating it by applying all the high-level specs (rules), and to load and plot saved data etc. The error you got during loading of the network is probably a bug -- I will try to fix it for the next released version.

Something you could try is to run the network using netpyne and then save and load the state using standard NEURON commands. But I have never tested this, so not sure if any issues might arise.

The other option is of course to just simulate the first 10 seconds every time. Since netpyne is implemented as parallel NEURON code you can use mpi straight away to run parallel simulations, either in computers with multiple cores or large HPCs/supercomputers (e.g. see NSG -- www.nsgportal.org). Also, you might consider if perhaps you don't need the full 10 secs to achieve steady state.

Thanks
Salva
VVolk
Posts: 1
Joined: Thu Sep 09, 2021 1:45 pm

Re: Save/load state

Post by VVolk »

Hello,

I was wondering if there is a solution to this problem. When I try to use sim.load('file_name.pkl') I get the following error:

Code: Select all

Loading file model_output.pkl ...
  Done; file loading time = 0.22 s
Loading simConfig...
Loading netParams...
Loading net...
  Created 2 cells
  Created 0 connections
  Created 2 stims
Traceback (most recent call last):
  File "network_model_2MUs_restore.py", line 51, in <module>
    sim.load('model_output.pkl')
  File "C:\Users\VICTORIAVOLK\AppData\Local\Continuum\anaconda3\lib\site-packages\netpyne\sim\wrappers.py", line 152, in load
    sim.loadAll(filename, instantiate=instantiate, createNEURONObj=createNEURONObj)
  File "C:\Users\VICTORIAVOLK\AppData\Local\Continuum\anaconda3\lib\site-packages\netpyne\sim\load.py", line 285, in loadAll
    loadNet(filename, data=data, instantiate=instantiate, compactConnFormat=connFormat)
  File "C:\Users\VICTORIAVOLK\AppData\Local\Continuum\anaconda3\lib\site-packages\netpyne\sim\load.py", line 234, in loadNet
    cell.createNEURONObj(prop)  # use same syntax as when creating based on high-level specs
  File "C:\Users\VICTORIAVOLK\AppData\Local\Continuum\anaconda3\lib\site-packages\netpyne\cell\compartCell.py", line 415, in createNEURONObj
    setattr(sec['pointps'][pointpName]['hObj'], pointpParamName, pointpParamValue)
LookupError: 'hObj' is not a defined hoc variable name.
I have encountered this error using both NetPyNE 0.9.7 and 1.0.0.2.

Looking at the GitHub link from the previous reply by salvadord I saw the potential use of BBSaveState(). I was wondering if this was the fix and, if so, how to implement it.

Thanks!
Post Reply