Reference simulator

Nengo is designed so that models created with the Nengo modeling API work on a variety of different simulators. Simulators have been created to take advantage of GPUs and neuromorphic hardware.

Nengo comes with a simulator that is relatively fast, but works on general purpose computers. For most users, the only thing that you need to know about the reference simulator is how to create and close a nengo.Simulator instance.

class nengo.Simulator(network, dt=0.001, seed=None, model=None)[source]

Reference simulator for Nengo models.

The simulator takes a Network and builds internal data structures to run the model defined by that network. Run the simulator with the run method, and access probed data through the data attribute.

Building and running the simulation may allocate resources like files and sockets. To properly free these resources, call the Simulator.close method. Alternatively, Simulator.close will automatically be called if you use the with syntax:

with nengo.Simulator(my_network) as sim:
    sim.run(0.1)
print(sim.data[my_probe])

Note that the data attribute is still accessible even when a simulator has been closed. Running the simulator, however, will raise an error.

Parameters:

network : Network or None

A network object to the built and then simulated. If None, then a Model with the build model must be provided instead.

dt : float, optional (Default: 0.001)

The length of a simulator timestep, in seconds.

seed : int, optional (Default: None)

A seed for all stochastic operators used in this simulator.

model : Model, optional (Default: None)

A Model that contains build artifacts to be simulated. Usually the simulator will build this model for you; however, if you want to build the network manually, or you want to inject build artifacts in the model before building the network, then you can pass in a Model instance.

Attributes

closed (bool) Whether the simulator has been closed. Once closed, it cannot be reopened.
data (ProbeDict) The ProbeDict mapping from Nengo objects to the data associated with those objects. In particular, each Probe maps to the data probed while running the simulation.
dg (dict) A dependency graph mapping from each Operator to the operators that depend on that operator.
model (Model) The Model containing the signals and operators necessary to simulate the network.
signals (SignalDict) The SignalDict mapping from Signal instances to NumPy arrays.
dt

(float) The time step of the simulator.

n_steps

(int) The current time step of the simulator.

time

(float) The current time of the simulator.

close()[source]

Closes the simulator.

Any call to Simulator.run, Simulator.run_steps, Simulator.step, and Simulator.reset on a closed simulator raises a SimulatorClosed exception.

reset(seed=None)[source]

Reset the simulator state.

Parameters:

seed : int, optional

A seed for all stochastic operators used in the simulator. This will change the random sequences generated for noise or inputs (e.g. from processes), but not the built objects (e.g. ensembles, connections).

run(time_in_seconds, progress_bar=True)[source]

Simulate for the given length of time.

Parameters:

time_in_seconds : float

Amount of time to run the simulation for.

progress_bar : bool or ProgressBar or ProgressUpdater, optional (Default: True)

Progress bar for displaying the progress of the simulation run.

If True, the default progress bar will be used. If False, the progress bar will be disabled. For more control over the progress bar, pass in a ProgressBar or ProgressUpdater instance.

run_steps(steps, progress_bar=True)[source]

Simulate for the given number of dt steps.

Parameters:

steps : int

Number of steps to run the simulation for.

progress_bar : bool or ProgressBar or ProgressUpdater, optional (Default: True)

Progress bar for displaying the progress of the simulation run.

If True, the default progress bar will be used. If False, the progress bar will be disabled. For more control over the progress bar, pass in a ProgressBar or ProgressUpdater instance.

step()[source]

Advance the simulator by 1 step (dt seconds).

trange(dt=None)[source]

Create a vector of times matching probed data.

Note that the range does not start at 0 as one might expect, but at the first timestep (i.e., dt).

Parameters:

dt : float, optional (Default: None)

The sampling period of the probe to create a range for. If None, the simulator’s dt will be used.

The build process

The build process translates a Nengo model to a set of data buffers (Signal instances) and computational operations (Operator instances) which implement the Nengo model defined with the modeling API. The build process is central to how the reference simulator works, and details how Nengo can be extended to include new neuron types, learning rules, and other components.

Bekolay et al., 2014 provides a high-level description and detailed picture of the build process. For lower-level details and reference documentation, read on.

