Fix mpb degenerate band truncation - #3307
Open
yorickreum wants to merge 2 commits into
Open
Conversation
added 2 commits
September 11, 2026 12:11
MPB splits a complex field into "<name>.r" and "<name>.i" datasets because HDF5 has no complex type, and compare_h5_files applied a relative tolerance to each half separately. For a phase-fixed field the imaginary half is only a roundoff residual -- 8e-6 of the real half in test_output_efield_z -- so that compared noise against noise and failed sporadically. Compare the pair as the single complex array it represents. tol is honoured now as well; it was accepted but a hard-coded 1e-3 was used. Part of NanoComp#2298, which also needs the degenerate-band fix that follows.
…it (NanoComp#2298) Bands 8 and 9 are degenerate at Gamma, so requesting exactly 8 bands cuts the pair in half: nothing in the converged subspace distinguishes them, and the vector returned as band 8 is an arbitrary member of the doublet. Its eigenvalue is reproducible to 1e-10 while the eigenvector moves by 1e-2 -- hence a failure that looks like noise but that no tolerance can fix. The residual splitting is numerical, not physical: it does not converge with resolution (8e-7 at 32, 2e-8 at 64) while the gap to band 10 settles at 1e-2. Request 10 bands, ending the block at that gap. Run-to-run variation of the band-8 field falls from 3.2e-02 to 1.8e-08, and the result becomes block-size independent (num_bands 9, 10 and 12 agree to 3e-06). The stored reference has to be regenerated, as the old one recorded an arbitrary member of the doublet. With this and the preceding commit, test_output_efield_z passed 30 consecutive runs, against 4 failures in 20 before. The reference was regenerated on a mingw-w64 build; the block-size independence above is the evidence that it is portable, but CI elsewhere should confirm it.
stevengj
reviewed
Sep 11, 2026
| self.assertClose(x, y, epsilon=tol, msg=f"dataset {base}") | ||
| for k in keys: | ||
| if k[-2:] in (".r", ".i") and k[:-2] in paired: | ||
| continue |
Collaborator
There was a problem hiding this comment.
Comparing the .r and .i components as a single complex array makes sense to me. I'm not sure what it has to do with the degeneracy problem, though?
stevengj
reviewed
Sep 11, 2026
| ms = self.init_solver(num_bands=10) | ||
| ms.run_tm() | ||
| mpb.fix_efield_phase(ms, 8) | ||
| mpb.output_efield_z(ms, 8) |
Collaborator
There was a problem hiding this comment.
Won't you still potentially get test failures if different versions of MPB produce a different linear combination for bands 8 and 9 at Gamma?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2298 by not splitting degenerate bands.