import pynn_brainscales.brainscales2 as pynn
import matplotlib.pyplot as plt
%matplotlib inline
# set the environment
from _static.common.helpers import setup_hardware_client, get_nightly_calibration
setup_hardware_client()
# load automatic calibration and set up pynn
calib = get_nightly_calibration()
pynn.setup(initial_config=calib)
# create input neurons
# these forward spikes at the times specified in `spike_time`
########## change here ##########
spike_time1 = [0.2]
spike_time2 = []
#################################
neuron1 = pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=spike_time1))
neuron2 = pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=spike_time2))
# create output neuron
output_neuron = pynn.Population(1, pynn.cells.HXNeuron())
# monitor its activity
output_neuron.record(["spikes", "v"])
# define synapses and set their weights (range: 0 - 63)
########## change here ##########
synapse_weight1 = 63
synapse_weight2 = 32
#################################
synapse1 = pynn.synapses.StaticSynapse(weight=synapse_weight1)
synapse2 = pynn.synapses.StaticSynapse(weight=synapse_weight2)
# create neuron connections
pynn.Projection(neuron1, output_neuron, pynn.AllToAllConnector(),
synapse_type=synapse1, receptor_type="excitatory")
pynn.Projection(neuron2, output_neuron, pynn.AllToAllConnector(),
synapse_type=synapse2, receptor_type="excitatory")
# run the network for a specified time,
# the duration is set in milliseconds
duration = 0.5
pynn.run(duration)
# examine the spikes of the output neuron
spiketrain = output_neuron.get_data("spikes").segments[0].spiketrains[0]
print(f"The output neuron fired {len(spiketrain)} times.")
print(f"The spiketimes were: {spiketrain}")
# the membrane potential of the output neuron can be visualized, too
mem_v = output_neuron.get_data("v").segments[0].irregularlysampledsignals[0]
plt.figure()
plt.plot(mem_v.times, mem_v)
plt.xlabel("time [ms]")
plt.ylabel("membrane potential [LSB]")
plt.show()
pynn.end()