Photonics

Photonics

equivalent python command for matrix data type

    • wcai05
      Subscriber

      Hi, I wonder what's the equivalent python command for the following lumerical script?


      pole = [0,0; 1,9; 6,9.8; 10,10]*1e-6;
      set("poles",pole);
      

      Thank you

    • Kyle
      Ansys Employee

      The Python equivalent of a Lumerical matrix is a NumPy array. There is more information on equivalent data types this page: Passing Data.
      You can then use the set command as a Python method, as described on this page: Script Commands as Methods.
    • wcai05
      Subscriber
      Thank you the problem was solved.
      Here's a follow-up question: As shown in the attached pictures, what should I return in my mux_based_TE_2D() function in order to make it behave as a base_script in the Optimization function?

      Thank you

    • Kyle
      Ansys Employee

      That function should take a lumapi.MODE object as an argument and set up the simulation with the required objects, as described on this page: Getting Started with lumopt - Python API. This page has an example that uses this approach: https://support.lumerical.com/hc/en-us/articles/360042305274
      Also, note that you are passing the function itself to the Optimization constructor, so you shouldn't be calling the function in line 108 in your second screenshot.
    • wcai05
      Subscriber
      Thank you the previous porblem was solved. However, I am receiving this new error that I have never seen before.
      I wonder if you can give me some hint on what is this source reffering to?
      Thank you!



    • wcai05
      Subscriber
      I initially thought I'll have to rename my mode source to 'source' in order to fix the issue. But even when I rename it, the same error message showed up.
      And the script does not continue running.
    • Kyle
      Ansys Employee
      The created source might be outside the simulation region. If you open the simulation created by the script, is there a plane wave source with the name "source" inside the simulation region?
    • wcai05
      Subscriber


      here's the generated FDTD Layout from my script. The ModeSource named source is within the FDTD region.
    • Kyle
      Ansys Employee

      As you can see in the Python files indicated in the traceback, this error occurs because the script command getnamednumber("source") returns a number less than 1. If you enter the command
      ?getnamednumber("source");
      In the script prompt with this file, what value is returned? Are you sure that this is the base simulation script file being used when you run the optimization?
    • wcai05
      Subscriber

      The FDTD layout shown in my last comment was generated by fdtd.save('mux_2D_init') which is the last line of my base_script function 'mux_based_TE_2D'.
      and when running: ?getnamednumber("source"); in the script prompt in the 'mux_2D_init.fsp' file is shows 1.

    • Kyle
      Ansys Employee
      That's odd, I'm not sure what might be causing this issue. One thing you could tryinpassing the base simulation to the optimization with this predefined FSP file rather than defining the it with a Python method. The "Project Init" section of this page describes how to do this: https://support.lumerical.com/hc/en-us/articles/360050995394.
    • wcai05
      Subscriber

      The script will work if the base simulation was defined in FSP file. The reason why I'm trying to redo it in python is that the run time of the script is too long so I wish to push it on to a cluster. however, the formatting of the cluster only allows one file to run.
    • Kyle
      Ansys Employee

      If it works with the FSP file directly, there might be something wrong with the Python method used to set up the geometry. A lumapi.FDTD object, representing an FDTD simulation, is passed to the Python method. This is the simulation where the geometry and simulation objects need to be added. I would recommend double checking that you're adding simulation objects to this FDTD object, you might be creating a new FDTD simulation and adding the objects to that.
Viewing 12 reply threads
  • You must be logged in to reply to this topic.