Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgroups and linked variables -- weak reference problem #1252

Open
mstimberg opened this issue Nov 24, 2020 · 3 comments
Open

Subgroups and linked variables -- weak reference problem #1252

mstimberg opened this issue Nov 24, 2020 · 3 comments
Assignees

Comments

@mstimberg
Copy link
Member

As reported in the discourse forum, using a VariableView of a subgroup in linked_var will lead to a ReferenceError. The following example reproduces the issue:

group1 = NeuronGroup(10, 'v : 1')
group2 = NeuronGroup(5, 'v : 1 (linked)')

group2.v = linked_var(group1[3:8].v)

The problem is that group1[3:8].v creates a VariableView object which only holds a weak reference to its group, and group1[3:8] therefore disappears. In linked_var, we are trying to access the group attribute which leads to the error.

I think in general the approach to only store a weak reference is the right one, because VariableView objects were previously a major source of memory problems. We can get away with this normally even if its group argument disappears because we hold strong references to the Variable object (which has the full data of v) and the Indexing object (which allows us to deduce that we need values 3–8 of v). This should be fixable by moving a bit around the logic of index interpretation between linked_var and LinkedVariable, but I'll have to have a closer look.

I'll mark this as low priority, though, because there are a number of workarounds. All the following variants will work:

# named subgroup
subgroup = group1[3:8]
group2.v = linked_var(subgroup.v)
# avoid VariableView by separating group and variable name
group2.v = linked_var(group1[3:8], 'v')
# link to full group and use absolute indices
group2.v = linked_var(group1, 'v', index=np.arange(3, 8))
@blackbird7112
Copy link
Contributor

Hello @mstimberg ,
I am Rohith Varma (@rohithvarma3000) and I would like to help to solve this issue. Could you guide me on how to help you solve this issue?

@mstimberg
Copy link
Member Author

I wouldn't recommend to tackle this issue right now, I am not 100% sure what the correct fix is myself :-) !

@blackbird7112
Copy link
Contributor

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants