Photonics

Photonics

Lumerical Python API

    • minusunny
      Subscriber

      Can i use python API feature to run EME simulation or it is applicable only for FDTD?

      import numpy as np
      import matplotlib.pyplot as plt
      import os
      import imp

      lumapi = imp.load_source("lumapi","C:\\Program Files\\Lumerical\\v231\\api\\python\\lumapi.py")
      os.add_dll_directory("C:\\Program Files\\Lumerical\\v231\\api\\python")

      mode = lumapi.MODE()

      mode.addeme()

      {

      PARAMETERS

      }

      mode.addemeport();

      {PARAMETERS

      }

      mode.addemeprofile();

      {

      parameters

      }

       mode.runeme()
        mode.emepropagate();

       

      Is this the right way to implement?

       

    • Lito Yap
      Ansys Employee

      @minusunny,

      The Python API applies to all Ansys Lumerical solvers. On windows, simply set the Python integration to use the bundled Python 3 and add the "import lumapi" into your script. Run the Python script.py script from the Script File Editor window as shown in the image below. 

      Note: On Linux, it requires the Gnome or Mate terminal when running from the Lumerical CAD/GUI. Otherwise, to run directly from Terminal, see this KB > How to run Lumerical API (Python) scripts in Linux – Ansys Optics.

    • minusunny
      Subscriber

      Hi, Thank you for your response, i understand that. I am running the software in windows and using spyder notebook to code in python. When i use mode.addeme() command , it is not allowing me to run. So I want to know if mode.addeme() is the right command to call EME solver using python, using the setup:

      import numpy as np
      import matplotlib.pyplot as plt
      import os
      import imp

      lumapi = imp.load_source("lumapi","C:\\Program Files\\Lumerical\\v231\\api\\python\\lumapi.py")
      os.add_dll_directory("C:\\Program Files\\Lumerical\\v231\\api\\python")

      mode = lumapi.MODE()

      mode.addeme()

      {

      PARAMETERS

      }

      mode.addemeport();

      {PARAMETERS

      }

      mode.addemeprofile();

      {

      parameters

      }

       mode.runeme()
        mode.emepropagate();

      I have searched for some examples with EME solver , but i could only find one with FDE,varFDTD, FDTD.

       

      • Lito Yap
        Ansys Employee

        Are you able to run the following commands from Spyder Notebook on windows? Does it create and save the FDTD simulation file? 

        import numpy as np
        import matplotlib.pyplot as plt
        import os
        import imp
        lumapi = imp.load_source("lumapi","C:\\Program Files\\Lumerical\\v231\\api\\python\\lumapi.py")
        os.add_dll_directory("C:\\Program Files\\Lumerical\\v231\\api\\python")
        fdtd = lumapi.FDTD()
        fdtd.addfdtd()
        fdtd.addring()
        fdtd.addmesh()
        fdtd.save("lumtestpy.fsp")
    • minusunny
      Subscriber

      Yes, I was able to run and is working fine.

      • Lito Yap
        Ansys Employee

        Try the script below on Spyder notebook. I ran this from the script file editor window in the CAD with Python integration using our bundled Python3. The script should create a new EME simulation file, “eme_test.lms” on your current working directory. 

        import numpy as np
        import matplotlib.pyplot as plt
        import os
        import imp
        lumapi = imp.load_source("lumapi","C:\\Program Files\\Lumerical\\v231\\api\\python\\lumapi.py")
        os.add_dll_directory("C:\\Program Files\\Lumerical\\v231\\api\\python")mode = lumapi.MODE()
        mode.addeme()
        mode.addring()
        mode.addmesh()
        mode.save("eme_test.lms")

    • minusunny
      Subscriber

      Thank you, it worked. Apparently , the notebook was showing error at wrong place. Now I am able to run the code.

    • minusunny
      Subscriber

      Another question how do i delcare EME simulation properties, group spans , as well as modes in python-format  ?

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