-
Notifications
You must be signed in to change notification settings - Fork 356
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
Fail gracefully when node_id
0 is used to access non-existent node
#2872
Conversation
Connect
node_id
0 is used to access non-existent node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good. I think this solution in is_in_range
is probably better fit than at PyNEST
. Future C++ API users thank you already :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolossus This looks good in principle and should not affect perfomance noticeably. But I noticed that in addition to the is_in_range()
you fixed in ModelRangeManager
, there is also one in modelrange
(
nest-simulator/nestkernel/modelrange.h
Line 37 in 291bdff
is_in_range( size_t node_id ) const |
@heplesser The |
Fixes #2636, fixes #2795.
This issue occurred when no nodes had been created and
node_id=0
was provided as an array-like object toConnect
or to access aNodeCollection
. That is, the following cases would result in a crash instead of an error message:Providing a
node_id=0
is not really valid and will fail if aNodeCollection
has been created. However, if no nodes have been created before trying to connect or access,node_id=0
passes through the consistency check ofModelRangeManager::is_in_range
becausefirst_node_id_
andlast_node_id_
both have 0 as default values. Instead of introducing two additional checks (first_node_id_ > 0
andlast_node_id_ > 0
) to account for this edge case, we can just ensure thatnode_id > 0
with the same effect.An alternative solution to this issue could be to ensure that
0
is not contained in array-like objects passed toConnect
orNodeCollection
on the PyNEST level.