Skip to content

[wien2k] Pure-Python case.symqmc generator (first dmftproj port step) - #5

Merged
the-hampel merged 1 commit into
TRIQS:unstablefrom
krystophny:port/dmftproj-symqmc-python
Oct 12, 2026
Merged

the-hampel merged 1 commit into
TRIQS:unstablefrom
krystophny:port/dmftproj-symqmc-python

Conversation

@krystophny

@krystophny krystophny commented Jun 15, 2026 •

Copy link
Copy Markdown

Part of #7 (dmftproj Fortran-to-Python port).

triqs_dftkit.wien2k.symqmc.write_symqmc(case) reads case.dmftsym, case.indmftpr and case.struct and writes the correlated-shell symmetry matrices in case.symqmc. It implements the dmftproj construction using Wigner D matrices, angular-basis transforms, orbital and spinor time reversal, and spin-1/2 phase blocks.

The CaOs2 tests cover the non-mixing cubic d basis, a spin-mixing fromfile basis (|j,m_j>), and an l=0 shell, using 16 operations including 8 antiunitary operations.

The cubic test generates into a temporary directory and compares directly against the shipped native CaOs2.symqmc: headers exactly, complex matrix entries at atol=1e-7, rtol=0, and Python unitarity at 1e-12. The converter tests retain their original Fortran fixture. The mixing and l=0 tests use their existing native matrix references.

The cubic matrices differ from the native fixture by 8.6e-8 in complex magnitude (6.9e-8 per real/imaginary component). The cause is native precision loss: set_ang_trans.f reads the eight-digit cubic template through CMPLX without KIND=8, magnetic operations apply the rounded basis twice, and outputqmc.f evaluates spin phases in single precision. Python uses exact cubic d coefficients and double-precision phases. Reproducing the native rounding and time-reversal construction in a local check reduces the residual to 2.2e-14. The separate native precision work remains in #14; this PR uses the existing fixture.

Both generator scripts pass locally with NumPy, and source/working-directory fixture preservation was checked. Full TRIQS integration runs in the PR's four-platform CI matrix.

Chris&AI

@krystophny

Copy link
Copy Markdown
Author

Accuracy: reproduces the released (single-precision) dmftproj case.symqmc to 6.8e-8. With the Fortran precision fix #14 + exact Python #12 this becomes 1.5e-14 (machine precision).

@the-hampel

Copy link
Copy Markdown
Member

Hi @krystophny, #4 is merged (c2f0576), so we moved on to this one.

Rebase. We force-pushed a rebase onto current unstable (7d21b9c → 4a26e2b). Please re-fetch before you work on it locally. Only your symqmc commit was replayed; the old #4 commit 830cb84 is gone. Conflict resolutions:

  • CaOs2.indmftpr: kept the unstable version (-2.0..3.0 Ry). symqmc does not depend on the window.
  • test/python/wien2k/CMakeLists.txt: kept both blocks.
  • CaOs2.dmftsym was already identical on unstable, so it dropped out of the commit.

Fresh build: 22/23 tests pass. Two issues, which we'd leave to you since they depend on the precision question below:

  1. Py_wien2k_symqmc_python fails. wien2k_soc_convert.ref.h5 now also holds dft_parproj_input/dft_symmpar_input, and this test only runs convert_dft_input. It also still uses h5diff, which checks arrays at 1e-6 regardless of precision, as found in [test] Add spin-orbit + spin-polarized Wien2k converter test (CaOs2) #4.
  2. The test overwrites a shared fixture. write_symqmc('CaOs2') writes into the build directory that Py_wien2k_soc_convert reads, replacing the Fortran CaOs2.symqmc. The Python output differs from it by up to 6.9e-8, so the result depends on test order: after symqmc_python has run, Py_wien2k_soc_convert fails at 1e-12 (max diff 3.4e-8). Generating into a temp dir, as wien2k_symqmc_mixing.py does, and comparing the generated file against the shipped CaOs2.symqmc at an explicit tolerance would fix both.

Precision question. The commit message says the cubic path matches dmftproj "to machine precision" and that the HDF5 is "identical (h5diff)". With the #4 fixture (cubic basis from case.cf_d_eg_t2g), the matrices differ by up to 6.9e-8; the h5diff check only passed because of its 1e-6 tolerance. We haven't checked which side is off. A single-precision read of the cubic template on the Fortran side, like the CMPLX cast you describe for the fromfile basis, would fit. Could you pin that down and set the tolerance (and the commit message) accordingly?

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

Generate correlated-shell spinor symmetry matrices from case.dmftsym,
case.indmftpr and case.struct using the dmftproj Wigner-D, angular-basis,
time-reversal and spin-phase construction. Cover the non-mixing cubic,
spin-mixing fromfile (|j,m_j>) and l=0 paths on the CaOs2 fixture.

The cubic matrices differ from the shipped native fixture by 8.6e-8 in
complex magnitude (6.9e-8 per real/imaginary component). set_ang_trans.f
reads the 8-digit cubic template through CMPLX without KIND=8; magnetic
operations apply this rounded basis twice. outputqmc.f also evaluates
spin phases in single precision. Python uses exact cubic d coefficients
and double-precision phases. Reproducing the native rounding in a local
check reduces the complex residual to 2.2e-14; the native precision fixes
remain separate in TRIQS#14.

Generate into a temporary directory and compare the complete symqmc
header exactly and the complex matrices at atol=1e-7, rtol=0. Check
Python cubic unitarity at 1e-12. This preserves the SOC converter's
shared fixture and avoids h5diff's hard-coded array tolerance and the
unrelated parproj archive groups. The fromfile and l=0 tests retain
their native matrix references. Read generator inputs from the source
fixtures instead of copying unused files into the build directory.
@krystophny
krystophny force-pushed the port/dmftproj-symqmc-python branch from 4a26e2b to 1622e01 Compare October 12, 2026 08:31
@krystophny

krystophny commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

GPT Sol did the remaining updates in 1622e01. The cubic test now uses a temporary directory, compares the native symqmc directly at atol=1e-7, rtol=0, and checks Python unitarity at 1e-12.

The cubic CMPLX cast, repeated basis transform for magnetic operations, and single-precision spin phases explain the residual; reproducing them gives 2.2e-14. The accuracy claims are corrected. Both generator tests pass locally, and Linux GCC/Clang plus macOS GCC each pass all 23 tests; macOS Clang is still building TRIQS.

Chris&AI

@the-hampel

Copy link
Copy Markdown
Member

Okay thanks @krystophny . All good from my side. I will go ahead with the merge.

@the-hampel
the-hampel merged commit 9c615a4 into TRIQS:unstable Oct 12, 2026
4 checks passed
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