Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns::analysis::anonymous_namespace{q2ns-analysis.cc} Namespace Reference

Functions

qpp::cmat ToDensityMatrix (const QState &s)
 Convert a supported QState backend to a density matrix.
 
double ClampToInterval (double x, double lo, double hi, double tol=1e-10)
 Clamp a scalar metric to a closed interval within numerical tolerance.
 
Eigen::MatrixXcd HermitianSqrtPSD (const Eigen::MatrixXcd &A, double negEigTol=1e-12)
 Compute the Hermitian square root of a positive semidefinite matrix.
 
double UhlmannFidelity (const Eigen::MatrixXcd &rho, const Eigen::MatrixXcd &sigma, double negEigTol=1e-12)
 Compute Uhlmann fidelity between two density matrices.
 
double HermitianTraceNorm (const Eigen::MatrixXcd &A)
 Compute the trace norm of a Hermitian matrix.
 

Function Documentation

◆ ClampToInterval()

double q2ns::analysis::anonymous_namespace{q2ns-analysis.cc}::ClampToInterval ( double  x,
double  lo,
double  hi,
double  tol = 1e-10 
)

Clamp a scalar metric to a closed interval within numerical tolerance.

Values slightly outside the target interval due to floating-point roundoff are clamped back to the nearest endpoint. Values outside the tolerance window are returned unchanged.

Parameters
xInput value.
loLower bound.
hiUpper bound.
tolNumerical tolerance for endpoint clamping.
Returns
Clamped value when within tolerance of the interval, otherwise x.

Definition at line 82 of file q2ns-analysis.cc.

References ClampToInterval().

Referenced by ClampToInterval().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HermitianSqrtPSD()

Eigen::MatrixXcd q2ns::analysis::anonymous_namespace{q2ns-analysis.cc}::HermitianSqrtPSD ( const Eigen::MatrixXcd &  A,
double  negEigTol = 1e-12 
)

Compute the Hermitian square root of a positive semidefinite matrix.

Small negative eigenvalues caused by numerical roundoff are clamped to zero.

Parameters
AInput matrix.
negEigTolTolerance for small negative eigenvalues.
Returns
Hermitian square root of A.

Definition at line 103 of file q2ns-analysis.cc.

References q2ns::H, and HermitianSqrtPSD().

Referenced by HermitianSqrtPSD(), and UhlmannFidelity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HermitianTraceNorm()

double q2ns::analysis::anonymous_namespace{q2ns-analysis.cc}::HermitianTraceNorm ( const Eigen::MatrixXcd &  A)

Compute the trace norm of a Hermitian matrix.

For a Hermitian matrix H, the trace norm is the sum of the absolute values of its eigenvalues.

The input is symmetrized first to suppress tiny anti-Hermitian numerical noise before diagonalization.

Parameters
AInput matrix.
Returns
Trace norm of A.
Exceptions
std::runtime_errorif the matrix is not square or if eigenvalue decomposition fails.

Definition at line 188 of file q2ns-analysis.cc.

References q2ns::H, and HermitianTraceNorm().

Referenced by HermitianTraceNorm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToDensityMatrix()

qpp::cmat q2ns::analysis::anonymous_namespace{q2ns-analysis.cc}::ToDensityMatrix ( const QState s)

Convert a supported QState backend to a density matrix.

This helper provides a common density-matrix representation for analysis routines that are naturally expressed in terms of rho, such as purity, entropy, and trace distance.

For ket and stabilizer backends, this may require constructing a dense matrix representation and can therefore be substantially more expensive than backend-native calculations.

Parameters
sInput state.
Returns
Dense density-matrix representation of s.
Exceptions
std::runtime_errorif the backend is unsupported or if conversion of a stabilizer state requires unavailable backend-specific functionality.

Definition at line 47 of file q2ns-analysis.cc.

References ToDensityMatrix().

Referenced by ToDensityMatrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UhlmannFidelity()

double q2ns::analysis::anonymous_namespace{q2ns-analysis.cc}::UhlmannFidelity ( const Eigen::MatrixXcd &  rho,
const Eigen::MatrixXcd &  sigma,
double  negEigTol = 1e-12 
)

Compute Uhlmann fidelity between two density matrices.

The returned value is F(rho, sigma) = (Tr sqrt(sqrt(rho) sigma sqrt(rho)))^2.

Parameters
rhoFirst density matrix.
sigmaSecond density matrix.
negEigTolTolerance for small negative eigenvalues in intermediate PSD checks.
Returns
Fidelity in the range [0.0, 1.0], up to numerical tolerance.

Definition at line 145 of file q2ns-analysis.cc.

References HermitianSqrtPSD(), UhlmannFidelity(), and q2ns::X.

Referenced by UhlmannFidelity().

Here is the call graph for this function:
Here is the caller graph for this function: