Skip to content

Commit 1e23ae3

Browse files
Merge branch 'master' into kotsalos/python_models
2 parents 6380e4a + 962ec51 commit 1e23ae3

File tree

8 files changed

+341
-113
lines changed

8 files changed

+341
-113
lines changed

.github/workflows/nrn-modeldb-ci.yaml

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ on:
88
schedule:
99
# Run at 2am every day
1010
- cron: '0 2 * * *'
11+
workflow_call:
12+
inputs:
13+
neuron_v1:
14+
description: Last official release (neuron) / NEURON pinned version / Azure drop (artifacts) url
15+
default: 'neuron'
16+
required: true
17+
type: string
18+
neuron_v2:
19+
description: Last nightly release (neuron-nightly) / NEURON pinned version / Azure drop (artifacts) url
20+
default: 'neuron-nightly'
21+
required: true
22+
type: string
23+
models_to_run:
24+
description: 'Empty for all models, space separated accession numbers for specific models'
25+
default: ''
26+
required: false
27+
type: string
28+
repo:
29+
default: 'neuronsimulator/nrn-modeldb-ci'
30+
type: string
31+
required: false
32+
33+
1134
workflow_dispatch:
1235
inputs:
1336
neuron_v1:
@@ -26,25 +49,25 @@ on:
2649
jobs:
2750
nrn-modeldb-ci:
2851
runs-on: ubuntu-latest
29-
timeout-minutes: 60
3052
strategy:
3153
fail-fast: false
32-
matrix:
33-
python-version: ["3.9"]
3454
env:
3555
DISPLAY: ${{ ':0' }}
36-
NEURON_V1: ${{ github.event.inputs.neuron_v1 || 'neuron' }}
37-
NEURON_V2: ${{ github.event.inputs.neuron_v2 || 'neuron-nightly' }}
38-
MODELS_TO_RUN: ${{ github.event.inputs.models_to_run || '' }}
56+
NEURON_V1: ${{ github.event.inputs.neuron_v1 || inputs.neuron_v1 || 'neuron' }}
57+
NEURON_V2: ${{ github.event.inputs.neuron_v2 || inputs.neuron_v2 || 'neuron-nightly' }}
58+
MODELS_TO_RUN: ${{ github.event.inputs.models_to_run || inputs.models_to_run || '' }}
3959

4060
steps:
41-
- uses: actions/checkout@v2
4261

43-
- name: check for Azure drop NEURON_V1 -> ${{ github.event.inputs.neuron_v1 }}
44-
if: github.event_name == 'workflow_dispatch' && startsWith(github.event.inputs.neuron_v1, 'https://dev.azure.com/neuronsimulator/')
62+
- uses: actions/checkout@v3
63+
with:
64+
repository: ${{ inputs.repo || github.repository }}
65+
66+
- name: check for Azure drop NEURON_V1 -> ${{ env.NEURON_V1 }}
67+
if: startsWith(env.NEURON_V1, 'https://dev.azure.com/neuronsimulator/')
4568
run: |
4669
# check URI
47-
curl -sfSI -X GET '${{ github.event.inputs.neuron_v1 }}'
70+
curl -sfSI -X GET '${{ env.NEURON_V1 }}'
4871
4972
# Download Azure drop and unzip
5073
AZURE_DROP_URL="$NEURON_V1"
@@ -56,11 +79,11 @@ jobs:
5679
# Set drop dir in the env
5780
echo "DROP_DIR_V1=`pwd`/DROP_V1" >> $GITHUB_ENV
5881
59-
- name: check for Azure drop NEURON_V2 -> ${{ github.event.inputs.neuron_v2 }}
60-
if: github.event_name == 'workflow_dispatch' && startsWith(github.event.inputs.neuron_v2, 'https://dev.azure.com/neuronsimulator/')
82+
- name: check for Azure drop NEURON_V2 -> ${{ env.NEURON_V2 }}
83+
if: startsWith(env.NEURON_V2, 'https://dev.azure.com/neuronsimulator/')
6184
run: |
6285
# check URI
63-
curl -sfSI -X GET '${{ github.event.inputs.neuron_v2 }}'
86+
curl -sfSI -X GET '${{ env.NEURON_V2 }}'
6487
6588
# Download Azure drop and unzip
6689
AZURE_DROP_URL="$NEURON_V2"
@@ -72,25 +95,36 @@ jobs:
7295
# Set drop dir in the env
7396
echo "DROP_DIR_V2=`pwd`/DROP_V2" >> $GITHUB_ENV
7497
75-
- name: Set up Python ${{ matrix.python-version }}
76-
uses: actions/setup-python@v2
98+
- uses: actions/setup-python@v4
7799
with:
78-
python-version: ${{ matrix.python-version }}
79-
100+
python-version: 3.9
101+
80102
- name: Set models to run for PR
81103
run: |
82-
# Select a few models to run CI for PRs
104+
# For PRs we only have a few models for quick sanity checking.
105+
# Once the PR is green you need to manually run the ModelDB CI workflow by simply selecting your branch in the UI.
106+
107+
# The follwing selection aims to target different features (since we haven't worked on unit testing yet -> #38 ).
108+
# Select a few models to run CI for PRs:
109+
# 64195 -> run: null
110+
# 22203 -> skip: true
111+
# 156120 -> several model directories
112+
# 97868 -> failed nrnivmodl
113+
# 146030 -> curate_patterns
114+
# 244679 -> no entry in modeldb-run.yaml
115+
# rest: -> currently yielding differences in the pipeline
116+
#echo 'MODELS_TO_RUN=64195 22203 156120 51781 97868 22203 97756 97917 105507 136803 138379 138382 146030 244679 251881' >> $GITHUB_ENV
83117
#TODO - temporary run added python models
84118
echo 'MODELS_TO_RUN=156039 194897 226422 186768 189922 195615 139421 144586 244412 39948 195569 249404 206400 144511 229276 151282 264834 151685' >> $GITHUB_ENV
85-
if: github.event_name == 'pull_request'
119+
if: github.event_name == 'pull_request' && inputs.repo == ''
86120

