Skip to content

Fix mpb degenerate band truncation - #3307

Open
yorickreum wants to merge 2 commits into
NanoComp:masterfrom
yorickreum:fix-mpb-degenerate-band-truncation
Open

Fix mpb degenerate band truncation#3307
yorickreum wants to merge 2 commits into
NanoComp:masterfrom
yorickreum:fix-mpb-degenerate-band-truncation

Conversation

@yorickreum

Copy link
Copy Markdown

Fixes #2298 by not splitting degenerate bands.

Yorick Reum 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.

@oskooi oskooi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

Comment thread python/tests/test_mpb.py
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Comment thread python/tests/test_mpb.py
ms = self.init_solver(num_bands=10)
ms.run_tm()
mpb.fix_efield_phase(ms, 8)
mpb.output_efield_z(ms, 8)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sporadic failure in test_output_efield_z of test_mpb.py

3 participants