Skip to content

Refine a zero-dispersion point with array samples, not Brent - #528

Open
jtravs wants to merge 1 commit into
mainfrom
perf/zdw-array-refinement
Open

jtravs wants to merge 1 commit into
mainfrom
perf/zdw-array-refinement

Conversation

@jtravs

@jtravs jtravs commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

tools._zdw_near refined each sign change of the dispersion with a scalar Brent search, which evaluates the cladding's glass model on every iterate, about 190 evaluations per call. An index model evaluates an array at about the cost of one point, so this refines with four rounds of 33 samples and a final linear interpolation instead. It speeds up capillary_params, soliton_params and the zero-dispersion design target.

brentq is still used elsewhere in tools.py, so its import stays.

Timing

capillary_params at 14 um and 15 bar, on an Apple M5 Max. These are medians of 15 calls, repeated twice with the two searches alternating in one process. The machine was busy (load average 7 to 9), so read the ratios rather than the absolute times.

Gas Brent Array samples Ratio
He 288 ms 100 ms 2.9
Ar 607 ms 253 ms 2.4
Kr 907 ms 351 ms 2.6

What changes in the results

  • Physical zeros are unchanged. Across He, Ne, Ar, Kr, Xe and N2 at five radius and pressure pairs, they agree with Brent within 3.2e-9 relative, which is the noise of the differenced beta2. The new test holds this at 1e-8 on seven of those cases, against a Brent search over 200 nm to 3 um.
  • A crash goes away. On main, xenon at 14 um and 15 bar raises ValueError from brentq, because Brent converges onto a pole of the differenced beta2 until the model returns NaN. It now reports 960.57 nm, which the same test confirms.
  • A vacuum-ultraviolet pump can get a different answer. For pumps of 150 nm and shorter, the reported wavelength moved by up to 1.7e-3 relative in the same matrix (Ar and Xe; no such change at 200 nm and longer). The brackets involved hold 3 to 5 sign changes inside one sample interval. Brent lands on any of them, and this search takes the first upwards in frequency. Neither answer is a physical zero: these are artefacts of the differencing stencil crossing a line, and the pole test keeps them with either search. That predates this change and is now _zdw_near reports sign changes of the differenced beta2 beside a gas resonance as zeros #527.
  • A sign change separated by non-finite samples is dropped, as one at the first sampling already was. Brent would have raised here.

Verification

  • tests/test_tools.py, tests/test_design_solvers.py, tests/test_soliton_content.py and tests/modes/test_capillary.py: 323 passed, on numpy_ref.
  • ruff, ruff format --check, basedpyright, codespell, numpydoc and poe changelog-check are clean.
  • The new lines are fully covered, by the new tests and the existing pole test, in a coverage run over those tests.
  • The full gate, slow lane and coverage lane were not run locally; CI gates them.

Related: #157 (the same question in modes.base.zdw) and #527.

🤖 Generated with Claude Code

`_zdw_near` refined each sign change of the dispersion with a scalar Brent search,
which evaluates the cladding's glass model on every iterate. An index model evaluates
an array at about the cost of one point, so four rounds of 33 samples reach the noise
of the differenced `beta2` for a fraction of the cost: `capillary_params` takes about
2.5 times less time.

The rounds also stop short of a pole of the differenced `beta2`, which Brent converges
onto until the model returns NaN: xenon in a 14 um capillary at 15 bar raised
`ValueError` from the search, and now reports its zero. A sign change that samples
which are not finite separate is dropped, as one at the first sampling already was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jtravs jtravs added the performance Slower or larger than it should be, with no wrong result label Nov 4, 2026
Copilot AI balanced review requested due to automatic review settings November 4, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T00:00:21.928259Z 9ae77f3 PR opened
🔒 Security Review ✅ Completed 2026-11-05T00:01:10.974370Z 9ae77f3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 solprop | 🛠️ Build #35657819 | 📁 Comparing 9ae77f3 against latest (8ed26dd)

  🔍 Preview build  

1 file changed
± _modules/solprop/tools.html

@codecov

codecov Bot commented Nov 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Slower or larger than it should be, with no wrong result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants