Loihi in Nengo GUI

Hi, how can Loihi backend be inserted in the Nengo GUI interface?

I believe running nengo --backend=nengo_loihi should work. To my understanding, if you have the NxSDK installed, it should run on the loihi chip. Otherwise it will run on the loihi simulator.

Also, I don’t think it’s built to work with SCRUM in the GUI (at the moment), I think for now you can only use the loihi chip outside the GUI. So if you’re on the Intel servers this might be the only way to go for the time being. The ABR folks probably can shed more light on this, but this is my current understanding.

Thank you, but unfortunately it doesn´t work. I would like to have something similar to this one https://www.youtube.com/watch?v=nIsK7dSXBo0&index=24&t=0s&list=LLeCKOp-ccDDBs1OxXHrG8cQ
But i didn´t find any example where the block Loihi is used in GUI

This feature is still under development. You can track the progress of it here: https://github.com/nengo/nengo-loihi/pull/28. For now, though, you’ll have to stick with Python files or Jupyter Notebooks for running nengo_loihi code.

1 Like

I see the PR was closed unmerged, Is there a way to use nengo_loihi in nengo_gui now?

Hi @nwzins,

Unfortunately, NengoGUI doesn’t natively support NengoLoihi (at least, if you want to run it on the simulation on the Loihi hardware). I did manage to get it to work (although, it does run into weird issues needing constant restarts of NengoGUI) by doing this:

  • In your Nengo model add this extra code to the script. You can put this code anywhere in your code:
def on_start(sim):

def on_close(sim):
    sim.__exit__(None, None, None)
  • Then open up Nengo from the command line with the additional -b nengo_loihi (use nengo_loihi backend) option. E.g,
nengo -b nengo_loihi

Thank you! I’d tryied -b nengo_loihi but it would just crash or not fully start up or something, what do the enter/exit functions do differently?

Follow up question @xchoo, do you know what I’d need to add to use the Loihi hardware and not the loihi simulator?

The recommended way to use Nengo simulators (when running the model in Jupyter notebook or directly from the script) is to use the with context block, like so:

with nengo.Simulator(model) as sim:

In each of the backends, there is code that detects the context block and instantiates the appropriate objects to get the simulator to run properly. For the NengoLoihi backend in particular, when the context block is created, a connection to the Loihi hardware is made so that Nengo can talk to NxSDK (which in turn talks to the Loihi hardware).

NengoGUI, however, doesn’t use the with context blocks to create and run the simulators (it was a design decision influenced by the design of the NengoGUI backend). Rather, NengoGUI creates the simulator objects manually, like so:

sim = nengo.Simulator(model)
# do stuff
# do more GUI stuff

Creating a simulator object in this way doesn’t do exactly what creating the with context block does, and this is what the additional on_start and on_close functions aim to do. The __enter__() function is automatically called when the with context block is created, so it has to be manually called if you are creating the simulator object manually. Likewise, for when the context block is exited (the __exit__() function is called).

NengoLoihi checks to see if you have the NxSDK package installed in your environment in order to make the decision of whether or not to run it on the Loihi hardware. If NengoLoihi is able to import the NxSDK package successfully, it will (by default) use the Loihi hardware to run the network. If NengoLoihi is unable to import NxSDK, it will use the “emulator” by default.

If you are running your network in a Jupyter notebook or through a Python interpreter, you can force NengoLoihi to use one or the other by setting the target option when creating the nengo_loihi.Simulator. As an example, the following code forces NengoLoihi to use the emulator even if NxSDK is available in your Python environment.

with nengo_loihi.Simulator(model, ..., target="sim") as sim:

Unfortunately, if you are using NengoGUI, you can’t set this target option, so in NengoGUI, whether or not NengoLoihi uses the hardware or not depends solely on the availability of NxSDK in your Python environment.