Photonics

Photonics

The following error was received:Failed to evaluate code when using lumopt.

    • Coulson Jiang
      Subscriber

      I'm trying to  inversely design a structure of waveguide by using lumopt, and i follow the example of Y splitter to determine the base structure.Then i modified the python code for topology optimization, but i receive the following error, which i cannot deal with. Can you give me some useful advice? Thanks so much.

        File "C:\Program Files\Lumerical\v202\api\python\lumopt\optimization.py", line 469, in run
          self.initialize(working_dir)
        File "C:\Program Files\Lumerical\v202\api\python\lumopt\optimization.py", line 543, in initialize
          self.base_script(self.sim.fdtd)
        File "C:\Program Files\Lumerical\v202\api\python\lumopt\utilities\base_script.py", line 42, in __call__
          return self.eval(cad_handle)
        File "C:\Program Files\Lumerical\v202\api\python\lumopt\utilities\base_script.py", line 52, in eval
          return cad_handle.eval(self.script_str)
        File "C:\Program Files\Lumerical\v202\api\python\lumapi.py", line 1184, in eval
          evalScript(self.handle, code)
        File "C:\Program Files\Lumerical\v202\api\python\lumapi.py", line 248, in evalScript
          raise LumApiError("Failed to evaluate code")
      lumapi.LumApiError: 'Failed to evaluate code'

    • Coulson Jiang
      Subscriber

      I found that the problem lies in the lumerical script I wrote, mainly because I called 'addimportedsource' command and wrote Ex and other source parameters by myself. The code is as follows, I wanna ask how to modify this to make the python file run? What's more, is a topology optimization must has a initial guess?

      addimportedsource;

      set('name','source');

      M=readdata("beam.txt");

      # define position vectors

      w0 = 0.5e-6;

      x = linspace(-3*w0,3*w0,200);

      y = linspace(-3*w0,3*w0,200);

      z = 0; 

      X = meshgridx(x,y);

      Y = meshgridy(x,y);

      lambda0 = 0.632e-6;

      f = c/lambda0;

      w = 2*pi*f;

      k = 2*pi/lambda0;

      Ex = sin(pi)*M;

      Ey = cos(pi)*M;

      Ez = 0*M;

      EM = rectilineardataset("EM fields",x,y,z);

      EM.addparameter("lambda",c/f,"f",f);

      EM.addattribute("E",Ex,Ey,Ez);

      select("source");

      set('direction','Backward');

      set('injection axis','z-axis');

      set('x',0);

      set('x span',3e-6);

      set('y',0);

      set('y span',3e-6);

      set('z',0.11e-6);

      importdataset(EM);

      set("center wavelength",lambda0);

      set("wavelength span",0);

      importdataset(EM);

      set("center wavelength",lambda0);

      set("wavelength span",0);

      matlabsave("EM.mat",EM);

       

    • Taylor Robertson
      Ansys Employee

      Hello,

      Your script is written in LSF, I would try and debug this in Lumerical before trying to call the script from python. Pay attention to the fsp file that this will run in, because many of these commands refer to objects in the fsp tree. If you are using lumopt it will likely start with a blank file, which is why this is called the set-up script. One thing I notice is that it is importing files which may be in a different directory then where python is running.

      To use initial conditions in toplogy optimization I would direct you to the initialization section of this article.

      https://optics.ansys.com/hc/en-us/articles/360052044913-Optimizable-Geometry-Python-API

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