Skip to content

Jupyter / IPython Notebooks#

It is possible to use ANNarchy in Jupyter / IPython notebooks. Several examples are provided in the examples directory of the source distribution.

There are nevertheless two things to take into account when re-running cells:

ANNarchy uses global variables to store the populations and projections#

Internally, there is a network manager that stores which population and projection has been declared. It is empty when starting a script, but it can know anything about the Jupyter cells. Here are the main consequences:

  1. If you re-run the line from ANNarchy import *, Python will not clear the stored populations and projections (by design, as ANNarchy is already cached)

  2. If you re-run a cell creating a population or projection, it will create a new population, not replace the previous one.

  3. If you create a new population / projection after a call to compile() in the current kernel, this will lead to an error, as the network is already compiled and new objects cannot (yet) be added on the fly.

The solution to these problems is to call the clear() command right after importing ANNarchy. This deletes all created objects and puts ANNarchy in a "clean" state:

from ANNarchy import *
clear()
ANNarchy 4.7 (4.7.3b) on darwin (posix).

When you change something to the parameters of your network, you can re-run this cell, as well as all cells defining your network. You will then be able to call compile() again.

This is equivalent to a reset of your network. However, if the structure of your network changes (new populations, changed equations), this will have no effect because of the second issue.

Python cannot dynamically reload modules#

If you change something in the definition of the neurons or synapses (anything that usually provoke a recompilation), this will have NO effect in the notebook, even if the network is successfully recompiled.

Python is unable to reload libraries dynamically at runtime (). The C++ core actually running the simulation is imported as a dynamic library, so the result of the recompilation will not be reloaded.

The only solution is to restart the kernel after all structural changes to the network.