87121
- name: Install dependencies and project
88122
id: install-deps
89123
run: |
90124
set
91125
# Set up Xvfb
92126
sudo apt-get install xvfb
93-
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1600x1200x24 & # run in bg
127+
sudo /usr/bin/Xvfb $DISPLAY -screen 0 1600x1200x24 -noreset -nolock -shmem & # run in bg
94128
# Install python dependencies
95129
python -m pip install --upgrade pip
96130
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
@@ -155,7 +189,7 @@ jobs:
155189
run: |
156190
diffreports2html ${nrn1_ver}.json ${nrn2_ver}.json
157191
158-
- uses: actions/upload-artifact@v2
192+
- uses: actions/upload-artifact@v3
159193
with:
160194
name: ${{ env.nrn1_ver }}-vs-${{ env.nrn2_ver }}
161195
path: |

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v3
1717
- name: Set up Python
18-
uses: actions/setup-python@v3
18+
uses: actions/setup-python@v4
1919
with:
2020
python-version: '3.x'
2121
- name: Install dependencies

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ Every `runmodels` report will hold out run statistics in the `"0"` key:
224224
},
225225
```
226226

227+
For every model there is a `<model.id>.yaml` that is dumped in the model run directory.
228+
This is used in case the model is re-run in `--inplace` mode (also useful for debugging).
229+
230+
```bash
231+
(venv) nrn-modeldb-ci$ cat test3682/synmap/3682.yaml
232+
```
233+
```yaml
234+
driver: /home/savulesc/Workspace/nrn-modeldb-ci/test3682/synmap/driver.hoc
235+
init: /home/savulesc/Workspace/nrn-modeldb-ci/test3682/synmap/mosinit.hoc
236+
model_dir: /home/savulesc/Workspace/nrn-modeldb-ci/test3682/synmap
237+
script:
238+
- echo 'use_mcell_ran4(1)' > temp
239+
- cat mosinit.hoc >> temp
240+
- mv temp mosinit.hoc
241+
start_dir: /home/savulesc/Workspace/nrn-modeldb-ci/test3682/synmap
242+
(venv) savulesc@bbd-cjngk03:~/Workspace/nrn-modeldb-ci$
243+
```
244+
227245
## Funding
228246

229247

modeldb/commands.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def runmodels(args=None):
3636
--virtual Run in headless mode. You need a back-end like Xvfb.
3737
--clean Auto-clean model working directory before running (useful for consecutive runs and failsafe)
3838
--norun Compile and link only (nrnivmodl).
39+
--inplace Skip model preparation logic, simply run NEURON.
3940
4041
Examples
4142
runmodels --workdir=/path/to/workdir # run all models
@@ -48,22 +49,29 @@ def runmodels(args=None):
4849
virtual = options.pop("--virtual", False)
4950
clean = options.pop("--clean", False)
5051
norun = options.pop("--norun", False)
52+
inplace = options.pop("--inplace", False)
5153

5254
if os.path.abspath(working_dir) == ROOT_DIR:
5355
print("Cannot run models directly into nrn-modeldb-ci ROOT_DIR -> {}".format(ROOT_DIR))
5456
sys.exit(1)
5557

56-
if not clean and is_dir_non_empty(working_dir):
57-
print("WARNING: WorkingDirectory {} exists and is non empty.".format(working_dir))
58-
print("\tre-run with --clean if you wish to overwrite model runs!")
58+
if clean and inplace:
59+
print("ERROR: --clean and --inplace are mutually exclusive")
5960
sys.exit(1)
6061

61-
mrm = ModelRunManager(working_dir, gout=gout, clean=clean, norun=norun)
62+
if not (clean or inplace) and is_dir_non_empty(working_dir):
63+
print("ERROR: WorkingDirectory {} exists and is non empty.".format(working_dir))
64+
print("\t re-run with one of these options:\n"
65+
"\t\t--clean \t-> if you wish to OVERWRITE model runs (delete content from --workdir and re-build from cache)\n"
66+
"\t\t--inplace \t-> if you wish to re-run the same model (content in --workdir is kept)\n")
67+
sys.exit(1)
68+
69+
mrm = ModelRunManager(working_dir, gout=gout, clean=clean, norun=norun, inplace=inplace)
6270
model_list = model_ids if model_ids else None
6371

6472
if virtual:
6573
from pyvirtualdisplay import Display
66-
with Display() as _:
74+
with Display(manage_global_env=False) as _:
6775
mrm.run_models(model_list)
6876
else:
6977
mrm.run_models(model_list)
@@ -206,11 +214,14 @@ def diffreports2html(args=None):
206214
file_loader = FileSystemLoader(os.path.join(Path(__file__).parent.resolve(), 'templates'))
207215
env = Environment(loader=file_loader)
208216
template = env.get_template('diffreport.html')
217+
runtime_template = env.get_template('runtimes.html')
209218

210219
report_title = '{}-vs-{}'.format(os.path.splitext(json_report1)[0],
211220
os.path.splitext(json_report2)[0])
212221
report_filename = os.path.join(Path(json_report1).resolve().parent, report_title + '.html')
213-
diff_dict, gout_dict = diff_reports(json_report1, json_report2)
222+
runtime_report_title = 'Runtimes ' + report_title
223+
runtime_report_filename = os.path.join(Path(json_report1).resolve().parent, "runtimes-" + report_title + '.html')
224+
diff_dict, gout_dict,runtime_dict, v1, v2 = diff_reports(json_report1, json_report2)
214225

215226
print('Writing {} ...'.format(report_filename))
216227
with open(report_filename, 'w') as fh:
@@ -220,3 +231,13 @@ def diffreports2html(args=None):
220231
gout_dict=gout_dict),
221232
)
222233
print('Done.')
234+
print('Writing {} ...'.format(runtime_report_filename))
235+
with open(runtime_report_filename, 'w') as fh:
236+
fh.write(runtime_template.render(
237+
title="{}".format(runtime_report_title),
238+
runtime_dict=runtime_dict,
239+
stats={"stats":diff_dict['0']},
240+
v1=v1,
241+
v2=v2),
242+
)
243+
print('Done.')

modeldb/modeldb-run.yaml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,7 @@
465465
- load_file("sample.hoc")
466466
- verify_graph_()
467467
script:
468-
- sed 's,tstop *=,tstop = 100//,
469-
- /whichAP/,$d
470-
- ''' sample.hoc > temp.tmp'
471-
- mv temp.tmp sample.hoc
468+
- sed -i'.bak' -e 's/tstop *=/tstop = 100\/\//g;/whichAP/,$d' sample.hoc
472469
76879:
473470
run:
474471
- tstop=20
@@ -503,10 +500,7 @@
503500
83590:
504501
run: []
505502
script:
506-
- sed 's/mustart = -0.400/mustart = 0.800/
507-
- ' s/sigmastart = 0.064/sigmastart = 0.128/'
508-
- ''' mylibs/TFparams.hoc > temp.tmp'
509-
- mv temp.tmp mylibs/TFparams.hoc
503+
- sed -i'.bak' -e 's/mustart = -0.400/mustart = 0.800/g;s/sigmastart = 0.064/sigmastart = 0.128/g' mylibs/TFparams.hoc
510504
84589:
511505
run:
512506
- //ignore sim in subdirectory
@@ -673,9 +667,7 @@
673667
- load_file("batch_.hoc")
674668
- verify_graph_()
675669
script:
676-
- sed 's/batch_flag=0/batch_flag=1/
677-
- s/tstop = 1e3/tstop = 20/' batch_.hoc > temp.tmp
678-
- mv temp.tmp batch_.hoc
670+
- sed -i'.bak' -e 's/batch_flag=0/batch_flag=1/g;s/tstop = 1e3/tstop = 20/g' batch_.hoc
679671
106551:
680672
run:
681673
- use_mcell_ran4(1)
@@ -823,8 +815,7 @@
823815
- //load_file("init.hoc")
824816
- //verify_graph_()
825817
script:
826-
- sed 's/tstop = 100/tstop = 20/' init.hoc > temp.tmp
827-
- mv temp.tmp init.hoc
818+
- sed -i'.bak' -e 's/tstop = 100/tstop = 20/g' init.hoc
828819
116835:
829820
run:
830821
- tstop=10
@@ -836,8 +827,7 @@
836827
- run()
837828
- verify_graph_()
838829
script:
839-
- sed 's/^showdemo=1/showdemo=0/' mosinit.hoc > temp.tmp
840-
- mv temp.tmp mosinit.hoc
830+
- sed -i'.bak' -e 's/^showdemo=1/showdemo=0/g' mosinit.hoc
841831
116956:
842832
run:
843833
- run()
@@ -962,16 +952,14 @@
962952
- run()
963953
- verify_graph_()
964954
script:
965-
- sed 's/tstop = 6500/tstop = 100/' session.ses > temp.tmp
966-
- mv temp.tmp session.ses
955+
- sed -i'.bak' -e 's/tstop = 6500/tstop = 100/g' session.ses
967956
124291:
968957
run:
969958
- stim.amp = 0.1
970959
- runa()
971960
- verify_graph_()
972961
script: # todo -> fix model for NEURON 8.0.0 and remove this script
973-
- sed 's/return 0;//' MOPP_Fig_1B_left/ichan2.mod > temp.tmp
974-
- mv temp.tmp MOPP_Fig_1B_left/ichan2.mod
962+
- sed -i'.bak' -e 's/return 0;//g' MOPP_Fig_1B_left/ichan2.mod
975963
138321:
976964
run:
977965
- run()
@@ -1076,21 +1064,21 @@
10761064
- run()
10771065
- verify_graph_()
10781066
script:
1079-
- sed -i 's/tstop = /tstop = 50\/\//' Fig8_tuft_NMDA_spike.hoc
1080-
- sed -i 's/simul_iter=/simul_iter=2 \/\//' Fig8_tuft_NMDA_spike.hoc
1067+
- sed -i'.bak' -e 's/tstop = /tstop = 50\/\//' Fig8_tuft_NMDA_spike.hoc
1068+
- sed -i'.bak' -e 's/simul_iter=/simul_iter=2 \/\//' Fig8_tuft_NMDA_spike.hoc
10811069
comment: usual simulation time is ~ 10 minutes (tstop = 120 and simul_iter=10)
10821070
206267:
10831071
run:
10841072
- run()
10851073
- verify_graph_()
10861074
script:
1087-
- sed -i 's/tstop=/tstop=100 \/\//' Start.hoc
1075+
- sed -i'.bak' -e 's/tstop=/tstop=100 \/\//' Start.hoc
10881076
157157:
10891077
run:
10901078
- run()
10911079
- verify_graph_()
10921080
script:
1093-
- sed -i 's/tstop = 5000/tstop = 250 \/\//g' PC.ses
1081+
- sed -i'.bak' -e 's/tstop = 5000/tstop = 250 \/\//g' PC.ses
10941082
244848:
10951083
run: null
10961084
comment: not straightforward to cut down simulation time, takes too long
@@ -1105,15 +1093,20 @@
11051093
- run()
11061094
- verify_graph_()
11071095
script:
1108-
- sed -i 's/500/5/g' BPF.hoc
1109-
- sed -i 's/2\([0|1]\)000/2\1/g' BPF.hoc
1096+
- sed -i'.bak' -e 's/500/5/g' BPF.hoc
1097+
- sed -i'.bak' -e 's/2\([0|1]\)000/2\1/g' BPF.hoc
11101098
comment: diving some numbers with 100 halvened the sim time
11111099
151126:
11121100
run:
11131101
- run()
11141102
- verify_graph_()
11151103
script:
1116-
- sed -i 's/tstop = 550/tstop = 100/' HAM_SR1.ses
1104+
- sed -i'.bak' -e 's/tstop = 550/tstop = 100/' HAM_SR1.ses
1105+
136803:
1106+
run:
1107+
- run()
1108+
- verify_graph_()
1109+
model_dir: mod_files
11171110
# python models
11181111
# find * -name mosinit.py
11191112
156039:

0 commit comments

Comments
 (0)