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.

[1]:
from io import StringIO
import traceback
import warnings

import nengo
import nengo.spa


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

ValidationError in NengoObject (simplified)

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


nengo.rc.set('exceptions', 'simplified', str(True))
print_exc(nengo_obj_simple)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-2-d058d9a98e32>", line 3, in nengo_obj_simple
    nengo.Ensemble(n_neurons=0, dimensions=1)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 34, in __call__
    inst.__init__(*args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/ensemble.py", line 159, in __init__
    self.n_neurons = n_neurons
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 492, in __setattr__
    raise exc_info[1].with_traceback(None)
nengo.exceptions.ValidationError: Ensemble.n_neurons: Value must be greater than or equal to 1 (got 0)

ValidationError in NengoObject (full)

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


nengo.rc.set('exceptions', 'simplified', str(False))
print_exc(nengo_obj_full)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-3-67bf25be1872>", line 3, in nengo_obj_full
    nengo.Ensemble(n_neurons=0, dimensions=1)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 34, in __call__
    inst.__init__(*args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/ensemble.py", line 159, in __init__
    self.n_neurons = n_neurons
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 494, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 144, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 306, in coerce
    return super().coerce(instance, num)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 288, in coerce
    obj=instance,
nengo.exceptions.ValidationError: Ensemble.n_neurons: Value must be greater than or equal to 1 (got 0)

ValidationError in non-NengoObject

[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-d59cc247948f>", line 13, 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 "/mnt/d/Documents/nengo-repos/nengo/nengo/dists.py", line 121, 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)

[5]:
def nengo_obj_readonly():
    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_readonly)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-5-b923ead4b682>", line 5, in nengo_obj_readonly
    p.target = ens
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 492, in __setattr__
    raise exc_info[1].with_traceback(None)
nengo.exceptions.ReadonlyError: Probe.target: target is read-only and cannot be changed

ReadonlyError in NengoObject (full)

[6]:
def nengo_obj_readonly_full():
    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_readonly_full)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-6-50fa33d2e3bf>", line 5, in nengo_obj_readonly_full
    p.target = ens
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 494, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 144, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/probe.py", line 25, in coerce
    return super().coerce(probe, target)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 238, in coerce
    return super().coerce(instance, nengo_obj)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 190, 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

[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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-7-d1681b491ee5>", line 4, in ensemble
    ens.neurons = None
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 494, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/ensemble.py", line 186, in neurons
    raise ReadonlyError(attr="neurons", obj=self)
nengo.exceptions.ReadonlyError: Ensemble.neurons: neurons is read-only and cannot be changed
[8]:
def param():
    class Frozen(nengo.params.FrozenObject):
        p = nengo.params.Parameter('p', readonly=False)

    Frozen()


print_exc(param)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-8-1626fef62178>", line 5, in param
    Frozen()
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 609, 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

[9]:
def simclose():
    with nengo.Network() as net:
        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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-9-4c6658111f63>", line 6, in simclose
    sim.run(0.01)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 333, in run
    self.run_steps(steps, progress_bar=progress_bar)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 357, in run_steps
    self.step()
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 363, in step
    raise SimulatorClosed("Simulator cannot run because it is closed.")
nengo.exceptions.SimulatorClosed: Simulator cannot run because it is closed.

BuildtimeError

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


print_exc(builderror)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-10-2f33f615befa>", line 3, in builderror
    nengo.builder.Builder.build(model, "")
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 240, in build
    raise BuildError("Cannot build object of type %r" % type(obj).__name__)
nengo.exceptions.BuildError: Cannot build object of type 'str'

ZeroActivityError

[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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-11-a3326b906315>", line 5, in zeroactivity
    with nengo.Simulator(net):
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 126, in __init__
    self.model.build(network, progress=pt.next_stage("Building", "Build"))
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 133, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 242, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/network.py", line 94, in build_network
    model.build(conn)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 133, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 242, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/connection.py", line 267, in build_connection
    eval_points, decoders, solver_info = model.build(conn.solver, conn, rng)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 133, in build
    built = self.builder.build(self, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/builder.py", line 242, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/connection.py", line 176, in build_solver
    return build_decoders(model, conn, rng)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/connection.py", line 138, in build_decoders
    decoders, solver_info = wrapped_solver(conn, gain, bias, x, targets, rng=rng)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/connection.py", line 154, in solve_for_decoders
    "ranges of any neurons." % (conn, conn.pre_obj)
nengo.exceptions.BuildError: Building <Connection from <Ensemble (unlabeled) at 0x7f6ec4a84630> to <Ensemble (unlabeled) at 0x7f6ec4a84630>>: 'activities' matrix is all zero for <Ensemble (unlabeled) at 0x7f6ec4a84630>. This is because no evaluation points fall in the firing ranges of any neurons.

SpaParseError

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


print_exc(spaparse)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-12-1e3720fa54ce>", line 3, in spaparse
    vocab['a']
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/spa/vocab.py", line 147, in __getitem__
    raise SpaParseError("Semantic pointers must begin with a capital letter.")
nengo.exceptions.SpaParseError: Semantic pointers must begin with a capital letter.

SpaModuleError

[13]:
def spamodule():
    with nengo.spa.SPA():
        nengo.spa.State(1)


print_exc(spamodule)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-13-f078a80e616b>", line 3, in spamodule
    nengo.spa.State(1)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/spa/spa.py", line 157, in __exit__
    "%s must be set as an attribute of a SPA network" % (net)
nengo.exceptions.SpaModuleError: <State (unlabeled) at 0x7f6ef6cd4668> must be set as an attribute of a SPA network

ObsoleteError

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


print_exc(obsolete)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-14-4140151134ff>", line 5, in obsolete
    nengo.Probe(c, 'decoders')
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 34, in __call__
    inst.__init__(*args, **kwargs)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/probe.py", line 140, in __init__
    self.attr = attr if attr is not None else self.obj.probeable[0]
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 108, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 494, in __setattr__
    super().__setattr__(name, val)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/params.py", line 144, in __set__
    self.data[instance] = self.coerce(instance, value)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/probe.py", line 38, in coerce
    obj=probe,
nengo.exceptions.ValidationError: Probe.attr: Attribute 'decoders' is not probeable on <Connection from <Ensemble (unlabeled) at 0x7f6ec4a84c88> to <Ensemble (unlabeled) at 0x7f6ec4a84c88>>.
Probeable attributes: ('output', 'input', 'weights')

ConfigError

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


print_exc(config)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-15-cfb1b1956a05>", line 2, in config
    nengo.Network().config[object]
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/config.py", line 380, 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

[16]:
def simerror():
    with nengo.Network() as net:
        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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-16-ac0c575e31a9>", line 5, in simerror
    sim.run(0.003)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 333, in run
    self.run_steps(steps, progress_bar=progress_bar)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 357, in run_steps
    self.step()
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/simulator.py", line 368, in step
    step_fn()
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/operator.py", line 813, in step_simpyfunc
    % function_name(self.fn)
nengo.exceptions.SimulationError: Function '<lambda>' returned non-finite value

NetworkContextError

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


print_exc(context)
nengo.Network.context.clear()
Traceback (most recent call last):
  File "<ipython-input-17-39167fa7fced>", line 4, in context
    nengo.Ensemble(10, 1)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/base.py", line 36, in __call__
    nengo.Network.add(inst)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/network.py", line 123, in add
    raise NetworkContextError("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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-17-39167fa7fced>", line 4, in context
    nengo.Ensemble(10, 1)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/network.py", line 221, 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 0x7f6ec4a84a90>' but instead got 'bad'.

NeuronTypeError

[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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-18-58336fa3c09d>", line 3, in direct
    d.step_math(None, None, None)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/neurons.py", line 264, in step_math
    raise SimulationError("Direct mode neurons shouldn't be simulated.")
nengo.exceptions.SimulationError: Direct mode neurons shouldn't be simulated.

FingerprintError

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


print_exc(fingerprint)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-19-92e75003770e>", line 2, in fingerprint
    nengo.cache.Fingerprint(lambda x: x)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/cache.py", line 198, in __init__
    "Object of type %r cannot be fingerprinted." % type(obj).__name__
nengo.exceptions.FingerprintError: Object of type 'function' cannot be fingerprinted.

CacheIOError

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


print_exc(cacheio)
Traceback (most recent call last):
  File "<ipython-input-1-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-20-fc9d7715963f>", line 3, in cacheio
    nengo.utils.nco.read(sio)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/utils/nco.py", line 151, in read
    HEADER_FORMAT, header
TypeError: a bytes-like object is required, not 'str'

Unconvertible

[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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-21-389f0b51e578>", line 5, in unconvertible
    nengo.utils.builder.remove_passthrough_nodes(net.nodes, net.connections)
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/utils/builder.py", line 217, in remove_passthrough_nodes
    "Cannot remove a Node with a feedback connection"
nengo.exceptions.Unconvertible: Cannot remove a Node with a feedback connection

SignalError

[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-d59cc247948f>", line 13, in print_exc
    func()
  File "<ipython-input-22-f076f40747ab>", line 3, in signal
    s.initial_value = 0
  File "/mnt/d/Documents/nengo-repos/nengo/nengo/builder/signal.py", line 200, in initial_value
    raise SignalError("Cannot change initial value after initialization")
nengo.exceptions.SignalError: Cannot change initial value after initialization