-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloihi_control_loop.py
149 lines (113 loc) · 5.56 KB
/
loihi_control_loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import sys
sys.path.append('./')
from loihi_network import LoihiNetwork
def check_input_layer_axon_id_list(layer_dim=5,
input_core_list=[0, 0, 0, 0, 0],
output_core_list=[0, 0, 0, 0, 0],
snip_dir='./snip_spike'):
"""
Check the axon id list for input layer
Args:
layer_dim (int): layer dimension
input_core_list (list): input layer core list
output_core_list (list): output layer core list
snip_dir (str): SNIP directory
"""
loihi_snn = LoihiNetwork(layer_dim, input_core_list, output_core_list)
board, encoder_channel, decoder_channel = loihi_snn.setup_loihi_snn(layer_dim, layer_dim, snip_dir,
print_axon=True)
board.startDriver()
board.disconnect()
def run_loihi_spike_online_interaction(layer_dim=5,
input_core_list=[0, 0, 0, 0, 0],
output_core_list=[0, 0, 0, 0, 0],
snip_dir='./snip_spike'):
"""
Online interaction simulation for interact each step with Loihi
Args:
layer_dim (int): layer dimension
input_core_list (list): input layer core list
output_core_list (list): output layer core list
snip_dir (str): SNIP directory
"""
loihi_snn = LoihiNetwork(layer_dim, input_core_list, output_core_list)
board, encoder_channel, decoder_channel = loihi_snn.setup_loihi_snn(layer_dim, layer_dim, snip_dir)
# Start Loihi simulation
loihi_sim_step = layer_dim + 2
board.startDriver()
board.run(loihi_sim_step, aSync=True)
# Begin control loop (for first layer_dim step active input neuron in sequence)
for ii in range(loihi_sim_step):
input_spike_list = [0 for _ in range(layer_dim)]
if ii < layer_dim:
input_spike_list[ii] = 1
# Write input_spike_list to Loihi
encoder_channel.write(layer_dim, input_spike_list)
# Read output_spike_list from Loihi
output_spike_list = decoder_channel.read(layer_dim)
print("Loihi step: ", ii, " Input Spike: ", input_spike_list, " Output Spike: ", output_spike_list)
# Stop Loihi simulation
board.finishRun()
board.disconnect()
def run_loihi_window_regular_online_interaction(layer_dim=5,
input_core_list=[0, 0, 0, 0, 0],
output_core_list=[0, 0, 0, 0, 0],
snip_dir='./snip_window_regular'):
"""
Online interaction simulation for interact each control step with Loihi window steps
(Input neurons generate regular spikes base on current input)
Args:
layer_dim (int): layer dimension
input_core_list (list): input layer core list
output_core_list (list): output layer core list
snip_dir (str): SNIP directory
"""
loihi_snn = LoihiNetwork(layer_dim, input_core_list, output_core_list)
board, encoder_channel, decoder_channel = loihi_snn.setup_loihi_snn(layer_dim, layer_dim, snip_dir)
# Start Loihi simulation
loihi_sim_step = layer_dim * 12
board.startDriver()
board.run(loihi_sim_step, aSync=True)
# Begin control loop (for each control loop iteration, give ii input neuron with (ii+1)*10 input current)
for ii in range(layer_dim):
input_current_list = [0 for _ in range(layer_dim)]
input_current_list[ii] = (ii + 1) * 10
# Write input_spike_list to Loihi
encoder_channel.write(layer_dim, input_current_list)
# Read output_spike_list from Loihi
output_fr_list = decoder_channel.read(layer_dim)
print("Control step: ", ii, " Input Current: ", input_current_list, " Output Spike Number: ", output_fr_list)
# Stop Loihi simulation
board.finishRun()
board.disconnect()
def run_loihi_window_poisson_online_interaction(layer_dim=5,
input_core_list=[0, 0, 0, 0, 0],
output_core_list=[0, 0, 0, 0, 0],
snip_dir='./snip_window_poisson'):
"""
Online interaction simulation for interact each control step with Loihi window steps
(Input neurons generate Poisson spikes base on input spike probability)
Args:
layer_dim (int): layer dimension
input_core_list (list): input layer core list
output_core_list (list): output layer core list
snip_dir (str): SNIP directory
"""
loihi_snn = LoihiNetwork(layer_dim, input_core_list, output_core_list)
board, encoder_channel, decoder_channel = loihi_snn.setup_loihi_snn(layer_dim, layer_dim, snip_dir)
# Start Loihi simulation
loihi_sim_step = layer_dim * 102
board.startDriver()
board.run(loihi_sim_step, aSync=True)
# Begin control loop (for each control loop iteration, give ii input neuron with (ii+1)*10 input spike probability)
for ii in range(layer_dim):
input_current_list = [0 for _ in range(layer_dim)]
input_current_list[ii] = (ii + 1) * 10
# Write input_spike_list to Loihi
encoder_channel.write(layer_dim, input_current_list)
# Read output_spike_list from Loihi
output_fr_list = decoder_channel.read(layer_dim)
print("Control step: ", ii, " Input Current: ", input_current_list, " Output Spike Number: ", output_fr_list)
# Stop Loihi simulation
board.finishRun()
board.disconnect()