Skip to content

Meaningful error messages when number of subscripts differs between compile and runtime#2024

Merged
nrnhines merged 29 commits into
masterfrom
hines/vardimfix
Nov 3, 2022
Merged

Meaningful error messages when number of subscripts differs between compile and runtime#2024
nrnhines merged 29 commits into
masterfrom
hines/vardimfix

Conversation

@nrnhines

Copy link
Copy Markdown
Member

Variables have always been allowed to be redeclared. But if the number of subscripts changes after compilation of a procedure, the stack can become corrupted, overflow, or generate a message far from the cause of the error.
This PR generates meaningful error message when the number of subscripts for a variable at compile time differs from the
number of subscripts at runtime due to redeclaring the variable after compiling a function.
A HOC example that used to segfault

double x[1][1][1]
proc foo() { local i
    for i = 1, 10000 {
        x = i
    }
}
double x[1]
foo()

now generates the message

nrniv: array dimension of x now 1 (at compile time it was 3)

@nrnhines nrnhines marked this pull request as draft October 13, 2022 11:00
@azure-pipelines

Copy link
Copy Markdown

✔️ c4cdc82 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 34bdfda -> Azure artifacts URL

@codecov-commenter

codecov-commenter commented Oct 20, 2022

Copy link
Copy Markdown

Codecov Report

Merging #2024 (d586408) into master (b47712b) will increase coverage by 0.17%.
The diff coverage is 95.00%.

@@            Coverage Diff             @@
##           master    #2024      +/-   ##
==========================================
+ Coverage   48.66%   48.84%   +0.17%     
==========================================
  Files         518      518              
  Lines      115929   116022      +93     
==========================================
+ Hits        56416    56670     +254     
+ Misses      59513    59352     -161     
Impacted Files Coverage Δ
src/nrnoc/secref.cpp 27.80% <50.00%> (+5.14%) ⬆️
src/oc/code.cpp 81.29% <91.66%> (+0.34%) ⬆️
src/oc/hoc_oop.cpp 75.25% <96.42%> (+0.69%) ⬆️
src/nrnpython/nrnpy_hoc.cpp 69.33% <97.72%> (+2.47%) ⬆️
src/ivoc/matrix.cpp 51.08% <100.00%> (+0.35%) ⬆️
src/nrncvode/netcvode.cpp 88.50% <100.00%> (ø)
src/nrnpython/nrnpy_nrn.cpp 74.32% <100.00%> (+0.01%) ⬆️
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@azure-pipelines

Copy link
Copy Markdown

✔️ eddcadc -> Azure artifacts URL

@alexsavulescu

Copy link
Copy Markdown
Member

@nrnhines nrnhines marked this pull request as ready for review October 20, 2022 14:40
@alexsavulescu

Copy link
Copy Markdown
Member

https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3290522300

~30 models now exhibit dimension errors

@nrnhines

Copy link
Copy Markdown
Member Author

~30 models now exhibit dimension errors

Can you rerun. Any that are Vector[0].x is array not function. Use x[...] syntax can be fixed easily. If some are not, I'll have to look in more detail

@azure-pipelines

Copy link
Copy Markdown

✔️ 4df6b9c -> Azure artifacts URL

@alexsavulescu

Copy link
Copy Markdown
Member

@alexsavulescu

Copy link
Copy Markdown
Member

✔️ 4df6b9c -> Azure artifacts URL

https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3298992007

Now we have 25 with is array not function and 1 with array dimension.

@olupton

olupton commented Nov 2, 2022

Copy link
Copy Markdown
Collaborator

@olupton This contains a few changes that are also helpful for my changes to olupton/data-structures that focus on validity checking of python _ref_var pointers. If acceptable, merging will help me get going on this again.

OK -- I can review the content of the PR. The last run of the ModelDB CI (https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3344566067) was still showing some differences with these changes, e.g.:

  • model 168314 %neuron-executable%: Matrix[7].x is array not function. Use x[...] syntax
  • models 187610, 237728, 258867 and 260967 %neuron-executable%: bad stack access: expecting double; really stack_ndim_datum 1

Is this expected / something you're aware of and happy with?

@nrnhines

nrnhines commented Nov 2, 2022

Copy link
Copy Markdown
Member Author

model 168314 %neuron-executable%: Matrix[7].x is array not function. Use x[...] syntax
models 187610, 237728, 258867 and 260967 %neuron-executable%: bad stack access: expecting double; really stack_ndim_datum 1

Thanks! I guess it is back to the drawing board in regard to the bad stack access. I'll have to examine that more closely. The Matrix fix I need to do in ModelDB.

