Random matrices¶
Module name: thewalrus.random
This submodule provides access to utility functions to generate random unitary, symplectic and covariance matrices.
Summary¶
|
Random covariance matrix. |
|
Random symplectic matrix representing a Gaussian transformation. |
|
Random unitary matrix representing an interferometer. |
|
Generates a random interferometer with blocks of at most size 2. |
|
Generates a banded unitary matrix. |
Code details¶
- random_banded_interferometer(N, w, top_one_init=True, real=False)[source]¶
Generates a banded unitary matrix.
- Parameters:
N (int) – number of modes
w (int) – bandwidth
top_one_init (bool) – if True places a 1times1 interferometer in the top-left-most block of the first matrix in the product
real (bool) – return a random real orthogonal matrix
- Returns:
random \(N\times N\) unitary with the specified block structure
- Return type:
array
- random_block_interferometer(N, top_one=True, real=False)[source]¶
Generates a random interferometer with blocks of at most size 2.
- Parameters:
N (int) – number of modes
top_one (bool) – if True places a 1times1 interferometer in the top-left most block
real (bool) – return a random real orthogonal matrix
- Returns:
random \(N\times N\) unitary with the specified block structure
- Return type:
array
- random_covariance(N, hbar=2, pure=False, block_diag=False)[source]¶
Random covariance matrix.
- Parameters:
N (int) – number of modes
hbar (float) – the value of \(\hbar\) to use in the definition of the quadrature operators \(x\) and \(p\)
pure (bool) – If True, a random covariance matrix corresponding to a pure state is returned.
block_diag (bool) – If True, uses passive Gaussian transformations that are orthogonal instead of unitary. This implies that the positions \(x\) do not mix with the momenta \(p\) and thus the covariance matrix is block diagonal.
- Returns:
random \(2N\times 2N\) covariance matrix
- Return type:
array
- random_interferometer(N, real=False)[source]¶
Random unitary matrix representing an interferometer. For more details, see [41].
- Parameters:
N (int) – number of modes
real (bool) – return a random real orthogonal matrix
- Returns:
random \(N\times N\) unitary distributed with the Haar measure
- Return type:
array
- random_symplectic(N, passive=False, block_diag=False, scale=1.0)[source]¶
Random symplectic matrix representing a Gaussian transformation.
The squeezing parameters \(r\) for active transformations are randomly sampled from the standard normal distribution, while passive transformations are randomly sampled from the Haar measure. Note that for the Symplectic group there is no notion of Haar measure since this is group is not compact.
- Parameters:
N (int) – number of modes
passive (bool) – If True, returns a passive Gaussian transformation (i.e., one that preserves photon number). If False, returns an active transformation.
block_diag (bool) – If True, uses passive Gaussian transformations that are orthogonal instead of unitary. This implies that the positions \(q\) do not mix with the momenta \(p\) and thus the symplectic operator is block diagonal
scale (float) – Sets the scale of the random values used as squeezing parameters. They will range from 0 to \(\sqrt{2}\texttt{scale}\)
- Returns:
random \(2N\times 2N\) symplectic matrix
- Return type:
array