Weakly-referenced in object neurongroup_stateupdater

Description of problem

Hi all,

I have a spatial neuron and the Extracellular space modeled as a NeuronGroup.
I’m trying to connect to the ECS only the variables from a particular compartment of the neuron.

I linked the variables and seemed ok, however I get the following error about no longer existing ecs variables I guess. But I really don’t know how to solve this.

Thanks to anyone will spend a minute to try to help me,
Barbara

Minimal code to reproduce problem

ecs.IKAn = linked_var(neuro.L[0].IKA)

Full traceback of error (if relevant)

ReferenceError: weakly-referenced object no longer exists

Error encountered with object named “neurongroup_stateupdater”.

Hi Barbara,
I will try to have a closer look at this soon. You should not get this kind of error, so this definitely counts as a bug. I somewhat understand why you get it, though. The normal use of linked_var is with a full NeuronGroup (or SpatialNeuron) but here you are using it with a subgroup. To avoid memory issues (long story…), the link between the groups is stored as a so-called “weak reference” which means that it will not keep the target group “alive” if nothing else refers to it. This is a problem here, because your subgroup is neuro.L[0], and this group is not permanently stored anywhere. It might work if you keep the subgroup alive by storing it to a variable, i.e.:

compartment = neuro.L[0]
ecs.IKAn = linked_var(compartment.IKA)

I am not 100% sure whether it does work in this way, though. If it does not, you could try to instead link to the complete group and set the compartment you are interested in via the index argument.

This would look like this:

ecs.IKAn = linked_var(neuro.IKA, index=[neuro.L.indices[0]])

(this assumes that the ecs is a NeuronGroup of size 1).

Let us know whether it works!

I checked with an example and the workarounds appear to work. The issue is a bit tricky to fix, but I realized that there is another even simpler workaround. Instead of the line you used, try:

ecs.IKAn = linked_var(neuro.L[0], 'IKA')
1 Like

Hi Marcel,
thanks for the workarounds! And sorry for my late reply!

I tried and in my case only the first suggestion works. Still…a great victory :slight_smile: since I thought I was making some mysterious huge mistake :slight_smile:

Best,
Barbara

1 Like