The forum is closed and this archive is read-only. To ask a question or start a discussion, use GitHub Discussions.

Go to GitHub Discussions
Help & QuestionsOct 20, 2026

Optimization Problem

by Bentzi

I am trying to optimize the EFL of a simple lens, no matter how I try or which optimization I use, the values does not change and nothing is chaning,

from optiland import optic, optimization from optiland.materials import glasses_selection from optiland.mtf import FFTMTF

class TessarLens(optic.Optic): """Tessar Lens f/4.5

Milton Laikin, Lens Design, 4th ed., CRC Press, 2007, p. 63
"""

def __init__(self):
    super().__init__()

    # add surfaces
    self.surfaces.add(index=0, radius=np.inf, thickness=np.inf)
    self.surfaces.add(index=1, radius=1.3329, thickness=0.2791, material="N-SK15")
    self.surfaces.add(index=2, radius=-9.9754, thickness=0.2054)
    self.surfaces.add(
        index=3,
        radius=-2.0917,
        thickness=0.09,
        material=("F2", "schott"),
    )
    self.surfaces.add(index=4, radius=1.2123, thickness=0.0709)
    self.surfaces.add(index=5, radius=np.inf, thickness=0.1534, is_stop=True)
    self.surfaces.add(index=6, radius=-7.5205, thickness=0.09, material="K10")
    self.surfaces.add(index=7, radius=1.3010, thickness=0.3389, material="N-SK15")
    self.surfaces.add(index=8, radius=-1.5218, thickness=3.4025)
    self.surfaces.add(index=9)

    # add aperture
    self.set_aperture(aperture_type="imageFNO", value=3.5)

    # add field
    self.fields.set_type(field_type="angle")
    self.fields.add(y=0)
    self.fields.add(y=2)
    self.fields.add(y=5)

    # add wavelength
    self.wavelengths.add(value=0.550)
    self.wavelengths.add(value=0.650)
    self.wavelengths.add(value=0.750, is_primary=True)
    self.wavelengths.add(value=0.850)
    self.wavelengths.add(value=0.950)

lens_system = TessarLens()

Display initial lens

lens_system.draw(title="Initial Tessar Lens") plt.show() fft_mtf = FFTMTF(lens_system, num_rays=1000, num_pixels=256) fft_mtf.view() plt.show() lens_system.info()

target_focal_length = 7 problem = optimization.OptimizationProblem()

Operand: Effective Focal Length (EFL)

1. add focal length operand

input_data = { "optic": lens_system}

problem.add_operand(operand_type="f2", target=7, weight=3, input_data=input_data)

3. add RMS spot size operand

input_data = { "optic": lens_system, "surface_number": -1, "Hx": 0, "Hy": 0, "num_rays": 5, "wavelength": 0.65, "distribution": "hexapolar", }

problem.add_operand( operand_type="rms_spot_size", target=0, weight=1, input_data=input_data, )

Variables: Radii

problem.add_variable(lens_system, "radius", surface_number=1, min_val = -20, max_val = 20) # Lens 1 front surface problem.add_variable(lens_system, "radius", surface_number=2, min_val = -20, max_val = 20) # Lens 1 back surface problem.add_variable(lens_system, "radius", surface_number=3, min_val = -20, max_val = 20) # Lens 2 front surface problem.add_variable(lens_system, "radius", surface_number=4, min_val = -20, max_val = 20) # Lens 2 back surface #problem.add_variable(lens_system, "reciprocal_radius", surface_number=5, min_val=-0.01, max_val=.01) # Lens 3 front surface problem.add_variable(lens_system, "radius", surface_number=6, min_val = -20, max_val = 20) # Lens 3 back surface problem.add_variable(lens_system, "radius", surface_number=7, min_val = -20, max_val = 20) # Lens 3 back surface problem.add_variable(lens_system, "radius", surface_number=8, min_val = -20, max_val = 20) # Lens 3 back surface

Variables: Thicknesses (air and glass)

problem.add_variable( lens_system, "thickness", surface_number=1, min_val=0.1, max_val=5.0 ) # Lens 1 thickness problem.add_variable( lens_system, "thickness", surface_number=2, min_val=0.1, max_val=5.0 ) # Air space 1 problem.add_variable( lens_system, "thickness", surface_number=3, min_val=0.1, max_val=5.0
) # Lens 2 thickness problem.add_variable( lens_system, "thickness", surface_number=4, min_val=0.1, max_val=5.0 ) # Air space 2 problem.add_variable( lens_system, "thickness", surface_number=5, min_val=0.1, max_val=5.0 ) # Lens 3 thickness problem.add_variable( lens_system, "thickness", surface_number=6, min_val=0.1, max_val=5.0 ) # Lens 3 airspace problem.add_variable( lens_system, "thickness", surface_number=7, min_val=0.1, max_val=5.0 ) # Lens 3 airspace problem.add_variable( lens_system, "thickness", surface_number=8, min_val=0.1, max_val=5.0 ) # Back focal length (approx)

optimizer = optimization.OrthogonalDescent(problem) optimizer.optimize(max_iter=100, tol=1e-6)

print(f"EFL = {lens_system.paraxial.f2():.2f} mm") problem.info()

Display the optimized lens

lens_system.draw(title="Optimized lens") plt.show() lens_system.info() fft_mtf = FFTMTF(lens_system, num_rays=1000, num_pixels=256) fft_mtf.view() plt.show() print(f"EFL = {lens_system.paraxial.f2():.2f} mm")