Newbie Question: Simulator and plotting

Hi all,

I have installed anaconda and I use it to run the GUI.

I am doing a tutorial example and I am running into two problems:

with nengo.Simulator(model) as sim: # Create the simulator
sim.run(1) # Run it for 1 second

Simulator apparently doesnt run on the nengo browser GUI. How do I run it on an interpreter or on Spyder (Anaconda)?

%matplotlib inline
This line cannot be written directly in the code. It should be written in some IPython. How the heck do I do that?

I tried a variation like
from IPython import get_ipython
get_ipython().magic(‘matplotlib inline’)

And I get AttributeError: ‘NoneType’ object has no attribute ‘magic’

br,
Sherif

Hi Sherif,

Welcome to the Nengo Forum!

If you’re running your code in the Nengo GUI, then you do not need to worry about creating a Simulator object. The GUI will do this for you. If you do have a Simulator call in your code, that’s okay; the GUI will just stop executing your code at that point, and make its own Simulator object. Just click the “play” button (right-pointing arrow) in the bottom right corner to start your simulation. You’ll also have to right-click on some objects in the visualization of your network to request plots for them. When you start Nengo GUI without loading a file (e.g. by typing nengo at the command line), it should pop up a basic example of a small network. Here you can try right-clicking on network objects to request additional plots. Also, the Basic Usage section of the README gives an outline of how to use the GUI.

The %matplotlib inline call is only necessary if you are running in a Jupyter Notebook. In that case, then it should work as %matplotlib inline. What it does is make sure that any plots you create appear in-line in the notebook, rather than as separate windows.

If you’re not running in a Jupyter Notebook (for example, you’re just calling the script from the command line with something like python your_script_here.py), then you don’t need any of that (i.e. none of the get_ipython().magic(‘matplotlib inline’) stuff, either). Outside of Notebooks, though, you’ll need to make sure you either save your plots to files or use plt.show() to pop up windows with your plots. For more information about using Matplotlib, see this written tutorial or this video tutorial.

Thanks for the response. As for plotting, I started the first example:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel(‘some numbers’)
plt.show()

I get the error:
ValueError: signal only works in main thread
on the line: plt.show()

Where/how are you running the script?

If you’re running in the GUI, then do not use Matplotlib. You can create plots in the GUI by right-clicking on objects in the main view pane and selecting different types of plots.