Exceptions

This should be an exhaustive list of the exceptions that can be raised by Nengo, and how they appear when they occur.

The exceptions are ordered roughly by how commonly we expect them to occur.

In [1]:
import traceback
import warnings
import nengo
import nengo.spa

def print_exc(func):
    try:
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            func()
    except:
        traceback.print_exc()

ValidationError in NengoObject (simplified)

In [2]:
def nengo_obj():
    with nengo.Network():
        ens = nengo.Ensemble(n_neurons=0, dimensions=1)


nengo.rc.set('exceptions', 'simplified', str(True))
print_exc(nengo_obj)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-2-307da82db606>", line 3, in nengo_obj
    ens = nengo.Ensemble(n_neurons=0, dimensions=1)
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 35, in __call__
    inst.__init__(*args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/ensemble.py", line 148, in __init__
    self.n_neurons = n_neurons
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 456, in __setattr__
    reraise(exc_info[0], exc_info[1], None)
  File "/home/travis/build/nengo/nengo/nengo/utils/compat.py", line 99, in reraise
    raise value.with_traceback(tb)
nengo.exceptions.ValidationError: Ensemble.n_neurons: Value must be greater than or equal to 1 (got 0)

ValidationError in NengoObject (full)

In [3]:
def nengo_obj():
    with nengo.Network():
        ens = nengo.Ensemble(n_neurons=0, dimensions=1)


nengo.rc.set('exceptions', 'simplified', str(False))
print_exc(nengo_obj)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-3-071b8e2ff919>", line 3, in nengo_obj
    ens = nengo.Ensemble(n_neurons=0, dimensions=1)
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 35, in __call__
    inst.__init__(*args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/ensemble.py", line 148, in __init__
    self.n_neurons = n_neurons
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 458, in __setattr__
    super(SupportDefaultsMixin, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 124, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 271, in coerce
    return super(IntParam, self).coerce(instance, num)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 255, in coerce
    num), attr=self.name, obj=instance)
nengo.exceptions.ValidationError: Ensemble.n_neurons: Value must be greater than or equal to 1 (got 0)

ValidationError in non-NengoObject

In [4]:
def dist():
    nengo.dists.PDF(x=[1, 1], p=[0.1, 0.2])


print_exc(dist)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-4-f390bafc04da>", line 2, in dist
    nengo.dists.PDF(x=[1, 1], p=[0.1, 0.2])
  File "/home/travis/build/nengo/nengo/nengo/dists.py", line 68, in __init__
    "PDF must sum to one (sums to %f)" % psum, attr='p', obj=self)
nengo.exceptions.ValidationError: PDF.p: PDF must sum to one (sums to 0.300000)

ReadonlyError in NengoObject (simplified)

In [5]:
def nengo_obj():
    with nengo.Network():
        ens = nengo.Ensemble(n_neurons=10, dimensions=1)
        p = nengo.Probe(ens)
        p.target = ens


nengo.rc.set('exceptions', 'simplified', str(True))
print_exc(nengo_obj)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-5-90d83dcd00de>", line 5, in nengo_obj
    p.target = ens
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 456, in __setattr__
    reraise(exc_info[0], exc_info[1], None)
  File "/home/travis/build/nengo/nengo/nengo/utils/compat.py", line 99, in reraise
    raise value.with_traceback(tb)
nengo.exceptions.ReadonlyError: Probe.target: target is read-only and cannot be changed

ReadonlyError in NengoObject (full)

In [6]:
def nengo_obj():
    with nengo.Network():
        ens = nengo.Ensemble(n_neurons=10, dimensions=1)
        p = nengo.Probe(ens)
        p.target = ens


