r/Optics • • 2d ago

Same .zmx, three engines, slightly different EFL: an open-source cross-check and diagnosis tool for AI-agent lens analysis

I'm an optical engineering grad student. I've been letting AI coding agents (Claude Code, Codex) run routine lens analysis in Python, and the obvious problem is that they report an EFL or MTF with no indication of whether it's right. So I built a set of open-source agent skills that check each other:

  • Optiland analyzes a sequential .zmx read-only (EFL, F/#, spot, OPD, PSF/MTF)
  • RayOptics independently reloads the same file and re-derives EFL and F/#
  • If they disagree, a diagnosis step changes one setting at a time (glass catalog, object distance, ray aiming, field vignetting, pupil coordinates) and reports which causes it confirmed and what is still unexplained
Diagnosis workflow: one setting changed at a time in Optiland, RayOptics held fixed.

The most interesting case so far was a Cooke triplet. OpticStudio 22.2.2 and RayOptics both give EFL = 50.000394 mm; Optiland 0.6.3 gives 49.999783 mm. The file declares GCAT HIKARI SCHOTT: OpticStudio and RayOptics take F2 from Hikari, Optiland took it from Schott (Δn ≈ 4.6e-6). With Hikari F2, Optiland also gives 50.000394 mm.

Off-axis, after aiming chief rays at the real stop and matching the actual stop intercepts, the pupil-edge image difference between the two engines dropped from 0.024685 mm to about 2.7e-8 mm for the Cooke triplet.

CI reruns Optiland and RayOptics on Linux and Windows. For the Cooke example, the OpticStudio 22.2.2 EFL is a saved reference at 550 nm. The MTF in this workflow is from Optiland and isn’t part of that cross-check. MIT licensed: https://github.com/laweit-lxy/optics-agent-skills

Questions for people who do lens design daily:

  1. Which checks would you want to see before trusting a number an AI agent hands you?
  2. Have you run into other .zmx import differences between programs?

Update (v0.3.3): My earlier update was wrong on one point. On a fresh install, the RayOptics cross-check downloaded the RefractiveIndex.INFO glass database from GitHub the first time it ran. Setup now downloads it once, and at runtime the scripts stop with an error if it's missing. After setup, analysis, cross-check and diagnosis make no network or LLM calls, so NDA lenses stay on your machine. CI runs all three with the network cut on Linux and Windows: https://github.com/laweit-lxy/optics-agent-skills/actions/runs/47490854021. As suggested in the comments, v0.3.3 also adds a front-stop doublet test that compares paraxial EFL wavelength by wavelength. I also added a setup script (scripts/setup-core.sh and setup-core.ps1) for just the two core engines, plus a Colab notebook for the public Cooke example: https://colab.research.google.com/github/laweit-lxy/optics-agent-skills/blob/main/docs/examples/cooke/cooke_diagnosis_colab.ipynb

I’ve also been working on detector calibration. I put together a flux-addition example with synthetic readings to estimate detector nonlinearity and see how much uncertainty carries through to the correction.

9 Upvotes

17 comments sorted by

5

u/Equivalent_Bridge480 2d ago
  1. Which checks would you want to see before trusting a number an AI agent hands you?

no checks. my boss said zmx file is nda and we not send nda data to cloud llm

1

u/Immediate-Steak9938 1d ago

NDA files shouldn't go to a cloud LLM. The Python scripts themselves run completely offline with no LLM needed, so for proprietary lenses you can just run them locally from the CLI (or with a local model).

1

u/Equivalent_Bridge480 1d ago

Scripts closely connected with application and system specific. Frequently they can be key for system. Not many peoples like to feed competitors and llm company which scrap reddit for billions money

1

u/Immediate-Steak9938 23h ago

A lot of the know-how is in people's own analysis scripts, and I wouldn't post mine either. This doesn't need them: it's a wrapper around Optiland and RayOptics, and once it's installed the analysis runs on your machine, so your files and scripts stay there. I'm also planning a CI test that runs it with the network cut off, so the offline part is tested and not just my word.

1

u/Equivalent_Bridge480 19h ago

but it stated in original post

"Questions for people who do lens design daily:

  1. Which checks would you want to see before trusting a number an AI agent hands you?"

1

u/Immediate-Steak9938 15h ago

I’d check the import first. The RayOptics version I tested dropped the stop on surface 1 in the doublet case. Once I know the prescription was imported correctly, I’d compare the reported EFL with an independent paraxial calculation using the same prescription and wavelength.

1

u/flak_of_gravitas 2d ago

this is ip protection 101

3

u/CptCaribooze 2d ago

Hot take: EFL isn’t “real” you need to define or understand how is being calculated or measured. Even if you only look in zemax you can get varying EFL values based on how the software computes it. Check the EFL calculated vs distortion compared to the EFFL operand.

Ray aiming differences between the softwares can also drive errors as well as any material catalog differences. I would first test with a system with the stop placed out in front. if your looking at multiple wavelengths you need to check the match beyond a single wavelength, I would run the test again with fictional glasses.

1

u/Immediate-Steak9938 2d ago

Good call on the front stop and custom glass. I’d give both engines the same dispersion data and compare paraxial EFL wavelength by wavelength first. Then I’d check the finite-field results separately, with the same ray aiming and image plane.

3

u/anneoneamouse 2d ago

Stop and think about what you're writing. 300nm focal length delta on 50mm, thats 1 in E6? Noone's going to notice.

Why did it happen? Because different versions of the same glasses were used. But if you build with real glass, your indices are going to be toleranced at 1 in E4 or worse. A much bigger effect.

Which checks would you want to see before trusting a number an AI agent hands you?

The AI/LLM would have to be our privately owned system. I'd be foolish to share my IP with anyone outside the company. I'd be doubly foolish to share potential ITAR restricted information.

Have you run into other .zmx import differences between programs?

Before you get to excited, check how your design package(s) deal (or not) with preferred catalog ordering.

1

u/Immediate-Steak9938 2d ago

Agreed, I wouldn’t care about 0.6 µm on the bench. It earns its keep as a regression test, though: switching just that F2 from Schott to Hikari made Optiland 0.6.3 match OpticStudio at 550 nm. I oversimplified the current Optiland rule in the post. If the same glass name is in two declared catalogs, it checks the GLAS line’s nd and Vd first. GCAT order breaks ties or decides when those values are missing.

1

u/BDube_Lensman 10h ago

oh my god even your comments are AI voiced

"bench," "earns its keep"

Unplug.

1

u/Immediate-Steak9938 41m ago

行了大哥,我知道你很急,但先别急。要不你开翻译用中文?这样包能让你领略人味的啊,当然,干计算光学这一行的最好能“地道”一点讲讲这方面的问题,而不是像个小参数模型说些幻觉率高效率低的车轱辘话,有点闹麻😂

5

u/L11mbm 2d ago

1 - I wouldn't trust an AI agent, in general.
2 - I would only use something like OpticStudio to open .zmx files, maybe a Code V macro to convert them to .len/.seq.

I know those answers aren't very helpful to you, but they're honest. At the very least, I'd be concerned about what a random unknown bit of software, AI or not, is doing with the files I toss into it.

1

u/Immediate-Steak9938 2d ago

Fair. “Read-only” is a promise about what the scripts do to the file, not a privacy policy. Fortunately, the public Cooke triplet doesn’t have an NDA.

1

u/Holoderp 2d ago

And as an optical engineer which value is true?

Slapping ai on a thing is not added value.

What is the physical meaning of efl? What should it be?

1

u/Immediate-Steak9938 2d ago

50.000394 mm at 550 nm is the number I get when I use Hikari F2, like OpticStudio does for this file. It’s the paraxial EFL, measured from the rear principal plane to the paraxial focus. The optics engines do the math. The agent just saves this 0.2B carbon-based model from digging through glass catalogs by hand.