An autonomous photonic device design agent, inspired by Andrej Karpathy's autoresearch. Instead of a human manually tuning device geometry and running simulations, an LLM agent (e.g. Claude Code) takes over the design loop: it reads instructions and constraints from a Markdown file, modifies the device geometry in Python, visually verifies the layout, runs a fabrication design-rule check, submits FDTD simulations to Tidy3D's cloud solver, inspects the resulting field patterns, and decides whether to keep or discard each design — all without human intervention.
Each iteration runs through a fixed loop:
Design → Verify (preview + DRC) → Simulate → Keep or Discard
A persistent experiment journal (output/journal.md) gives the agent
long-term memory across iterations, so it learns from both successes and
failures and avoids repeating dead ends. The human's job is to define the
problem (device type, constraints, target metric) in program.md; the
agent does the engineering.
See a few examples of what the AI photonic designer has designed:
| File | Role |
|---|---|
program.md |
Agent instructions, constraints, loop rules |
design.py |
Device geometry (the only file the agent modifies) |
simulate.py |
Runs Tidy3D FDTD simulation, extracts metric, plots fields |
preview.py |
Generates geometry preview for visual inspection |
drc.py |
Fabrication rule check via KLayout |
output/ |
All generated files (logs, plots, journal, best design) |
pip install tidy3d numpy matplotlib klayout
tidy3d configure --apikey=YOUR_API_KEYGet your Tidy3D API key at tidy3d.simulation.cloud.
Point Claude Code (or any compatible LLM agent with shell + Python
execution) at program.md:
claude "Follow the instructions in program.md and start designing!"The agent will run the loop for the number of experiments specified in
program.md (default: 50). Watch progress in output/journal.md and
output/results.tsv.
To adapt this framework to a new photonic device:
- Edit
program.md— describe the target device, metric, and constraints. - Edit
design.py— update the initial geometry and theevaluate()function that computes the target metric from simulation data. - The rest of the infrastructure (
simulate.py,preview.py,drc.py) is device-agnostic and does not need to change.
Inspired by karpathy/autoresearch. Built on Tidy3D for FDTD simulation and KLayout for DRC.