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

PR for everything I've done so far on my fork #53

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
42f3bcb
added various script to run life_demo via sca
soichih Jan 14, 2016
d625875
fixing file attribute
soichih Jan 14, 2016
65874d5
updated templates
soichih Jan 14, 2016
8bd8878
updated products.json template
soichih Jan 14, 2016
6ff817a
split demo.sh into demo_start.sh and demo_status.sh
soichih Jan 14, 2016
713210b
fixed demo_status.sh file attribute
soichih Jan 14, 2016
9d5d4be
added progress report for waiting on pbs queue
soichih Jan 14, 2016
ea25ad0
updated the status handling logic
soichih Jan 14, 2016
137fb32
bug fix for status handling logic
soichih Jan 14, 2016
d7ef81a
another update for job status logic
soichih Jan 14, 2016
4e5cb70
fixed typo
soichih Jan 14, 2016
70bcc59
added a bit more progress reporting
soichih Jan 14, 2016
e21ac6b
switching to raw data type
soichih Jan 14, 2016
7d7ed01
added showstart output for status
soichih Jan 16, 2016
acdad06
added debug output
soichih Jan 18, 2016
36bd3dd
updated sca_progress_url handling
soichih Jan 18, 2016
b84fbce
added various progress reporting
soichih Jan 18, 2016
5ce5548
added missing semicolons
soichih Jan 18, 2016
11de7bd
added more progress reporting
soichih Jan 18, 2016
eb1f13a
fixed typo and removed bulk of progress report
soichih Jan 18, 2016
0284fee
another progress update
soichih Jan 18, 2016
30ca3c8
added libcurl https issue work around
soichih Jan 19, 2016
c2ad294
updated demo_start.sh to generate its own pbs script
soichih Jan 19, 2016
c737d0b
typo fix
soichih Jan 19, 2016
039f6b4
updated the way it's detecting bigred
soichih Jan 19, 2016
065383a
reverted the way matlab was invoked on karst
soichih Jan 19, 2016
17d17a3
removing demo.pbs which is now auto generated
soichih Jan 19, 2016
31e93c2
updated progress percentage
soichih Jan 19, 2016
01a3f60
added module load ccm
soichih Jan 19, 2016
dfa0dd5
removed status setting to waiting
soichih Feb 4, 2016
6275675
added progress:1 at the end of life_demo.m
soichih Feb 4, 2016
161a3f2
setting status to running when the pbs script is executed
soichih Feb 4, 2016
cf60b5e
another attempt to fix progress bar going to 0
soichih Feb 4, 2016
6fad04a
de-refernced SCA variable in pbs script
soichih Feb 5, 2016
b40233d
added a bit more progress reporting
soichih Feb 5, 2016
7e8b9f1
fixing PBS_O_WORKDIR deref
soichih Feb 5, 2016
52abed2
fixed incorrect messaging
soichih Feb 5, 2016
767ffed
changed timing of module load curl
soichih Feb 5, 2016
f72dbea
updated ccmrun
soichih Feb 5, 2016
4312a82
put LD_LIBRARY_PATH patch back
soichih Feb 9, 2016
7ccb8a9
switched curl fix strategy
soichih Feb 9, 2016
a665c68
updated the way matlab is invoked
soichih Feb 9, 2016
7844b68
switching to use curl to download file
soichih Feb 9, 2016
69d08d3
added a bit more note on waiting pbs queue
soichih Feb 9, 2016
94a9971
forgot to put -O on curl
soichih Feb 9, 2016
2bb8674
added LD_LIBRARY_PATH unset
soichih Feb 12, 2016
687fa1e
another unset for LD_LIBRARY_PATH
soichih Feb 12, 2016
f7cedc5
added pakcage.json
soichih Apr 19, 2016
495d194
updated to replace products.json mock up
soichih Apr 19, 2016
c9a359e
updated start script to use input data specified
soichih Apr 19, 2016
797bd95
added install.sh
soichih Apr 22, 2016
8d369c8
replaced underscore with jq
soichih Apr 22, 2016
8d83f2f
abondoned install.sh
soichih Apr 22, 2016
fadb3fb
fixed typo
soichih Apr 22, 2016
e61b23a
updated to emit updated version of template products
soichih Apr 22, 2016
b74cb0f
updated pbs name
soichih Apr 26, 2016
334c6b9
completely removed underscore
soichih Apr 29, 2016
c7d07b9
decided to remove data directory even for rerun (it might be corrupted)
soichih Apr 29, 2016
afae33d
replaces sca ref in package.json
soichih May 26, 2016
462d017
updated hardcoded entries in demo.m
soichih May 26, 2016
6ae6e97
updated data type
soichih Jun 1, 2016
b89fccd
removed one hardcoded path
soichih Jun 30, 2016
3ba1269
remved comment
soichih Jun 30, 2016
2b69707
added products.json clean up
soichih Jun 30, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions demo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

