Fock representations

Module name: thewalrus.fock_gradients

This module contains the Fock representation of the standard Gaussian gates as well as their gradients.

Summary

displacement(r, phi, cutoff[, dtype])

Calculates the matrix elements of the displacement gate using a recurrence relation.

squeezing(r, theta, cutoff[, dtype])

Calculates the matrix elements of the squeezing gate using a recurrence relation.

beamsplitter(theta, phi, cutoff[, dtype])

Calculates the Fock representation of the beamsplitter.

two_mode_squeezing(r, theta, cutoff[, dtype])

Calculates the matrix elements of the two-mode squeezing gate recursively.

mzgate(theta, phi, cutoff[, dtype])

Calculates the Fock representation of the Mach-Zehnder interferometer.

grad_displacement(T, r, phi)

Calculates the gradients of the displacement gate with respect to the displacement magnitude and angle.

grad_squeezing(T, r, phi)

Calculates the gradients of the squeezing gate with respect to the squeezing magnitude and angle

grad_beamsplitter(T, theta, phi)

Calculates the gradients of the beamsplitter gate with respect to the transmissivity angle and reflection phase

grad_two_mode_squeezing(T, r, theta)

Calculates the gradients of the two-mode squeezing gate with respect to the squeezing magnitude and angle

grad_mzgate(T, theta, phi)

Calculates the gradients of the Mach-Zehnder interferometer with respect to the transmissivity angle and reflection phase

Code details

beamsplitter(theta, phi, cutoff, dtype=<class 'numpy.complex128'>)[source]

Calculates the Fock representation of the beamsplitter.

Parameters:
  • theta (float) – transmissivity angle of the beamsplitter. The transmissivity is \(t=\cos(\theta)\)

  • phi (float) – reflection phase of the beamsplitter

  • cutoff (int) – Fock ladder cutoff

  • dtype (data type) – Specifies the data type used for the calculation

Returns:

The Fock representation of the gate

Return type:

array[float]

displacement(r, phi, cutoff, dtype=<class 'numpy.complex128'>)[source]

Calculates the matrix elements of the displacement gate using a recurrence relation.

Parameters:
  • r (float) – displacement magnitude

  • phi (float) – displacement angle

  • cutoff (int) – Fock ladder cutoff

  • dtype (data type) – Specifies the data type used for the calculation

Returns:

matrix representing the displacement operation.

Return type:

array[complex]

grad_beamsplitter(T, theta, phi)[source]

Calculates the gradients of the beamsplitter gate with respect to the transmissivity angle and reflection phase

Parameters:
  • T (array[complex]) – array representing the gate

  • theta (float) – transmissivity angle of the beamsplitter. The transmissivity is \(t=\cos(\theta)\)

  • phi (float) – reflection phase of the beamsplitter

Returns:

The gradient of the beamsplitter gate with respect to theta and phi

Return type:

tuple[array[complex], array[complex]]

grad_displacement(T, r, phi)[source]

Calculates the gradients of the displacement gate with respect to the displacement magnitude and angle.

Parameters:
  • T (array[complex]) – array representing the gate

  • r (float) – displacement magnitude

  • phi (float) – displacement angle

Returns:

The gradient of the displacement gate with respect to r and phi

Return type:

tuple[array[complex], array[complex]]

grad_mzgate(T, theta, phi)[source]

Calculates the gradients of the Mach-Zehnder interferometer with respect to the transmissivity angle and reflection phase

Parameters:
  • T (array[complex]) – array representing the gate

  • theta (float) – internal of the mzgate

  • phi (float) – external phase of the mzgate

Returns:

The gradient of the mzgate gate with respect to theta and phi

Return type:

tuple[array[complex], array[complex]]

grad_squeezing(T, r, phi)[source]

Calculates the gradients of the squeezing gate with respect to the squeezing magnitude and angle

Parameters:
  • T (array[complex]) – array representing the gate

  • r (float) – squeezing magnitude

  • phi (float) – squeezing angle

Returns:

The gradient of the squeezing gate with respect to the r and phi

Return type:

tuple[array[complex], array[complex]]

grad_two_mode_squeezing(T, r, theta)[source]

Calculates the gradients of the two-mode squeezing gate with respect to the squeezing magnitude and angle

Parameters:
  • T (array[complex]) – array representing the gate

  • r (float) – squeezing magnitude

  • theta (float) – squeezing angle

Returns:

The gradient of the two-mode squeezing gate with respect to r and phi

Return type:

tuple[array[complex], array[complex]]

mzgate(theta, phi, cutoff, dtype=<class 'numpy.complex128'>)[source]

Calculates the Fock representation of the Mach-Zehnder interferometer.

Parameters:
  • theta (float) – internal phase of the Mach-Zehnder interferometer

  • phi (float) – external phase of the Mach-Zehnder interferometer

  • cutoff (int) – Fock ladder cutoff

  • dtype (data type) – Specifies the data type used for the calculation

Returns:

The Fock representation of the gate

Return type:

array[float]

squeezing(r, theta, cutoff, dtype=<class 'numpy.complex128'>)[source]

Calculates the matrix elements of the squeezing gate using a recurrence relation.

Parameters:
  • r (float) – squeezing magnitude

  • theta (float) – squeezing angle

  • cutoff (int) – Fock ladder cutoff

  • dtype (data type) – Specifies the data type used for the calculation

Returns:

matrix representing the squeezing gate.

Return type:

array[complex]

two_mode_squeezing(r, theta, cutoff, dtype=<class 'numpy.complex128'>)[source]

Calculates the matrix elements of the two-mode squeezing gate recursively.

Parameters:
  • r (float) – squeezing magnitude

  • theta (float) – squeezing angle

  • cutoff (int) – Fock ladder cutoff

  • dtype (data type) – Specifies the data type used for the calculation

Returns:

The Fock representation of the gate

Return type:

array[float]