def __init__(self, model, use_snips=True, seed=None, snip_max_spikes_per_step=50, allocator=OneToOne()): if isinstance(allocator, RoundRobin) and use_snips: raise SimulationError("snips are not supported for the " "RoundRobin allocator") self.closed = False self.use_snips = use_snips self.check_nxsdk_version() self.nxsdk_board = None self.nengo_io_h2c = None # IO snip host-to-chip channel self.nengo_io_c2h = None # IO snip chip-to-host channel self._probe_filters = {} self._probe_filter_pos = {} self._snip_probe_data = collections.OrderedDict() self._chip2host_sent_steps = 0 # Maximum number of spikes that can be sent through # the nengo_io_h2c channel on one timestep. self.snip_max_spikes_per_step = snip_max_spikes_per_step # clear cached content from SpikeProbe class attribute d_func(SpikeProbe, b'cHJvYmVEaWN0', b'Y2xlYXI=') self.build(model, allocator=allocator, seed=seed)
def test_builder_poptype_errors(): pytest.importorskip('nxsdk') # Test error in build_synapse model = Model() block = LoihiBlock(1) block.compartment.configure_lif() model.add_block(block) synapse = Synapse(1) synapse.set_full_weights([1]) synapse.pop_type = 8 block.add_synapse(synapse) discretize_model(model) allocator = OneToOne() # one core per ensemble board = allocator(model) with pytest.raises(ValueError, match="[Ss]ynapse.*[Uu]nrec.*pop.*type"): build_board(board) # Test error in collect_axons model = Model() block0 = LoihiBlock(1) block0.compartment.configure_lif() model.add_block(block0) block1 = LoihiBlock(1) block1.compartment.configure_lif() model.add_block(block1) axon = Axon(1) block0.add_axon(axon) synapse = Synapse(1) synapse.set_full_weights([1]) synapse.pop_type = 8 axon.target = synapse block1.add_synapse(synapse) discretize_model(model) board = allocator(model) with pytest.raises(ValueError, match="[Aa]xon.*[Uu]nrec.*pop.*type"): build_board(board)
def test_deterministic_network_allocation(Simulator, seed): # test that we get the same simulations results across allocators. # the determinism of the allocation itself is covered by other unit tests. n_neurons = 64 n_ensembles = 8 tau = 0.1 sim_t = 1.0 with nengo.Network(seed=seed) as model: prev = nengo.Node(output=1) p = [] for i in range(n_ensembles): ens = nengo.Ensemble(n_neurons, 1) nengo.Connection(prev, ens, synapse=tau) p.append(nengo.Probe(ens, synapse=tau)) prev = ens with nengo.Simulator(model) as sim_ref: sim_ref.run(sim_t) allocation = [ (1, OneToOne()), (1, RoundRobin(n_chips=1)), (3, RoundRobin(n_chips=3)), (8, RoundRobin(n_chips=8)), ] sim_prev = None for n_chips_used, allocator in allocation: with Simulator(model, precompute=True, hardware_options={'allocator': allocator}) as sim_loihi: sim_loihi.run(sim_t) assert n_chips_used == sim_loihi.sims["loihi"].board.n_chips for p_i in p: assert rms(sim_loihi.data[p_i] - sim_ref.data[p_i]) < 0.05 if sim_prev is not None: assert np.allclose(sim_prev.data[p_i], sim_loihi.data[p_i]) sim_prev = sim_loihi
def __init__(self, model, use_snips=True, seed=None, snip_max_spikes_per_step=50, allocator=OneToOne()): if isinstance(allocator, RoundRobin) and use_snips: raise SimulationError("snips are not supported for the " "RoundRobin allocator") self.closed = False self.use_snips = use_snips self.check_nxsdk_version() self.n2board = None self.nengo_io_h2c = None # IO snip host-to-chip channel self.nengo_io_c2h = None # IO snip chip-to-host channel self._probe_filters = {} self._probe_filter_pos = {} self._snip_probe_data = collections.OrderedDict() self._chip2host_sent_steps = 0 # Maximum number of spikes that can be sent through # the nengo_io_h2c channel on one timestep. self.snip_max_spikes_per_step = snip_max_spikes_per_step nxsdk_dir = os.path.realpath( os.path.join(os.path.dirname(nxsdk.__file__), "..")) self.cwd = os.getcwd() logger.debug("cd to %s", nxsdk_dir) os.chdir(nxsdk_dir) # probeDict is a class attribute, so might contain things left over # from previous simulators N2SpikeProbe.probeDict.clear() self.build(model, allocator=allocator, seed=seed)
def test_one_to_one_allocator_big_block_error(): model = Model() model.add_block(LoihiBlock(1050)) with pytest.raises(ValidationError, match="Segment does not fit"): OneToOne()(model)
axon0 = Axon(1) input = LoihiInput() input.add_axon(axon0) model.add_input(input) synapse0 = Synapse(1) synapse0.set_full_weights([[1]]) axon0.target = synapse0 block0.add_synapse(synapse0) discretize_model(model) return model @pytest.mark.parametrize("allocator", [OneToOne(), RoundRobin(n_chips=1)]) def test_one_to_one_allocator(allocator): # RoundRobin(n_chips=1) is equivalent to OneToOne() model = _basic_model() board = allocator(model) assert board.n_chips == 1 assert board.n_cores_per_chip == [3] assert board.n_synapses_per_core == [[1, 1, 0]] chip = board.chips[0] assert chip.board is board assert chip.n_cores == 3 assert chip.cores[0].chip is chip assert len(chip.cores[0].synapses) == 1
def test_one_to_one_allocator_big_block_error(): model = Model() model.add_block(LoihiBlock(1050)) with pytest.raises(ValidationError): OneToOne()(model)