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()
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-2-6e36c811bd24>", line 3, in nengo_obj
ens = nengo.Ensemble(n_neurons=0, dimensions=1)
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 35, in __call__
inst.__init__(*args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\ensemble.py", line 148, in __init__
self.n_neurons = n_neurons
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 456, in __setattr__
reraise(exc_info[0], exc_info[1], None)
File "d:\documents\nengo_repos\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)
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-3-9197d6770900>", line 3, in nengo_obj
ens = nengo.Ensemble(n_neurons=0, dimensions=1)
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 35, in __call__
inst.__init__(*args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\ensemble.py", line 148, in __init__
self.n_neurons = n_neurons
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 458, in __setattr__
super(SupportDefaultsMixin, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\params.py", line 124, in __set__
self.data[instance] = self.coerce(instance, value)
File "d:\documents\nengo_repos\nengo\nengo\params.py", line 271, in coerce
return super(IntParam, self).coerce(instance, num)
File "d:\documents\nengo_repos\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)
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-4-c5ba72006dad>", line 2, in dist
nengo.dists.PDF(x=[1, 1], p=[0.1, 0.2])
File "d:\documents\nengo_repos\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)
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-5-1d0b5dd0bd42>", line 5, in nengo_obj
p.target = ens
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 456, in __setattr__
reraise(exc_info[0], exc_info[1], None)
File "d:\documents\nengo_repos\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
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-6-a089d4f43453>", line 5, in nengo_obj
p.target = ens
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 458, in __setattr__
super(SupportDefaultsMixin, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\params.py", line 124, in __set__
self.data[instance] = self.coerce(instance, value)
File "d:\documents\nengo_repos\nengo\nengo\probe.py", line 24, in coerce
return super(TargetParam, self).coerce(probe, target)
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 226, in coerce
return super(NengoObjectParam, self).coerce(instance, nengo_obj)
File "d:\documents\nengo_repos\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
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-7-f06a59b96231>", line 4, in ensemble
ens.neurons = None
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 458, in __setattr__
super(SupportDefaultsMixin, self).__setattr__(name, val)
File "d:\documents\nengo_repos\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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-8-853aad8fd15a>", line 5, in param
f = Frozen()
File "d:\documents\nengo_repos\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
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-9-d6ec664b675d>", line 6, in simclose
sim.run(0.01)
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 321, in run
self.run_steps(steps, progress_bar=progress_bar)
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 345, in run_steps
self.step()
File "d:\documents\nengo_repos\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.
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-10-b1b0372de682>", line 3, in builderror
nengo.builder.Builder.build(model, "")
File "d:\documents\nengo_repos\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'
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-11-dfc293e55cd3>", line 5, in zeroactivity
with nengo.Simulator(net):
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 160, in __init__
progress=pt.next_stage("Building", "Build"))
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 123, in build
built = self.builder.build(self, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 218, in build
return cls.builders[obj_cls](model, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\network.py", line 113, in build_network
model.build(conn)
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 123, in build
built = self.builder.build(self, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 218, in build
return cls.builders[obj_cls](model, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\connection.py", line 258, in build_connection
conn.solver, conn, rng, transform)
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 123, in build
built = self.builder.build(self, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\builder.py", line 218, in build
return cls.builders[obj_cls](model, obj, *args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\builder\connection.py", line 164, in build_solver
return build_decoders(model, conn, rng, transform)
File "d:\documents\nengo_repos\nengo\nengo\builder\connection.py", line 120, in build_decoders
conn, gain, bias, x, targets, rng=rng, E=E)
File "d:\documents\nengo_repos\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 0x2991425b668> to <Ensemble (unlabeled) at 0x2991425b668>>: 'activities' matrix is all zero for <Ensemble (unlabeled) at 0x2991425b668>. This is because no evaluation points fall in the firing ranges of any neurons.
In [12]:
def spaparse():
vocab = nengo.spa.Vocabulary(16)
vocab['a']
print_exc(spaparse)
Traceback (most recent call last):
File "<ipython-input-1-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-12-a4683a73ea41>", line 3, in spaparse
vocab['a']
File "d:\documents\nengo_repos\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.
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-13-435380a533be>", line 3, in spamodule
st = nengo.spa.State(1)
File "d:\documents\nengo_repos\nengo\nengo\spa\spa.py", line 145, in __exit__
"a SPA network" % (net))
nengo.exceptions.SpaModuleError: <State (unlabeled) at 0x29913ac74a8> must be set as an attribute of a SPA network
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-14-e52d127bd928>", line 5, in obsolete
p = nengo.Probe(c, 'decoders')
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 35, in __call__
inst.__init__(*args, **kwargs)
File "d:\documents\nengo_repos\nengo\nengo\probe.py", line 126, in __init__
self.attr = attr if attr is not None else self.obj.probeable[0]
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 106, in __setattr__
super(NengoObject, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\config.py", line 458, in __setattr__
super(SupportDefaultsMixin, self).__setattr__(name, val)
File "d:\documents\nengo_repos\nengo\nengo\params.py", line 124, in __set__
self.data[instance] = self.coerce(instance, value)
File "d:\documents\nengo_repos\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.
In [15]:
def config():
nengo.Network().config[object]
print_exc(config)
Traceback (most recent call last):
File "<ipython-input-1-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-15-d4d5765b03c3>", line 2, in config
nengo.Network().config[object]
File "d:\documents\nengo_repos\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.
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-16-409b13b04d5a>", line 5, in simerror
sim.run(0.003)
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 321, in run
self.run_steps(steps, progress_bar=progress_bar)
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 345, in run_steps
self.step()
File "d:\documents\nengo_repos\nengo\nengo\simulator.py", line 356, in step
step_fn()
File "d:\documents\nengo_repos\nengo\nengo\builder\operator.py", line 774, in step_simpyfunc
function_name(self.fn))
nengo.exceptions.SimulationError: Function '<lambda>' returned non-finite value
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-40df65c4caac>", line 4, in context
ens = nengo.Ensemble(10, 1)
File "d:\documents\nengo_repos\nengo\nengo\base.py", line 37, in __call__
nengo.Network.add(inst)
File "d:\documents\nengo_repos\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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-17-40df65c4caac>", line 4, in context
ens = nengo.Ensemble(10, 1)
File "d:\documents\nengo_repos\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 0x299143592b0>' but instead got 'bad'.
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-18-b945a7fba508>", line 3, in direct
d.step_math(None, None, None)
File "d:\documents\nengo_repos\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.
In [19]:
def fingerprint():
nengo.cache.Fingerprint(lambda x: x)
print_exc(fingerprint)
Traceback (most recent call last):
File "<ipython-input-1-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-19-da0e15bb2fa5>", line 2, in fingerprint
nengo.cache.Fingerprint(lambda x: x)
File "d:\documents\nengo_repos\nengo\nengo\cache.py", line 162, in __init__
% type(obj).__name__)
nengo.exceptions.FingerprintError: Object of type 'function' cannot be fingerprinted.
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-20-f926726d3027>", line 4, in cacheio
nengo.utils.nco.read(sio)
File "d:\documents\nengo_repos\nengo\nengo\utils\nco.py", line 152, in read
struct.unpack(HEADER_FORMAT, header))
TypeError: a bytes-like object is required, not 'str'
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-21-f295108a2eb4>", line 5, in unconvertible
nengo.utils.builder.remove_passthrough_nodes(net.nodes, net.connections)
File "d:\documents\nengo_repos\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
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-b62501498822>", line 10, in print_exc
func()
File "<ipython-input-22-334f8676127c>", line 3, in signal
s.initial_value = 0
File "d:\documents\nengo_repos\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