Photonics

Photonics

Topics related to Lumerical and more

Issue starting Lumerical FDTD via Python API

TAGGED: , ,

    • johnrollinson
      Subscriber

      Hello,

      I am running into an issue where I can run FDTD simulations via the GUI, but I cannot run them via the Python API. If I try to run the following line:

      fdtd = lumapi.FDTD(hide=False)

      The execution will just hang indefinitely. If I kill the script, I get the following error output:

      Traceback (most recent call last):

       File "/home/rhome/rollij2/lumerical/gf_grating_coupler/45spclo/sin_gc_uniform_base_sim.py", line 502, in

        with lumapi.FDTD(hide=False) as fdtd:

       File "/opt/lumerical/v211/api/python/lumapi.py", line 1294, in __init__

        super(FDTD, self).__init__('fdtd', filename, key, hide, serverArgs, **kwargs)

       File "/opt/lumerical/v211/api/python/lumapi.py", line 1072, in __init__

        self.handle = open(product, key, hide, serverArgs)

       File "/opt/lumerical/v211/api/python/lumapi.py", line 231, in open

        h = iapi.appOpen(url, k)

      KeyboardInterrupt

      Exception ignored in:

      Traceback (most recent call last):

       File "/opt/lumerical/v211/api/python/lumapi.py", line 1170, in __del__

        close(self.handle)

      AttributeError: 'FDTD' object has no attribute 'handle'


      So it looks like it is getting stuck when it is trying to open an FDTD instance. This issue just started appearing today, seemingly out of nowhere. Any help in debugging or fixing the issue is greatly appreciated.

    • johnrollinson
      Subscriber
      Update: We updated our Lumerical installation and the issue is still persisting (previously we were using v2020 R2.4, I believe).
      Now, instead of getting stuck indefinitely, it is giving us an error (still at the same point in the code though):
      lumapi.LumApiError: 'appOpen error: \n Failed to start messaging, check licenses...'
      As far as I am aware, there have been no changes to our license. When we check the Ansys license manager log, we don't see any errors.
    • johnrollinson
      Subscriber
      Another update: it seems like the issue only happens when I try to run Python scripts from a separate Python IDE. If I run the script from the Lumerical script file editor, this issue doesn't happen.
    • Guilin Sun
      Ansys Employee
      Lumerical API with Python works with built-in Python. So please uninstall your own version of Python.
    • johnrollinson
      Subscriber
      I have already configured my IDE to use the python interpreter provided by Lumerical:
      /opt/lumerical/v211/python/bin/python3.6
      So I'm not sure that this is related to the version of Python
    • Lito Yap
      Ansys Employee
      @johnrollinson´╗┐ Our bundled Python cannot install additional modules in case your script is using one that is not included in our package. You can use your own Python3 installation and include the path for the Lumerical API/module in your environment.
      /opt/lumerical/v211/api/python
      Best,
      Lito
    • johnrollinson
      Subscriber
      I have tried both way (using my own version of python and explicitly including the lumapi path, or just using the version of python provided by Lumerical) and I get the same error using both methods.
      The error output is from lumapi, so there I don't think there is any issue importing the module.
      The error output indicates that the script gets to the point of trying to open an FDTD instance (self.handle = open(product, key, hide, serverArgs)). For reasons which are unclear to me, this line is failing when I run a script outside of Lumerical (e.g. from either command line or from an IDE) but passes when I run it from the Lumerical GUI (from the script file editor).
      Just to be clear, in the past I have never had any issues running python scripts outside of the Lumerical GUI. This issue only started appearing this week, even though as far as I am aware, there have been no changes to my python environment.
    • Lito Yap
      Ansys Employee
      Were you using a different older version before this issue happen? Or the currently installed version was working before and the issue just recently happened?

    • johnrollinson
      Subscriber
      Previously I was using an older version (I believe it was either 2020 R2.4 or 2021 R1 but I can't remember). The issue then started while I was using the older version. We updated to the latest version hoping this might fix the issue, however it has not. The only thing which has changed after updating is the error that Python is reporting (presumably due to changes in the error handling for the updated the lumapi module). But the line at which the code is failing is still the same.
    • Lito Yap
      Ansys Employee
      To further troubleshoot the issue, we will contact you in a separate email.
      Best,
      Lito
    • seekjim20
      Subscriber
      We have the same problem with MODE SOLUTION (Version 2021), it reports
      "LumApiError: 'appOpen error: \n Failed to start messaging, check licenses...'"
      We previously used 2019b and 2020a, and did not have this issue. It only came up when we upgraded to 2021.
      The MODE Solution window actually opens properly. It is just that it does not return the proper handle back to Python, and thus we can not continue from the Python script.
    • Lito Yap
      Ansys Employee
      Please configure Lumerical 2021 R1 to obtain the license from the correct License Manager. Either Lumerical (Standard) Or Ansys (Standard). Consult your IT/license server admin which license manager is running on the license server you are accessing.
      Best Lito

    • mrPhoton
      Subscriber
      Unfortunately we are also experiencing this same problem and it is worth mentioning that we never had this problem in pre 2021 releases. The fault is intermittent, and periodically breaks for various Lumerical products. Several of our users have all independently verified that they have configured their licenses properly and have experienced the same problem with the API. It appears not to be license configuring issue from the user but a fault from the python API establishing a connection with the software.
      We have observed this issue on both Linux (CentOS7) and Windows 10. I can guarantee that the software license is correctly configured as if we set the license to the incorrect web address, the user is not able to load the GUI (as expected), and neither is the automation API. When the license is correctly configured users may manually open the GUI without issue. The automation API also causes the GUI to open without prompting for a license, however the simulation handle initialization (i.e. mode = lumapi.MODE(), fdtd = lumapi.FDTD()) does not run correctly and the handle to the simulation is not assigned to to a variable in python and subsequent operations cannot be performed.
      To further illustrate that the error is intermittent, (and also the fact that the license is correctly configured) please see the following traceback, where interaction with FDTD is fine, but MODE which is configured with the same floating license, opens the GUI but fails to establish a connection with lumapi on Linux CentOS7:
      >>> import lumapi
      >>> fdtd = lumapi.FDTD >>> fdtd.addrect
      >>> fdtd.delete >>> fdtd.close >>> mode = lumapi.MODE Traceback (most recent call last):
      File "", line 1, in
      File "/opt/lumerical/v212/api/python/lumapi.py", line 1303, in __init__
      super(MODE, self).__init__('mode', filename, key, hide, serverArgs, **kwargs)
      File "/opt/lumerical/v212/api/python/lumapi.py", line 1076, in __init__
      self.handle = open(product, key, hide, serverArgs)
      File "/opt/lumerical/v212/api/python/lumapi.py", line 238, in open
      raise LumApiError(error)
      lumapi.LumApiError: 'appOpen error: \n Failed to start messaging, check licenses...libGL error: No matching fbConfigs or visuals found\nlibGL error: failed to load driver: swrast\n'
      >>> mode.addrect Exception ignored in:
      Traceback (most recent call last):
      File "/opt/lumerical/v212/api/python/lumapi.py", line 1174, in __del__
      close(self.handle)
      AttributeError: 'MODE' object has no attribute 'handle'
      Traceback (most recent call last):
      File "", line 1, in
      NameError: name 'mode' is not defined

    • Lito Yap
      Ansys Employee
      From your post, it seems that you are running the script from python on the terminal. Are you using your installation of python3? Does the script work when this is run from the GUI using the script editor using the Lumerical bundled python?
      Copy and paste the output of the following:
      cat ~/.config/Lumerical/License.ini
      cat /opt/lumerical/v212/Lumerical/License.ini
      env | grep LICENSE_FILE
      env | ´╗┐PATH
    • Lito Yap
      Ansys Employee
      If you run the script outside the Lumerical CAD/GUI using your Python3 installation. Ensure that your have the Lumerical "bin" and "api" install folders in your PATH and PYTHONPATH. And your installation of Python3 has the modules required by the Lumerical API and those that are required by your script. https://forum.ansys.com/discussion/28304/ansys-insight-adding-lumerical-environment-variables-on-linux
    • ad513649
      Subscriber
      I have the same exact issue and it has appeared all of sudden. It was working fine until 2 days back and without any changes to the installation it seems to have thrown this error.
    • Lito Yap
      Ansys Employee
      ,Were there any updates to your OS? Or did you update Lumerical? Send the screenshot of the error message and your Python integration status window.

    • LAKS
      Subscriber
      I have the same error, which also appeared suddenly when running the lumapi.FDTD() command. Error message: LumApiError: 'appOpen error: \n Failed to start messaging, check licenses...'
      Until yesterday I have been running python scripts for Lumerical with my Python3 installation without any problem.
      Regarding Lumerical I am running: Ansys Lumerical 2021 R2.3 Finite DIfference IDE.
      My license are correctly installed (since I checked my License Manager and the Lumerical GUI opens without problem) and I added the line sys.path.append("/opt/lumerical/v212/api/python/") to my code. There were no updates to my OS (Centos7), nor were there updates for Lumerical. I also followed the steps in https://forum.ansys.com/discussion/28304/ansys-insight-adding-lumerical-environment-variables-on-linux#latest. However, the error reappears.
      Find attached a screenshot of my Python integration status window.


    • Lito Yap
      Ansys Employee
      Did you change license servers? Were you accessing a different license server before the issue happened? Have you tried running your python script directly from the CAD/GUI script editor window with the current Python API status set to use the Lumerical bundled Python3 (as per your screenshot)?
    • msultan
      Subscriber

      I start to have this problem after upgrading the license server from Lumerical to ANSYS. I am running my python script from Spyder because I am using pandas and other packages that are not available with Lumerical python. It was running fine with 2021 but once I updated to 2022 I start to have this issue.
    • Lito Yap
      Ansys Employee
      You are eligible for commercial support, kindly register for commerical support with Lumerical and submit your support request thru Lumerical Support. We will contact to resolve your issue.
    • Lito Yap
      Ansys Employee
      See this KB guide on running Lumerical Python API from terminal in Linux.
    • Maira Perez
      Subscriber

      Hello,

      I am facing the same situation of being able to run FDTD simulations (.fsp) SBATCH files in the hpc server however, whenever I try to run Python API files I encounter the following error

      CONFIGURATION FILE {'root': '/cm/shared/apps/lumerical/2021-R1/api/python', 'lumapi': '/cm/shared/apps/lumerical/2021-R1/api/python'}
      Initializing super optimization
      Checking for one forward simulation : Traceback (most recent call last):
        File "good_python.py", line 70, in
          opt.run(working_dir = working_dir)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumopt/optimization.py", line 460, in run
          self.initialize(working_dir=working_dir)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumopt/optimization.py", line 119, in initialize
          self.one_forward = check_one_forward_sim(self.optimizations[0])
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumopt/optimization.py", line 82, in check_one_forward_sim
          co_opt.sim = Simulation(self.workingDir, co_opt.use_var_fdtd, co_opt.hide_fdtd_cad)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumopt/utilities/simulation.py", line 22, in __init__
          self.fdtd = lumapi.MODE(hide = hide_fdtd_cad) if use_var_fdtd else lumapi.FDTD(hide = hide_fdtd_cad)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumapi.py", line 1298, in __init__
          super(FDTD, self).__init__('fdtd', filename, key, hide, serverArgs, **kwargs)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumapi.py", line 1076, in __init__
          self.handle = open(product, key, hide, serverArgs)
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumapi.py", line 238, in open
          raise LumApiError(error)
      lumapi.LumApiError: 'appOpen error: \n Failed to start messaging, check licenses.../cm/shared/apps/lumerical/2021-R1/bin/fdtd-solutions: line 8: 1892805 Aborted                 $FDTD_BIN_DIR/fdtd-solutions-app "$@"\n'
      Exception ignored in: >
      Traceback (most recent call last):
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumapi.py", line 1174, in __del__
          close(self.handle)
      AttributeError: 'FDTD' object has no attribute 'handle'
      Exception ignored in: >
      Traceback (most recent call last):
        File "/cm/shared/apps/lumerical/2021-R1/api/python/lumopt/utilities/simulation.py", line 67, in __del__
          self.fdtd.close()
      AttributeError: 'Simulation' object has no attribute 'fdtd'
       
      I have tried all the suggested steps in this post and I had followed the KB guide, however, and am still getting the same error.
       
      I would appreciate your help.
       
      Kind regards,
      Maira BPS
       
    • Samuel Fux
      Subscriber

      Hi,

      I am having the same problem with FDTD 2022R1.01 that I installed on the HPC cluster of our university.

      Running FDTD via the Python API on a login node works, but as soon as I try to submit the same as batch job through Slurm, I get the error:

      Traceback (most recent call last):
        File "test_sim_joblist.py", line 22, in
          fdtd = lumapi.FDTD()
        File "/cluster/apps/nss/fdtd/2022R1.01/x86_64/opt/lumerical/v221/api/python/lumapi.py", line 1371, in __init__
          super(FDTD, self).__init__('fdtd', filename, key, hide, serverArgs, **kwargs)
        File "/cluster/apps/nss/fdtd/2022R1.01/x86_64/opt/lumerical/v221/api/python/lumapi.py", line 1093, in __init__
          self.handle = open(product, key, hide, serverArgs)
        File "/cluster/apps/nss/fdtd/2022R1.01/x86_64/opt/lumerical/v221/api/python/lumapi.py", line 239, in open
          raise LumApiError(error)
      lumapi.LumApiError: 'appOpen error: \n Failed to start messaging, check licenses.../cluster/apps/nss/fdtd/2022R1.01/x86_64/opt/lumerical/v221/bin/fdtd-solutions: line 8: 75535 Aborted                 $FDTD_BIN_DIR/fdtd-solutions-app "$@"\n'

      The license configuration is correct (I can open the GUI without any error message). I think that the error is caused by fdtd trying to open a graphical window in a batch job (which will obviously not work).

       

      Is it possible to run FDTD via the Python API in batch mode without opening a graphical window?

       

      I can workaround the problem by using a virtual framebuffer (Xvfb), that provides a fake graphical frontend, but it would be nice to have a clean solution. Can you please add some option in the Python API to be able to run computations in batch mode without opening any graphical windows? This would make it much simpler to use the software on an HPC cluster.

       

      Best regards

       

      Samuel Fux

       

       

    • junhyungpark
      Subscriber

      Hello,

      I am facing the similar situation of ocassionally being unable to open FDTD file using python api in the ubuntu linux server. I run the python code in a seperate python IDE other than built-in python version. When my python code opens FDTD file at first time, it normally opens the file, however, when python code open FDTD files sequentially, Opening error usually occurs.

       

      python code in cmd 

      >>> from importlib.machinery import SourceFileLoader
      >>> api_path = "/opt/lumerical/v231/api/python/lumapi.py"
      >>> 
      >>> lumapi = SourceFileLoader("lumapi", api_path).load_module()
      >>> fdtd = lumapi.FDTD(hide =True)
      Traceback (most recent call last):
        File "", line 1, in
        File "/opt/lumerical/v231/api/python/lumapi.py", line 1394, in __init__
          super(FDTD, self).__init__('fdtd', filename, key, hide, serverArgs, **kwargs)
        File "/opt/lumerical/v231/api/python/lumapi.py", line 1112, in __init__
          self.handle = open(product, key, hide, serverArgs)
        File "/opt/lumerical/v231/api/python/lumapi.py", line 242, in open
          raise LumApiError(error)
      lumapi.LumApiError: 'Exception [::appOpened]: Session not found'
      >>> 

      Also, I have same issue when using lumapi in vs code.
       
      I would appreciate your help.
       
      Best regards,
      Junhyung Park
    • Mustafa Hammood
      Subscriber

      I'm having the same issue as the others here. I'm seeing the same traceback as highlighted by @Maira Perez and @Samuel Fux and others.


      Here are my notes and observations:

      - Lumerical launches okay from the terminal but does not launch from python. The terminal freezes and i end up with "session not found" error.

      - Lumerical only launches properly (from the terminal) after "export QT_QPA_PLATFORM=xcb" which led me to think that it's an issues with QT and i uninstalled and reinstalled QT. I later realized that Lumerical uses its own QT and not the system's.

      - an interesting pattern is that when lumerical fails to launch from the terminal, my vpn connection to the server gets interrupted.

      - When the application fails to launch via the python api, i sometimes get an error saying that the license is not configured properly, even though the system license is defnitely configured properly as can be seen when launching via the terminal.

      I'm reaching a bit of a roadblock after spending 8 hours today debugging this issue with strace and other methods. I've tried reinstalling Lumerical (used both R2.1 and and R2.2), reinstalling QT, reinstalling python/conda (using py3.9, 3.10, 3.11), and reinstalling VSCode. I have also installed the required libraries (https://optics.ansys.com/hc/en-us/articles/1500005392522-Ubuntu-Linux-installation-guide). I configured the env variables appropriately (https://optics.ansys.com/hc/en-us/articles/5771091294739-How-to-run-Lumerical-API-Python-scripts-in-Linux)

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