class nengo.builder.Signal(initial_value, name=None, base=None, readonly=False)[source]

Represents data or views onto data within a Nengo simulation.

Signals are tightly coupled to NumPy arrays, which is how live data is represented in a Nengo simulation. Signals provide a view onto the important metadata of the live NumPy array, and maintain the original value of the array in order to reset the simulation to the initial state.

Parameters:

initial_value : array_like

The initial value of the signal. Much of the metadata tracked by the Signal is based on this array as well (e.g., dtype).

name : str, optional (Default: None)

Name of the signal. Primarily used for debugging. If None, the memory location of the Signal will be used.

base : Signal, optional (Default: None)

The base signal, if this signal is a view on another signal. Linking the two signals with the base argument is necessary to ensure that their live data is also linked.

readonly : bool, optional (Default: False)

Whether this signal and its related live data should be marked as readonly. Writing to these arrays will raise an exception.

base

(Signal or None) The base signal, if this signal is a view.

Linking the two signals with the base argument is necessary to ensure that their live data is also linked.

dtype

(numpy.dtype) Data type of the signal (e.g., float64).

elemoffset

(int) Offset of data from base in elements.

elemstrides

(int) Strides of data in elements.

initial_value

(numpy.ndarray) Initial value of the signal.

Much of the metadata tracked by the Signal is based on this array as well (e.g., dtype).

is_view

(bool) True if this Signal is a view on another Signal.

itemsize

(int) Size of an array element in bytes.

name

(str) Name of the signal. Primarily used for debugging.

ndim

(int) Number of array dimensions.

offset

(int) Offset of data from base in bytes.

readonly

(bool) Whether associated live data can be changed.

shape

(tuple) Tuple of array dimensions.

size

(int) Total number of elements.

strides

(tuple) Strides of data in bytes.

column()[source]

Return a view on this signal with column vector shape.

may_share_memory(other)[source]

Determine if two signals might overlap in memory.

This comparison is not exact and errs on the side of false positives. See numpy.may_share_memory for more details.

Parameters:

other : Signal

The other signal we are investigating.

reshape(*shape)[source]

Return a view on this signal with a different shape.

Note that reshape cannot change the overall size of the signal. See numpy.reshape for more details.

Any number of integers can be passed to this method, describing the desired shape of the returned signal.

row()[source]

Return a view on this signal with row vector shape.

class nengo.builder.Operator(tag=None)[source]

Base class for operator instances understood by Nengo.

During one simulator timestep, a Signal can experience

  1. at most one set operator (optional)
  2. any number of increments
  3. any number of reads
  4. at most one update

in this specific order.

A set defines the state of the signal at time \(t\), the start of the simulation timestep. That state can then be modified by increment operations. A signal’s state will only be read after all increments are complete. The state is then finalized by an update, which denotes the state that the signal should be at time \(t + dt\).

Each operator must keep track of the signals that it manipulates, and which of these four types of manipulations is done to each signal so that the simulator can order all of the operators properly.

Note

There are intentionally no default values for the reads, sets, incs, and updates properties to ensure that subclasses explicitly set these values.

Parameters:

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Attributes

tag (str or None) A label associated with the operator, for debugging purposes.
incs

Signals incremented by this operator.

Increments will be applied after sets (if it is set), and before reads.

reads

Signals that are read and not modified by this operator.

Reads occur after increments, and before updates.

sets

Signals set by this operator.

Sets occur first, before increments. A signal that is set here cannot be set or updated by any other operator.

updates

Signals updated by this operator.

Updates are the last operation to occur to a signal.

init_signals(signals)[source]

Initialize the signals associated with this operator.

The signals will be initialized into signals. Operator subclasses that use extra buffers should create them here.

Parameters:

signals : SignalDict

A mapping from signals to their associated live ndarrays.

make_step(signals, dt, rng)[source]

Returns a callable that performs the desired computation.

This method must be implemented by subclasses. To fully understand what an operator does, look at its implementation of make_step.

Parameters:

signals : SignalDict

A mapping from signals to their associated live ndarrays.

dt : float

Length of each simulation timestep, in seconds.

rng : numpy.random.RandomState

Random number generator for stochastic operators.

