Problem with parallel simulations script

Hello,

I was implementing a parallel simulations script in PLECS standalone, and only one trace was held after executing the script. At the end to solve it I copied the Scope block from the demo “buck_converter_with_parameter_sweep.plecs”, and after doing so, it worked as expected. Then I also tried to delete the Scope block from the example and place a new one, resulting in the same problem of only holding one of the traces. Is there some setting of the Scope that I am missing or is this a different problem?
The version of PLECS is 4.9.6 running in a Macbook pro M3.
Thanks for the help.

Hi Lucho,

To hold multiple traces in a Scope during parallel simulations, you must call plecs('scope', 'scopePath', 'HoldTrace', 'traceName')in the callback function:

plecs('scope', './Scope', 'HoldTrace', 'L = 220 μH');

If you insert a new Scope block but don’t reference it correctly or omit the HoldTrace call, only one trace will be shown and depending on your script an error message.

If you need further help, please post your script.

Thanks for the reply. I was aware of that, but the problem remains when I experiment with the demo model buck_converter_with_parameter_sweep.plecs, and delete the “original“ Scope and place a new one. In that case, the name of the block remains the same, so I don’t have to modify the script. To be very specific, what I do is the following:

  1. Open buck_converter_with_parameter_sweep.plecs
  2. Delete the Scope block in the schematic.
  3. Place a new Scope block (since I deleted the previous, the name of the new block is still Scope)
  4. Go to Scope Parameters and change the number of plots to 2.
  5. Reconnect the terminals from the Signal Demultiplexer to the new Scope.
  6. Run the Parameter Sweep (Parallel) script.
  7. Only one trace is held.

I am also including the script of the example for reference.


% Clear all previous traces in scope 'Scope' in the current model
plecs('clc');
plecs('scope', './Scope', 'ClearTraces');

% Evaluate simulation results in callback function
function result = callback(index, data)
   % hold and label trace
	name = ['L = ', mat2str(inductorValues(index)), 'μH'];
	plecs('scope', './Scope', 'HoldTrace', name);
	
	% Find maximum current values and index
	if isstruct(data)
		[maxi, maxidx] = max(data.Values(1,:));
		maxt = data.Time(maxidx);
		% Reducing simulation results by return value 'result' 
 		result = [maxi, maxt];
 	else
 		% Print error message to Octave console
 		printf(' Error in Simulation %d for L=%duH: %s\n',
                  index, inductorValues(index), data);
	end
end

% Set value for L1 to be swept
inductorValues = [40:20:220]; % in uH
% Initialize simStruct as cell array with all values for L1
for ix = 1:length(inductorValues)
	simStructs{ix}.ModelVars.varL = inductorValues(ix) * 1e-6;
% Name of 'ModelVars' can be assigned for diagnostic purposes	
	simStructs{ix}.Name = ['L=' mat2str(inductorValues(ix)) 'μH'];
end

% Create a shortcut in simulation 5
simStructs{5}.ModelVars.varR = 0;

% Start simulation, return result from callback function into 'out'
% Analysis will be moved to callback function to reduce simulation results
out = plecs('simulate', simStructs, @(index, data) callback(index, data));

for ix = 1:length(inductorValues)
	% Detect if errors occurred in parallel simulation 
   if ischar(out{ix})
   	printf(' Error for L=%dμH: %s\n',
   			 inductorValues(ix), out{ix});
	% Output maximum current values to Octave console
   else
 		printf(' Max current for L=%dμH: %fA at %fs\n', 
	          inductorValues(ix), out{ix}(1), out{ix}(2));
	end
end

Thank you for your clear and step-by-step instructions. Unfortunately, I wasn’t able to reproduce the same behavior on my end. Would you mind sending me your non-working model directly? That would help me take a closer look and better understand what might be going wrong.

It turns out that if I save the model, close it, and open it again, then the traces are held. But still, if I modify the scope, for example, I want to add other signals to be plotted, then only one trace will be held, and I have to save, close, and open the model again for it to work. I am attaching a small video of the behavior that I experience, and the non-working model.

Video link:

Model:

buck_converter_with_parameter_sweep.plecs (26.5 KB)

Thank you for the detailed explanation and for sharing the video and model — that’s very helpful.

I was able to reproduce the behavior you described. This issue appears to occur with parallel simulation runs, while sequential simulation works as expected.

We’re currently looking into this and will keep you posted as we work toward a solution. Thanks again for bringing this to our attention!

Thank you so much for following up and trying to solve it. Hope it gets fixed soon.

This bug has been resolved in PLECS 4.9.7, which you can download from our website.

1 Like