addpath(getenv('SCA_SERVICE_DIR'))
addpath(genpath('/N/u/hayashis/Karst/life/vistasoft-master'))
addpath(genpath('./data'))

life_demo()

saveas(ans(0), 'figure0.png')
saveas(ans(1), 'figure1.png')
saveas(ans(2), 'figure2.png')
saveas(ans(3), 'figure3.png')
saveas(ans(4), 'figure4.png')
saveas(ans(5), 'figure5.png')
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "sca-service-life",
"version": "1.0.0",
"description": "run life demo application",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "start.sh",
"stop": "stop.sh",
"status": "status.sh"
},
"repository": {
"type": "git",
"url": "https://github.com/soichih/sca-service-life.git"
},
"author": "Soichi Hayashi <[email protected]>",
"license": "ISC",
"bugs": {
"url": "https://github.com/soichih/sca-service-life/issues"
},
"homepage": "https://github.com/soichih/sca-service-life#readme"
}
17 changes: 17 additions & 0 deletions scripts/life_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
% This helps speeding up computations espacially for large conenctomes.
feOpenLocalCluster;


%% Build the file names for the diffusion data, the anatomical MRI.
dwiFile = fullfile(lifeDemoDataPath('diffusion'),'life_demo_scan1_subject1_b2000_150dirs_stanford.nii.gz');
dwiFileRepeat = fullfile(lifeDemoDataPath('diffusion'),'life_demo_scan2_subject1_b2000_150dirs_stanford.nii.gz');
Expand All @@ -76,13 +77,17 @@
% The final connectome and data astructure will be saved with this name:
feFileName = 'life_build_model_demo_CSD_PROB';

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Initializing the LiFE model structure','progress', 0), weboptions('MediaType','application/json'));

%% (1.1) Initialize the LiFE model structure, 'fe' in the code below.
% This structure contains the forward model of diffusion based on the
% tractography solution. It also contains all the information necessary to
% compute model accuracry, and perform statistical tests. You can type
% help('feBuildModel') in the MatLab prompt for more information.
fe = feConnectomeInit(dwiFile,fgFileName,feFileName,[],dwiFileRepeat,t1File);

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Fitting the model','progress', 0.25), weboptions('MediaType','application/json'));

