Skip to content

Keep the full complex generalized group velocity in kappa_offdiag - #185

Merged
mjv500 merged 1 commit into
tdep-developers:mainfrom
Surefire618:fix/coherence-gauge-invariance
Aug 17, 2026
Merged

Keep the full complex generalized group velocity in kappa_offdiag#185
mjv500 merged 1 commit into
tdep-developers:mainfrom
Surefire618:fix/coherence-gauge-invariance

Conversation

@Surefire618

@Surefire618 Surefire618 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Keep the full complex generalized group velocity in kappa_offdiag

The bug

get_kappa_offdiag drops the imaginary part of the off-diagonal group velocity:

! I can take the real part since at the end we sum over
! both modes and the imaginary components disappear.
buf_vel(:, i, j) = real(cv0, r8)

The premise is true — v_ij = conj(v_ji), so sum_ij Im v_ij = 0 — but buf_vel is not summed linearly. It is accumulated quadratically,

buf_velsq(:, :, i, j) = buf_velsq(:, :, i, j) + lo_outerproduct(v1, v1)

and sum_ij Im v^a Im v^b does not vanish. What is left, Re v^a Re v^b, is not invariant under v_ss' -> exp(i(th_s' - th_s)) v_ss', so kappa_offdiag depends on the arbitrary phases that zheev returns for the eigenvectors.

The fix

Keep cv0 complex and take the real part of the outer product instead:

buf_vel(:, i, j) = cv0
...
buf_velsq(:, :, i, j) = buf_velsq(:, :, i, j) + &
                        real(lo_outerproduct(v1, v1), r8)

lo_complex_outerproduct(a, b) is m(i,j) = conj(a(j)) * b(i), so this gives Re v^a Re v^b + Im v^a Im v^b, the gauge-invariant combination. buf_vel and the local v0, v1 in get_kappa_offdiag become complex; the variables of the same name in get_kappa are untouched.

The fix in this branch fix/coherence-gauge-invariance is prepared for a merge.

Evidence

MgO from tdep-tutorials/04_thermal_conductivity/Examples/MgO, 300 K, third order, isotope scattering on, adaptive Gaussian integration, one MPI rank.

Gauge-invariance test (test only branch, do no merge)

To test gauge invariance I prepared a random-phase-injection patch, available as the branch Surefire618:random_phase_injection. It multiplies every eigenvector by a random phase, e_s -> exp(i th_s) e_s, before the off-diagonal velocity is built.

The patch is enabled by setting the environment variable TDEP_GAUGE_SEED:

export TDEP_GAUGE_SEED=1
thermal_conductivity -qg 8 8 8 --temperature 300

The original behaviour is recovered by taking the real part of the velocities:

! buf_vel(:, i, j) = cv0
buf_vel(:, i, j) = real(cv0, r8)

A sanity check confirms that the phased vectors are still orthonormal and are still eigenvectors with the same eigenvalues. The patch also writes v_ss' to outfile.velocity_offdiagonal. This test branch Surefire618:random_phase_injection is for diagnostics only and is not proposed for merging.

The coherence channel at 8³ reads:

gauge original (W/mK) fixed (W/mK)
none 0.088432413 0.099657622
TDEP_GAUGE_SEED=1 0.041501821 0.099657622
TDEP_GAUGE_SEED=2 0.038095586 0.099657622
TDEP_GAUGE_SEED=3 0.075441779 0.099657622

The input files and the thermal_conductivity log files are attached for reference:
mgo_gauge.tar.gz

get_kappa_offdiag discarded the imaginary part of the off-diagonal group
velocity before squaring it:

    buf_vel(:, i, j) = real(cv0, r8)

justified by "I can take the real part since at the end we sum over both
modes and the imaginary components disappear". The premise holds --
sum_ij Im v_ij is zero because v_ij = conj(v_ji) -- but the quantity
accumulated afterwards is quadratic:

    buf_velsq(:, :, i, j) += lo_outerproduct(v1, v1)

and sum_ij Im v^a Im v^b does not vanish. Dropping it leaves
Re v^a Re v^b alone, which is not invariant under the arbitrary per-mode
phases zheev returns, so kappa_offdiag depends on the eigenvector basis.
Measured on three materials, a random phase gauge moved it by 27-59 %
while leaving kappa_sma bit-identical.

Keeping cv0 complex and taking the real part of the outer product gives
Re v^a Re v^b + Im v^a Im v^b, the gauge invariant bilinear
(lo_complex_outerproduct conjugates its first argument). kappa_offdiag is
then bit-identical across gauges; kappa_sma, frequencies, linewidths,
lifetimes, heat capacities and group velocities are unchanged.

kappa_offdiag itself moves: 0.00481941 -> 0.00830067 (KI, Pm-3m),
0.05503408 -> 0.06626228 (Rb2O, Fm-3m), 0.07273678/0.14298927 ->
0.16748196/0.37433862 (KPTe2, R-3m) W/mK at 300 K on a 6^3 mesh.
@mjv500

mjv500 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Hi Shao, thanks for the fix. I am running the CLI.

Your text is not clear about the merge though: "The branch is for diagnostics only and is not proposed for merging" yet you are making a merge request... Please elaborate, and clean up the final branch for the MR if that is what you want

@Surefire618

Copy link
Copy Markdown
Contributor Author

Hi Matthieu, thanks for testing.

Sorry for the ambiguous wording. There are two separate branches:

The fix: Surefire618:fix/coherence-gauge-invariance. The only change is to keep the generalized group velocity complex. This is the branch this MR points at, and the one to merge.

The test: Surefire618:random_phase_injection. It adds a toy experiment that demonstrates the gauge dependence of the original result and the gauge invariance after the fix. This branch is for diagnostics only and is not part of this MR.

The sentence you quoted refers to the second branch only. I will make that explicit in the PR description.

Best wishes, Shuo

@mjv500 mjv500 self-assigned this Aug 17, 2026
@mjv500
mjv500 self-requested a review August 17, 2026 09:59

@mjv500 mjv500 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks clean to me and passes automatic tests

@mjv500
mjv500 merged commit 6739e8b into tdep-developers:main Aug 17, 2026
1 check passed
@mjv500

mjv500 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Thanks @Surefire618 !

@Surefire618
Surefire618 deleted the fix/coherence-gauge-invariance branch August 17, 2026 10:14
@flokno

flokno commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Good catch!

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.

3 participants