How can I use Matlab Compiler to make a stand alone script including simFunction Objects
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am currently trying to make a standalone version of my Matlab scripts in order to run it on a cluster. Unfortunately I am running into problems, when calling simFunctions (supplied by the SimBiology Toolbox).
In the Matlab terminal everything works just fine, but as soon as I compile it and do a test run through the terminal I get this error:
Warning: Variable 'Model' originally saved as a SimBiology.Model cannot be instantiated as an object and will be read in as a cell.
> In TEST_Script (line 2)
Undefined function or variable 'createSimFunction'.
Error in TEST_Script (line 5)
MATLAB:UndefinedFunction
I read http://ch.mathworks.com/products/compiler/supported/compiler_support.html that simBiology Models and simFunctions can be compiled.
Here is the code
%%Load Model
load Model;
%%Generate SimFunction
mySimFunction = createSimFunction(Model, {'Parameter_1','Parameter_2','Parameter_3','Parameter_4','Parameter_5','Parameter_6'},...
{'Output_1','Output_2','Output_3','Output_4','Output_5'},[], 'UseParallel',false);
%%Generate Input
Input = [1,10,10,5,5,1000];
%%Evaluate SimFunction
stopTime = 100000;
[~,y] = mySimFunction(Input,[],[],stopTime);
Similarly, when I import only the simFunctions and omit generating them in the script I get this error:
> In TEST_Script2 (line 2)
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Error in TEST_Script2 (line 9)
When using feval() for createSimFunction
%%Load Model
load Model;
fun = 'createSimFunction';
%%Generate SimFunction
mySimFunction = feval(fun,Model, {'Parameter_1','Parameter_2','Parameter_3','Parameter_4','Parameter_5','Parameter_6'},...
{'Output_1','Output_2','Output_3','Output_4','Output_5'},[], 'UseParallel',false);
%%Generate Input
Input = [1,10,10,5,5,1000];
%%Evaluate SimFunction
stopTime = 100000;
[~,y] = mySimFunction(Input,[],[],stopTime);
myResult = vertcat(y{:});
I get this error:
Undefined function 'createSimFunction' for input arguments of type 'cell'.
I am grateful for any kind of help.
Thanks, Christoph
PS I am using MATLAB2015b, MRCv90
PPS I attached files
0 个评论
采纳的回答
Ingrid Tigges
2015-9-24
Steven is right with respect to the link he is refering to. After the loading of your simfunction in your file TEST, you need the line
%#function SimBiology.function.SimFunction
In order to compile your code you need the following kind of code:
load mysimfunction;
accelerate(mySimFunction) %to accelerate the simulation of the simfunction
save('new_simfunction','mySimFunction') %save the accelerated simfunction
out=mySimFunction.DependentFiles;
mccCommand = ['mcc -m TEST.m -N -p simbio -a new_simfunction.mat -a lacI_Repression.mat' ...
sprintf(' -a %s', out{:})]; %mention the use of the two mat files so that they are compiled into TEST.exe.
% The mex file of the accelerated version of the
% SimFunction needs to be included (out{:})
eval(mccCommand)
Note that it uses the accelerated SimFunction. Hence you need to load new_simfunction in TEST.m. The complete script TEST.m looks like as follows:
%%Generate simFunction Object
% The Model was exported from Matlab SimBiology by the export to workspace
% function. Afterwards it was saved as a .mat file.
%load('lacI_Repression.mat')
%mySimFunction = createSimFunction(Model,{'unnamed.DNA','unnamed.lacI'},{'unnamed.DNA_lacI'},[],'UseParallel',false);
%%Load simFunction
% loads the previouse generated simFunction (saved as a workspace .mat)
load new_simfunction;
%#function SimBiology.function.SimFunction
% needed to load the class SimFunction
%%Generate Input
% arbitrary inputs
Input = [100,500];
%%Evaluate SimFunction
stopTime = 100; % stoptime for the model
[~,y] = mySimFunction(Input,[],[],stopTime); % simFunction evaluation
myResult = vertcat(y{:}) % extracting the results from the cell array
%%END
I hope this helps.
Ingrid
更多回答(2 个)
Arthur Goldsipe
2015-9-23
Hi Christoph,
I believe you misread the compiler support page. "Regular" SimBiology models are listed in the "Cannot be compiled" column.
However, a SimFunction can be compiled. It looks like you tried this in TEST_Script2, but something went wrong. We should be able to get that to work, but I think you will need to provide the exact code (ideally including any MAT files loaded by the code). Can you attach those files to your question?
Steven Lord
2015-9-23
My suspicion is that you're running into the "Fixing Callback Problems: Missing Functions" problem described in the MATLAB Compiler documentation. Since the only places references to SimFunction appear are in the MAT-file (see the Tip in that section) or in the FEVAL statement, I think if you called createSimFunction directly (NOT via FEVAL) that would work.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scan Parameter Ranges 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!