Skip to content

Investigate our use of update_namespace #1831

@mstimberg

Description

@mstimberg

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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions