nengo / nengo-dl

Deep learning integration for Nengo
https://www.nengo.ai/nengo-dl
Other
88 stars 22 forks source link

Reopening the simulator raises an obscure error #115

Closed arvoelke closed 4 years ago

arvoelke commented 4 years ago

Version: master

Minimal reproducer

sim = nengo_dl.Simulator(nengo.Network())
with sim:
    pass
with sim:
    pass

Stack trace

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-f89be4cbbd16> in <module>
      2 with sim:
      3     pass
----> 4 with sim:
      5     pass

~/git/nengo-dl/nengo_dl/simulator.py in __enter__(self)
   1905 
   1906     def __enter__(self):
-> 1907         self._graph_context = self.graph.as_default()
   1908         self._device_context = self.graph.device(self.tensor_graph.device)
   1909 

AttributeError: 'NoneType' object has no attribute 'as_default'

Expected behaviour

Would expect either to be able to reopen the simulator (IMO useful for interactively coding in jupyter), or to get a more informative error message.

tbekolay commented 4 years ago

Reopening the simulator is definitely not a use case we can support on all backends, so I don't think any backend should allow it. A more informative error message seems appropriate though.

drasmuss commented 4 years ago

We should probably add a test for this in Nengo core as well (asserting that you can't reopen a closed Simulator).