When those lines are commented out, I get the error "dot indexing is not supported for variables of this type". This tells me that the struct that I am loading is not getting correctly loaded. Any thoughts or pointers are much appreciated!
help with parallel simulation and setting up parallel worker workspaces, getting error with
8 ビュー (過去 30 日間)
古いコメントを表示
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
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.
回答 (1 件)
Alvaro
2022 年 11 月 22 日
編集済み: Alvaro
2022 年 11 月 22 日
You can set a diary for each worker and print the iteration that a particular worker is working on as well as any parameters that were passed to that worker. Afterwards, you can peek into the diaries to see what each worker was doing during the simulation.
A simple example is attached where an array of random numbers is passed to a pool of workers and each worker writes in their respective diary the iteration and random number assigned to it.
The following thread has more details on how this process works.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Model Predictive Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!