nengo.rc.set('exceptions', 'simplified', str(False))
print_exc(nengo_obj)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-6-e63cc3b8fd29>", line 5, in nengo_obj
    p.target = ens
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 458, in __setattr__
    super(SupportDefaultsMixin, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 124, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/home/travis/build/nengo/nengo/nengo/probe.py", line 24, in coerce
    return super(TargetParam, self).coerce(probe, target)
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 226, in coerce
    return super(NengoObjectParam, self).coerce(instance, nengo_obj)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 166, in coerce
    raise ReadonlyError(attr=self.name, obj=instance)
nengo.exceptions.ReadonlyError: Probe.target: target is read-only and cannot be changed

ReadonlyError in non-NengoObject

In [7]:
def ensemble():
    with nengo.Network():
        ens = nengo.Ensemble(n_neurons=10, dimensions=1)
        ens.neurons = None


print_exc(ensemble)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-7-d1681b491ee5>", line 4, in ensemble
    ens.neurons = None
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 458, in __setattr__
    super(SupportDefaultsMixin, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/ensemble.py", line 175, in neurons
    raise ReadonlyError(attr="neurons", obj=self)
nengo.exceptions.ReadonlyError: Ensemble.neurons: neurons is read-only and cannot be changed
In [8]:
def param():
    class Frozen(nengo.params.FrozenObject):
        p = nengo.params.Parameter('p', readonly=False)

    f = Frozen()


print_exc(param)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-8-b63706febe71>", line 5, in param
    f = Frozen()
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 501, in __init__
    raise ReadonlyError(attr=p, obj=self, msg=msg)
nengo.exceptions.ReadonlyError: Frozen.Parameter('p', default=Unconfigurable, optional=False, readonly=False): All parameters of a FrozenObject must be readonly

SimulatorClosed

In [9]:
def simclose():
    with nengo.Network() as net:
        e = nengo.Ensemble(10, 1)
    with nengo.Simulator(net) as sim:
        sim.run(0.01)
    sim.run(0.01)


print_exc(simclose)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-9-62a65039c008>", line 6, in simclose
    sim.run(0.01)
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 321, in run
    self.run_steps(steps, progress_bar=progress_bar)
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 345, in run_steps
    self.step()
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 351, in step
    raise SimulatorClosed("Simulator cannot run because it is closed.")
nengo.exceptions.SimulatorClosed: Simulator cannot run because it is closed.

BuildtimeError

In [10]:
def builderror():
    model = nengo.builder.Model()
    nengo.builder.Builder.build(model, "")


print_exc(builderror)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-10-2f33f615befa>", line 3, in builderror
    nengo.builder.Builder.build(model, "")
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 216, in build
    "Cannot build object of type %r" % type(obj).__name__)
nengo.exceptions.BuildError: Cannot build object of type 'str'

ZeroActivityError

In [11]:
def zeroactivity():
    with nengo.Network() as net:
        e = nengo.Ensemble(1, 1, gain=[0], bias=[-1], encoders=[[1]])
        nengo.Connection(e, e)
    with nengo.Simulator(net):
        pass


print_exc(zeroactivity)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-11-a3326b906315>", line 5, in zeroactivity
    with nengo.Simulator(net):
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 160, in __init__
    progress=pt.next_stage("Building", "Build"))
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 123, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 218, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/network.py", line 113, in build_network
    model.build(conn)
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 123, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 218, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/connection.py", line 258, in build_connection
    conn.solver, conn, rng, transform)
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 123, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/builder.py", line 218, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/builder/connection.py", line 164, in build_solver
    return build_decoders(model, conn, rng, transform)
  File "/home/travis/build/nengo/nengo/nengo/builder/connection.py", line 120, in build_decoders
    conn, gain, bias, x, targets, rng=rng, E=E)
  File "/home/travis/build/nengo/nengo/nengo/builder/connection.py", line 133, in solve_for_decoders
    "ranges of any neurons." % (conn, conn.pre_obj))
nengo.exceptions.BuildError: Building <Connection from <Ensemble (unlabeled) at 0x7ff09653c390> to <Ensemble (unlabeled) at 0x7ff09653c390>>: 'activities' matrix is all zero for <Ensemble (unlabeled) at 0x7ff09653c390>. This is because no evaluation points fall in the firing ranges of any neurons.

SpaParseError

In [12]:
def spaparse():
    vocab = nengo.spa.Vocabulary(16)
    vocab['a']


print_exc(spaparse)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-12-1e3720fa54ce>", line 3, in spaparse
    vocab['a']
  File "/home/travis/build/nengo/nengo/nengo/spa/vocab.py", line 138, in __getitem__
    "Semantic pointers must begin with a capital letter.")
nengo.exceptions.SpaParseError: Semantic pointers must begin with a capital letter.

SpaModuleError

In [13]:
def spamodule():
    with nengo.spa.SPA() as net:
        st = nengo.spa.State(1)


print_exc(spamodule)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-13-b1d3bdbc8b89>", line 3, in spamodule
    st = nengo.spa.State(1)
  File "/home/travis/build/nengo/nengo/nengo/spa/spa.py", line 145, in __exit__
    "a SPA network" % (net))
nengo.exceptions.SpaModuleError: <State (unlabeled) at 0x7ff0a0654128> must be set as an attribute of a SPA network

ObsoleteError

In [14]:
def obsolete():
    with nengo.Network() as net:
        e = nengo.Ensemble(10, 1)
        c = nengo.Connection(e, e)
        p = nengo.Probe(c, 'decoders')


print_exc(obsolete)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-14-21a80acb6227>", line 5, in obsolete
    p = nengo.Probe(c, 'decoders')
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 35, in __call__
    inst.__init__(*args, **kwargs)
  File "/home/travis/build/nengo/nengo/nengo/probe.py", line 126, in __init__
    self.attr = attr if attr is not None else self.obj.probeable[0]
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 458, in __setattr__
    super(SupportDefaultsMixin, self).__setattr__(name, val)
  File "/home/travis/build/nengo/nengo/nengo/params.py", line 124, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/home/travis/build/nengo/nengo/nengo/probe.py", line 35, in coerce
    since="v2.1.0")
nengo.exceptions.ObsoleteError: Obsolete since v2.1.0: 'decoders' and 'transform' are now combined into 'weights'. Probe 'weights' instead.

ConfigError

In [15]:
def config():
    nengo.Network().config[object]


