[Nengo-Loihi]: Adding NxSDK code to Nengo-Loihi/Nengo

My instinct would be to create an ensemble, connect in to a set of input neurons in that ensemble (which will be represented on Loihi as single compartments), connect out from a separate set of output neurons (which will create output compartments), then go in and manually connect those input/output compartments.

Here’s a sketch:

with nengo.Network() as net:
    n = 10  # number of input/output compartments
    phases = np.linspace(0, 2*np.pi, n)
    inp = nengo.Node(lambda t: np.sin(t + phases))

    ens = nengo.Ensemble(2 * n, 1)
    out = nengo.Node(size_in=n)
    probe = nengo.Probe(out)

    nengo.Connection(inp, ens.neurons[:n])
    nengo.Connection(ens.neurons[n:], out)

sim = nengo_loihi.Simulator(net)
hw_interface = sim.sims["loihi"]
nxsdk_board = hw_interface.nxsdk_board
board = hw_interface.board

blocks = sim.model.objs[ens]
assert len(blocks) == 1
block = blocks[0]

# get the nengo_loihi.block.Synapse
synapse = sim.model.objs[input_conn]["weights"]

chip_idx, core_idx, block_idx, compartment_idxs, _ = board.find_block(block)
nxsdk_core = nxsdk_board.n2Chips[chip_idx].n2CoresAsList[core_idx]

synapse_unique_idxs = np.unique(synapse.indices)
input_compartment_idxs = [compartment_idxs[i] for i in synapse_unique_idxs]
output_compartment_idxs = [i for i in compartment_idxs if i not in input_compartment_idxs]

# do configuration here using nxsdk_core, and input/output compartment idxs
# NengoLoihi currently only puts one block per core, so you should be able to use
# any compartments not in `compartment_idxs` as extra compartments that you can
# configure yourself.