iddata object is casted to struct in parfeval

2 views (last 30 days)
Jan Kappen
Jan Kappen on 17 Mar 2022
Edited: Jan Kappen on 17 Mar 2022
Hi all,
I'm trying to train my nlarx models in a background pool to abort the training after a timeout. But input data of type iddata is always casted to its struct representations, see this example:
load dryer2_data output input; % matlab example data
data = iddata(output,input,0.08); % create the iddata object
str = feval(@testFun, data, "feval"); % simulate a "normal" call
disp(str)
fut1 = parfeval(@testFun, 1, data, "parfeval"); % should be same as above
timeoutSec = 100;
[~, str] = fetchNext(fut1, timeoutSec);
disp(str)
fut2 = parfeval(backgroundPool, @testFun, 1, data, "parfevalBackgroundPool"); % should be same as above, but in backgroundPool
timeoutSec = 100;
[~, str] = fetchNext(fut2, timeoutSec);
disp(str)
function str = testFun(data, from)
str = sprintf("Hello from '%s'\n'data' is class '%s'\n", from, class(data));
try
nlarx(data,[1 1 1],idLinear);
str = sprintf("%sNo error in testFun.\n", str);
catch E
str = sprintf("%sError in testFun: %s\n", str, E.message);
end
end
which generates this output:
Hello from 'feval'
'data' is class 'iddata'
No error in testFun.
Hello from 'parfeval'
'data' is class 'struct'
Error in testFun: Unable to validate the data input for the "nlarx" command. It should be specified using an IDDATA object.
Hello from 'parfevalBackgroundPool'
'data' is class 'struct'
Error in testFun: Unable to validate the data input for the "nlarx" command. It should be specified using an IDDATA object.
As you can see, the iddata is casted to struct and therefore can't be used in nlarx. Creating the new iddata object in testFun doesn't work either, because iddata() seems to use assignin which does not work in a parallel worker.
What can I do to implement the timeout?
Thank you!
Some side notes:
  • I know feval is not recommended but it shows the issue here pretty well due to the similar syntax
  • I do not have parallel computing toolbox
  • You'll need System Identification Toolbox
  • I'm using ML 2022a
BTW, are there any options to print/display text from the worker, i.e. from testFun?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by