# Symplectic operations¶

Module name: thewalrus.symplectic

Contains some Gaussian operations and auxiliary functions.

## Auxiliary functions¶

 expand(S, modes, N) Expands a Symplectic matrix S to act on the entire subsystem. expand_vector(alpha, mode, N[, hbar]) Returns the phase-space displacement vector associated to a displacement. expand_passive(T, modes, N) Returns the expanded linear optical transformation acting on specified modes, with identity acting on all other modes reduced_state(mu, cov, modes) Returns the vector of means and the covariance matrix of the specified modes. is_symplectic(S[, rtol, atol]) Checks if matrix S is a symplectic matrix sympmat(N[, dtype]) Returns the matrix $$\Omega_n = \begin{bmatrix}0 & I_n\\ -I_n & 0\end{bmatrix}$$ Permutes the entries of the input from xxpp ordering to xpxp ordering. Permutes the entries of the input from xpxp ordering to xxpp ordering.

## Gaussian states¶

 vacuum_state(modes[, hbar, dtype]) Returns the vacuum state.

## Gates and operations¶

 two_mode_squeezing(r, phi[, dtype]) Two-mode squeezing. squeezing(r[, phi, dtype]) Squeezing. Interferometer. loss(mu, cov, T, mode[, nbar, hbar]) Loss channel acting on a Gaussian state. mean_photon_number(mu, cov[, hbar]) Calculates the mean photon number for a given one-mode state. beam_splitter(theta, phi[, dtype]) Beam-splitter. rotation(theta[, dtype]) Rotation gate.

## Code details¶

autonne(A, rtol=1e-05, atol=1e-08, svd_order=True)[source]

Autonne-Takagi decomposition of a complex symmetric (not Hermitian!) matrix.

Parameters
• A (array) – square, symmetric matrix

• rtol (float) – the relative tolerance parameter between A and A.T

• atol (float) – the absolute tolerance parameter between A and A.T

• svd_order (boolean) – whether to return result by ordering the singular values of A in descending (True) or asceding (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]

beam_splitter(theta, phi, dtype=<class 'numpy.float64'>)[source]

Beam-splitter.

Parameters
• theta (float) – transmissivity parameter

• phi (float) – phase parameter

• dtype (numpy.dtype) – datatype to represent the Symplectic matrix

Returns

symplectic-orthogonal transformation matrix of an interferometer with angles theta and phi

Return type

array

expand(S, modes, N)[source]

Expands a Symplectic matrix S to act on the entire subsystem.

Parameters
• S (array) – a $$2M\times 2M$$ Symplectic matrix

• modes (Sequence[int]) – the list of modes S acts on

• N (int) – full size of the subsystem

Returns

the resulting $$2N\times 2N$$ Symplectic matrix

Return type

array

expand_passive(T, modes, N)[source]

Returns the expanded linear optical transformation acting on specified modes, with identity acting on all other modes

Parameters
• T (array) – square $$M \times M$$ matrix of linear optical transformation

• modes (array) – the $$M$$ modes of the transformation

• N (int) – number of modes in the new expanded transformation

Returns

$$N \times N$$ array of expanded passive transformation

Return type

array

expand_vector(alpha, mode, N, hbar=2.0)[source]

Returns the phase-space displacement vector associated to a displacement.

Parameters
• alpha (complex) – complex displacement

• mode (int) – mode index

• N (int) – number of modes

Returns

phase-space displacement vector of size 2*N

Return type

array

interferometer(U)[source]

Interferometer.

Parameters

U (array) – unitary matrix

Returns

symplectic transformation matrix

Return type

array

is_symplectic(S, rtol=1e-05, atol=1e-08)[source]

Checks if matrix S is a symplectic matrix

Parameters

S (array) – a square matrix

Returns

whether the given matrix is symplectic

Return type

(bool)

loss(mu, cov, T, mode, nbar=0, hbar=2)[source]

Loss channel acting on a Gaussian state.

Parameters
• mu (array) – means vector

