def test_split_chip_to_host(): with nengo.Network() as net: ens_onchip = nengo.Ensemble(10, 1) ens_offchip = nengo.Ensemble(10, 1) node_offchip = nengo.Node(size_in=1) connections = [ nengo.Connection(ens_onchip, ens_offchip), nengo.Connection(ens_onchip, ens_offchip, learning_rule_type=nengo.PES()), nengo.Connection(ens_onchip, node_offchip), nengo.Connection(ens_onchip.neurons, ens_offchip, transform=np.ones((1, 10))), nengo.Connection(ens_onchip.neurons, node_offchip, transform=np.ones((1, 10))), ] connections.append( nengo.Connection(ens_onchip, connections[1].learning_rule)) networks = SplitNetworks(net, node_neurons=default_node_neurons) networks.move(ens_onchip, "chip") networks.move(ens_offchip, "host") networks.move(node_offchip, "host") for conn in connections: split_chip_to_host(networks, conn) for added in networks.adds: if isinstance(added, HostReceiveNode): receive = added elif isinstance(added, nengo.Probe): probe = added else: assert added.post is conn.post receive2post = added assert networks.location(receive) == "host" assert networks.location(receive2post) == "host" assert receive2post.pre is receive assert networks.location(probe) == "chip" assert probe.target is conn.pre or probe.target is conn.pre.ensemble assert probe.synapse is None assert probe in networks.chip2host_params assert probe in networks.chip2host_receivers assert networks.chip2host_receivers[probe] is receive if conn.learning_rule_type is not None: assert conn.learning_rule in networks.needs_sender assert isinstance(networks.needs_sender[conn.learning_rule], PESModulatoryTarget) assert conn in networks.removes networks.adds.clear() # makes next loop iteration easier
def test_split_host_to_chip(): with nengo.Network() as net: ens_offchip = nengo.Ensemble(10, 1) node_offchip = nengo.Node(np.sin) ens_onchip = nengo.Ensemble(10, 1) connections = [ nengo.Connection(ens_offchip, ens_onchip), nengo.Connection(node_offchip, ens_onchip), nengo.Connection(ens_offchip, ens_onchip.neurons, transform=np.ones((10, 1))), nengo.Connection(node_offchip, ens_onchip.neurons, transform=np.ones((10, 1))), ] networks = SplitNetworks(net, node_neurons=default_node_neurons) networks.move(ens_offchip, "host") networks.move(node_offchip, "host") networks.move(ens_onchip, "chip") for conn in connections: split_host_to_chip(networks, conn) for added in networks.adds: if isinstance(added, nengo.Ensemble): ens = added elif isinstance(added, ChipReceiveNode): receive = added elif isinstance(added, HostSendNode): send = added # Otherwise must be connection elif added.pre is conn.pre: pre2ens = added elif added.post is conn.post: receive2post = added else: ensneurons2send = added assert networks.location(ens) == "host" assert isinstance(ens.neuron_type, NIF) assert pre2ens.post is ens assert networks.location(receive) == "chip" assert networks.location(receive2post) == "chip" assert receive2post.pre is receive assert networks.location(send) == "host" assert networks.location(ensneurons2send) == "host" assert ensneurons2send.pre == ens.neurons assert ensneurons2send.post is send assert conn in networks.removes networks.adds.clear() # makes next loop iteration easier
def test_place_probes(): with nengo.Network() as net: offchip1 = nengo.Node(0) with nengo.Network(): onchip1 = nengo.Ensemble(10, 1) offchip2 = nengo.Ensemble(10, 1) onchip2 = nengo.Ensemble(10, 1) onchip3 = nengo.Connection(onchip1, onchip2) offchip3 = nengo.Connection(offchip1, offchip2) offchip_probes = [ nengo.Probe(offchip1), nengo.Probe(offchip2), nengo.Probe(offchip3), ] onchip_probes = [ nengo.Probe(onchip1), nengo.Probe(onchip2), nengo.Probe(onchip3), ] networks = SplitNetworks(net, node_neurons=default_node_neurons) for obj in [offchip1, offchip2, offchip3]: networks.move(obj, "host") for obj in [onchip1, onchip2, onchip3]: networks.move(obj, "chip") place_probes(networks) assert all(networks.location(p) == "host" for p in offchip_probes) assert all(networks.location(p) == "chip" for p in onchip_probes)
def test_place_inter_network_connection(): with nengo.Network() as net: offchip = nengo.Ensemble(10, 1) onchip = nengo.Ensemble(10, 1) onon = nengo.Connection(onchip, onchip) onoff = nengo.Connection(onchip, offchip) offon = nengo.Connection(offchip, onchip) offoff = nengo.Connection(offchip, offchip) networks = SplitNetworks(net, node_neurons=default_node_neurons) networks.move(onchip, "chip") networks.move(offchip, "host") place_internetwork_connections(networks, networks.original.all_connections) assert onoff not in networks assert offon not in networks assert networks.location(onon) == "chip" assert networks.location(offoff) == "host"
def test_split_pre_from_host(): with nengo.Network() as net: pre_1 = nengo.Node(0, label="pre_1") pre_2 = nengo.Ensemble(10, 1, label="pre_2") pre_3 = nengo.Node(size_in=1, label="pre_3") pre_4 = nengo.Ensemble(1, 1, label="pre_4") send = HostSendNode(dimensions=1) onchip = nengo.Ensemble(1, 1, label="onchip") post1 = nengo.Ensemble(10, 1, label="post1") post2 = nengo.Node(size_in=1, label="post2") pre_connections = [ nengo.Connection(pre_1, pre_2), nengo.Connection(pre_2, pre_3), nengo.Connection(pre_3, pre_4), nengo.Connection(pre_4.neurons, send), ] post_connections = [ nengo.Connection(onchip, post1), nengo.Connection(post1, post2), ] networks = SplitNetworks(net, node_neurons=default_node_neurons) for obj in [pre_1, pre_3, send, post1, post2]: networks.move(obj, "host") for obj in [pre_2, pre_4]: networks.add(obj, "host") for conn in pre_connections + post_connections: networks.move(conn, "host") networks.move(onchip, "chip") split_pre_from_host(networks) for obj in [pre_1, pre_2, pre_3, pre_4, send] + pre_connections: assert networks.location(obj) == "host_pre", obj for obj in [post1, post2] + post_connections: assert networks.location(obj) == "host", obj assert networks.location(onchip) == "chip"