Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Psom with docker agent not tested but all is there
Browse files Browse the repository at this point in the history
  • Loading branch information
poquirion committed Apr 29, 2016
1 parent f740be5 commit 1c59b05
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 15 deletions.
26 changes: 26 additions & 0 deletions docker_psom_worker_submit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Script config
# docker command
DOCKER_EXE=docker
# docker options DEFAULT: " -v $HOME:$HOME --user $UID "
DOCKER_OPTIONS=" -v $HOME:$HOME --user $UID "
# image that docker will use to run agent, image is pulled before it is run.
DOCKER_IMAGE=simexp/niak-boss:latest
# Worker init script
WORKER_INIT_SCRIPT=psom_worker.py


if [ $# != 2 ]
then
echo "usage: $0 <psom_dir> <output_dir> <worker_id>"
exit 1
fi

PSOM_DIR=$1s
OUTPUT_DIR=$2
WORKER_ID=$3


${DOCKER_EXE} pull ${DOCKER_IMAGE}
${DOCKER_EXE} run --rm ${DOCKER_OPTIONS} ${DOCKER_IMAGE} \
/bin/bash -lic "${PSOM_DIR}/${WORKER_INIT_SCRIPT} -d ${OUTPUT_DIR} -w ${WORKER_ID}"
2 changes: 1 addition & 1 deletion psom_config.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
end
end

if ~ismember(opt.mode,{'session','background','batch','qsub','msub','condor','cbrain'})
if ~ismember(opt.mode,{'session','background','batch','qsub','msub','condor','cbrain','docker'})
error('%s is an unknown mode of pipeline execution. Sorry dude, I must quit ...',opt.mode);
end

Expand Down
6 changes: 3 additions & 3 deletions psom_gb_vars.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
gb_psom_shell_options = '';

% Options for the execution mode of the pipeline
%gb_psom_mode = 'session';
gb_psom_mode = 'background';
gb_psom_mode = 'session';
%gb_psom_mode = 'background';

% Options for the execution mode of the pipeline manager
gb_psom_mode_pm = 'background';
gb_psom_mode_pm = 'session';

% Options for the execution mode of the deamon
gb_psom_mode_deamon = 'background';
Expand Down
1 change: 1 addition & 0 deletions psom_gb_vars_local.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
gb_psom_shell_options = '';

% Options for the execution mode of the pipeline
%gb_psom_mode = 'docker';
gb_psom_mode = 'cbrain';
% gb_psom_mode = 'cbrain_psom_agent_start';

Expand Down
2 changes: 1 addition & 1 deletion psom_run_pipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
% Limit the number of workers based on the number of jobs in the pipeline
opt.max_queued = min(opt.max_queued,length(fieldnames(pipeline)));

if ~ismember(opt.mode,{'session','background','batch','qsub','msub','bsub','condor','cbrain'})
if ~ismember(opt.mode,{'session','background','batch','qsub','msub','bsub','condor','cbrain','docker'})
error('%s is an unknown mode of pipeline execution. Sorry dude, I must quit ...',opt.mode);
end

Expand Down
62 changes: 52 additions & 10 deletions psom_run_script.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
list_fields = { 'flag_short_job_names' , 'path_search' , 'file_handle' , 'name_job' , 'init_matlab' , 'flag_debug' , 'shell_options' , 'command_matlab' , 'mode' , 'qsub_options' };
list_defaults = { true , gb_psom_path_search , [] , 'psom_script' , gb_psom_init_matlab , false , gb_psom_shell_options , '' , NaN , gb_psom_qsub_options };
opt = psom_struct_defaults(opt,list_fields,list_defaults);

if opt.flag_debug
msg = sprintf('\n The execution mode is %s\n',opt.mode);
fprintf(msg);
Expand Down Expand Up @@ -204,7 +205,7 @@
logs = [];
else
list_fields = { 'txt' , 'eqsub' , 'oqsub' , 'failed' , 'exit' };
if ismember(opt.mode,{'qsub','msub','bsub','condor','cbrain'})
if ismember(opt.mode,{'qsub','msub','bsub','condor','cbrain','docker'})
list_defaults = { NaN , NaN , NaN , NaN , '' };
else
list_defaults = { NaN , '' , '' , '' , '' };
Expand All @@ -213,7 +214,7 @@
end

%% Check that the execution mode exists
if ~ismember(opt.mode,{'session','background','batch','qsub','msub','bsub','condor','cbrain'})
if ~ismember(opt.mode,{'session','background','batch','qsub','msub','bsub','condor','cbrain','docker'})
error('%s is an unknown mode of command execution. Sorry dude, I must quit ...',opt.mode);
end

Expand Down Expand Up @@ -306,7 +307,7 @@
else
sub_eval(cmd);
end
flag_failed = false;
flag_failed = 0;
msg = '';

if ~isempty(logs.exit)
Expand Down Expand Up @@ -400,24 +401,65 @@
case {'cbrain'}

sub = [gb_psom_path_psom 'cbrain_psom_worker_submit.sh'];
% There might be a better way to find the job path and id,
% however, I do not know the code well
% enough at that point.
result_path = regexp(script,'(^.*)/logs','tokens'){1}{1};
agent_id = regexp(script,'psom_*(\w*)','tokens'){1}{1};
instr_cbrain = sprintf('%s %s %s', sub, result_path, agent_id);

if opt.flag_debug
if strcmp(gb_psom_language,'octave')
% In octave, the error stream is lost. Redirect it to standard output
instr_cbrain = [instr_cbrain ' 2>&1'];
end
msg = sprintf(' The script is executed using the command :\n%s\n\n',instr_qsub);
fprintf('%s',msg);
if ~isempty(opt.file_handle)
fprintf(opt.file_handle,'%s',msg);
end

end
fprintf(1,'%s \n',instr_cbrain);
[flag_failed,msg] = system(instr_cbrain)

case {'docker'}

sub=['qsub']
script = [gb_psom_path_psom 'run_in_docker.sh'];
% There might be a better way to find the job path and id, however, I do not know the code well
% enough at that point.
le_path = regexp(script,'(^.*)/logs','tokens'){1}{1};
le_id = regexp(script,'psom_*(\w*)','tokens'){1}{1};
instr_cbrain = sprintf('%s %s %s',sub,le_path,le_id);
result_path = regexp(script,'(^.*)/logs','tokens'){1}{1};
agent_id = regexp(script,'psom_*(\w*)','tokens'){1}{1};

if ~isempty(logs)
qsub_logs = [' -e \"' logs.eqsub '\" -o \"' logs.oqsub '\"'];
else
qsub_logs = '';
end
if opt.flag_short_job_names
name_job = opt.name_job(1:min(length(opt.name_job),8));
else
name_job = opt.name_job;
end

instr_qsub_docker = sprintf('%s %s -N %s %s %s', sub, qsub_logs, name_job, opt.qsub_options ...
, ['\"' script, gb_psom_path_psom, result_path, agent_id '\"']);

if opt.flag_debug
if strcmp(gb_psom_language,'octave')
instr_cbrain = [instr_qsub ' 2>&1']; % In octave, the error stream is lost. Redirect it to standard output
% In octave, the error stream is lost. Redirect it to standard output
instr_qsub_docker = [instr_qsub_docker ' 2>&1'];
end
msg = sprintf(' The script is executed using the command :\n%s\n\n',instr_qsub);
msg = sprintf(' The script is executed using the command :\n%s\n\n',instr_qsub);
fprintf('%s',msg);
if ~isempty(opt.file_handle)
fprintf(opt.file_handle,'%s',msg);
end

end
fprintf(1,'%s \n',instr_cbrain);
[flag_failed,msg] = system(instr_cbrain);
fprintf(1,'%s \n', instr_qsub_docker);
[flag_failed,msg] = system(instr_qsub_docker)

end

Expand Down

0 comments on commit 1c59b05

Please sign in to comment.