Photonics

Photonics

Topics related to Lumerical and more.

Python script is not running from CAD/GUI Script File Editor of Lumerical FDTD

    • mo_911
      Subscriber
      Hello, I just wanted to follow the steps on the page "Inverse design of y-branch" (https://optics.ansys.com/hc/en-us/articles/360042305274), but step 1 of 1 is not working. I have checked that "Python Integration Status" is active and the box "Use Python provided by Lumerical" was checked. Then I opened the sample python file "varFDTD_y_branch.py" and ran it from the CAD/GUI Script File Editor, but I got a syntax error even in the first line "import lumapi". I suspect that the python is not running. I am wondering how to fix this issue. Please find attached the screenshots related to this issue. Thanks.
    • jackzhf
      Subscriber

       

      lumapi might be missing and here is some helpful information:

       

      • Working directory : It should be possible to store the files in any locations as desired. However, it is recommended to put the Lumerical and Python files in the same folder in order for the above script files to work properly. It is also important to check the Lumerical working directory has the correct path, see here for instructions to change the Lumerical working directory.
        • Linux: /opt/lumerical/interconnect/api/python/
        • Windows: C:\Program Files\Lumerical\FDTD\api\python

       

      During the Lumerical product installation process, a lumapi.py file should be automatically installed in this location.

      This module is the key to enable Lumerical-Python API connection. Once the lumapi module is imported to Python, the integration should be read.”

       

      https://optics.ansys.com/hc/en-us/articles/360034416574-FDTD-application-example

      https://optics.ansys.com/hc/en-us/articles/360041873053-Session-management-Python-API

      https://optics.ansys.com/hc/en-us/articles/360037824513-Python-API-overview

       

    • Guilin Sun
      Ansys Employee

      Do you use your own Python? If you independently download and install your own version, this can happen. We recommend to uninstall your own phyton, reinstall Lumerical software, and in most case it will work, as Lumerical package has the correct Python version and configurations. Otherwise you will need to reconfigure the phyton and other settings, which are not that easy and obvious.

       

       

    • mo_911
      Subscriber

      Hi jackzhf, 

      Thank you for your reply. 

      I found that a lumapi.py file was already installed at a location "/opt/lumerical/v221/api/python" (please see the screenshot attached). 

      After changing the Lumerical working directory to the location above, I still got the same error even in the first line "import lumapi" (please see the screenshot attached).

      I am suspecting that even the python command "import" is not working. 

      Thanks

    • mo_911
      Subscriber

      Hi Guilin Sun,

      Thank you for your comment. No, I have not installed my own python. That's why I want to use the python that was automatically installed with Lumerical. As I showed in my first post, the python integration status is "active" on Lumerical, but it looks like even the python command "import" is not working. 

      Thanks.

    • Guilin Sun
      Ansys Employee

       

      You did not reply me if you installed your own python or use the software package? Please uninstall the python you installed, and reinstall lumerical package: unintal first, restart the computer, and sometimes you may need a clean installation. please refer “clean installation”  https://optics.ansys.com/hc/en-us/articles/5613618572947-Fixing-installation-or-license-activation-issues

       

      Please note that using the packaged python, you do not have the python GUI.

       

       

    • Lito
      Ansys Employee

       

      @mok,
      Try to set your PATH and PYTHONPATH environment variables. See these KB guides for details.

      >https://optics.ansys.com/hc/en-us/articles/7595785040403-Setting-environment-variable-in-Linux 

      >https://optics.ansys.com/hc/en-us/articles/5771091294739-How-to-run-Lumerical-API-Python-scripts-in-Linux 

       
    • mo_911
      Subscriber

      Hi Lito Yap,

      Thank you for your comment. Yes, I can try to install the latest release later, probably tomorrow with our administrator. I will let you know when I install it. 

      Thanks

    • mo_911
      Subscriber

      Hi Lito Yap,

      I created a new brank python file named "220719_Test_Script.py" and copied the commands you wrote to it. Then I opened the file on Lumerical Script Editor and ran it. Then the terminal window showed up and then the Lumerical FDTD window showed up as well. I think that both python and lumapi are working with these commands. 

      Thanks

      • Lito
        Ansys Employee

        @mok,
        Try to set your PATH and PYTHONPATH environment variables. See these KB guides for details.

        >https://optics.ansys.com/hc/en-us/articles/7595785040403-Setting-environment-variable-in-Linux 

        >https://optics.ansys.com/hc/en-us/articles/5771091294739-How-to-run-Lumerical-API-Python-scripts-in-Linux 

    • mo_911
      Subscriber

      Hi All, 

      I created a new blank python file named "FDTD_y_branch_test.py" and copied the lines 1 - 20 of the Lumerical sample python file "varFDTD_y_branch.py" to it. Then I opened the file on Lumerical Script Editor and ran it. Then the terminal window showed up and it says "ImportError".

      After reading the messages shown in the terminal, I realize that another python was already installed with "Cadence" that was installed on the same linux machine. I guess this is the reason why the Lumerical sample python file "varFDTD_y_branch.py" is not running properly, but I do not know how to fix this issue. 

      Thanks

    • Lito
      Ansys Employee

      @mok,

      • set the PATH and PYTHONPATH a per our KB.
      • remove the “product preference.ini” files from your “~/.config/Lumerical/” folder as shown here
      • run the “varFDTD_y_branch.py” script after 
      • mo_911
        Subscriber

        I am just wondering why you recommended removing ".ini" file. I found that there are multiple ".ini" files. Should only "FDTD Solutions.ini" be deleted in this case?

    • mo_911
      Subscriber

      Finally, I was able to run "varFDTD_y_branch.py" properly after deleting the path to the python files installed with Cadence in .cshrc file on Linux. The MODE window showed up as the screenshot attached. 

      • jackzhf
        Subscriber

        Nice. You may need to fix similar issue if you use python with Cadence in the future.

        • mo_911
          Subscriber

          That's true. I will try to solve this issue without deleting the path later. 

    • Lito
      Ansys Employee

      Great! ??

    • mo_911
      Subscriber

      Thank you all for your prompt replies and comments!!

Viewing 13 reply threads
  • The topic ‘Python script is not running from CAD/GUI Script File Editor of Lumerical FDTD’ is closed to new replies.