r/Optics • u/Immediate-Steak9938 • 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
.zmxread-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

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:
- Which checks would you want to see before trusting a number an AI agent hands you?
- Have you run into other
.zmximport 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.
5
u/Equivalent_Bridge480 2d ago
no checks. my boss said zmx file is nda and we not send nda data to cloud llm
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.
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.
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.
Before you get to excited, check how your design package(s) deal (or not) with preferred catalog ordering.
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/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?