• cov (array) – covariance matri

• T (float) – transmission; 1 corresponds to no loss, 0 to full loss.

• mode (int) – mode to act on

• nbar (float) – thermal mean population (default 0)

• hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$

Returns

the means vector and covariance matrix of the resulting state

Return type

tuple[array]

mean_photon_number(mu, cov, hbar=2)[source]

Calculates the mean photon number for a given one-mode state.

Parameters
• mu (array) – length-2 vector of means

• cov (array) – $$2\times 2$$ covariance matrix

• hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$

Returns

the photon number expectation and variance

Return type

tuple

passive_transformation(mu, cov, T, hbar=2)[source]

Perform a covariance matrix transformation for an arbitrary linear optical channel on an $$N$$ modes state mapping it to a to an $$M$$ modes state.

Parameters
• mu (array) – $$2N$$-length means vector

• cov (array) – $$2N \times 2N$$ covariance matrix

• T (array) – $$M \times N$$ linear optical transformation

Keyword Arguments

hbar (float) – the value to use for hbar

Returns

$$2M$$-length transformed means vector array $$2M \times 2M$$ tranformed covariance matrix

Return type

array

reduced_state(mu, cov, modes)[source]

Returns the vector of means and the covariance matrix of the specified modes.

Parameters

modes (int of Sequence[int]) – indices of the requested modes

Returns

means is an array containing the vector of means, and cov is a square array containing the covariance matrix. Both use the $$xp$$-ordering.

Return type

tuple (means, cov)

rotation(theta, dtype=<class 'numpy.float64'>)[source]

Rotation gate.

Parameters
• theta (float) – rotation angle

• dtype (numpy.dtype) – datatype to represent the Symplectic matrix

Returns

rotation matrix by angle theta

Return type

array

squeezing(r, phi=None, dtype=<class 'numpy.float64'>)[source]

Squeezing. In fock space this corresponds to:

$\exp(\tfrac{1}{2}r e^{i \phi} (a^2 - a^{\dagger 2}) ).$

By passing an array of squeezing parameters and phases, it applies a tensor product of squeezing operations.

Parameters
• r (Union[array, float]) – squeezing magnitude

• phi (Union[array, float]) – rotation parameter. If None, then the function uses zeros of the same shape as r.

• dtype (numpy.dtype) – datatype to represent the Symplectic matrix. Defaults to numpy.float64.

Returns

symplectic transformation matrix

Return type

array

sympmat(N, dtype=<class 'numpy.float64'>)[source]

Returns the matrix $$\Omega_n = \begin{bmatrix}0 & I_n\\ -I_n & 0\end{bmatrix}$$

Parameters
• N (int) – positive integer

• dtype (numpy.dtype) – datatype to represent the Symplectic matrix

Returns

$$2N\times 2N$$ array

Return type

array

two_mode_squeezing(r, phi, dtype=<class 'numpy.float64'>)[source]

Two-mode squeezing.

Parameters
• r (float) – squeezing magnitude

• phi (float) – rotation parameter

• dtype (numpy.dtype) – datatype to represent the Symplectic matrix

Returns

symplectic transformation matrix

Return type

array

vacuum_state(modes, hbar=2.0, dtype=<class 'numpy.float64'>)[source]

Returns the vacuum state.

Parameters
• modes (str) – Returns the vector of means and the covariance matrix

• hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$

• dtype (numpy.dtype) – datatype to represent the covariance matrix and vector of means

Returns

the means vector and covariance matrix of the vacuum state

Return type

list[array]

xpxp_to_xxpp(S)[source]

Permutes the entries of the input from xpxp ordering to xxpp ordering.

Parameters

S (array) – input even dimensional square matrix or vector

Returns

permuted matrix or vector

Return type

(array)

xxpp_to_xpxp(S)[source]

Permutes the entries of the input from xxpp ordering to xpxp ordering.

Parameters

S (array) – input even dimensional square matrix or array

Returns

permuted matrix or array

Return type

(array)