Operators

class nengo.builder.operator.Reset(dst, value=0, tag=None)[source]

Assign a constant value to a Signal.

Implements dst[...] = value.

Parameters:

dst : Signal

The Signal to reset.

value : float, optional (Default: 0)

The constant value to which dst is set.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [dst]
  2. incs []
  3. reads []
  4. updates []

Attributes

dst (Signal) The Signal to reset.
tag (str or None) A label associated with the operator, for debugging purposes.
value (float) The constant value to which dst is set.
class nengo.builder.operator.Copy(dst, src, tag=None)[source]

Assign the value of one signal to another.

Implements dst[...] = src.

Parameters:

dst : Signal

The signal that will be assigned to (set).

src : Signal

The signal that will be copied (read).

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [dst]
  2. incs []
  3. reads [src]
  4. updates []

Attributes

dst (Signal) The signal that will be assigned to (set).
src (Signal) The signal that will be copied (read).
tag (str or None) A label associated with the operator, for debugging purposes.
class nengo.builder.operator.SlicedCopy(dst, src, dst_slice=Ellipsis, src_slice=Ellipsis, inc=False, tag=None)[source]

Assign the value of a slice of one signal to another slice.

Implements dst[dst_slice] = src[src_slice].

This operator can also implement dst[dst_slice] += src[src_slice] using the parameter inc.

Parameters:

dst : Signal

The signal that will be assigned to (set).

src : Signal

The signal that will be copied (read).

dst_slice : slice or Ellipsis, optional (Default: Ellipsis)

Slice associated with dst.

src_slice : slice or Ellipsis, optional (Default: Ellipsis)

Slice associated with src

inc : bool, optional (Default: False)

Whether this should be an increment rather than a copy.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [] if inc else [dst]
  2. incs [dst] if inc else []
  3. reads [src]
  4. updates []

Attributes

dst (Signal) The signal that will be assigned to (set).
dst_slice (list or Ellipsis) Indices associated with dst.
src (Signal) The signal that will be copied (read).
src_slice (list or Ellipsis) Indices associated with src
tag (str or None) A label associated with the operator, for debugging purposes.
class nengo.builder.operator.ElementwiseInc(A, X, Y, tag=None)[source]

Increment signal Y by A * X (with broadcasting).

Implements Y[...] += A * X.

Parameters:

A : Signal

The first signal to be multiplied.

X : Signal

The second signal to be multiplied.

Y : Signal

The signal to be incremented.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets []
  2. incs [Y]
  3. reads [A, X]
  4. updates []

Attributes

A (Signal) The first signal to be multiplied.
tag (str or None) A label associated with the operator, for debugging purposes.
X (Signal) The second signal to be multiplied.
Y (Signal) The signal to be incremented.
class nengo.builder.operator.DotInc(A, X, Y, tag=None)[source]

Increment signal Y by dot(A, X).

Implements Y[...] += np.dot(A, X).

Note

Currently, this only supports matrix-vector multiplies for compatibility with Nengo OCL.

Parameters:

A : Signal

The first signal to be multiplied.

X : Signal

The second signal to be multiplied.

Y : Signal

The signal to be incremented.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets []
  2. incs [Y]
  3. reads [A, X]
  4. updates []

Attributes

A (Signal) The first signal to be multiplied.
tag (str or None) A label associated with the operator, for debugging purposes.
X (Signal) The second signal to be multiplied.
Y (Signal) The signal to be incremented.
class nengo.builder.operator.TimeUpdate(step, time, tag=None)[source]

Updates the simulation step and time.

Implements step[...] += 1 and time[...] = step * dt.

A separate operator is used (rather than a combination of Copy and DotInc) so that other backends can manage these important parts of the simulation state separately from other signals.

Parameters:

step : Signal

The signal associated with the integer step counter.

time : Signal

The signal associated with the time (a float, in seconds).

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [step, time]
  2. incs []
  3. reads []
  4. updates []

Attributes

step (Signal) The signal associated with the integer step counter.
tag (str or None) A label associated with the operator, for debugging purposes.
time (Signal) The signal associated with the time (a float, in seconds).
class nengo.builder.operator.PreserveValue(dst, tag=None)[source]

