parfor error for global SA Morris method using SimBiology
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
emjey
am 26 Aug. 2019
Kommentiert: emjey
am 26 Aug. 2019
hi, I am trying to use parallel toolbox to speed up my global SA with Morris method. Basically it averages elementary effects for a specific parameters across the entire parameter space. An elementary effect is calculated as EE = (f(p) - f(p+delta))/delta. For more details see Wentworth et al. J. UNCERTAINTY QUANTIFICATION, Vol. 4, pp. 266–297 (https://projects.ncsu.edu/crsc/reports/ftp/pdf/crsc-tr15-01.pdf).
So far I failed with my attempts, such as for this code - here using SimBiology 'sbioselect' and 'sbiosimulate'
clear variables; close all; clc;
format shortG
r = 5; % number of trajectories
l = 10; s = 2;
delta = l/(s*(l-1));
disp("Load model & parameter file")
paramsFile = strcat('PARAMETERS/Lotka_parameters.csv');
paramsDF = readtable(paramsFile);
sbioloadproject('SBPROJ/lotka.sbproj','m1')
p = length(paramsDF.parameter);
% Morris ===========================================================
d = zeros(r,p);
for i = 1:r
f = zeros(1,(p+1));
% an example for the Morris C matrix capturing one trajectory in parameter space
C = [15 0.085556 15;
15 0.005 15;
15 0.005 9.4444;
9.4444 0.005 9.4444];
% for each trajectory for p parameters, there are p+1 evaluations to be made
for j = 1:(p+1)
for k = 1:size(C,2) % columns = parameters
blub = sbioselect(m1, 'Name', paramsDF.parameter(k));
blub.Value = C(j,k);
end
[t,y] = sbiosimulate(m1);
f(j) = y(end,varNo); % looking for the endpoint as the sensitivity function
end
% Calculating elementary effects
v = zeros(1,p);
for j = 1:p
Cindex = find(diff(C(:,j)) ~= 0);
v(j) = ((f(Cindex) - f(Cindex+1))/delta;
end
d(i,:) = v;
end
%% disp("Calculating EE statistics")
... based on d(i,j)
Although the code is correct from the syntaxt point of view, at run time I get the error:
Load model & parameter file
Starting parallel pool (parpool) using the 'local' profile ...
connected to 4 workers.
Error using sbiosimulate (line 136)
Expected input number 1, MOBJ, to be one of these types:
SimBiology.Model
Instead its type was double.
Error in test (line 19)
parfor i = 1:r
Any comments would be very appreciated. I attach lotka.sbproj and parametr file as well.
Best, M
0 Kommentare
Akzeptierte Antwort
Florian Augustin
am 26 Aug. 2019
Hi,
It looks like you are running into an issue that the SimBiology model is not copied to the workers natively. In MATLAB versions R2019a and earlier, you have to use parallel.pool.Constant to send the model to the workers in your parallel pool. The following tweak to your code should do this for you.
m1ParConst = parallel.pool.Constant(m1);
parfor i = 1:r
% ...
% Get the model from the parPool constant as follows:
blub = sbioselect(m1ParConst.Value, 'Name', paramsDF.parameter(k));
% ...
end
Let me know if this doesn't solve your problem.
Best
-Florian
Weitere Antworten (0)
Communitys
Weitere Antworten in SimBiology Community
Siehe auch
Kategorien
Mehr zu Extend Modeling Environment finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!