ZOS-API Local optimization crashing

  • 15 March 2022
  • 3 replies
  • 170 views

Hi!

I am experiencing a bug when running local optimisations via the ZOS-API in python. I am using interactive extension. Example of the code is:

LocalOpt = TheSystem.Tools.OpenLocalOptimization()

LocalOpt.Algorithm = ZOSAPI.Tools.Optimization.OptimizationAlgorithm.DampedLeastSquares

LocalOpt.Cycles = ZOSAPI.Tools.Optimization.OptimizationCycles.Fixed_50_Cycles

LocalOpt.NumberOfCores = 8

LocalOpt.RunAndWaitForCompletion()

LocalOpt.Close()

Upon running this, it sometimes completes correctly, but sometimes the optics studio window crashes and closes. Then when i open it back up, it asks if i want to restore the file. I have also tried this on multiple machines with different installations of ZEMAX, and the same thing occurs: sometimes it completes the optimisation and sometimes it crashes. 

Has anyone else experienced this issue, or know a fix? Thanks very much in advance!!


3 replies

Userlevel 7
Badge +2

Hi Sunny,

 

I’m regularly using the optimizer through ZOS-API with Python and never ran into this issue. I’ve tried running your code on the default lens file in OpticStudio about 10 times and all of them worked fine.

Can you tell us if its happening with all the files or only with a particular one? If it happens only with a particular file, it might be helpful to share this file. Also, if you have something else in the code that might be causing it, it might be worth sharing as well.

Hope you find a fix soon.

Take care,


David

Userlevel 6
Badge +2

Hi @sunny.howard! As David mentioned, this probably isn’t an issue with the ZOS-API. My guess is that there is something happening during the optimization that OpticStudio cannot resolve. Crashes like these can be tricky to pin down, so I suggest looking into the following:

What kind of Merit Function are you using? Is it a built-in one, or one you generated yourself?

  • If it’s one you wrote, take a look at the operands you’re using. I wonder if there’s an operand which cannot be calculated during one of the cycles in the optimization. 

Also, what values have you set as variable?

  • It sounds like perhaps there is a conflict between what you are trying to achieve via the Merit Function, and what you are allowing to change with your variables. It might help to to use boundary operands to constrain your solution space. 

Do you have ray aiming active?

  • Ray aiming is an iterative algorithm. If it’s active, confirm it’s required. If it is, ensure that potential changes in your system will not “break” the ray aiming. For example - if you have a tilt as a variable in your system, test to see what value cause the algorithm to fail. 

Since the crashes happen during optimization, I would guess the problem has to do with changes happening to the system. These are some ideas I have off the top of my head based on that fact. There could be other avenues to check, but I suggest starting with these :). 

 

 

Thank you both for your swift replies! 

The problem stopped happening at somepoint, and weirdly I am now actually struggling to reproduce it… so its fixed?! If it reoccurs I will follow your advice!

 

Thanks again,

Sunny

Reply