Skip to content

[wien2k] pure-Python case.oubwin band-window generator - #8

Merged
the-hampel merged 3 commits into
TRIQS:unstablefrom
krystophny:port/dmftproj-oubwin-python
Oct 13, 2026
Merged

the-hampel merged 3 commits into
TRIQS:unstablefrom
krystophny:port/dmftproj-oubwin-python

Conversation

@krystophny

@krystophny krystophny commented Jun 16, 2026 •

Copy link
Copy Markdown

Part of #7 (dmftproj Fortran-to-Python port), following the merged #5.

triqs_dftkit.wien2k.oubwin.write_oubwin(case) reads case.almblm{up,dn} (or the non-spin-polarized case.almblm) and the energy window in case.indmftpr. It selects the contiguous band range per k-point and spin and writes case.oubwin{up,dn} in the dmftproj format. This step supports energy-window projection mode 0; band-index modes raise NotImplementedError.

Window selection preserves set_projections.f's separate window-open and window-valid flags. A window that opens only at the final band remains excluded with zero bounds, including when nbmin == nbmax.

The CaOs2 test decompresses the existing .almblm{up,dn}.gz fixtures into a temporary directory and compares both generated spin outputs against the shipped CaOs2.oubwinup, ignoring only trailing whitespace removed from that reference. The selected bands are 43–92. No duplicate truncated inputs are added.

The existing test also checks the reported final-band cases, strict lower/inclusive upper energy boundaries, Fermi shifts, distinct per-k-point lowest-band weights, and output records for excluded points. It passes locally with NumPy; full package integration is checked by the PR's CI matrix.

Chris&AI

@krystophny

Copy link
Copy Markdown
Author

Accuracy: case.oubwin is integer band-window data, reproduced byte-identically (independent of the precision fix).

@the-hampel

Copy link
Copy Markdown
Member

Hi @krystophny, #5 is merged (9c615a4), so we moved on to this one.

Rebase. We force-pushed a rebase onto current unstable (334a8a7 → 517c014). Please re-fetch before you work on it locally. Only your oubwin commit was replayed. The only conflict was test/python/wien2k/CMakeLists.txt, where we kept both blocks.

Fresh build: 23/24 tests pass. Py_wien2k_oubwin_python fails because of fixture changes from #4, not the generator. With the new -2..3 Ry window the generator selects bands 43–92, matching the shipped fixture:

  1. [test] Add spin-orbit + spin-polarized Wien2k converter test (CaOs2) #4 stripped trailing whitespace from the shipped CaOs2.oubwinup. The generator reproduces native dmftproj byte for byte, including the trailing blanks after the weight, so the string comparison fails.
  2. CaOs2.oubwindn was dropped in [test] Add spin-orbit + spin-polarized Wien2k converter test (CaOs2) #4: it is identical to oubwinup for SO and the converter only reads up. The test should compare both generated files against oubwinup.

Review: one blocking finding in _select_window. set_projections.f keeps two flags: the local included (window opened) and kp%included (window valid). The latter is set only when the window closes (E > e2) or reaches nbmax. If the only in-window band is nbmax (including nbmin == nbmax), the first branch fires, kp%included stays .FALSE., and the k-point is written as 0 0. The Python merges the two flags, so the same input gives an included k-point with nb_top < nb_bot:

_select_window(10, 13, np.array([-3., -2., -1., 0.5]), 0., 0., 1.)  # -> (True, 13, 0)
_select_window(5, 5, np.array([0.5]), 0., 0., 1.)                    # -> (True, 5, 0)

Please track the two flags separately, as the Fortran does. If you think dropping that k-point is a Fortran bug worth fixing, change both sides together and say so in the commit message.

Non-blocking:

  • The CaOs2 fixture has one k-point with weight 1.0, so the per-k weight, the not-included path and edge cases like the one above are untested. A few synthetic unit tests of _select_window would cover them.
  • The truncated CaOs2.almblm{up,dn} are exact prefixes of the CaOs2.almblm{up,dn}.gz already on unstable. Reading the .gz files (e.g. via gzip.open) would avoid shipping a second copy.

