zkit.mwigner.covariance
Phase-space covariance diagnostics of 2D wavefunctions.
For a wavefunction \(\psi(x, y)\) on a uniform grid this module computes the \(4\times4\) covariance matrix of \(R = (x, p_x, y, p_y)\), its symplectic eigenvalues, the purity of the Gaussian state with the same covariance, its principal components, and the Schmidt spectrum of the reduced density matrix \(\rho(x, x')\) obtained by tracing over \(y\).
Momentum moments use spectral (FFT) derivatives,
which are exact to round-off for states that decay to zero at the grid boundary. Atomic units, \(\hbar = 1\). The moments use the flat momentum operator \(-i\nabla\); for a position-dependent mass this is the canonical momentum, not \(m\,v\).
The symplectic eigenvalues \(\nu_k\) of a continuous-variable state satisfy \(\nu_k \ge 1/2\), with equality for all \(k\) exactly for a pure Gaussian state. A projection of the state onto a single quadrature is a continuous variable and is not used as a two-level system here.
- zkit.mwigner.covariance.compute_4d_covariance(psi_2d, dx, dy)
Covariance matrix of \(R = (x, p_x, y, p_y)\) for a 2D wavefunction.
The wavefunction is normalised to unit probability on the grid. The grid coordinates are centred: \(x_i = (i - (n_x - 1)/2)\,\Delta x\), likewise for \(y\). The matrix is the symmetrised, centred covariance
\[\Sigma_{ij} = \tfrac12 \langle \{R_i, R_j\} \rangle - \langle R_i \rangle \langle R_j \rangle ,\]with momentum moments from spectral (FFT) derivatives. A pure Gaussian state gives symplectic eigenvalues \(\nu = 1/2\).
- Parameters:
psi_2d (numpy.ndarray) – Complex wavefunction on a uniform \((n_x, n_y)\) grid.
dx (float) – Grid spacings (a.u.).
dy (float) – Grid spacings (a.u.).
- Returns:
Real symmetric \(4\times4\) matrix ordered \((x, p_x, y, p_y)\).
- Return type:
numpy.ndarray
- Raises:
ValueError – If the wavefunction has zero norm.
- zkit.mwigner.covariance.symplectic_eigenvalues(Sigma)
Symplectic eigenvalues \(\nu_k\) of a covariance matrix.
The covariance is ordered \((q_1, p_1, q_2, p_2, \ldots)\), and the symplectic form pairs each coordinate with its conjugate momentum (a \(2\times2\) block \([[0, 1], [-1, 0]]\) per pair). The \(\nu_k\) are the moduli of the eigenvalues \(\pm i\nu_k\) of \(J\Sigma\). A physical state has \(\nu_k \ge 1/2\) (\(\hbar = 1\)); \(\nu_k = 1/2\) for all \(k\) exactly for a pure Gaussian state.
- Parameters:
Sigma (numpy.ndarray) – Real \(2n\times 2n\) covariance matrix.
- Returns:
The \(2n\) values \(\lvert\operatorname{Im}\lambda\rvert\), sorted in descending order (each \(\nu_k\) appears twice).
- Return type:
numpy.ndarray
- zkit.mwigner.covariance.effective_schmidt_rank(eigenvalues)
Effective Schmidt rank \(N_{\mathrm{eff}} = 1 / \sum_i \lambda_i^2\).
\(\lambda_i\) are the Schmidt eigenvalues of the reduced density matrix (
schmidt_spectrum()); values below \(10^{-12}\) are ignored. \(N_{\mathrm{eff}}\) and the von Neumann entropy are functions of the same spectrum and carry the same information.- Parameters:
eigenvalues (array_like) – Schmidt eigenvalues.
- Returns:
\(N_{\mathrm{eff}}\), or 0 when no eigenvalue exceeds \(10^{-12}\).
- Return type:
float
- zkit.mwigner.covariance.schmidt_spectrum(rho_or_eigs, dx=None)
Schmidt eigenvalues of the reduced density matrix \(\rho(x, x')\).
- Parameters:
rho_or_eigs (numpy.ndarray) – Either the reduced density matrix on the \(x\) grid (2D array) or precomputed eigenvalues (1D array).
dx (float, optional) – Grid spacing; required when a density matrix is passed (it is normalised to unit trace with the quadrature weight
dx).
- Returns:
Eigenvalues above \(10^{-12}\), in descending order (empty for a non-positive trace).
- Return type:
numpy.ndarray
- Raises:
ValueError – If a density matrix is passed without
dx.
- zkit.mwigner.covariance.gaussian_purity(symplectic_eigs)
Purity of the Gaussian state with a given covariance matrix.
For an \(n\)-mode Gaussian state
\[\mu_G = \prod_{k=1}^{n} \frac{1}{2\nu_k} ,\]which is 1 for a pure Gaussian state. \(\mu_G\) is the purity of the Gaussian state with the same covariance, not of the actual state: a true purity \(\operatorname{Tr}\rho^2 < \mu_G\) indicates non-Gaussian structure. For strongly delocalised states \(\nu_k \gg 1\) and \(\mu_G\) underflows towards 0, where the comparison is not meaningful.
- Parameters:
symplectic_eigs (array_like) – Symplectic eigenvalues \(\nu_k\) (each counted once per entry given).
- Returns:
\(1 / \prod (2\nu_k)\) over the entries given.
- Return type:
float
- zkit.mwigner.covariance.principal_components(Sigma)
Ordinary eigendecomposition of a covariance matrix.
The eigenvalues are the variances along the uncorrelated directions of the phase-space distribution, and the eigenvectors the corresponding linear combinations of \((x, p_x, y, p_y)\). These are not symplectic eigenvalues and do not define a two-level system.
- Parameters:
Sigma (numpy.ndarray) – Real symmetric covariance matrix.
- Returns:
(eigvals, eigvecs)with eigenvalues in descending order and the eigenvectors as columns.- Return type:
tuple of numpy.ndarray
- zkit.mwigner.covariance.covariance_diagnostics(psi_2d, dx, dy, rho=None)
Covariance diagnostics of one 2D wavefunction snapshot.
- Parameters:
psi_2d (numpy.ndarray) – Complex wavefunction on a uniform grid.
dx (float) – Grid spacings (a.u.).
dy (float) – Grid spacings (a.u.).
rho (numpy.ndarray, optional) – Reduced density matrix \(\rho(x, x')\); computed from
psi_2das \(\sum_y \psi(x, y)\,\psi^*(x', y)\,\Delta x\) when not given.
- Returns:
Sigma: \(4\times4\) covariance matrix (compute_4d_covariance());diag: variancesSxx,Spxpx,Syy,Spypy;offdiag: covariancesSxpx,Sypy,Sxy,Spxpy,xpy,ypx;nu: symplectic eigenvalues;mu_G: Gaussian purity;mu_true: \(\sum_i \lambda_i^2\) of the Schmidt spectrum;non_gaussian:mu_true < mu_G, orNonewhen \(\mu_G \le 10^{-6}\);pc_evalsandpc_evecs: principal components ofSigma.- Return type:
dict