neurolib-dev / neurolib

Easy whole-brain modeling for computational neuroscientists 🧠💻👩🏿‍🔬
MIT License
406 stars 84 forks source link

Todo: enum list of models #124

Open caglorithm opened 3 years ago

caglorithm commented 3 years ago

There should be a way to list all available models. Similar to how TVB handles it would be nice: http://docs.thevirtualbrain.com/_modules/tvb/simulator/models.html

caglorithm commented 3 years ago

Still don't know how to solve this in the best way. This is what I've been imagining: Ideally, the user could do

import neurolib
print(neurolib.models)

and get a list of the model's module names (e.g., neurolib.models.aln), and the name and the description attribute of each model.

This gets the name of all submodules for example (in neurolib/__init__py). But then? Do I need to import them to get the attributes of each model class? Seems a bit overkill.

import pkgutil
import neurolib.models

package = neurolib.models

models = []
for _, modname, _ in pkgutil.walk_packages(
    path=package.__path__, prefix=package.__name__ + ".", onerror=lambda x: None
):
    if modname.split(".")[-1] == "model":
        models.append(modname)

image

Obviously the easiest way would be to hardcode a list. But that's not fun, innit?

jajcayn commented 3 years ago

I think you actually need to import them in order to get the info stored in the class itself... so some packages define something like __all__ = [] as a list in some __init__ file which also then can work like "from neurolib.models import *" and it'll import only stuff that is inside __all__... that can be also used to print out available models I guess?

however, print(neurolib.models) won't work I am afraid..