Marks a signal as set for the graph checker.

This operator does no computation. It simply marks a signal as set, allowing us to apply other ops to signals that we want to preserve their value across multiple time steps. It is used primarily for learning rules.

Parameters:

dst : Signal

The signal whose value we want to preserve.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [dst]
  2. incs []
  3. reads []
  4. updates []

Attributes

dst (Signal) The signal whose value we want to preserve.
tag (str or None) A label associated with the operator, for debugging purposes.
class nengo.builder.operator.SimPyFunc(output, fn, t, x, tag=None)[source]

Set a signal to a Python function with optional arguments.

Implements output[...] = fn(*args) where args can include the current simulation time t and an input signal x.

Note that output may also be None, in which case the function is called but no output is captured.

Parameters:

output : Signal or None

The signal to be set. If None, the function is still called.

fn : callable

The function to call.

t : Signal or None

The signal associated with the time (a float, in seconds). If None, the time will not be passed to fn.

x : Signal or None

An input signal to pass to fn. If None, an input signal will not be passed to fn.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [] if output is None else [output]
  2. incs []
  3. reads ([] if t is None else [t]) + ([] if x is None else [x])
  4. updates []

Attributes

fn (callable) The function to call.
output (Signal or None) The signal to be set. If None, the function is still called.
t (Signal or None) The signal associated with the time (a float, in seconds). If None, the time will not be passed to fn.
tag (str or None) A label associated with the operator, for debugging purposes.
x (Signal or None) An input signal to pass to fn. If None, an input signal will not be passed to fn.
class nengo.builder.neurons.SimNeurons(neurons, J, output, states=None, tag=None)[source]

Set a neuron model output for the given input current.

Implements neurons.step_math(dt, J, output, *states).

Parameters:

neurons : NeuronType

The NeuronType, which defines a step_math function.

J : Signal

The input current.

output : Signal

The neuron output signal that will be set.

states : list, optional (Default: None)

A list of additional neuron state signals set by step_math.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets [output] + states
  2. incs []
  3. reads [J]
  4. updates []

Attributes

J (Signal) The input current.
neurons (NeuronType) The NeuronType, which defines a step_math function.
output (Signal) The neuron output signal that will be set.
states (list) A list of additional neuron state signals set by step_math.
tag (str or None) A label associated with the operator, for debugging purposes.
class nengo.builder.learning_rules.SimBCM(pre_filtered, post_filtered, theta, delta, learning_rate, tag=None)[source]

Calculate connection weight change according to the BCM rule.

Implements the Bienenstock-Cooper-Munroe learning rule of the form

\[\Delta \omega_{ij} = \kappa a_j (a_j - \theta_j) a_i\]

where

  • \(\kappa\) is a scalar learning rate,
  • \(a_j\) is the activity of a postsynaptic neuron,
  • \(\theta_j\) is an estimate of the average \(a_j\), and
  • \(a_i\) is the activity of a presynaptic neuron.
Parameters:

pre_filtered : Signal

The presynaptic activity, \(a_i\).

post_filtered : Signal

The postsynaptic activity, \(a_j\).

theta : Signal

The modification threshold, \(\theta_j\).

delta : Signal

The synaptic weight change to be applied, \(\Delta \omega_{ij}\).

learning_rate : float

The scalar learning rate, \(\kappa\).

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets []
  2. incs []
  3. reads [pre_filtered, post_filtered, theta]
  4. updates [delta]

Attributes

delta (Signal) The synaptic weight change to be applied, \(\Delta \omega_{ij}\).
learning_rate (float) The scalar learning rate, \(\kappa\).
post_filtered (Signal) The postsynaptic activity, \(a_j\).
pre_filtered (Signal) The presynaptic activity, \(a_i\).
tag (str or None) A label associated with the operator, for debugging purposes.
theta (Signal) The modification threshold, \(\theta_j\).
class nengo.builder.learning_rules.SimOja(pre_filtered, post_filtered, weights, delta, learning_rate, beta, tag=None)[source]

Calculate connection weight change according to the Oja rule.

Implements the Oja learning rule of the form

