Colton Harper in MATLAB Answers
Ultima attività il 15 Set 2020

In March of 2020, there was a question about parfor loops and simbiology. (https://www.mathworks.com/matlabcentral/answers/510565-issues-with-doses-variants-in-parfor-loop-in-simbiology?s_tid=srchtitle) I currently use a parfor loop, but my model is fairly large and uses a lot of molecules -- around 40 species and 40 reactions. As a result, it takes a very long time to obtain my results. I was wondering if you think SimFunction (along with 'UseParallel' and 'AutoAccelerate') would be appropriate for me to use. -- Below, you'll find that I use a parfor appoach and make sure the files are accessible through the latter two functions. After seeing the aforementioned post, I'm wondering if I should be using SimFunction, sbiosimulate, sbioaccelerate, sbioensemblerun, or another method to optimize my approach. Here is the general structure for what I am trying to accomplish: I am using SimBiology 2019b. The solver I need to use is SSA, monte carlo style. I have a chemical reaction network set up. I add an event at 3000 seconds to set the concentration of an 'input' species to a given value. I have a species in the chemical reaction network that I view as the 'output' species. My goal is to run 100 simulations for each given input amount. Then, I would like to increase the input amount over 100 steps in a uniformly increasing manner at each step and observe the behavior of the 'output' species. Here is the structure of my code: for i = 1:100 %100 steps with uniform increasing 'input' species amounts sbioloadproject('model.sbproj'); cs = getconfigset(m1, 'default'); cs.SolverType = 'ssa'; solver = cs.SolverOptions; solver.LogDecimation = 1000; inputSpecies = sbioselect(m1,'Type','species','Name','inputSpecies'); %The 'input' species inputSpecies.InitialAmount = 0; parameterTimeunits = addparameter(m1,'Timeunits',1.0,'ValueUnits','minute','ConstantValue',true); parameterMolunits = addparameter(m1,'Molunits',1.0,'ValueUnits','molecule','ConstantValue',true); inputSpecies = addevent(m1, '(time/Timeunits) >= 3000', ['inputSpecies = (1500000*' num2str(i) ')*Molunits']); sbiosaveproject modelParallel.sbproj m1 inputSpecies clear m1; %simulate the model parfor j=1:100 %Number of simulation runs per input step [m1,inputSpecies] = loadSimBiologyModel('modelParallel.sbproj'); [t,x,names] = sbiosimulate(m1); parsave(['StochasticTest_Input' num2str(i) '_Instance' num2str(j)], inputSpecies, t, x, names); end end function [m2,inputSpecies2] = loadSimBiologyModel(filename) sbioloadproject(filename); m2 = m1; inputSpecies2 = inputSpecies; end function parsave(fname,inputSpecies,t,x, names) save(fname,'inputSpecies','t','x','names'); end %I'll then take all these datafiles, interpolate them, and combine it into one dateset. %Then I'll observe the amount of output over time for the varying range of input. With my current approach, I haven't become very familiar with parameters or doses. Would you be able to provide me some insights on A.) if SimFunciton (along with 'UseParallel' and 'AutoAccelerate') is appropriate and if so, B.) since the parameters and doses don't seem applicable to my setup, how can I adapt the function inputs appropriately? Any tips, suggestions, or critiques are happily welcomed. If you need any more info, please let me know.
emjey in MATLAB Answers
Ultima attività il 20 Mar 2020

I have a question about runing the sbproj models in parfor loop 1. I load project and set up the solver: sbioloadproject('modelName.sbproj','m1') csObj = getconfigset(m1); csObj.SolverType = 'sundials'; csObj.SolverOptions.AbsoluteToleranceScaling = 1; csObj.SolverOptions.AbsoluteTolerance = 1E-16; csObj.SolverOptions.RelativeTolerance = 1E-12; csObj.MaximumWallClock = 60; 2. I define dose and variant: dose1 = getdose(m1,'myDose1'); v1 = getvariant(m1,'myVariant1'); 3. accelerate the model sbioaccelerate(m1,csObj,v1,dose1); 4. simulate in parfor loop m1ParConst = parallel.pool.Constant(m1); parfor i = 1:r [...] % dose1 = getdose(m1ParConst.Value,'rela_3mgpkg_80kg_q2wx31'); % v1 = getvariant(m1,'myVariant1'); [t,y] = sbiosimulate(m1ParConst.Value,[],v1,dose1); [...] end Question: Q1. Is this correct? If I include dose1 and v1 definition (i.e. if I uncomment dose1 and v1 in parfor loop) I get an error: Undefined function 'getdose' for input arguments of type 'double'. Error in parallel_function>make_general_channel/channel_general (line 923) O = F(C{:}); Error in remoteParallelFunction (line 46) out = parallel.internal.pool.serialize(feval(channel, channelArgs{:})); Q2: are the solver settings respected? If I try to include csOBj in 'sbiosimulate' call I get an error as well.
emjey in MATLAB Answers
Ultima attività il 26 Ago 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