This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpsom_demo_clean.m
195 lines (168 loc) · 6.87 KB
/
psom_demo_clean.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
function [] = psom_demo_clean(path_demo,opt)
% This is a script to demonstrate how to use the "clean" capabilities of
% PSOM in a pipeline.
%
% SYNTAX:
% PSOM_DEMO_CLEAN(PATH_DEMO,OPT)
%
% _________________________________________________________________________
% INPUTS:
%
% PATH_DEMO
% (string, default local_path_demo defined in the file
% PSOM_GB_VARS)
% the full path to the PSOM demo folder. IMPORTANT WARNING : PSOM
% will empty totally this folder and then build example files and
% logs in it.
%
% OPT
% (structure, optional) the option structure passed on to
% PSOM_RUN_PIPELINE. If not specified, the default values will be
% used. Note that the default for the demo are different from
% NIAK_RUN_PIPELINE. Specifically :
%
% MODE
% default 'batch'
%
% MODE_PIPELINE_MANAGER
% default 'session'
%
% MAX_QUEUED
% default 2
%
% TIME_BETWEEN_CHECKS
% default 0.5
%
% This default configuration was selected for fast execution of the
% demo. Note that these defaults cannot be changed through editing
% PSOM_GB_VARS.
%
% _________________________________________________________________________
% OUTPUTS:
%
% _________________________________________________________________________
% COMMENTS:
%
% _________________________________________________________________________
% COMMENTS:
%
% This demo will create some files and one folder in PATH_DEMO
%
% Copyright (c) Pierre Bellec, Centre de recherche de l'institut de
% gériatrie de Montréal, Département d'informatique et de recherche
% opérationnelle, Université de Montréal, Canada, 2010.
% Maintainer : [email protected]
% See licensing information in the code.
% Keywords : pipeline, PSOM, demo
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Setting up the default execution mode %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
psom_gb_vars
if nargin<1||isempty(path_demo)
local_path_demo = gb_psom_path_demo;
else
local_path_demo = path_demo;
end
% Set up the options to run the pipeline
opt.path_logs = [local_path_demo 'logs' filesep]; % where to store the log files
if ~isfield(opt,'mode')
opt.mode = 'batch';
end
if ~isfield(opt,'mode_pipeline_manager')
opt.mode_pipeline_manager = 'session';
end
if ~isfield(opt,'max_queued')
opt.max_queued = 2;
end
if ~isfield(opt,'time_between_checks')
opt.time_between_checks = 0.5;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Prepare the demo folder %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
msg = 'The demo is about to remove the content of the following folder and save the demo results there:';
msg2 = local_path_demo;
msg3 = 'Press CTRL-C to stop here or any key to continue.';
stars = repmat('*',[1 max([length(msg),length(msg2),length(msg3)])]);
fprintf('\n%s\n%s\n%s\n%s\n%s\n\n',stars,msg,msg2,msg3,stars);
pause
if exist(local_path_demo,'dir')
rmdir(local_path_demo,'s');
end
file_weights = [local_path_demo filesep 'weights.mat'];
weights = rand([2 50]);
psom_mkdir(local_path_demo);
save(file_weights,'weights');
%%%%%%%%%%%%%%%%%%%%%%%%%%
%% What is a pipeline ? %%
%%%%%%%%%%%%%%%%%%%%%%%%%%
msg = 'The demo is about to generate a toy pipeline and plot the dependency graph.';
msg2 = 'Press CTRL-C to stop here or any key to continue.';
stars = repmat('*',[1 max(length(msg),length(msg2))]);
fprintf('\n%s\n%s\n%s\n%s\n\n',stars,msg,msg2,stars);
pause
% Job "message"
pipeline.message.command = 'fprintf(''The number of samples was : %i. Well that info will be in the logs anyway but still...\n'',opt.nb_samples)';
pipeline.message.opt.nb_samples = 30;
% Job "tseries1"
pipeline.tseries1.command = 'tseries = randn([opt.nb_samples 1]); save(files_out,''tseries'')';
pipeline.tseries1.files_in = {};
pipeline.tseries1.files_out = [local_path_demo 'tseries1.mat'];
pipeline.tseries1.opt.nb_samples = pipeline.message.opt.nb_samples;
% Job "tseries2"
pipeline.tseries2.command = 'tseries = randn([opt.nb_samples 1]); save(files_out,''tseries'')';
pipeline.tseries2.files_in = {};
pipeline.tseries2.files_out = [local_path_demo 'tseries2.mat'];
pipeline.tseries2.opt.nb_samples = pipeline.message.opt.nb_samples;
% Job "fft"
pipeline.fft.command = 'load(files_in{1}); ftseries = zeros([size(tseries,1) 2]); ftseries(:,1) = fft(tseries); load(files_in{2}); ftseries(:,2) = fft(tseries); save(files_out,''ftseries'')';
pipeline.fft.files_in = {pipeline.tseries1.files_out,pipeline.tseries2.files_out};
pipeline.fft.files_out = [local_path_demo 'ftseries.mat'];
pipeline.fft.opt = struct();
% Job "weights"
pipeline.weights.command = 'load(files_in.fft); load(files_in.sessions.session1); res = ftseries * weights; save(files_out,''res'')';
pipeline.weights.files_in.fft = pipeline.fft.files_out;
pipeline.weights.files_in.sessions.session1 = [local_path_demo 'weights.mat'];
pipeline.weights.files_out = [local_path_demo 'results.mat'];
pipeline.weights.opt = struct();
% Job "clean"
pipeline = psom_add_clean(pipeline,'clean_tseries1',pipeline.tseries1.files_out);
psom_visu_dependencies(pipeline);
%%%%%%%%%%%%%%%%%%%%
%% Run a pipeline %%
%%%%%%%%%%%%%%%%%%%%
msg = 'The demo is about to execute the toy pipeline.';
msg2 = 'Press CTRL-C to stop here or any key to continue.';
stars = repmat('*',[1 max(length(msg),length(msg2))]);
fprintf('\n%s\n%s\n%s\n%s\n\n',stars,msg,msg2,stars);
pause
% The following line is running the pipeline manager on the toy pipeline
psom_run_pipeline(pipeline,opt);
%%%%%%%%%%%%%%%%%%%%%%%
%% RE-run a pipeline %%
%%%%%%%%%%%%%%%%%%%%%%%
msg = 'The demo is about to re-execute the toy pipeline forcing the restart of fft.';
msg2 = 'Press CTRL-C to stop here or any key to continue.';
stars = repmat('*',[1 max(length(msg),length(msg2))]);
fprintf('\n%s\n%s\n%s\n%s\n\n',stars,msg,msg2,stars);
pause
% The following line is running the pipeline manager on the toy pipeline
opt.restart = {'fft'};
psom_run_pipeline(pipeline,opt);