print_exc(config)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-15-cfb1b1956a05>", line 2, in config
    nengo.Network().config[object]
  File "/home/travis/build/nengo/nengo/nengo/config.py", line 349, in __getitem__
    "Call 'configures(%(name)s)' first." % {'name': key.__name__})
nengo.exceptions.ConfigError: Type 'object' is not set up for configuration. Call 'configures(object)' first.

SimulationError

In [16]:
def simerror():
    with nengo.Network() as net:
        n = nengo.Node(lambda t: None if t > 0.002 else 1.0)
    with nengo.Simulator(net) as sim:
        sim.run(0.003)


print_exc(simerror)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-16-df8408000318>", line 5, in simerror
    sim.run(0.003)
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 321, in run
    self.run_steps(steps, progress_bar=progress_bar)
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 345, in run_steps
    self.step()
  File "/home/travis/build/nengo/nengo/nengo/simulator.py", line 356, in step
    step_fn()
  File "/home/travis/build/nengo/nengo/nengo/builder/operator.py", line 774, in step_simpyfunc
    function_name(self.fn))
nengo.exceptions.SimulationError: Function '<lambda>' returned non-finite value

NetworkContextError

In [17]:
def context():
    with nengo.Network():
        nengo.Network.context.append("bad")
        ens = nengo.Ensemble(10, 1)


print_exc(context)
nengo.Network.context.clear()
Traceback (most recent call last):
  File "<ipython-input-17-72d05208441a>", line 4, in context
    ens = nengo.Ensemble(10, 1)
  File "/home/travis/build/nengo/nengo/nengo/base.py", line 37, in __call__
    nengo.Network.add(inst)
  File "/home/travis/build/nengo/nengo/nengo/network.py", line 118, in add
    "Current context (%s) is not a network" % network)
nengo.exceptions.NetworkContextError: Current context (bad) is not a network

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-17-72d05208441a>", line 4, in context
    ens = nengo.Ensemble(10, 1)
  File "/home/travis/build/nengo/nengo/nengo/network.py", line 211, in __exit__
    "to be '%s' but instead got '%s'." % (self, network))
nengo.exceptions.NetworkContextError: Network.context in bad state; was expecting current context to be '<Network (unlabeled) at 0x7ff09653c4e0>' but instead got 'bad'.

NeuronTypeError

In [18]:
def direct():
    d = nengo.neurons.Direct()
    d.step_math(None, None, None)


print_exc(direct)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-18-58336fa3c09d>", line 3, in direct
    d.step_math(None, None, None)
  File "/home/travis/build/nengo/nengo/nengo/neurons.py", line 221, in step_math
    raise SimulationError("Direct mode neurons shouldn't be simulated.")
nengo.exceptions.SimulationError: Direct mode neurons shouldn't be simulated.

FingerprintError

In [19]:
def fingerprint():
    nengo.cache.Fingerprint(lambda x: x)


print_exc(fingerprint)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-19-92e75003770e>", line 2, in fingerprint
    nengo.cache.Fingerprint(lambda x: x)
  File "/home/travis/build/nengo/nengo/nengo/cache.py", line 162, in __init__
    % type(obj).__name__)
nengo.exceptions.FingerprintError: Object of type 'function' cannot be fingerprinted.

CacheIOError

In [20]:
def cacheio():
    from nengo.utils.compat import StringIO
    sio = StringIO("a" * 40)
    nengo.utils.nco.read(sio)


print_exc(cacheio)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-20-cd7f7664677f>", line 4, in cacheio
    nengo.utils.nco.read(sio)
  File "/home/travis/build/nengo/nengo/nengo/utils/nco.py", line 152, in read
    struct.unpack(HEADER_FORMAT, header))
TypeError: a bytes-like object is required, not 'str'

Unconvertible

In [21]:
def unconvertible():
    with nengo.Network() as net:
        n = nengo.Node(output=None, size_in=1)
        nengo.Connection(n, n, synapse=None)
    nengo.utils.builder.remove_passthrough_nodes(net.nodes, net.connections)


print_exc(unconvertible)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-21-389f0b51e578>", line 5, in unconvertible
    nengo.utils.builder.remove_passthrough_nodes(net.nodes, net.connections)
  File "/home/travis/build/nengo/nengo/nengo/utils/builder.py", line 233, in remove_passthrough_nodes
    "Cannot remove a Node with a feedback connection")
nengo.exceptions.Unconvertible: Cannot remove a Node with a feedback connection

SignalError

In [22]:
def signal():
    s = nengo.builder.signal.Signal([1])
    s.initial_value = 0


print_exc(signal)
Traceback (most recent call last):
  File "<ipython-input-1-de550d58b263>", line 10, in print_exc
    func()
  File "<ipython-input-22-f076f40747ab>", line 3, in signal
    s.initial_value = 0
  File "/home/travis/build/nengo/nengo/nengo/builder/signal.py", line 146, in initial_value
    raise SignalError("Cannot change initial value after initialization")
nengo.exceptions.SignalError: Cannot change initial value after initialization