\[\Delta \omega_{ij} = \kappa (a_i a_j - \beta a_j^2 \omega_{ij})\]

where

  • \(\kappa\) is a scalar learning rate,
  • \(a_i\) is the activity of a presynaptic neuron,
  • \(a_j\) is the activity of a postsynaptic neuron,
  • \(\beta\) is a scalar forgetting rate, and
  • \(\omega_{ij}\) is the connection weight between the two neurons.
Parameters:

pre_filtered : Signal

The presynaptic activity, \(a_i\).

post_filtered : Signal

The postsynaptic activity, \(a_j\).

weights : Signal

The connection weight matrix, \(\omega_{ij}\).

delta : Signal

The synaptic weight change to be applied, \(\Delta \omega_{ij}\).

learning_rate : float

The scalar learning rate, \(\kappa\).

beta : float

The scalar forgetting rate, \(\beta\).

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets []
  2. incs []
  3. reads [pre_filtered, post_filtered, weights]
  4. updates [delta]

Attributes

beta (float) The scalar forgetting rate, \(\beta\).
delta (Signal) The synaptic weight change to be applied, \(\Delta \omega_{ij}\).
learning_rate (float) The scalar learning rate, \(\kappa\).
post_filtered (Signal) The postsynaptic activity, \(a_j\).
pre_filtered (Signal) The presynaptic activity, \(a_i\).
tag (str or None) A label associated with the operator, for debugging purposes.
weights (Signal) The connection weight matrix, \(\omega_{ij}\).
class nengo.builder.learning_rules.SimVoja(pre_decoded, post_filtered, scaled_encoders, delta, scale, learning_signal, learning_rate, tag=None)[source]

Simulates a simplified version of Oja’s rule in the vector space.

See Associative Memory learning example for details.

Parameters:

pre_decoded : Signal

Decoded activity from presynaptic ensemble, \(a_i\).

post_filtered : Signal

Filtered postsynaptic activity signal.

scaled_encoders : Signal

2d array of encoders, multiplied by scale.

delta : Signal

The synaptic weight change to be applied, \(\Delta \omega_{ij}\).

scale : ndarray

The length of each encoder.

learning_signal : Signal

Scalar signal to be multiplied by learning_rate. Expected to range between 0 and 1 to turn learning off or on, respectively.

learning_rate : float

The scalar learning rate.

tag : str, optional (Default: None)

A label associated with the operator, for debugging purposes.

Notes

  1. sets []
  2. incs []
  3. reads [pre_decoded, post_filtered, scaled_encoders, learning_signal]
  4. updates [delta]

Attributes

delta (Signal) The synaptic weight change to be applied, \(\Delta \omega_{ij}\).
learning_rate (float) The scalar learning rate.
learning_signal (Signal) Scalar signal to be multiplied by learning_rate. Expected to range between 0 and 1 to turn learning off or on, respectively.
post_filtered (Signal) Filtered postsynaptic activity signal.
pre_decoded (Signal) Decoded activity from presynaptic ensemble, \(a_i\).
scale (ndarray) The length of each encoder.
scaled_encoders (Signal) 2d array of encoders, multiplied by scale.
tag (str or None) A label associated with the operator, for debugging purposes.

Build functions

class nengo.builder.Builder[source]

Manages the build functions known to the Nengo build process.

Consists of two class methods to encapsulate the build function registry. All build functions should use the Builder.register method as a decorator. For example:

@nengo.builder.Builder.register(MyRule)
def build_my_rule(model, my_rule, rule):
    ...

registers a build function for MyRule objects.

Build functions should not be called directly, but instead called through the Model.build method. Model.build uses the Builder.build method to ensure that the correct build function is called based on the type of the object passed to it. For example, to build the learning rule type my_rule from above, do:

model.build(my_rule, connection.learning_rule)

This will call the build_my_rule function from above with the arguments model, my_rule, connection.learning_rule.

Attributes

builders (dict) Mapping from types to the build function associated with that type.
classmethod build(model, obj, *args, **kwargs)[source]

Build obj into model.

This method looks up the appropriate build function for obj and calls with the model and other arguments provided.

Note that if a build function is not specified for a particular type (e.g., EnsembleArray), the type’s method resolution order will be examined to determine the class hierarchy and look for superclasses with defined build functions (e.g., Network in the case of EnsembleArray).

This indirection (calling Builder.build instead of the build function directly) enables users to augment the build process in their own models, rather than having to modify Nengo itself.

In addition to the parameters listed below, further positional and keyword arguments will be passed onto the build function unchanged.

Parameters:

model : Model

The Model instance in which to store build artifacts.

obj : object

The object to build into the model.

classmethod register(nengo_class)[source]

A decorator for adding a class to the build function registry.

Raises a warning if a build function already exists for the class.

Parameters:

nengo_class : Class

The type associated with the build function being decorated.

class nengo.builder.Model(dt=0.001, label=None, decoder_cache=<nengo.cache.NoDecoderCache object>)[source]

Stores artifacts from the build process, which are used by Simulator.

Parameters:

dt : float, optional (Default: 0.001)

The length of a simulator timestep, in seconds.

label : str, optional (Default: None)

A name or description to differentiate models.

decoder_cache : DecoderCache, optional (Default: NoDecoderCache())

Interface to a cache for expensive parts of the build process.

Attributes

config (Config or None) Build functions can set a config object here to affect sub-builders.
decoder_cache (DecoderCache) Interface to a cache for expensive parts of the build process.
dt (float) The length of each timestep, in seconds.
label (str or None) A name or description to differentiate models.
operators (list) List of all operators created in the build process. All operators must be added to this list, as it is used by Simulator.
params (dict) Mapping from objects to namedtuples containing parameters generated in the build process.
probes (list) List of all probes. Probes must be added to this list in the build process, as this list is used by Simulator.
seeded (dict) All objects are assigned a seed, whether the user defined the seed or it was automatically generated. ‘seeded’ keeps track of whether the seed is user-defined. We consider the seed to be user-defined if it was set directly on the object, or if a seed was set on the network in which the object resides, or if a seed was set on any ancestor network of the network in which the object resides.
seeds (dict) Mapping from objects to the integer seed assigned to that object.
sig (dict) A dictionary of dictionaries that organizes all of the signals created in the build process, as build functions often need to access signals created by other build functions.
step (Signal) The current step (i.e., how many timesteps have occurred thus far).
time (Signal) The current point in time.
toplevel (Network) The top-level network being built. This is sometimes useful for accessing network elements after build, or for the network builder to determine if it is the top-level network.
add_op(op)[source]

Add an operator to the model.

In addition to adding the operator, this method performs additional error checking by calling the operator’s make_step function. Calling make_step catches errors in which signals are not properly initialized early, which aids debugging. For that reason, we recommend calling this method over directly accessing the operators attribute.

build(obj, *args, **kwargs)[source]

Build an object into this model.

See Builder.build for more details.

Parameters:

obj : object

The object to build into this model.

has_built(obj)[source]

Returns true if the object has already been built in this model.

Note

Some objects (e.g. synapses) can be built multiple times, and therefore will always result in this method returning False even though they have been built.

This check is implemented by checking if the object is in the params dictionary. Build function should therefore add themselves to model.params if they cannot be built multiple times.

Parameters:

obj : object

The object to query.

nengo.builder.network.build_network(model, network)[source]

Builds a Network object into a model.

The network builder does this by mapping each high-level object to its associated signals and operators one-by-one, in the following order:

  1. Ensembles, nodes, neurons
  2. Subnetworks (recursively)
  3. Connections, learning rules
  4. Probes

Before calling any of the individual objects’ build functions, random number seeds are assigned to objects that did not have a seed explicitly set by the user. Whether the seed was assigned manually or automatically is tracked, and the decoder cache is only used when the seed is assigned manually.

Parameters:

model : Model

The model to build into.

network : Network

The network to build.

Notes

Sets model.params[network] to None.

nengo.builder.ensemble.build_ensemble(model, ens)[source]

Builds an Ensemble object into a model.

