Skip to content

Allow segment.mechanism.func(args)#2475

Merged
nrnhines merged 39 commits into
masterfrom
hines/mechfunc
Oct 16, 2023
Merged

Allow segment.mechanism.func(args)#2475
nrnhines merged 39 commits into
masterfrom
hines/mechfunc

Conversation

@nrnhines

@nrnhines nrnhines commented Aug 25, 2023

Copy link
Copy Markdown
Member

Closes #686
Includes #2504
Includes #2460

Allow mechanism function calls using the syntax section(x).mechanism.func(args) without requiring a setup call to h.setdata_mechanism(section(x)) for the case where func uses range variables.
E.g. the old syntax required:

h.setdata_hh(soma(.5))
h.rates_hh(-65)

and the new recommended syntax is

soma(.5).hh.rates(-65)
  • Need user documentation.
  • Need careful review and testing of try/catch for NPyMechFunc_call
  • Are data handles used when possible (instead of pointers)?
  • Is nrn.MechFunc sufficiently complete? Generically its methods are name() and mech(). A nrn.Mechanism presently has no provision for listing the FUNCTION and PROCEDURE available from the mod file, e.g. via dir(...).
  • An interesting feature of this implementation is that the call makes minimal use of HOC. (Just args on the hoc stack).

Timeit results from

$ cat temp2.py
import timeit

setup= '''
from neuron import h
s = h.Section()
s.insert("hh")
z = s(.5).hh.rates
zz = s(.5).hh.vtrap
'''

def tim(s):
    print(s, min(timeit.repeat(s, setup, number=10000)))

tim("s(.5).hh.rates(-30)")
tim("z(-30)")
tim("h.rates_hh(-30)")
tim("h.setdata_hh(s(.5));h.rates_hh(-30)")

tim("zz(0, 1)")

are

$ python3 temp2.py
s(.5).hh.rates(-30) 0.20718456991016865
z(-30) 0.0590008000144735
h.rates_hh(-30) 0.10944443196058273
h.setdata_hh(s(.5));h.rates_hh(-30) 0.3778606569394469
zz(0, 1) 0.05770030908752233

@azure-pipelines

Copy link
Copy Markdown

✔️ 077c083 -> Azure artifacts URL

@codecov

codecov Bot commented Aug 25, 2023

Copy link
Copy Markdown

Codecov Report

Merging #2475 (4574f28) into master (6004512) will decrease coverage by 0.14%.
The diff coverage is 96.69%.

@@            Coverage Diff             @@
##           master    #2475      +/-   ##
==========================================
- Coverage   65.98%   65.85%   -0.14%     
==========================================
  Files         560      559       -1     
  Lines      108876   108787      -89     
==========================================
- Hits        71844    71641     -203     
- Misses      37032    37146     +114     
Files Coverage Δ
src/nmodl/nocpout.cpp 95.31% <100.00%> (+0.23%) ⬆️
src/nmodl/parsact.cpp 88.05% <100.00%> (+0.36%) ⬆️
src/nmodl/parse1.ypp 82.59% <100.00%> (+0.27%) ⬆️
src/nrnoc/init.cpp 89.94% <100.00%> (+0.08%) ⬆️
src/nrnoc/membfunc.cpp 66.66% <100.00%> (+1.28%) ⬆️
src/nrnoc/membfunc.h 100.00% <ø> (ø)
src/nrnpython/nrnpy_hoc.cpp 70.94% <100.00%> (ø)
src/nrnpython/nrnpy_utils.h 86.73% <ø> (ø)
src/nrnpython/nrnpy_nrn.cpp 74.60% <93.04%> (+1.60%) ⬆️

... and 7 files with indirect coverage changes

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

@bbpbuildbot

This comment has been minimized.

@azure-pipelines

Copy link
Copy Markdown

✔️ 6bb061e -> Azure artifacts URL

@bbpbuildbot

This comment has been minimized.

@nrnhines nrnhines marked this pull request as draft October 3, 2023 09:51
@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

Factorization (incomplete) of new NPyMechObj with new_pymechobj.
    Unsolved tests failures:
         21 - pytest_coreneuron::basic_tests_py3.10 (Failed)
        102 - coreneuron_modtests::datareturn_py_cpu (Failed)
@bbpbuildbot

This comment has been minimized.

@bbpbuildbot

This comment has been minimized.

@azure-pipelines

Copy link
Copy Markdown

✔️ 0ab60ff -> Azure artifacts URL

@bbpbuildbot

This comment has been minimized.

@nrnhines nrnhines marked this pull request as ready for review October 13, 2023 21:46
@pramodk

pramodk commented Oct 13, 2023

Copy link
Copy Markdown
Member

apple m1 failure seems unrelated. Will take a look tomorrow.

@pramodk pramodk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Gitlab CI launched internally for Apple M1 has passed: https://bbpgitlab.epfl.ch/hpc/cellular/nrn/-/jobs/965444

Comment thread src/nmodl/nocpout.cpp
Comment thread src/nrnpython/nrnpy_nrn.h Outdated
Comment thread test/pytest_coreneuron/test_basic.py Outdated
@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 24 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 61 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@azure-pipelines

Copy link
Copy Markdown

✔️ 4574f28 -> Azure artifacts URL

@ramcdougal

Copy link
Copy Markdown
Member

Is nrn.MechFunc sufficiently complete? Generically its methods are name() and mech(). A nrn.Mechanism presently has no provision for listing the FUNCTION and PROCEDURE available from the mod file, e.g. via dir(...).

With respect to our conversation with @Helveg earlier today, nrn.hh ought to provide a way of getting the generic density mechanism h.hh (and similarly for all density mechanisms)

@nrnhines nrnhines merged commit 6cb0bac into master Oct 16, 2023
@nrnhines nrnhines deleted the hines/mechfunc branch October 16, 2023 23:31
@Helveg

Helveg commented Oct 17, 2023

Copy link
Copy Markdown
Contributor

@ramcdougal @nrnhines I suppose that Robert's latest comment hasn't been addressed in this PR? Equality checks also fail between nrn.Mechanisms

@nrnhines

nrnhines commented Oct 17, 2023

Copy link
Copy Markdown
Member Author

@ramcdougal @Helveg

equality, access to generic type.

That is an oversight on my part. I'll start another PR. Does anyone offhand know if there is an issue to be associated with it?
Is it worthwhile to extend equality to mechanism functions?

@Helveg

Helveg commented Oct 17, 2023

Copy link
Copy Markdown
Contributor

We didn't open an issue yet, just the Slack thread and comments here.

I use equality checks to avoid circular logic by keeping a bag of already visited NEURON objects in a differ that I'm writing for NEURON that reports differences between 2 objects recursively visiting everything attached/related to the input objects. Generally speaking, anything that leads to a more complete Python interface would allow Python tooling to write cleaner and simpler code.

Right now I'm monkey patching the __hash__ and __eq__ methods, but I'm sure I'll run into a readonly class object soon enough ;)

@ramcdougal

ramcdougal commented Oct 17, 2023

Copy link
Copy Markdown
Member

I was going to object to your use of "more complete" because you can get all the information you seek through either sec.psection() directly or MechanismStandard or MechanismType... But yeah, that's fair, if equality doesn't work that is incomplete.

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.

seg fault when calling mechanism function that depends on location without setdata

6 participants