# How to enable synapses to access variables of neurons in Brian2

**URL:** <https://brian.discourse.group/t/how-to-enable-synapses-to-access-variables-of-neurons-in-brian2/1437>\
**Category:** Science, Projects, and Showcases\
**Created:** [21 April 2025 07:53 UTC](https://brian.discourse.group/t/how-to-enable-synapses-to-access-variables-of-neurons-in-brian2/1437 "2025-04-21T07:53:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luka](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@Luka](https://brian.discourse.group/u/Luka)\
**Post date:** [21 April 2025 07:53 UTC](https://brian.discourse.group/t/how-to-enable-synapses-to-access-variables-of-neurons-in-brian2/1437/1 "2025-04-21T07:53:47Z")

</div>

Hello everyone,  
I am currently attempting to replicate NALSM from the paper “[Increasing Liquid State Machine Performance with Edge-of-Chaos Dynamics Organized by Astrocyte-modulated Plasticity](https://proceedings.neurips.cc/paper_files/paper/2021/hash/d79c8788088c2193f0244d8f1f36d2db-Abstract.html).” The authors have proposed a STDP method with adaptive depression learning rate to train LSM (as shown in formula 7 in the figure) and have implemented the model in the Tensorflow framework.

 ![2](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/6bfafc9b66ccf3a74e703535d1359e9a7040060c.png)  
In simple terms, the global depression learning rate A\_ is controlled by the number of input spikes and the number of liquid spikes. Therefore, I attempted to set up a virtual population of neurons (astro) connected to the input and liquid to calculate A\_ (as shown in the figure below).  
 ![1](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/51f2ac115bafa660aeae2c7d95b1abf1a5fdef84.png)  
However, how can I make the synapses access/link to A\_ within astro? Does Brian2 support such an implementation? I have attached my complete code below. Thank you very much for your suggestions.

```auto
from brian2 import (
	NeuronGroup,
	Synapses,
	Network,
	SpikeMonitor,
	StateMonitor,
	PoissonGroup
)
from brian2 import ms, Hz
from brian2 import defaultclock, collect
import matplotlib.pyplot as plt

defaultclock.dt = 1. * ms
tau = 10. * ms

# input and liquid neurons
neuron_inp = PoissonGroup(1, 400 * Hz)
neuron_liq = PoissonGroup(1, 400 * Hz)
# syn with STDP
eqs_synapse = '''
dTpre / dt = -Tpre / tau : 1 (event-driven)
dTpost / dt = -Tpost / tau : 1 (event-driven)
w : 1
Aastro : 1
'''
eqs_synapse_on_pre = '''
Tpre += 0.1
w -= Tpost * Aastro
'''
eqs_synapse_on_post = '''
Tpost += 0.1
w += Tpre * 0.15
'''
syns = Synapses(neuron_inp, neuron_liq, eqs_synapse,
				on_pre=eqs_synapse_on_pre, on_post=eqs_synapse_on_post)
syns.connect()
syns.w = 0.5
st_syns = StateMonitor(syns, ['Tpre', 'Tpost', 'w', 'Aastro'], record=True)

eqs_astro = '''
dAastro / dt = (-Aastro + 0.15) / (100. * ms) : 1
'''
G = NeuronGroup(1, eqs_astro, method ='euler')
G.Aastro = 0.15
# syns.Aastro = linked_var(G, 'Aastro') # link
syn_inp = Synapses(neuron_inp, G, '', on_pre='Aastro -= 0.01')
syn_inp.connect()
syn_liq = Synapses(neuron_liq, G, '', on_pre='Aastro += 0.01')
syn_liq.connect()
sp_inp = SpikeMonitor(neuron_inp, record=True)
sp_liq = SpikeMonitor(neuron_liq, record=True)
st_asto = StateMonitor(G, ['Aastro'], record=True)

net = Network(collect())
net.run(21 * ms)

fig, axs = plt.subplots(4, 2, figsize=(7, 5), sharex='all')
axs[0, 0].plot(sp_inp.t / ms, sp_inp.i, '.k', label='input spikes')
axs[0, 0].legend()
axs[1, 0].plot(sp_liq.t / ms, sp_liq.i, '.k', label='liquid spikes')
axs[1, 0].legend()
axs[3, 0].plot(st_asto.t / ms, st_asto.Aastro[0], label='A_ from astro')
axs[3, 0].legend()
axs[0, 1].plot(st_syns.t / ms, st_syns.Tpre[0], label='Tpre')
axs[0, 1].legend()
axs[1, 1].plot(st_syns.t / ms, st_syns.Tpost[0], label='Tpost')
axs[1, 1].legend()
axs[2, 1].plot(st_syns.t / ms, st_syns.w[0], label='w')
axs[2, 1].legend()
axs[3, 1].plot(st_syns.t / ms, st_syns.Aastro[0], label='A_ from syn')
axs[3, 1].legend()
axs[3, 1].set(xlim=[-0.5, 20.5])
plt.tight_layout()
plt.show()

```

 ![3](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/c83b8bf6a4762674163dfc8a63d15990e05867ba.png)

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [23 April 2025 14:29 UTC](https://brian.discourse.group/t/how-to-enable-synapses-to-access-variables-of-neurons-in-brian2/1437/2 "2025-04-23T14:29:34Z")

</div>

Hi @Luka. This is indeed possible in Brian, we enabled this type of synaptic modulation when we wrote our book chapter on astrocyte modeling with Brian: [https://doi.org/10.1101/198366](https://doi.org/10.1101/198366) The example codes from this chapter might be useful: [Examples — Brian 2 2.8.0.4 documentation](https://brian2.readthedocs.io/en/stable/examples/index.html#frompapers-stimberg-et-al-2018)

In short, the idea is that you can have a `Synapses` that target another `Synapses` – in your example, the astro group can have a `Synapses` that targets the synapses with STDP. In your code, you’d add:

```python
syn_astro_syn = Synapses(G, syns, "Aastro_post = Aastro_pre : 1 (summed)")
syn_astro_syn.connect()

```

In your case, this mechanism is a bit more “powerful” than needed – it allows you to have several units in the group `G`, and connecting subsets of them to each synapse (the `summed` means that it will sum up the pre-synaptic contributions). For a single, global value, the linked mechanism would indeed be simpler and more efficient. It cannot be used in `Synapses` right now, but we actually implemented this very feature recently. The next Brian release (towards the end of April, I think) will include it, and then you will be able to mark the `Aastro` variable in your synapses as `(linked)` and link it to the `Aastro` variable in the other group. If you already want to try out this feature, you could install Brian’s development version as described in the [documentation](https://brian2.readthedocs.io/en/stable/introduction/install.html#development-install).

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Luka](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@Luka](https://brian.discourse.group/u/Luka)\
**Post date:** [24 April 2025 01:32 UTC](https://brian.discourse.group/t/how-to-enable-synapses-to-access-variables-of-neurons-in-brian2/1437/3 "2025-04-24T01:32:05Z")

</div>

Thank you very much for your advice. It is very helpful to me. 😸
