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

Stats about the usage of various NMODL constructs in ModelDB #1331

Open
alkino opened this issue Jul 8, 2024 · 0 comments
Open

Stats about the usage of various NMODL constructs in ModelDB #1331

alkino opened this issue Jul 8, 2024 · 0 comments

Comments

@alkino
Copy link
Member

alkino commented Jul 8, 2024

Here is a script to have usage of keywords in your mod files.

import os
from nmodl.dsl import visitor
import nmodl

class NodeVisitor(visitor.AstVisitor):
    def __init__(self):
        visitor.AstVisitor.__init__(self)
        self.dict = {}
    def visit_node(self, node):
        type_name = node.get_node_type_name()
        self.dict[type_name] = self.dict.get(type_name, 0) + 1

visit = NodeVisitor()

files = (os.path.join(dirpath,f) for (dirpath, dirnames, filenames) in os.walk("/home/alkino/EPFL/nrn-modeldb-ci/cache/out/") for f in filenames if f.endswith(".mod"))
for f in files:
    driver = nmodl.NmodlDriver()
    try:
        ast = driver.parse_file(f)
    except RuntimeError:
        print(f)

    ast.visit_children(visit)

print(visit.dict)

It requires a small addition to https://github.com/BlueBrain/nmodl/blob/master/src/language/templates/ast/ast.cpp#L134
Before v.visit_{{}} add:

{% if not node.is_program_node %}
v.visit_node(*this);
{% endif %}

Add the same for the constVisitor function right below.

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

No branches or pull requests

1 participant