-
Notifications
You must be signed in to change notification settings - Fork 174
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
A standard way for Simulators to free resources #739
Comments
Moreover it fits that |
+1 I think, it would be good to have a standard that all backends adhere to. It would be annoying if each backend has it's own way of closing. |
I would propose the following:
As long as no more than one simulator is created in a script, everything in those scripts can be kept as is. If more than one simulator in one script is created, one can either manage simulators with explicitly calling Note that the following works with a context manager: with Simulator(model) as sim:
sim.run(...)
data = sim.data[probe] # The sim object still exists to read out data, but run() calls may fail |
That proposal sounds right to me (and nice clarification on the interaction between I think I also agree with allowing |
nengo_spinnaker supports that. |
nengo_mpi would definitely benefit from this, and +1 to what's been proposed so far. |
This issue should be resolved with PR #859. |
Some backends need ways to indicate that they are finished and their resources are no longer needed. For example,
nengo_spinnaker
needs to put the SpiNNaker machine back into a clean state so that new programs can be loaded on (without rebooting the board).Right now, the
nengo_spinnaker
implementation does this with asim.close()
call. You can callsim.run(time)
multiple times, and then do asim.close()
when you are finished with the simulator. You cannot callsim.run(time)
after callingsim.close()
.It also supports using the
Simulator
as a context manager, with an empty__enter__
and a__exit__
that just callsself.close()
. Using the context manager is strictly optional.Right now, you must call
close
after running a Simulation. Otherwise, the board gets left in a state that means it needs to be physically reset before loading a new program. It might be possible to add anatexit
handler to do this, at the cost of a global list of un-closed Simulators (and this would be in addition to theclose
system, since we need to support running one Simulator and then another within the same program, such asnengo_gui
).As was discussed a bit in #737 , it's not clear whether we should add a
sim.close()
to all Simulators (and have it do nothing if the Simulator doesn't need to be closed), or whether this should be something that each backend that needs it can implement in their own way. I guess the first question is, which backends could use something like this? Would it be useful innengo_ocl
? What aboutnengo_mpi
ornengo_bluegene
?The second question is, if we do make a
close()
method standard, should we also include the context manager version?On the first question, I think this is something that will be needed with hardware backends if they are to run in
nengo_gui
. I'd like to add anatexit
handler tonengo_spinnaker
so that if people forget theclose
when writing scripts it will still get closed, but something explicit like this is still needed if people want to run multiple simulations in the same script. I can foresee a similar thing happening withnengo_brainstorm
andnengo_mpi
. So I think it'd be nice to just add a standard.close()
method to all Simulators. Of course, we can always just do aif hasattr(sim, 'close'): sim.close()
instead.On the second question, I'd vote that if we do support a
.close()
method we should also support being a context manager. It's only 4 lines of code, and this is exactly the sort of situation context managers are for.The text was updated successfully, but these errors were encountered: