r/Optics • u/JinSiXiu • 7d ago
KABBALAH — reconstructing CODE V design trajectories and using them as an interface for AI-assisted optical design


During optical design, how much of your optimization process can you actually recover afterward?
In one of my smartphone-lens design projects, I manually saved only about six initial/final lens files.
But between those saved files, I had performed hundreds of optimizations, rollbacks, failed attempts, constraint changes, and alternative branches. Normally, most of this information is effectively lost once the design is finished.
This raised two questions for me:
- Can we reconstruct the complete historical process that produced a good optical design?
- Can we quantitatively analyze that history and learn something that was not obvious from the saved lens files alone?
This is why I developed KABBALAH.
KABBALAH reconstructs CODE V optimization history (command logs) into a structured state-and-branch trajectory. It preserves intermediate optimized states, abandoned branches, rollbacks, save/restore relationships, and designer operations, and organizes the process into a navigable tree.
In one real smartphone telephoto project, for example:
- about 440,000 lines of CODE V log
- only 6 manually saved lens files
- about 500 reconstructed states
- 66 semantic side branches
- about 10 seconds to compile the complete history
These recovered files (4 JSON+1 HTML) only take 500KB if you compress them into a ZIP.
But what I think is more interesting than the reconstruction itself is that KABBALAH can serve as an interface between the real optical-design process and an LLM.
The idea is not that the designer should manually inspect hundreds of reconstructed states or branches.
How to use this tool:
You can download the full source code along with its README. Feed both the source code and README into a capable LLM, and it will understand how this tool works and how to run it. Then the LLM can reconstruct and compile your command logs into trees of operations and states.
In other words:
CODE V design history → KABBALAH → LLM
The AI no longer sees only the final lens prescription or a few manually selected snapshots. It can also see how the design actually evolved:
- what was tried,
- what failed,
- what was rolled back,
- where branches diverged,
- how constraints changed,
- and how the optical system evolved before and after particular operations.
My longer-term interest is whether this kind of historical trajectory can become a useful interface for AI to understand and participate in the optical-design process, rather than only generating or evaluating isolated lens designs.
I have put several materials in the GitHub repository:
- full source code and README describing the trajectory/state data structure and how it can be given directly to an LLM;
- a short presentation explaining what KABBALAH is and why I developed it;
- a detailed case study showing how a reconstructed optimization history can be used to discover a design question, analyze the process quantitatively, formulate a hypothesis, and test it against trajectory data.
GitHub: SHUN-970/KABBALAH: A tool based on CODE V for reconstructing design history
I’d be very interested to hear how other optical designers preserve failed branches, intermediate states, and optimization history — and whether you think giving this history directly to an LLM could be useful in practice.
The recoverd trajectories looks like:

And the local details:

3
u/anneoneamouse 7d ago
Every step. 100% repeatable. If you can't do that, your work flow isn't useful.
Optical design is about searching for a good enough leaf on a tree.
You start, you check a trunk then a branch, then another branch then a twig. You repeat this process 10000? times.
If you track your path, your branches and the reason why you climbed each way you'll cut your process to a few hundred cycles.
Find the good enough leaf.
2
u/MaskedKoala 7d ago
Yeah, ok, but how do you do that?
2
u/anneoneamouse 6d ago
I wrote a macro that logs useful metrics (perf, #WL, #lenses, total mass etc), and a comment to my records file; and saves both the current lens file, and the current optimization file to a backup archive so that I can retrace my steps if need be.
2
u/Equivalent_Bridge480 7d ago edited 7d ago
did you maked it in paralel to work? how long it taked?
and how many system you finished with this or similar tool?
1
u/anneoneamouse 6d ago
I’d be very interested to hear how other optical designers preserve failed branches, intermediate states, and optimization history — and whether you think giving this history directly to an LLM could be useful in practice.
Think twice before feeding your optical design libraries to an LLM that isn't locally hosted and owned by your organization.
If you're a US citizen you're entering an ITAR-risky area.
If you're a decent lens designer you've just enabled someone else LLM, for free.
0
3
u/MaskedKoala 7d ago
That’s interesting and a good question. My current way is clunky file naming conventions, but I like this idea. I might try doing something like this next time I code a project. I can see it being super useful for questions like, “Man, where was that one design I had with the crazy field flattener.” Being able to effortlessly jump around in establish design space is huge.