Main¶
|
Nengo Loihi simulator for Loihi hardware and emulator. |
|
Add nengo_loihi config option to network. |
Modify Nengo’s default parameters for better performance with Loihi. |
-
class
nengo_loihi.Simulator(network, dt=0.001, seed=None, model=None, precompute=False, target=None, progress_bar=None, remove_passthrough=True, hardware_options=None)[source]¶ Nengo Loihi simulator for Loihi hardware and emulator.
The simulator takes a
nengo.Networkand builds internal data structures to run the model defined by that network on Loihi emulator or hardware. Run the simulator with theSimulator.runmethod, and access probed data through thedataattribute.Building and running the simulation allocates resources. To properly free these resources, call the
Simulator.closemethod. Alternatively,Simulator.closewill automatically be called if you usewithsyntax:with nengo_loihi.Simulator(my_network) as sim: sim.run(0.1) print(sim.data[my_probe])
Note that the
dataattribute is still accessible even when a simulator has been closed. Running the simulator, however, will raise an error.- Parameters
- networkNetwork
A network object to be built and then simulated. If None, then the model parameter must be provided instead.
- dtfloat, optional (Default: 0.001)
The length of a simulator timestep, in seconds.
- seedint, optional (Default: None)
A seed for all stochastic operators used in this simulator. Will be set to
network.seed + 1if not given.- modelModel, optional (Default: None)
A
Modelthat 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 aModelinstance.- precomputebool, optional (Default: False)
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.
- targetstr, 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.- hardware_optionsdict, optional (Default: {})
Dictionary of additional configuration for the hardware. See
hardware.HardwareInterfacefor possible parameters.
- Attributes
- closedbool
Whether the simulator has been closed. Once closed, it cannot be reopened.
- dataProbeDict
The dictionary mapping from Nengo objects to the data associated with those objects. In particular, each
nengo.Probemaps to the data probed while running the simulation.- modelModel
The
Modelcontaining the data structures necessary for simulating the network.- precomputebool
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.
-
property
dt¶ (float) The step time of the simulator.
-
property
n_steps¶ (int) The current time step of the simulator.
-
property
time¶ (float) The current time of the simulator.
-
close(self)[source]¶ Closes the simulator.
Any call to
Simulator.run,Simulator.run_steps,Simulator.step, andSimulator.reseton a closed simulator raises aSimulatorClosedexception.
-
reset(self, seed=None)[source]¶ Reset the simulator state.
- Parameters
- seedint, 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(self, 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 nearestdt. For example, ifdtis 0.001 andrunis called withtime_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_secondsfloat
Amount of time to run the simulation for. Must be positive.
-
run_steps(self, steps)[source]¶ Simulate for the given number of
dtsteps.- Parameters
- stepsint
Number of steps to run the simulation for.
-
trange(self, 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_everyfloat, optional (Default: None)
The sampling period of the probe to create a range for. If None, a time value for every
dtwill be produced.
-
nengo_loihi.add_params(network)[source]¶ Add nengo_loihi config option to network.
The following options will be added:
nengo.Ensembleon_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.Ensemblemax_rates: Set toUniform(low=100, high=120)intercepts: Set toUniform(low=-0.5, high=0.5)