I am writing a program where I need to make several changes to values in the Lens Data Editor (e.g. parameters of a coordinate break surface) and evaluate merit function operands after each set of changes. The problem is this is extremely slow, to the point that setting the parameters dominates runtime far beyond the time spent raytracing. For example, this function averages about 1 second per call:
def set_offset(oss, surface_number, x, y, about_x, about_y): oss.LDE.GetSurfaceAt(surface_number).SurfaceData.Decenter_X = x oss.LDE.GetSurfaceAt(surface_number).SurfaceData.Decenter_Y = y oss.LDE.GetSurfaceAt(surface_number).SurfaceData.TiltAbout_X = about_x oss.LDE.GetSurfaceAt(surface_number).SurfaceData.TiltAbout_Y = about_y
I’m sure there are some minor optimizations I can make, but at its core, setting a single variable in memory shouldn’t take anywhere near 0.25 seconds.
- Am I doing something wildly wrong, or is there a far more efficient way to modify LDE entries?
- Is there a better way to go about large multidimensional parameter sweeps than a loop setting those parameter values and calling oss.MFE.CalculateMeritFunction() ?
I am using Zemax 2023 R2.01 and running the Python API in interactive mode.
Thanks!