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 chip/simulator.
nengo_loihi.builder.Builder Fills in the Loihi Model object based on the Nengo Network.
nengo_loihi.loihi_cx.CxSimulator(model[, seed]) Software emulator for Loihi chip.
nengo_loihi.loihi_interface.LoihiSimulator(…) 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 chip/simulator.

This is a subclass of CxModel, which defines methods for adding ensembles, discretizing, and tracking the simulator. This class handles build functions and keeping track of chip/host communication.

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.

label : str or None

A name or description to differentiate models.

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.

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.

inter_scale

Scaling applied to input from interneurons.

Such that if all inter_n interneurons are firing at their max rate inter_rate, then the total output when averaged over time will be 1.

class nengo_loihi.builder.Builder[source]

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

classmethod register(nengo_class)[source]

Register methods to build Nengo objects into Model.

class nengo_loihi.loihi_cx.CxSimulator(model, seed=None)[source]

Software emulator for Loihi chip.

Parameters:
model : Model

Model specification that will be simulated.

seed : int, optional (Default: None)

A seed for all stochastic operations done in this simulator.

build(model, seed=None)[source]

Set up NumPy arrays to emulate chip memory and I/O.

clear()[source]

Clear all signals set in build (to free up memory)

step()[source]

Advance the simulation 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.

class nengo_loihi.loihi_interface.LoihiSimulator(cx_model, use_snips=True, seed=None)[source]

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

Parameters:
cx_model : CxModel

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.