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

Fix upper case state variable name naming clash #766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

clinssen
Copy link
Contributor

Fixes #765.

@clinssen clinssen changed the title fix upper case state variable name naming clash Fix upper case state variable name naming clash Apr 24, 2022
@@ -127,7 +127,7 @@ template <> void RecordablesMap<{{neuronName}}>::create()
{%- for variable in neuron.get_vector_state_symbols() %}
for (size_t i = 0; i < {{printer.print_vector_size_parameter(variable)}}; i++)
{
size_t elem = {{neuronName}}::State_::{{names.name(variable).upper()}} + i;
size_t elem = {{neuronName}}::State_::STATE_VEC_VAR_{{names.name(variable).upper()}} + i;
recordablesMap_.insert(get_var_name(i, "{{names.name(variable).upper()}}_"), this->get_data_access_functor(elem));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. The code will compile, but we still have an unchecked runtime problem. The function insert_recordables at line 131 inserts in the map as key the array's name in an upper case form and adds a _{i} as the entry name in the recordables. So if we have an array x with n elements, we will insert X_{i} for i in [1, n]. With this in mind, the user might then want to create two variables in his nestml file, one array variable named x and another double variable named X_1. What will happen when inserting the recordables is that the double variables X_1 will be inserted first, and then the array entries, but the map already contains X_1, and therefore the first entry of the array will never be recorded.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that, and I think the best way is to override the find function in the generic RecordableMap as the create function. Instead of inserting each entry of the array, we should only register a constant pointer to the array and only store its name as x, and then we have to implement a logic that can resolve the global name to a local name (mapping x to x_i).
Assume we have the following map : map : { "x" : [x1, x2,...., xn]}, and let's say we want to deliver x_i to the DataLoggingRequest. Calling map.find("x_i"), should return a pair containing x as the name and a callable that can access the array at position i.

With this, we can also save us runtime overhead. Assume that we have an array with size n >M (big number), and we are only interested in the result of the last entry to be recorded, but at the same time that entry depends on the previous entries. Firstly, the constructor will be very expensive as it must iterate over the entries and register them in the map, but from the python side, the user will only want to record the last entry. With the new suggested changes, the entries will be registered all together at once by having the whole array representing them, and then when setting the record_from in pynest to x_i, the find function should parse the input and split it to (x, i) and then returns an access function to the array at position i.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep it simple and add a check that if a vector variable foo exists, there exists no declaration in the model of a variable named FOO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but u must prevent not just FOO but also every FOO_i for i < len(foo)

@clinssen
Copy link
Contributor Author

Perhaps we could eliminate the use of .upper() to uppercase variable names in the generated code (and also move to C++ enum class for StateVecElems to ensure proper scoping of the enum members).

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

Successfully merging this pull request may close these issues.

Can't have variable with upcased name when using arrays
2 participants