latest

API reference

nengo_loihi.add_params(network) Add nengo_loihi config option to network.
nengo_loihi.set_defaults() Modify Nengo’s default parameters for better performance with Loihi.
nengo_loihi.Simulator(network[, dt, seed, …]) Nengo Loihi simulator for Loihi hardware and emulator.
nengo_loihi.builder.Model([dt, label, builder]) The data structure for the emulator/hardware simulator.
nengo_loihi.builder.Builder Fills in the Loihi Model object based on the Nengo Network.
nengo_loihi.emulator.EmulatorInterface(model) Software emulator for Loihi chip behaviour.
nengo_loihi.hardware.HardwareInterface(model) Simulator to place a Model onto a Loihi board and run it.
nengo_loihi.add_params(network)[source]

Add nengo_loihi config option to network.

The following options will be added:

nengo.Ensemble
  • on_chip: Whether the ensemble should be simulated on a Loihi chip. Marking specific ensembles for simulation off of a Loihi chip can help with debugging.

Examples

>>> with nengo.Network() as model:
...     ens = nengo.Ensemble(10, dimensions=1)
...     # By default, ens will be placed on a Loihi chip
...     nengo_loihi.add_params(model)
...     model.config[ens].on_chip = False
...     # Now it will be simulated with Nengo
nengo_loihi.set_defaults()[source]

Modify Nengo’s default parameters for better performance with Loihi.

The following defaults will be modified:

nengo.Ensemble
  • max_rates: Set to Uniform(low=100, high=120)
  • intercepts: Set to Uniform(low=-0.5, high=0.5)
class nengo_loihi.Simulator(network, dt=0.001, seed=None, model=None, precompute=False, target=None, progress_bar=None, remove_passthrough=True)[source]

Nengo Loihi simulator for Loihi hardware and emulator.

The simulator takes a nengo.Network and builds internal data structures to run the model defined by that network on Loihi emulator or hardware. Run the simulator with the Simulator.run method, and access probed data through the data attribute.

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

with nengo_loihi.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 be built and then simulated. If None, then the model parameter 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. Will be set to network.seed + 1 if not given.

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.

precompute : bool, optional (Default: True)

Whether model inputs should be precomputed to speed up simulation. When precompute is False, the simulator will be run one step at a time in order to use model outputs as inputs in other parts of the model.

target : str, optional (Default: None)

Whether the simulator should target the emulator ('sim') or Loihi hardware ('loihi'). If None, target will default to 'loihi' if NxSDK is installed, and the emulator if it is not.

Attributes:
closed : bool

Whether the simulator has been closed. Once closed, it cannot be reopened.

data : ProbeDict

The dictionary mapping from Nengo objects to the data associated with those objects. In particular, each nengo.Probe maps to the data probed while running the simulation.

model : Model

The Model containing the data structures necessary for simulating the network.

precompute : bool

Whether model inputs should be precomputed to speed up simulation. When precompute is False, the simulator will be run one step at a time in order to use model outputs as inputs in other parts of the model.

dt

(float) The step time 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)[source]

Simulate for the given length of time.

If the given length of time is not a multiple of dt, it will be rounded to the nearest dt. For example, if dt is 0.001 and run is called with time_in_seconds=0.0006, the simulator will advance one timestep, resulting in the actual simulator time being 0.001.

The given length of time must be positive. The simulator cannot be run backwards.

Parameters:
time_in_seconds : float

Amount of time to run the simulation for. Must be positive.

step()[source]

Advance the simulator by 1 step (dt seconds).

run_steps(steps)[source]

Simulate for the given number of dt steps.

Parameters:
steps : int

Number of steps to run the simulation for.

trange(sample_every=None, 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:
sample_every : float, optional (Default: None)

The sampling period of the probe to create a range for. If None, a time value for every dt will be produced.

class nengo_loihi.builder.Model(dt=0.001, label=None, builder=None)[source]

The data structure for the emulator/hardware simulator.

Defines methods for adding inputs and blocks. Also handles build functions, and information associated with building the Nengo model.

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.

builder : Builder, optional (Default: None)

A Builder instance to keep track of build functions. If None, the default builder will be used.

Attributes:
builder : Builder

The build functions used by this model.

dt : float

The length of a simulator timestep, in seconds.

chip2host_params : dict

Mapping from Nengo objects to any additional parameters associated with those objects for use during the build process.

decode_neurons : DecodeNeurons

Type of neurons used to facilitate decoded (NEF-style) connections.

decode_tau : float

Time constant of lowpass synaptic filter used with decode neurons.

blocks : list of LoihiBlock

List of Loihi blocks simulated by this model.

inputs : list of LoihiInput

List of inputs to this model.

intercept_limit : float

Limit for clipping intercepts, to avoid neurons with high gains.

label : str or None

A name or description to differentiate models.

node_neurons : DecodeNeurons

Type of neurons used to convert real-valued node outputs to spikes for the chip.

objs : dict

Dictionary mapping from Nengo objects to Nengo Loihi objects.

params : dict

Mapping from objects to namedtuples containing parameters generated in the build process.

pes_error_scale : float

Scaling for PES errors, before rounding and clipping to -127..127.

pes_wgt_exp : int

Learning weight exponent (base 2) for PES learning connections. This controls the maximum weight magnitude (where a larger exponent means larger potential weights, but lower weight resolution).

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.

vth_nonspiking : float

Voltage threshold for non-spiking neurons (i.e. voltage decoders).

class nengo_loihi.builder.Builder[source]

Fills in the Loihi Model object based on the Nengo Network.

We cannot use the Nengo builder as is because we make normal Nengo networks for host-to-chip and chip-to-host communication. To keep Nengo and Nengo Loihi builders separate, we make a blank subclass, which effectively copies the class.

class nengo_loihi.emulator.EmulatorInterface(model, seed=None)[source]

Software emulator for Loihi chip behaviour.

Parameters:
model : Model

Model specification that will be simulated.

seed : int, optional (Default: None)

A seed for all stochastic operations done in this simulator.

run_steps(steps)[source]

Simulate for the given number of dt steps.

Parameters:
steps : int

Number of steps to run the simulation for.

step()[source]

Advance the simulation by 1 step (dt seconds).

class nengo_loihi.hardware.HardwareInterface(model, use_snips=True, seed=None)[source]

Simulator to place a Model onto a Loihi board and run it.

Parameters:
model : Model

Model specification that will be placed on the Loihi board.

seed : int, optional (Default: None)

A seed for stochastic operations.

Warning

Setting the seed has no effect on stochastic operations run on the Loihi board.