refactor(notebooks): use internal adam and optimize helper - batch 4#513
Conversation
Spell Check ReportTidyFab0GC.ipynb: Checked 9 notebook(s). Found spelling errors in 1 file(s). |
groberts-flex
left a comment
There was a problem hiding this comment.
thanks @marcorudolphflex! overall looks great! I'm a little curious about the RF one where the optimization curve looks less smooth. I wonder if that's some other changes since the last time develop was run or the alternate Adam optimizer behaves slightly differently than optax. Either way, the final performance looks good and I don't think this is a blocker at all!
One small other thing that I came across while going through this with codex was that in TidyFab0GC.ipynb, the best_params are taken from the param_history but those are updated in the callback before the device is stepped. So we could either use the final parameters that are returned or fill in the final device and figure of merit into the param_history.
Thanks! Good catch, went with the "final params" way here. |
Makes sense, that's good to know! It does seem likely the changes are from somewhere else. This all looks good to me, thanks for doing these conversions |
follow-up from #463
Replaces the optax Adam with our Adam and makes use of the
optimizehelper where easily possible. This is the fourth batch, reduced to the 9 notebooks from #465 wheredevelopstill had real optax usage.Metalens.ipynb,Autograd27Smatrix.ipynb, andAutograd25WaveguideCrossing.ipynbare intentionally left out for separate discussion.Results are roughly unchanged overall. Relevant comparison notes copied from #465 are below.
Percent differences below use
(branch - develop) / develop. For max objectives, positive is better; for min objectives/costs, negative is better.3.0199e-015.1519e-01+2.1320e-01+70.60%4.799e-014.801e-01+2.0e-04+0.04%-1.98 dBvs. branch-1.99 dB2.2378e+012.3344e+01+9.660e-01+4.32%8.792e-018.790e-01-2.0e-04-0.02%+0.02%; final efficiency0.91to0.894.0488e-024.0460e-02-2.8e-05-0.07%8.134e-018.139e-01+5.0e-04+0.06%20.81231520.717626-9.4689e-02-0.45%1.194e-011.185e-01-9.0e-04-0.75%0.099308317757073240.0993083177570732400.00%❓ TidyFab0GC.ipynb
Objective (max.): develop
3.0199e-01vs. branch5.1519e-01(+70.60%)Unexpectedly better. This may be from client/solver changes rather than the optimizer refactor.
Autograd19ApodizedCoupler.ipynb
Objective (max.): develop
4.799e-01vs. branch4.801e-01(+0.04%)Maximum coupling efficiency: develop
-1.98 dBvs. branch-1.99 dBRerun is back in line with develop.
Autograd7Metalens.ipynb
Objective (max.): develop
2.2378e+01vs. branch2.3344e+01(+4.32%)Plot/result roughly unchanged.
Autograd26DiffractiveBeamSplitter.ipynb
develop:
branch:
Later final-efficiency output: develop
0.91vs. branch0.89.Autograd28FiberLens.ipynb
Objective / final flux (max.): develop
4.0488e-02vs. branch4.0460e-02(-0.07%)Plot/result nearly unchanged.
BilayerSiNSiGC.ipynb
Objective (max.): develop
8.134e-01vs. branch8.139e-01(+0.06%)Effectively unchanged.
RFAutograd1RectangularPatchAntenna.ipynb
Final nonzero FOM: develop
20.812315vs. branch20.717626(-0.45%).Optimization a little less smooth now, result differs a bit:
Autograd13Metasurface.ipynb
Final loss (min.): develop
1.194e-01vs. branch1.185e-01(-0.75%).Autograd23FabricationAwareInvdes.ipynb
Did not rerun this notebook because I do not have credits for the prefab/fabrication-aware run path. No result shift is expected from this diff.
Note
Low Risk
Notebook-only optimizer wiring changes with no library API changes; numerical drift is minor except one flagged rerun outlier.
Overview
Fourth batch of inverse-design notebook cleanup: nine tutorials drop optax in favor of
tidy3d.plugins.autogradadam,apply_updates, andoptimize()where the loop is a straight min/max with bounds.TidyFab0GCis refactored to calloptimize(..., direction="max")with a step callback and min-featureboundsinstead of hand-rolled Adam steps. Others (Autograd19ApodizedCoupler,Autograd13Metasurface,Autograd26DiffractiveBeamSplitter, etc.) keep explicit loops but swapoptax.adam/optax.apply_updatesfor the internal Adam API; notebooks that still need custom iteration (e.g.betaramping, live plots) are not forced ontooptimize().Metalens.ipynb,Autograd27Smatrix, andAutograd25WaveguideCrossingare out of scope for this batch.Reruns vs.
developare mostly within ~1% on objectives;TidyFab0GCshows a large objective jump that may be environment/solver noise rather than the optimizer swap.Autograd23FabricationAwareInvdeswas not fully rerun (prefab credits).Reviewed by Cursor Bugbot for commit ec0d8ee. Bugbot is set up for automated code reviews on this repo. Configure here.