Attribution: this comment was produced by Claude (Opus 5.5) running in Claude Code, driven by @the-hampel.

Port the dmftproj almblm reader and case.oubwin writer to NumPy. Given
case.almblm{up,dn} and the energy window in case.indmftpr, select the
contiguous band range per k-point and spin and write case.oubwin{up,dn}
in the dmftproj format. Support proj_mode 0; band-index modes remain
explicitly unsupported. Part of TRIQS#7.

Keep window-open and window-valid flags separate, as set_projections.f
does. A window opening only at nbmax remains excluded with zero bounds,
including nbmin == nbmax. Preserve this native behavior on both sides.

Reuse the existing compressed CaOs2 almblm fixtures, decompressing into
a temporary directory. Compare both spin outputs with CaOs2.oubwinup,
ignoring only trailing whitespace stripped from the shipped reference.
Add focused checks for the final-band edge cases, energy boundaries,
Fermi shifts, per-k lowest-band weights and excluded output records.

Validation: the generator test passes locally with NumPy, including both
reviewer reproducers and regeneration of the 43-92 CaOs2 band window.
@krystophny
krystophny force-pushed the port/dmftproj-oubwin-python branch from 517c014 to 2dd14bf Compare October 12, 2026 12:13
@krystophny

krystophny commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

GPT Sol did the remaining updates in 2dd14bf. Window-open and window-valid flags now preserve the Fortran final-band behavior. Focused regressions cover both reported cases, energy boundaries, Fermi shifts, per-k weights and excluded records.

Both generated spin files are compared against oubwinup, ignoring only trailing whitespace; the test reuses the existing .gz inputs. The commit message and PR description are corrected. All 24 tests pass on Linux GCC and Clang; macOS CI is still running.

Chris&AI

krystophny added a commit to krystophny/dftkit that referenced this pull request Oct 12, 2026
Read the almblm coefficients, assemble and locally rotate correlated
projectors, apply the cubic/complex basis, and Loewdin-orthonormalize the
stacked shells before writing ctqmcout. Part of TRIQS#7, following TRIQS#8.

Keep the native separate window-open/valid flags. Validate matching SO
spin windows and use each spin's own band offsets. Reject unsupported
non-SO, band-index, cubic p/f and non-identity struct rotation paths
instead of producing misleading files; subsequent port stages add them.

Reuse the current full-rank CaOs2 inputs and TRIQS#8 fixture handling. Compare
integer fields exactly and finite float fields at atol=1e-7, rtol=0.
Add regressions for final-band-only windows and mismatched SO spins.
Local validation gives max native residual 1.3e-8 and full 20x50 projector
orthonormality error 3.2e-15. The old rank-deficient-window claims no
longer apply to this fixture.
@krystophny

Copy link
Copy Markdown
Author

GPT Sol completed another adversarial review against the linked port context. Fixed reading multiple correlated-shell representation records before the SO flag, rejected inconsistent per-sort SO flags, and accepted inline window comments. The native window fixture and focused parser regressions pass; the dependent stack has been restacked. Latest-head CI is running/queued.

Chris&AI

@the-hampel
the-hampel merged commit b58a54b into TRIQS:unstable Oct 13, 2026
4 checks passed
the-hampel pushed a commit to krystophny/dftkit that referenced this pull request Oct 13, 2026
Read the almblm coefficients, assemble and locally rotate correlated
projectors, apply the cubic/complex basis, and Loewdin-orthonormalize the
stacked shells before writing ctqmcout. Part of TRIQS#7, following TRIQS#8.

Keep the native separate window-open/valid flags. Validate matching SO
spin windows and use each spin's own band offsets. Reject unsupported
non-SO, band-index, cubic p/f and non-identity struct rotation paths
instead of producing misleading files; subsequent port stages add them.

Reuse the current full-rank CaOs2 inputs and TRIQS#8 fixture handling. Compare
integer fields exactly and finite float fields at atol=1e-7, rtol=0.
Add regressions for final-band-only windows and mismatched SO spins.
Local validation gives max native residual 1.3e-8 and full 20x50 projector
orthonormality error 3.2e-15. The old rank-deficient-window claims no
longer apply to this fixture.
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.

2 participants