A brief of summary of what happens in the ensemble build process, in order:

  1. Generate evaluation points and encoders.
  2. Normalize encoders to unit length.
  3. Determine bias and gain.
  4. Create neuron input signal
  5. Add operator for injecting bias.
  6. Call build function for neuron type.
  7. Scale encoders by gain and radius.
  8. Add operators for mulitplying decoded input signal by encoders and incrementing the result in the neuron input signal.
  9. Call build function for injected noise.

Some of these steps may be altered or omitted depending on the parameters of the ensemble, in particular the neuron type. For example, most steps are omitted for the Direct neuron type.

Parameters:

model : Model

The model to build into.

ens : Ensemble

The ensemble to build.

Notes

Sets model.params[ens] to a BuiltEnsemble instance.

class nengo.builder.ensemble.BuiltEnsemble[source]

Collects the parameters generated in build_ensemble.

These are stored here because in the majority of cases the equivalent attribute in the original ensemble is a Distribution. The attributes of a BuiltEnsemble are the full NumPy arrays used in the simulation.

See the Ensemble documentation for more details on each parameter.

Parameters:

eval_points : ndarray

Evaluation points.

encoders : ndarray

Normalized encoders.

intercepts : ndarray

X-intercept of each neuron.

max_rates : ndarray

Maximum firing rates for each neuron.

scaled_encoders : ndarray

Normalized encoders scaled by the gain and radius. This quantity is used in the actual simulation, unlike encoders.

gain : ndarray

Gain of each neuron.

bias : ndarray

Bias current injected into each neuron.

nengo.builder.node.build_node(model, node)[source]

Builds a Node object into a model.

The node build function is relatively simple. It involves creating input and output signals, and connecting them with an Operator that depends on the type of node.output.

Parameters:

model : Model

The model to build into.

node : Node

The node to build.

Notes

Sets model.params[node] to None.

nengo.builder.connection.build_connection(model, conn)[source]

Builds a Connection object into a model.

A brief of summary of what happens in the connection build process, in order:

  1. Solve for decoders.
  2. Incorporate transform matrix with decoders to get weights.
  3. Add operators for computing the function or multiplying neural activity by weights.
  4. Call build function for the synapse.
  5. Call build function for the learning rule.
  6. Add operator for applying learning rule delta to weights.

Some of these steps may be altered or omitted depending on the parameters of the connection, in particular the pre and post types.

Parameters:

model : Model

The model to build into.

conn : Connection

The connection to build.

Notes

Sets model.params[conn] to a BuiltConnection instance.

class nengo.builder.connection.BuiltConnection[source]

Collects the parameters generated in build_connection.

These are stored here because in the majority of cases the equivalent attribute in the original connection is a Distribution. The attributes of a BuiltConnection are the full NumPy arrays used in the simulation.

See the Connection documentation for more details on each parameter.

Note

The decoders attribute is obsolete as of Nengo 2.1.0. Use the weights attribute instead.

Parameters:

eval_points : ndarray

Evaluation points.

solver_info : dict

Information dictionary returned by the Solver.

weights : ndarray

Connection weights. May be synaptic connection weights defined in the connection’s transform, or a combination of the decoders automatically solved for and the specified transform.

transform : ndarray

The transform matrix.

nengo.builder.probe.build_probe(model, probe)[source]

Builds a Probe object into a model.

Under the hood, there are two types of probes: connection probes and signal probes.

Connection probes are those that are built by creating a new Connection object from the probe’s target to the probe, and calling that connection’s build function. Creating and building a connection ensure that the result of probing the target’s attribute is the same as would result from that target being connected to another object.

Signal probes are those that are built by finding the correct Signal in the model and calling the build function corresponding to the probe’s synapse.

Parameters:

model : Model

The model to build into.

probe : Probe

The connection to build.

Notes

Sets model.params[probe] to a list. Simulator appends to that list when running a simulation.

nengo.builder.neurons.build_neurons(model, neurontype, neurons)[source]

Builds a NeuronType object into a model.

This build function works with any NeuronType that does not require extra state, like RectifiedLinear and LIFRate. This function adds a SimNeurons operator connecting the input current to the neural output signals.

Parameters:

model : Model

The model to build into.

neurontype : NeuronType

Neuron type to build.

neuron : Neurons

The neuron population object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same NeuronType instance.

