In Cython, we have code to update certain elements of the namespace at every time step to make sure that no outdated reference is used:
|
# There is one type of objects that we have to inject into the |
|
# namespace with their current value at each time step: dynamic |
|
# arrays that change in size during runs, where the size change is not |
|
# initiated by the template itself |
|
for name, var in self.variables.items(): |
|
if isinstance(var, DynamicArrayVariable) and var.needs_reference_update: |
|
array_name = self.device.get_array_name(var, self.variables) |
|
if array_name in self.namespace: |
|
self.nonconstant_values.append((array_name, var.get_value)) |
|
if f"_num{name}" in self.namespace: |
|
self.nonconstant_values.append((f"_num{name}", var.get_len)) |
|
|
|
def update_namespace(self): |
|
# update the values of the non-constant values in the namespace |
|
for name, func in self.nonconstant_values: |
|
self.namespace[name] = func() |
I need to investigate what situation could actually trigger this, i.e. why we added this in the first place. The only situation I can find off the top of my head related to this would be structural plasticity, but we do not support this, so… I'll do some historical digging in issues/git history to figure this out. In any case, it does not seem to be a situation that is encountered often, our test suite coverage indicates that no variable is ever marked as needing this update across the whole test suite.
(Discussed with @Legend101Zz in the context of #1769)
In Cython, we have code to update certain elements of the namespace at every time step to make sure that no outdated reference is used:
brian2/brian2/codegen/runtime/cython_rt/cython_rt.py
Lines 272 to 287 in a5862c7
I need to investigate what situation could actually trigger this, i.e. why we added this in the first place. The only situation I can find off the top of my head related to this would be structural plasticity, but we do not support this, so… I'll do some historical digging in issues/git history to figure this out. In any case, it does not seem to be a situation that is encountered often, our test suite coverage indicates that no variable is ever marked as needing this update across the whole test suite.
(Discussed with @Legend101Zz in the context of #1769)