Decompositions

Module name: thewalrus.decompositions

This module implements common shared matrix decompositions that are used to perform gate decompositions.

Summary

williamson(V[, rtol, atol])

Williamson decomposition of positive-definite (real) symmetric matrix.

symplectic_eigenvals(cov)

Returns the symplectic eigenvalues of a covariance matrix.

blochmessiah(S)

Returns the Bloch-Messiah decomposition of a symplectic matrix S = uff @ dff @ vff

Code details

blochmessiah(S)[source]
Returns the Bloch-Messiah decomposition of a symplectic matrix S = uff @ dff @ vff

where uff and vff are orthogonal symplectic matrices and dff is a diagonal matrix of the form diag(d1,d2,…,dn,d1^-1, d2^-1,…,dn^-1),

Parameters:

S (array[float]) – 2N x 2N real symplectic matrix

Returns:

orthogonal symplectic matrix uff

array[float], : diagonal matrix dff array[float]) : orthogonal symplectic matrix vff

Return type:

tuple(array[float],

symplectic_eigenvals(cov)[source]

Returns the symplectic eigenvalues of a covariance matrix.

Parameters:

cov (array) – a covariance matrix

Returns:

symplectic eigenvalues

Return type:

(array)

takagi(A, svd_order=True)[source]

Autonne-Takagi decomposition of a complex symmetric (not Hermitian!) matrix. Note that the input matrix is internally symmetrized by taking its upper triangular part. If the input matrix is indeed symmetric this leaves it unchanged. See Carl Caves note.

Parameters:
  • A (array) – square, symmetric matrix

  • svd_order (boolean) – whether to return result by ordering the singular values of A in descending (True) or ascending (False) order.

Returns:

(r, U), where r are the singular values, and U is the Autonne-Takagi unitary, such that \(A = U \diag(r) U^T\).

Return type:

tuple[array, array]

williamson(V, rtol=1e-05, atol=1e-08)[source]

Williamson decomposition of positive-definite (real) symmetric matrix.

See this thread and the Williamson decomposition documentation

Parameters:
  • V (array[float]) – positive definite symmetric (real) matrix

  • rtol (float) – the relative tolerance parameter used in np.allclose

  • atol (float) – the absolute tolerance parameter used in np.allclose

Returns:

(Db, S) where Db is a diagonal matrix

and S is a symplectic matrix such that \(V = S^T Db S\)

Return type:

tuple[array,array]