Photonics

Photonics

Topics related to Lumerical and more.

lumopt errors

TAGGED: 

    • ashish.singh
      Subscriber


      CONFIGURATION FILE {'root': 'C:\\\\Program Files\\\\Lumerical\\\\v242\\\\api\\\\python', 'lumapi': 'C:\\\\Program Files\\\\Lumerical\\\\v242\\\\api\\\\python'}
      Traceback (most recent call last):

        File ~\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
          exec(code, globals, locals)

        File c:\users\ge83sax\desktop\optimization\opt.py:90
          geometry = FunctionDefinedPolygon(

      TypeError: FunctionDefinedPolygon.__init__() got an unexpected keyword argument 'unfold_symmetry'

      please help me out 

       

       

    • anna.wirth-singh
      Ansys Employee

      Hi Ashish,

      I'm sorry to hear you are having issues with lumopt. Can you please provide some more information about the line geometry = FunctionDefinedPolygon(arguments) ? I am not able to see the function arguments in the post, so perhaps you can paste the code in plain text. That will help to diagnose the problem. 

      Here is an example of how a geometry can be defined:

      geometry = FunctionDefinedPolygon(func = your_function,
                                       initial_params = initial_params,
                                       bounds = bounds,
                                       z = 0.0,
                                       depth = depth,
                                       eps_out = eps_out,
                                       eps_in = eps_in,
                                       dx = 1.0e-11)

       

      Where 'your_function' is a function you have written to return the points in a polygon, ordered in a counter clockwise direction.

      I do not see 'unfold_symmetry' as one of the keywords of FunctionDefinedPolygon, so that is likely where the error is coming from. The available keyword parameters are listed here: Geometries — LumOpt documentation

      Best,

      Anna

    • ashish.singh
      Subscriber

      # Define the geometry function to keep each ring separate
      def concentric_rings_function(params):
          central_radius = params[0]  # in meters
          gap_width = params[1]       # in meters
          period = params[2]          # in meters

          verts = []
          for i in range(n_rings):
              # Calculate inner and outer radii for each ring
              r_inner = central_radius + i * period - gap_width / 2
              r_outer = central_radius + i * period + gap_width / 2
              num_sides = 64000 # Increased number of points for smoother rings
              angles = np.linspace(0, 2 * np.pi, num_sides, endpoint=False)
              
              # Define outer and inner vertices for each ring
              outer_vertices = np.array([[r_outer * np.cos(theta), r_outer * np.sin(theta)] for theta in angles])
              inner_vertices = np.array([[r_inner * np.cos(theta), r_inner * np.sin(theta)] for theta in angles])
              
              # Close the ring by appending the first point at the end of each ring
              ring_vertices = np.vstack((outer_vertices, inner_vertices[::-1], outer_vertices[0:1]))
              verts.append(ring_vertices)  # Keep each ring separate in the list

          return verts  # Returns a list of arrays, each array representing a ring

          return np.array(verts)  # Convert the list to a numpy array with consistent shape
      # Create the FunctionDefinedPolygon geometry
      geometry = FunctionDefinedPolygon(
          func=concentric_rings_function,
          initial_params=initial_params,
          bounds=bounds,
          z=gold_thickness+sio2_thickness+(gaas_thickness/2),
          depth=gaas_thickness,
          eps_out=1.0 ** 2,         # Dielectric constant outside the rings (e.g., air)
          eps_in=3.47668 ** 2,      # Dielectric constant inside the rings (e.g., GaAs)
          edge_precision=5,         # Precision of the polygon edges
          dx=1.0e-5,   
          unfold_symmetry=False,              # Spatial resolution for the polygon
      )

      # === Define ModeMatch FOM ===
      # Initialize ModeMatch with the specified monitor name
      mode_match_fom = ModeMatch(
          monitor_name='fom',                  # Exact monitor name as in Lumerical FDTD simulation
          mode_number=1,                       # Mode number to calculate overlap with
          direction='Forward',                 # Propagation direction ('Forward' or 'Backward')
          multi_freq_src=False,                # False for single frequency mode calculation
          target_T_fwd=lambda wl: np.ones(wl.size),  # Target transmission function
          norm_p=1,                            # p-norm for figure of merit calculation (1 for standard FOM)
          target_fom=0                         # Target value for FOM (optional)
      )

      # === Define Wavelength Settings ===
      wavelengths = Wavelengths(start=1.2e-6, stop=1.6e-6, points=100)  # Define the wavelength range and points

      # === Define Optimization Algorithm ===
      optimizer = ScipyOptimizers(
          max_iter=50,
          method='L-BFGS-B',
          scaling_factor=1e9,                # Scales parameters from meters to nanometers
          pgtol=1e-6,
          ftol=1e-6,
          scale_initial_gradient_to=0.0,
          penalty_fun=None,
          penalty_jac=None
      )

      # === Setup and Run Optimization ===
      # Define paths and parameters for optimization
      base_script_path = 'cbg2.lsf'          # Path to the Lumerical script file
      geometry = None                        # Define your specific geometry here

      opt = Optimization(
          base_script=base_script_path,      # Path to Lumerical script for simulation setup
          wavelengths=wavelengths,           # Wavelength settings for simulation
          fom=mode_match_fom,                # Figure of Merit (FOM) configuration
          geometry=geometry,                 # Geometry configuration, like concentric rings
          optimizer=optimizer,               # Optimizer configuration
          use_var_fdtd=False,                # Use standard FDTD rather than VarFDTD
          hide_fdtd_cad=False,               # Whether to hide the FDTD CAD window
          use_deps=True,                     # Use FDTD’s numerical derivatives
          plot_history=True,                 # Plot optimization history
          store_all_simulations=True,        # Store all simulation results from each iteration
          save_global_index=False,           # Save global index monitor results (optional)
          label='Bullseye Structure Optimization',  # Label for the optimization project
          source_name='source'               # Name of the source in the Lumerical simulation
      )

      # Run the optimization, saving results to the specified working directory
      working_directory = os.path.join(os.path.dirname(__file__), 'optimization_results')
      opt.run(working_directory=working_directory)

      this is the code i am using i want to optimize a structure using RCWA which as multiple parameters which i need to optimize. Any insight or help will be greatly appreciated 

    • anna.wirth-singh
      Ansys Employee

      Hi Ashish,

      Thank you for providing your code. From my understanding, lumopt was built to work with FDTD (a time-domain algorithm) and I am not sure it will work for RCWA (a frequency-domain algorithm) without substantial modifications. 

      Have you considered using the built-in optimization utility?  Please see: Optimization utility – Ansys Optics. This utility can be called from the script as shown in this example: Creating optimization tasks using a script – Ansys Optics. I think this would be more straightforward to set up than lumopt.

      I think you could define a Structure Group to build your structure from script: Structure Groups - Simulation object – Ansys Optics. Defining an Analysis group would be the best way to define a custom figure of merit. In the Analysis group script, you can perform calculations and if you specify those variable to be results, then they can be used as FoM for optimization. Could you tell me a bit more about the figure of merit you want to optimize? In your script, it looks like you are using the ModeMatch FoM, which is mostly applied to waveguides. Do you want to optimize the transmission through the structure?

      While this example is not for RCWA, this example has both an analysis group and an optimization that uses the result from that analysis so it will be useful to have a look: 

      Plasmonic gap waveguide – Ansys Optics

       

      Best,

      Anna

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