nengo.builder.neurons.build_lif(model, lif, neurons)[source]

Builds a LIF object into a model.

In addition to adding a SimNeurons operator, this build function sets up signals to track the voltage and refractory times for each neuron.

Parameters:

model : Model

The model to build into.

lif : LIF

Neuron type to build.

neuron : Neurons

The neuron population object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same LIF instance.

nengo.builder.neurons.build_alifrate(model, alifrate, neurons)[source]

Builds an AdaptiveLIFRate object into a model.

In addition to adding a SimNeurons operator, this build function sets up signals to track the adaptation term for each neuron.

Parameters:

model : Model

The model to build into.

alifrate : AdaptiveLIFRate

Neuron type to build.

neuron : Neurons

The neuron population object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same AdaptiveLIFRate instance.

nengo.builder.neurons.build_alif(model, alif, neurons)[source]

Builds an AdaptiveLIF object into a model.

In addition to adding a SimNeurons operator, this build function sets up signals to track the voltage, refractory time, and adaptation term for each neuron.

Parameters:

model : Model

The model to build into.

alif : AdaptiveLIF

Neuron type to build.

neuron : Neurons

The neuron population object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same AdaptiveLIF instance.

nengo.builder.neurons.build_izhikevich(model, izhikevich, neurons)[source]

Builds an Izhikevich object into a model.

In addition to adding a SimNeurons operator, this build function sets up signals to track the voltage and recovery terms for each neuron.

Parameters:

model : Model

The model to build into.

izhikevich : Izhikevich

Neuron type to build.

neuron : Neurons

The neuron population object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same Izhikevich instance.

nengo.builder.learning_rules.build_learning_rule(model, rule)[source]

Builds a LearningRule object into a model.

A brief of summary of what happens in the learning rule build process, in order:

  1. Create a delta signal for the weight change.
  2. Add an operator to increment the weights by delta.
  3. Call build function for the learning rule type.

The learning rule system is designed to work with multiple learning rules on the same connection. If only one learning rule was to be applied to the connection, then we could directly modify the weights, rather than calculating the delta here and applying it in build_connection. However, with multiple learning rules, we must isolate each delta signal in case calculating the delta depends on the weights themselves, making the calculation depend on the order of the learning rule evaluations.

Parameters:

model : Model

The model to build into.

rule : LearningRule

The learning rule to build.

Notes

Sets model.params[rule] to None.

nengo.builder.learning_rules.build_bcm(model, bcm, rule)[source]

Builds a BCM object into a model.

Calls synapse build functions to filter the pre and post activities, and adds a SimBCM operator to the model to calculate the delta.

Parameters:

model : Model

The model to build into.

bcm : BCM

Learning rule type to build.

rule : LearningRule

The learning rule object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same BCM instance.

nengo.builder.learning_rules.build_oja(model, oja, rule)[source]

Builds a BCM object into a model.

Calls synapse build functions to filter the pre and post activities, and adds a SimOja operator to the model to calculate the delta.

Parameters:

model : Model

The model to build into.

oja : Oja

Learning rule type to build.

rule : LearningRule

The learning rule object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same Oja instance.

nengo.builder.learning_rules.build_voja(model, voja, rule)[source]

Builds a Voja object into a model.

Calls synapse build functions to filter the post activities, and adds a SimVoja operator to the model to calculate the delta.

Parameters:

model : Model

The model to build into.

voja : Voja

Learning rule type to build.

rule : LearningRule

The learning rule object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same Voja instance.

nengo.builder.learning_rules.build_pes(model, pes, rule)[source]

Builds a PES object into a model.

Calls synapse build functions to filter the pre activities, and adds several operators to implement the PES learning rule. Unlike other learning rules, there is no corresponding Operator subclass for the PES rule. Instead, the rule is implemented with generic operators like ElementwiseInc and DotInc. Generic operators are used because they are more likely to be implemented on other backends like Nengo OCL.

Parameters:

model : Model

The model to build into.

pes : PES

Learning rule type to build.

rule : LearningRule

The learning rule object corresponding to the neuron type.

Notes

Does not modify model.params[] and can therefore be called more than once with the same PES instance.