Cancel
Showing results for 
Search instead for 
Did you mean: 

Batch runs from Matlab

Experimenter
Experimenter

Hello,

 

I am using Matlab scripts to have batch runs in Amesim. As per the demo model, this is the syntax we use for adding model parameters into the batch_cfg struct.

 

% Setup and run a batch simulation
batch_cfg = struct('type', 'set', 'param', [struct('type', 'real', 'name', 'k@elect01')]);
batch_cfg.param(1).set = {'100', '200', '500', '1000'};
ameputbatch(sname, batch_cfg);
amerunbatch(sname, sim_opt)

What is the modification required to this to add a global parameter into the batch_cfg struct instead of a submodel parameter?

 

 

3 REPLIES

Re: Batch runs from Matlab

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

Hello @Ojas_Patil

 

As you've mentioned, it's not crystal-clear that global parameters can be used in a batch definition through the Matlab scripting facilities. But it is Smiley Happy

 

Indeed, use in the same way the batch definition for a global as follows:

batch_cfg = struct('type', 'set', 'param', [struct('type', 'real', 'name', 'MyGP_name')]);

The "MyGP_name" is the name of the GP you've created before in the Global Parameters list or through the Matlab method called "ameputgpar(sys_name, name, value)". So you just have to use the GP name instead of the parameter path in the structure.

 

Then, you can use the script as you did before with local parameters.

Look at my screenshot, Matlab should display the same workspace structure "batch_cfg" as mine if you follow my explanations.

 

matlab_batch_gp.pngMatlab workspace detailed content after batch with GP definition

If you have more questions, feel free to contact us Smiley Happy

Have a nice day

All you need is a solver and here we go!

Re: Batch runs from Matlab

Experimenter
Experimenter

Hello,

 

Thank you for giving the syntax on how to add a global parameter into the Matlab script for batch runs.

 

Since I am still getting errors, I dug deeper. It turns out that if the model has text parameters as global parameters, the amerunbatch() function is not able to work properly, even if you dont refer to any global parameter in the batch config file. If you delete the global text parameter, the amerunbatch() function works fine. Any ideas on how to deal with this?

 

I have replicated the error using a smaller model. The error vanishes when I delete the global text parameter.

 

This is the code used to call the model from Matlab.

addpath(fullfile(getenv('AME'),'scripting','matlab','amesim'));

sname='batchruntest';

sim_opt = amegetsimopt(sname);
sim_opt.finalTime = 10;
sim_opt.printInterval = 0.1;


batch_cfg = struct('type', 'set', 'param', struct('type', 'real', 'name', 'k@constant_1'));
batch_cfg.param(1).set = {0,1,2,3};

ameputbatch(sname, batch_cfg);
amerunbatch(sname, sim_opt)

 

Capture.PNGModel with text global parameter

 

Capture2.PNGError in model with text parameter

 

Capture3.PNGModel without text global parameter

 

Capture4.PNGNo error in model without text global parameter

 

 

 

 

 

 

Re: Batch runs from Matlab

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

Hi,

 

I could repeat your issue with 15.2.2. Sorry I don't have an official answer but I found a strange workaround on my machine.

 

Starting from your batchruntest.ame just create a Supercomponent over the model

  • Select all -> right-click Create supercomponent... ->  Keep references
  • Keep references will ensure that the model is accessing the top-level Global Parameters and not local ones within the Supercomponent

You should then be able to run your script.

 

It is a bit cumbersome but hope it is helpful. Also that the development team will provide a better answer!

 

Best Regards,

Martin