Skip to content

Commit

Permalink
use GH cli to get list of neuron simulator models
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavulescu committed May 30, 2023
1 parent 7bac176 commit b970c57
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nrn-modeldb-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ jobs:
id: install-deps
run: |
set
# Install GH cli
sudo apt-get install gh
# Set up Xvfb
sudo apt-get install xvfb
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1600x1200x24 -noreset -nolock -shmem & # run in bg
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ The following commands are now available:
| MODELDB_RUN_FILE | yaml file containing run instructions for models (required for `runmodels`) |
| MODELDB_METADATA_FILE | yaml file containing model info for those downloaded with `getmodels` |
| MODELS_ZIP_DIR | location of cache folder for models populated via `getmodels` |
| MDB_NEURON_MODELS_URL | url used to get list of all NEURON model ids (necessary for `getmodels`) |
| MDB_MODEL_DOWNLOAD_URL | url template used for model downloading (cf `{model_id}`) |

## Model Run

Expand Down
2 changes: 1 addition & 1 deletion modeldb/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def modeldb_config(args=None):
Examples
modeldb-config
modeldb-config --item=MDB_NEURON_MODELS_URL
modeldb-config --item=MODELS_ZIP_DIR
"""
options = docopt(modeldb_config.__doc__, args)
item = options.pop("--item", None)
Expand Down
4 changes: 0 additions & 4 deletions modeldb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import os

MDB_NEURON_MODELS_URL = (
"http://modeldb.science/api/v1/models?modeling_application=NEURON"
)

ROOT_DIR = os.path.abspath(__file__ + "/../../")

MODELS_ZIP_DIR = "%s/cache" % ROOT_DIR
Expand Down
15 changes: 14 additions & 1 deletion modeldb/modeldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import traceback
from pprint import pformat


def download_model(arg_tuple):
model_id, model_run_info = arg_tuple
try:
Expand Down Expand Up @@ -60,11 +61,23 @@ def __init__(self):
except Exception as e:
raise e

def _gh_cli_get_neuron_simulator_repositories(self):
import subprocess

# Run the gh command to fetch the repository list and capture the output
command = ['gh', 'repo', 'list', 'modeldbrepository', '--topic', 'neuron-simulator', '--json', 'name', '-L', '2000']
output = subprocess.check_output(command, text=True)

# Parse the json output to get the repository names
import json
repositories = json.loads(output)
return [int(repository['name']) for repository in repositories]

def _download_models(self, model_list=None):
if not os.path.isdir(MODELS_ZIP_DIR):
logging.info("Creating cache directory: {}".format(MODELS_ZIP_DIR))
os.mkdir(MODELS_ZIP_DIR)
models = requests.get(MDB_NEURON_MODELS_URL).json() if model_list is None else model_list
models = self._gh_cli_get_neuron_simulator_repositories() if model_list is None else model_list
pool = multiprocessing.Pool()
processed_models = pool.imap_unordered(
download_model,
Expand Down

0 comments on commit b970c57

Please sign in to comment.