Using a nested parameter sweep in an optimization

Hello there,

I’m having an issue with a using a nested parameter sweep to run a fom script in an optimization. I need the parameter sweep to output a variable that is a 750x3 matrix, which I know it does when run on its own outside of the optimization.

However when I run it inside of the optimization, the data that is pulled into the fom script workspace is a 750x1 matrix. I found this out by setting the fom of the optimization of the script to equal the size of the array to figure out its dimensions. The data it does pick up is the first row of the data that should be coming out of the parameter sweep. I figured this all out through playing with making the fom equal to the first element of the array and comparing to a separate sweep using the same parameters. I know it is not an issue with the script itself because it will run properly with a 750x1 matrix to give a scalar fom, it just won’t be the correct result I need.

I think this is similar to the issue being had by Optimization of geometrical parameters for two possible states with different material properties but that solution won’t work for me. There is no way to simplify my data, I need all 750x3 elements from the sweep to do my calculation. I’ve also found How can I access the results of a nested parametersweep in the custom figure of merit script (for optimization)?, but the solution suggested there also won’t work because the data I need is already coming from an analysis group.

So in essence, is there any way I’m missing to get the optimization to actually access (or to use a load command inside of the fom script) all 750x3 points of the variables I need?

Attached is the simulation file I’m trying to work with if you want to actually look at the optimization I’m trying to do.

optimization file.fsp (361.4 KB)


I’m the original poster of the second link you’ve shared there. I think you may still be able to use the proposed workaround there even though the data is already coming from an analysis group.

For instance, if you have an additional analysis group producing your data (like bandstructure or something), you might try going into the model analysis group and using the runanalysis()* and getresult() commands. This should allow you to access the data from the other analysis group, manipulate it, and produce a number. Then, inherit that number into the optimization. This is how I solved the issue actually.

Hope this helps,

Thanks for the suggestion, but I’m not sure something like that will work for me. Unless I’m drastically misunderstanding the way to model group works, it only accesses data from that specific simulation (like any other analysis group). I however can not do any calculation at all until I have the data from the entire sweep.

In essence I am trying to calculate the frequency and angle dependent reflection from my structure. The calculation I need to run requires that 2D matrix to get the true answer, there is no way I can run that calculation (which is a double integral over that reflection data multiplied by some frequency and angle dependent function) before I have the entire 750x3 matrix.

Thank you though!

I see, that is a bit trickier. I was able to do a partial calculation with each element of the sweep and then combine them in the figure of merit script.

What I might try in your case is the following. In the model analysis group, use a series of conditionals that differentiate each sweep element, and create a variable that stores that sweep data (so this would be a 750x1 array in your case.)

At the very end, have a conditional that checks if each three of those variables has value, if yes (only true in the third and final instance of the sweep) and then do your overall calculation that will return a number.

This is totally dependent on whether or not the value assignment will persist from sweep run to sweep run, so these variables need to be actual analysis variables and not just defined in the script itself… not 100% sure if that will work, but may be worth a shot.


You make a fair point. I managed to find a work around in using conditionals in my analysis group to save each iteration of the sweep to a specific variable with all other iterations only saving a zero array. Then using the sum operation in the parameter sweep it sums up the zeros and the one iteration that has actual reflection data.

Which means that I end up importing three different 750x1 arrays into the optimization workspace and have to put them back together. It’s more of a brute force way of doing it than I wanted but at least it works.

Thanks for the ideas.

1 Like