%% (1.2) Fit the model.
% Hereafter we fit the forward model of tracrography using a least-squared
% method. The information generated by fitting the model (fiber weights
Expand Down Expand Up @@ -110,6 +115,8 @@
% fascicle in the connectome.
prob.w = feGet(fe,'fiber weights');

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Plotting graphs','progress', 0.4), weboptions('MediaType','application/json'));

%% (1.7) Plot a histogram of the RMSE.
% We plot the histogram of RMSE across white-mater voxels.
[fh(1), ~, ~] = plotHistRMSE(prob);
Expand All @@ -121,6 +128,9 @@

%% (1.9) Plot a histogram of the fitted fascicle weights.
[fh(3), ~] = plotHistWeights(prob);

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Initializing the LiFE model structure (2)','progress', 0.5), weboptions('MediaType','application/json'));

fe = feConnectomeInit(dwiFile,fgFileName,feFileName,[],dwiFileRepeat,t1File);

%% Extract the coordinates of the white-matter voxels
Expand All @@ -143,6 +153,7 @@
% tractography solution. It also contains all the information necessary to
% compute model accuracry, and perform statistical tests. You can type
% help('feBuildModel') in the MatLab prompt for more information.
webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Initializing the LiFE model structure (3)','progress', 0.7), weboptions('MediaType','application/json'));
fe = feConnectomeInit(dwiFile,fgFileName,feFileName,[],dwiFileRepeat,t1File);

%% (2.2) Fit the model.
Expand Down Expand Up @@ -172,6 +183,8 @@
% fascicle in the connectome.
det.w = feGet(fe,'fiber weights');

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Plotting graphs (2)','progress', 0.8), weboptions('MediaType','application/json'));

%% (2.7) Plot a histogram of the RMSE.
% We plot the histogram of RMSE across white-mater voxels.
[fh(1), ~, ~] = plotHistRMSE(det);
Expand Down Expand Up @@ -219,6 +232,8 @@
det.rmse = det.rmse( det.coordsIdx);
clear p d

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Plotting graphs (3)','progress', 0.95), weboptions('MediaType','application/json'));

%% (3.2) Make a scatter plot of the RMSE of the two tractography models
fh(4) = scatterPlotRMSE(det,prob);

Expand All @@ -238,6 +253,8 @@
% Movers Distance between the distributions.
fh(6) = distributionPlotEarthMoversDistance(se);

webwrite(getenv('SCA_PROGRESS_URL'), struct('msg','Completed','progress', 1), weboptions('MediaType','application/json'));

end

% ---------- Local Plot Functions ----------- %
Expand Down
142 changes: 142 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/bash

#make sure jq is installed on $SCA_SERVICE_DIR
if [ ! -f $SCA_SERVICE_DIR/jq ];
then
echo "installing jq"
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -O $SCA_SERVICE_DIR/jq
chmod +x $SCA_SERVICE_DIR/jq
fi

#patch libssl issue caused by some module overriding libpath
unset LD_LIBRARY_PATH

#TODO - clean.sh?
echo "clean up from previous run"
rm products.json
rm finished

#find out which environment we are in
hostname | grep karst > /dev/null
if [ $? -eq 0 ]; then
execenv=karst
fi
echo $HOME | grep -i bigred > /dev/null
if [ $? -eq 0 ]; then
execenv=bigred
fi

#create pbs script
if [ $execenv == "karst" ]; then
cat <<EOT > task.pbs
#!/bin/bash
#PBS -l nodes=1:ppn=16:dc2
#PBS -l walltime=1:00:00
#PBS -N sca-service-life
#PBS -V
#Karst
EOT
fi

if [ $execenv == "bigred" ]; then
cat <<EOT > task.pbs
#!/bin/bash
#PBS -l nodes=1:ppn=32:dc2
#PBS -l walltime=1:00:00
#PBS -l gres=ccm
#PBS -N lifedemo
#PBS -V
#BigRed2
EOT
fi

cat <<EOT >> task.pbs

#fixing .module sometimes causes curl / git to fail
unset LD_LIBRARY_PATH

curl -X POST -H "Content-Type: application/json" -d "{\"progress\": 0, \"status\": \"running\"}" $SCA_PROGRESS_URL

cd \$PBS_O_WORKDIR

#data might be already staged if user is rerunning this
#but.. sometime data could get corrupted.. so let's remove it for now.
rm -rf data

#if [ ! -d data ]
#then
echo "untarring input data"
input_task_id=`$SCA_SERVICE_DIR/jq -r '.input_task_id' config.json`
filename=`$SCA_SERVICE_DIR/jq -r '.files[0] .filename' config.json`

curl -X POST -H "Content-Type: application/json" -d "{\"msg\":\"Untarring \$filename\"}" $SCA_PROGRESS_URL
tar -xzf ../\$input_task_id/\$filename
#fi
EOT

#create pbs script
if [ $execenv == "karst" ]; then
cat <<EOT >> task.pbs
curl -X POST -H "Content-Type: application/json" -d "{\"msg\":\"running matlab\"}" $SCA_PROGRESS_URL

module load matlab
matlab -nodisplay -nosplash < $SCA_SERVICE_DIR/demo.m
ret=\$?
#fix LD_LIBRARY_PATH so that curl works
unset LD_LIBRARY_PATH
EOT
fi

if [ $execenv == "bigred" ]; then
cat <<EOT >> task.pbs
curl -X POST -H "Content-Type: application/json" -d "{\"msg\":\"running matlab with ccmrun\"}" $SCA_PROGRESS_URL

module load matlab
module load ccm
ccmrun matlab -nodisplay -nosplash < $SCA_SERVICE_DIR/demo.m
ret=\$?
#fix broken curl due to matlab
#export LD_LIBRARY_PATH=/usr/lib64/:\$LD_LIBRARY_PATH
unset LD_LIBRARY_PATH
EOT
fi

#rest is about the same for everyone
cat <<EOT >> task.pbs

if [ \$ret -eq 0 ]
then
status="finished"
msg="Successfully ran lifedemo"

#output products.json (should be part of the life_demo)
cat <<EOTP > products.json
[
{
"type": "soichih/life/out",
"graphs": {
"error_distribution": {"filename": "figure1.png", "type": "image/png"},
"error_ratio": {"filename": "figure2.png", "type": "image/png"},
"fascicles": {"filename": "figure3.png", "type": "image/png"},
"heat": {"filename": "figure4.png", "type": "image/png"},
"evidence": {"filename": "figure5.png", "type": "image/png"}
}
}
]
EOTP

else
status="failed"
msg="lifedemo returned code:\$ret"
fi

curl -X POST -H "Content-Type: application/json" -d "{\"status\": \"\$status\", \"msg\":\"\$msg\"}" $SCA_PROGRESS_URL

echo \$ret > finished
exit \$ret #tell pbs the return code?
EOT

jobid=`qsub task.pbs`
echo $jobid > jobid
curl -X POST -H "Content-Type: application/json" -d "{\"status\": \"waiting\", \"progress\": 0, \"msg\":\"Job: $jobid Waiting in PBS queue on $execenv\"}" $SCA_PROGRESS_URL

52 changes: 52 additions & 0 deletions status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

#return code 0 = running
#return code 1 = finished successfully
#return code 2 = failed

##now wait for running to go away
#progress_url={$SCA_PROGRESS_URL}/{$SCA_PROGRESS_KEY}

if [ -f finished ]; then
code=`cat finished`
if [ $code -eq 0 ]; then
echo "finished successfully"
exit 1 #success!
else
echo "finished with code:$code"
exit 2 #failed
fi
fi

#if [ -f started ]; then
# echo "running"
# exit 0 #running!
#fi

if [ -f jobid ]; then
jobid=`cat jobid`
jobstate=`qstat -f $jobid | grep job_state | cut -b17`
if [ $jobstate == "Q" ]; then
echo "Waiting in the queue"
eststart=`showstart $jobid | grep start`
curl -X POST -H "Content-Type: application/json" -d "{\"msg\":\"Waiting in the PBS queue : $eststart\"}" $SCA_PROGRESS_URL
exit 0 #running!
fi
if [ $jobstate == "R" ]; then
echo "Running"
exit 0 #running!
fi

#assume failed for all other state
echo "Jobs failed - PBS job state: $jobstate"
exit 2
fi

echo "can't determine the status!"
exit 3

#echo "running.job.id is gone.. job must have finished"
#code=`cat exit.code`
#curl -X POST -H "Content-Type: application/json" -d "{\"status\": \"finished\", \"msg\":\"lifedemo ended with code:$code\"}" $progress_url
#echo "job finished with code $code"
#exit $code
10 changes: 10 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

#if [ -f finished ]; then
# echo "can't stop job that's already finished"
# exit 1
#fi

jobid=`cat jobid`
echo "running qdel $jobid"
qdel $jobid