@azure-pipelines

Copy link
Copy Markdown

✔️ 007145e -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ a88d395 -> Azure artifacts URL

@nrnhines

nrnhines commented Nov 2, 2022

Copy link
Copy Markdown
Member Author

Decided to allow legacy Matrix.x(i,j) to avoid changing a model in ModelDB. Hopefully, the nrn-modeldb-ci will pass now. I'll try my hand at getting it started.

@nrnhines

nrnhines commented Nov 2, 2022

Copy link
Copy Markdown
Member Author

Sorry. Could not remember how to specify use of the hines/vardimfix branch for a nrn-modeldb-ci action.

@azure-pipelines

Copy link
Copy Markdown

✔️ d586408 -> Azure artifacts URL

@olupton

olupton commented Nov 2, 2022

Copy link
Copy Markdown
Collaborator

Sorry. Could not remember how to specify use of the hines/vardimfix branch for a nrn-modeldb-ci action.

It uses the Python wheels, so you take the URL posted by the bot:

✔️ d586408 -> Azure artifacts URL

and manually launch the pipeline:

Screenshot 2022-11-02 at 17 34 30

which I did to get https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3379383559

@nrnhines

nrnhines commented Nov 2, 2022

Copy link
Copy Markdown
Member Author

Hmm. Another surprise. 114355 now generates a bad stack access: expecting stack_ndim_datum; really double
Will look into it.

@azure-pipelines

Copy link
Copy Markdown

✔️ a2cce15 -> Azure artifacts URL

@olupton olupton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally looks good to me, I launched https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3383688282 comparing this against neuron-nightly (i.e. the current master) to check one more time.

Comment thread share/lib/hoc/import3d/import3d_sec.hoc
Comment thread src/nrnoc/secref.cpp Outdated
Comment thread src/oc/code.cpp Outdated
@olupton

olupton commented Nov 3, 2022

Copy link
Copy Markdown
Collaborator

Generally looks good to me, I launched https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/3383688282 comparing this against neuron-nightly (i.e. the current master) to check one more time.

This one looks good. We should follow up later on today's diffs between neuron (8.2.1) and neuron-nightly (master).

@azure-pipelines

Copy link
Copy Markdown

✔️ 55f75f9 -> Azure artifacts URL

@nrnhines nrnhines merged commit a8362dc into master Nov 3, 2022
@nrnhines nrnhines deleted the hines/vardimfix branch November 3, 2022 14:07
@pramodk

pramodk commented Nov 4, 2022

Copy link
Copy Markdown
Member

@wvangeit @DrTaDa: Just want to inform you about this PR/change in the current master / future releases of NEURON. In one of our internal GitLab CI test I saw today error like:

image

This is one of the old circuits (accessible in /gpfs/bbp.cscs.ch/project/proj12/jenkins/cellular/circuit-1k/) and may not be relevant for new circuits but mentioning this anyway.

Just a note: On our internal discussion @olupton clarified following:
There will be some kind of variable called axon that was initially declared/used as a scalar and subsequently got used as a vector. That was never safe, and now it’s an error…
(note that in the description of the PR, “compile time” generally means HOC compile time — roughly when the .hoc file is parsed, not C/C++/CMake/… compile time)

@olupton

olupton commented Nov 4, 2022

Copy link
Copy Markdown
Collaborator

@nrnhines a distilled version of the above failure (thanks a lot to @WeinaJi 💪🎉 ) is:

begintemplate Cell
public axon
create axon[2]
endtemplate Cell
objref CellRef
CellRef = new Cell()
// Expression A:
CellRef.axon[1](0)
// Expression B:
CellRef.axon[0] connect CellRef.axon[1](0), 1

where expression A produces:

nrniv: [...](...) syntax only allowed for array range variables: axon

and if it is commented out, expression B produces:

nrniv: array dimension of axon now 1 (at compile time it was 0)
  in vardimtests/test10.hoc near line 8
  CellRef.axon[0] connect CellRef.axon[1](0), 1
                                               ^

what do you think the best fix would be here?

olupton added a commit that referenced this pull request Nov 4, 2022
This demonstrates an error that started appearing in BBP-internal models
after #2024 was merged.
@olupton olupton mentioned this pull request Nov 4, 2022
@nrnhines

nrnhines commented Nov 4, 2022

Copy link
Copy Markdown
Member Author

CellRef.axon[1](0)

Expression A is an invalid statement in hoc world (in python world it refers to the segment at x=0)
Expression B is supposed to work. I'll look into it now. It is a special case I missed.

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.

5 participants