Photonics

Photonics

Topics related to Lumerical and more.

Automation with Lumapi and use of script commands

    • Raksha Singla
      Subscriber

      Hello, 

      I have recently started to work with Lumerical and have some technical questions about the automation of running simulations and analysis in FDTD. I am setting up simulations using the GUI of Lumerical and then creating *.fsp files from the optimization and sweep window to run them later using the terminal. I include some analysis objects in the simulation which from what I understand need to be run one by one for Lumerical to perform the calculations from the raw data. 

      I would like to automate this step using the python API package lumapi.

      1. I can extract datasets from *.fsp files from Lumapi if I have previously "Run analysis" on the CAD.

      However, I would like this to be automated in my py script to "runanalysis" on each *fsp created in sweep and then extract and save data elsewhere. Could someone suggest ways for this?

      I tried the following, this code loops over many filenames (all the *fsp files which have already run an FDTD sim)

      with lumapi.FDTD(filename) as fdtd:
              data = method_to_get_data(fdtd)

      method_to_get_data(fdtd):
               fdtd.runanalysis()

      but got the error:

      raise LumApiError(message)
      lumapi.LumApiError: 'in runanalysis: one or more analysis objects encountered errors'

      2. Do I need to "Run analysis" on each *fsp file of the sweep explicitly on the CAD? 

      3. I saw many different scripting examples but is there a way to extract the full *lsf file from a Lumerical project setup I created on the CAD - one that would have the setup, analysis objects, and sweep info in it. Sort of like export to *lsf?

       

    • Taylor Robertson
      Ansys Employee

      Hello Raksha,

      1. This is interesting it seems like ther is an error in one of the analysis groups in one of the files. It would be hard to say why without more information. Can you tell which file this was and then which analysis group? Does this cause python to stop running or it is just a warning? If so perhaps it would be worth while to wrap the runanalysis in a try...except{} which should allow the code to continue.
      2. Runanalysis is a post processing scripted step. The Analysis Groups - Simulation object have scripts associated with and can save .mat files of these results. You could adapt the scripts associated with analysis groups into a stand alone script that would have the same functionality. There is not a one click to solution unfortunately to do this, but I think should be straightforward. You can then use eval from python or adapt the script to python.
      3. When you run FDTD it cannot currently create standalone datasets usually. This is a feature we are exploring, but is not supported yet. Therefore you do need to open the file and run a script to get the resulst saved to another file like json, mat or h5.

      I might also suggest leveraging the sweep utillity, this can be helpful because it will save the files and if you simply load from files it will open and runalysis automatically. If it is set up correctly it will create a dataset with the relevant results.

      Parameter sweep utility

      savesweep - Script command

      loadsweep - Script command

       

      I hope this helps let me know if it isn't clear.

    • Raksha Singla
      Subscriber

      Thank you for your reply. I have been working with Q and lowQ analysis objects with a micropillar cavity design. Strangely, I do not get the error consistently, hence I am unable to inform you more.

      My current workflow is
      1. Setup structure and add analysis and param sweeps using the CAD. 
      2. Then using the option "save to files" from sweep in the CAD.
      3. Running them (generated fsp files) sequentially through Command prompt on Windows
      4. Using a python script to open a new FDTD object for each fsp file of the sweep -> runanalysis() on it and extract data to save elsewhere.

      This seems to work well without raising errors.

    • Raksha Singla
      Subscriber

      I forgot to mention, i had lowQanalysis, Qanalysis, and mode_expansion monitors in place when the error message appeared. 
      The python code terminated due to the error (not a simple warning). The error message did not specify which of the analysis objects failed.

    • Taylor Robertson
      Ansys Employee

      Hello Raksha,

       

      This sounds reasonable it is likely that there may have been issues (possibly extracting the data from Q analysis groups) that cause the code to fail. This can happen in sweeps from time to time and you will need to understand why the analysis is failing to understand how to fix it. For point 4 you could also do this using load from files it should perform the same functionality.

       

      Best Regards,

       

    • Raksha Singla
      Subscriber

      Hello Taylor R.,

      I investigated a bit more and now understand the reason for runanalysis failures with Lumapi. Perhaps, the API could be improved on error messages.

      Here is the situation, If there are multiple analysis objects and if some are disabled or any of them fails to run properly -

       1. partial execution occurs on CAD (clicking on run analysis button)

      2. using the API and running from python fails and exits the code without giving much information on which object failed. 

      I am not sure if it is related to the order in which the analysis groups are added to the simulation or not.

Viewing 5 reply threads
  • The topic ‘Automation with Lumapi and use of script commands’ is closed to new replies.