Photonics

Photonics

Parameter Sweep with Vector/Matrix/Array as Parameter

    • stefan.appel
      Subscriber

      Hi everyone,

      I am trying to set up a sweep in Ansys Lumerical FDTD where the parameter I want to sweep over is a matrix.

      There is an option to set the parameter type as 'Matrix', which I have selected.
      I have set the sweep 'Type' set to 'Values' (instead of 'Ranges' - I can not imagine a range of matrices, or text strings for that matter as well). My custom analysis group controlled by this sweep also accepts matrices of any size, so there is no problem there.

      However, when I then enter a matrix such as [1;2] for 'Value_1', the matrix is not accepted and the value is reset to 0. The same happens for any 'Value_i', also when using the addsweepparameter command to set up the 'Matrix'-type sweep parameter, including all values, simultaneously.

      Is this intended? Is this a bug? Is it a feature which is not implemented yet?
      Is there any other workaround except programming a 'custom' sweep with for loops, multiple files and parallel job execution?

      Thank you for your help!

      Best,
      Stefan

    • Guilin Sun
      Ansys Employee

      Which product is this referring?

      In general, this is desired.This is because, in the "model", you have to spcify the object and its parameter. If you cannot find an object with matrix as its parameter, then you cannot pass the value to it. So please check the object that is intended to accept matrix.

      As for " loops, multiple files and parallel job execution", you can definitely do it by script file that specifies the parameters to the objects, and using a loop to sweep. The only thing is, you need to collect the result after the simulation terminates and before the next simulation begins, if they have the same file name. You can rename the simulation files each time if you want, and then reload each file to extract the results.

      You can use addjob and runjobs

      https://optics.ansys.com/hc/en-us/articles/360034410714-addjob-Script-command

      https://optics.ansys.com/hc/en-us/articles/360034931373-runjobs-Script-command

      for the sweep.

       

       

       

       

       

    • stefan.appel
      Subscriber

      Regarding your questions and comments:

      - Which product is this referring?
      I am trying to set up a sweep in Ansys Lumerical FDTD

      - So please check the object that is intended to accept matrix.
      My custom analysis group controlled by this sweep accepts matrices of any size, so there is no problem there.

      - You can rename the simualtion files each time if you want
      As written, I want to run the sweep in parallell jobs, so indeed I will have to use multiple files with different names.

      As you correctly guessed, my custom analysis group is indeed the 'model' root group.

      Attached, you can find some screenshots of the problem:
      This is the "model" analysis group - I want to sweep the parameter "source_amp". As you can see, it is a matrix parameter, and it is set to a 1x3 matrix at the moment.

      Here, I am trying to edit the sweep with the 'source_amp' parameter from above

      As soon as I hit enter, I get this result: My matrix input is gone

      When clicking the value again to edit it, it shows 0 instead of the matrix I entered:

      When I save or run the sweep, I also find that my analysis group 'model' has its parameter 'source_amp' set to 0.

      I can not believe this is "in general desired". Is this a bug?

    • stefan.appel
      Subscriber

      Update on a workaround: Programming a custom sweep without such bugs is messy, especially if you also need nested sweeps.

      However, there is an easier way if the matrices do not chage size during the sweep:

      Customize your analysis group to have two parameters A,B instaed of the single matrix input X.
      Parameter A will be of the type Matrix, and will have an extra, leading dimension compared to X. So size(A) == [N,size(X)], where N is the number of matrices you want to sweep over.
      Parameter B will be of type number and will be used to select the correct (hyper)-row in this parameter A.
      Add a line to your analysis group setup script: X = pinch(A,1,B); or for better readability: X = pinch(A(B,:,:,...,:));

      Set parameter A before sweeping to contain all matrices you want to sweep over, such that A(i,:,...,:) = Xi
      Set parameter B to 1.
      Set up a sweep over parameter B running from 1 to N in integers.

    • Guilin Sun
      Ansys Employee

      Thank you for your solution!

      Which FDTD version you are using? I tested both "model" and "analysis group", and both cannot add a [1 3] matrix. It becomes [1 1], so it is a scalar.

      Before you assign values to the matrix in the sweep, could you please check inside the analysis script with such as

      ?layer_thick;

      and see its dimension?

      I would not think that the sweep can be done with the matrix, since the result is a function of the sweep parameters. When it is a matrix, how can the sweeping result affiliate with the matrix, with changing values? you can specify different thickness, and either sweep them at the same time (if so, since it has a function as you already know, you can assign other thickness based on the one in the sweep); or you need to do nested sweep, which will need different thickness variables.

       

      Please step back and think how the sweep is packaged. You can visualize the swept result from this example and think how can we assign a matrix as a variable: https://optics.ansys.com/hc/en-us/articles/360034922913-Creating-nested-parameter-sweeps

       

    • stefan.appel
      Subscriber

      I am using version 2021 R2.2

      There's a point there: Using various matrices directly as a parameter range or as a plot axis is definitely not possible with the current way the matrix datasets storage works in Lumerical, you are right.

      It may therefore be a good idea to remove the 'matrix' option from sweep parameters.

      Also, while trying to find a solution for arbitrary-sized matrices Xi (matrix size chaging during the sweep, so size(Xi) != size(Xj) ), I thought about using a cell array instead of a normal array for parameter A. Like this, one could store the matrices Xi like A{i} = Xi.

      However, I found out that cell array-type parameters in analysis groups do not work - one can not set any values to them, and the setup script won't find any parameter that is of type cell array.

    • Guilin Sun
      Ansys Employee

      I guess it can be useful later for some applications that we do not know yet. It is unlikely to remove it.

      Please note that not all script commands can work in "model" and "groups". If you want it to work, please file a feature request: https://forum.ansys.com/forums/topic/vote-new-features-and-file-your-feature-request/#latest

Viewing 6 reply threads
  • You must be logged in to reply to this topic.