MATLAB Answers

help with parallel simulation and setting up parallel worker workspaces, getting error with

조회 수: 1(최근 30일)
Tim Darrah
Tim Darrah 2021년 3월 24일
댓글: Mario Malic 2021년 3월 29일
A brief description (in case I'm turning this into a xy problem):
I'm working on a project where we are conducting run to failure experiments for a UAV and have two identical simulink models, except one of them has some extra monitoring and log output. We run the UAV mission, then degrade some of the parameters, and repeat this over and over until the UAV crashes or violates a safety threshold. This is good, but we want to know before the UAV actually crashes, which is where the parallel part comes in. We simulate the "digital twin" in parallel to collect many samples after each real mission, and then generate a distribution from those samples that can tell us if the UAV is going to crash on the next mission. With a 1D polyfit and sliding window, we can forecast a few missions out. In order for this to work, the degradation parameters from the main workspace with the real UAV need passed to each parallel workspace. The problem is that I am getting an error "Array indices must be positive integers or logical values" for each of the parallel workers.
I have a function called parallel_initializer_handler() that is executed on line 173 of next_paper.mlx which creates the workspace for each parallel worker. When I execute this function in the main workspace, I do not get any error, and the struct which I am updating is successfully updated.
This is how I am setting this up:
in(n) = Simulink.SimulationInput("digitaltwin1c");
out = parsim(in, 'ShowSimulationManager',"off", 'ShowProgress',"off", "UseFastRestart", "on", "SetupFcn", @()parallel_initializer_handler(i, lookback, horizon, r_var, q_var, m_var, twin_sample_rate));
Should I approach this differently? How can I peer into each of the parallel workspaces to see what is happening? How can I fix the error, and know that I am passing variables correctly? How can I get some output that says, "this is parallel worker X, the value of my variable is Y" ?
  댓글 수: 4
Mario Malic
Mario Malic 2021년 3월 29일
assignin is under the same roof as evalin, maybe there isn't other way to transfer variables into Simulink workspace.
r = normrnd(mu, sigma, numberofsims, 1)
% r is now a vector size(r) = [numberofsims, 1]
From the second example in parsim documentation:
for i = length(r)
in(i) = Simulink.SimulationInput('CSTR');
in(i) = in(i).setVariable('FeedTemp0',r(i));
end
Does your simulink model take any other parameter values from workspace? They might be missing, that might be why you got an error in the first place.
If yes, assuming that you use TransferBaseWorkspaceVariables, you should still use the SetupFcn to replace the values for each worker.
Also, can you paste the whole error so It can be seen for which variable does this error occur?
Array indices must be positive integers or logical values.

댓글을 달려면 로그인하십시오.

답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by