New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated `Network.restore` calls fail #681

Closed
mstimberg opened this Issue Apr 19, 2016 · 2 comments

Comments

Projects
None yet
1 participant
@mstimberg
Member

mstimberg commented Apr 19, 2016

The following code will fail at the second restore:

In [1]: from brian2 import *

In [2]: G = NeuronGroup(1, 'v: 1')

In [3]: store()

In [4]: restore()

In [5]: restore()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-ad7bb0bcaaad> in <module>()
----> 1 restore()

/home/marcel/programming/brian2/brian2/core/magic.pyc in restore(name, filename)
    411     Network.restore
    412     '''
--> 413     magic_network.restore(name=name, filename=filename, level=1)
    414 
    415 

/home/marcel/programming/brian2/brian2/core/magic.pyc in restore(self, name, filename, level)
    244         '''
    245         self._update_magic_objects(level=level+1)
--> 246         super(MagicNetwork, self).restore(name=name, filename=filename)
    247         self.objects[:] = []
    248 

/home/marcel/programming/brian2/brian2/core/base.pyc in device_override_decorated_function(*args, **kwds)
    276                 return getattr(curdev, name)(*args, **kwds)
    277             else:
--> 278                 return func(*args, **kwds)
    279 
    280         device_override_decorated_function.__doc__ = func.__doc__

/home/marcel/programming/brian2/brian2/core/network.pyc in restore(self, name, filename)
    431             with open(filename, 'rb') as f:
    432                 state = pickle.load(f)[name]
--> 433         self.t_ = state.pop('0_t')
    434         clocks = set([obj.clock for obj in self.objects])
    435         restored_objects = set()

KeyError: '0_t'

The problem seems to be the state.pop which pops the 0_t value from the stored state (instead of e.g. popping it from a copy).

@mstimberg mstimberg added this to the 2.0 milestone Apr 19, 2016

@mstimberg

This comment has been minimized.

Show comment
Hide comment
@mstimberg

mstimberg Apr 19, 2016

Member

I mentioned this on the mailing list but not here: a simple workaround is to have an additional (under normal circumstances useless) store() after each restore(), this will recreate the stored state:

In [1]: from brian2 import *

In [2]: G = NeuronGroup(1, 'v: 1')

In [3]: store()

In [4]: restore()

In [5]: store()

In [6]: restore()

In [7]: store()

In [8]: restore()

In [9]: # ...
Member

mstimberg commented Apr 19, 2016

I mentioned this on the mailing list but not here: a simple workaround is to have an additional (under normal circumstances useless) store() after each restore(), this will recreate the stored state:

In [1]: from brian2 import *

In [2]: G = NeuronGroup(1, 'v: 1')

In [3]: store()

In [4]: restore()

In [5]: store()

In [6]: restore()

In [7]: store()

In [8]: restore()

In [9]: # ...

mstimberg added a commit that referenced this issue Apr 20, 2016

@mstimberg mstimberg self-assigned this Apr 20, 2016

@mstimberg

This comment has been minimized.

Show comment
Hide comment
@mstimberg

mstimberg Apr 20, 2016

Member

Another workaround: storing the state to disk is not affected:

In [1]: from brian2 import *

In [2]: G = NeuronGroup(1, 'v : 1')

In [3]: store(filename='stored_state.pickle')

In [4]: restore(filename='stored_state.pickle')

In [5]: restore(filename='stored_state.pickle')

In [6]:
Member

mstimberg commented Apr 20, 2016

Another workaround: storing the state to disk is not affected:

In [1]: from brian2 import *

In [2]: G = NeuronGroup(1, 'v : 1')

In [3]: store(filename='stored_state.pickle')

In [4]: restore(filename='stored_state.pickle')

In [5]: restore(filename='stored_state.pickle')

In [6]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment