KeyError: 'spike' in SpikeMonitor

Hi. I hope you are well.
I have a problem with “Spike Monitor”. I get this result from my simulation
Stn
but when I use “SpikeMonitir” order, I recieve this error:

Traceback (most recent call last):
  File "STN.py", line 181, in <module>
    sp=SpikeMonitor(GSTN)
  File "/home/atefeh/.local/lib/python3.8/site-packages/brian2/monitors/spikemonitor.py", line 420, in __init__
    super(SpikeMonitor, self).__init__(source, event='spike',
  File "/home/atefeh/.local/lib/python3.8/site-packages/brian2/monitors/spikemonitor.py", line 77, in __init__
    parent_obj = source.thresholder[event]
KeyError: 'spike'

I will be very happy if you help me another time!
with respect

Admittedly, this error message is not very good… You get this error message because your model did not specify any threshold, so Brian does not know what you consider a spike. Make sure to also set a refractory condition to avoid that the SpikeMonitor records multiple spikes during a single spike. I’m pasting the explanation from the documentation here:

In some cases, the condition for leaving the refractory period is not easily expressed as a certain time span. For example, in a Hodgkin-Huxley type model the threshold is only used for counting spikes and the refractoriness is used to prevent to count multiple spikes for a single threshold crossing (the threshold condition would evaluate to True for several time points). When a neuron should leave the refractory period is not easily expressed as a time span but more naturally as a condition that the neuron should remain refractory for as long as it stays above the threshold. This can be achieved by using a string expression for the refractory keyword that evaluates to a boolean condition:

G = NeuronGroup(N, model='...', threshold='v > -20*mV',
                refractory='v >= -20*mV')

PS: I moved your question to its own topic. Please open new topics instead of replying to existing ones for independent questions.

Thank you very much .Do you mean that my code is no longer capable of forming synapses because it cannot detect spikes?

If your synapses are based on spike-based interactions, i.e. with on_pre statements that trigger post-synaptic changes, then indeed they won’t work without a threshold definition in the pre-synaptic group. But in that case you’d also get an error message similar to the one that you got previously. If your synapses are modelled as continuous interaction, i.e. as some function of the pre-synaptic membrane potential (see e.g. this example) then they will work without any threshold definition.

Thank you very much for your patience and accuracy in answering. Thank you again!