Circuit Components Utils

BtoChar

The s-parametrized Dgate as a Map.

BtoQ

The Operation that changes the representation of an object from Bargmann (B) into quadrature (Q).

BtoPS

The s-parametrized Stratonovich-Weyl kernel as a Map.

TraceOut

A circuit component to perform trace-out operations.

Inheritance diagram of BtoChar, BtoQ, BtoPS, TraceOut

BtoChar

class mrmustard.lab.circuit_components_utils.BtoChar(modes, s)[source]

Bases: Map

The s-parametrized Dgate as a Map. Also known as the Fourier transform of the Stratonovich-Weyl kernel. See https://arxiv.org/abs/quant-ph/9707010.

This is an unphysical component whose purpose is to modify the internal representation of another component. In particular it transforms between the Bargmann representation and the s-parametrized Characteristic functions. Note that it can be applied to a subset of modes.

>>> from mrmustard.lab import BtoChar, GaussianKet
>>> from mrmustard import math
>>> chi = (GaussianKet.random([0]) >> BtoChar([0], s=0)).ansatz
>>> assert math.allclose(chi(0,0), 1.0)
Parameters:
  • modes (int | tuple[int, ...]) – The modes of this channel.

  • s (float) – The s parameter of this channel.

This class represents the transformation from the Bargmann (B) representation to characteristic function (Char).

Any operator, say O can be expressed in the displacement basis. Formally, we have that the s-parametrized phase space basis is characterized by the following operators

\[D_s(\alpha) = exp(s|\alpha|^2/2) D(\alpha).\]

The s-parametrized phase space representation of an object O, would therefore be

\[\mathrm{Tr}(D_s(\alpha) O).\]

Important s-parametrizations include:

  • s=1: returns the complex Fourier transform (or often called the symplectic Fourier transform) of Galuber-Sudarshan P function.

  • s=0: returns the characteristic function, which is equivalent to the complex Fourier transform of the Wigner function.

  • s=-1: returns the complex Fourier transform of the Q function.

inverse()[source]

Returns the mathematical inverse of the transformation, if it exists. Note that it can be unphysical, for example when the original is not unitary.

>>> from mrmustard.lab import GaussianDM, Identity, Operation
>>> rho = GaussianDM.random(modes=0, seed=1)
>>> rho_as_operator = Operation.from_bargmann([0], [0], rho.ansatz.triple)
>>> assert rho_as_operator >> rho_as_operator.inverse() == Identity([0])
Returns:

The inverse of the transformation.

Raises:
  • NotImplementedError – If the input and output wires have different lengths.

  • NotImplementedError – If the transformation is not in the Bargmann representation.

fock_array(shape=None)[source]

Returns an array representation of this component in the Fock basis with the given shape. If the shape is not given, it defaults to the auto_shape of the component.

Parameters:

shape (int | Sequence[int] | None) – The shape of the returned representation. If shape is given as an int, it is broadcasted to all the dimensions. If not given, it is generated via auto_shape.

Returns:

The Fock representation of this component.

Return type:

array

Raises:

ValueError – If the shape is not valid for the component.

BtoQ

class mrmustard.lab.circuit_components_utils.BtoQ(modes, phi=0.0)[source]

Bases: Operation

The Operation that changes the representation of an object from Bargmann (B) into quadrature (Q). By default it’s defined on the output ket side.

>>> from mrmustard import math
>>> from mrmustard.lab import BtoQ, GaussianKet, QuadratureEigenstate
>>> psi = GaussianKet.random([0])
>>> assert math.allclose(psi >> QuadratureEigenstate(0, x=1).dual, (psi >> BtoQ(0)).ansatz(1))
Parameters:
  • modes (int | tuple[int, ...]) – The modes of this channel.

  • phi (float | Sequence[float]) – The quadrature angle. 0 corresponds to the x quadrature, and \(\pi/2\) to the p quadrature.

inverse()[source]

Returns the mathematical inverse of the transformation, if it exists. Note that it can be unphysical, for example when the original is not unitary.

>>> from mrmustard.lab import GaussianDM, Identity, Operation
>>> rho = GaussianDM.random(modes=0, seed=1)
>>> rho_as_operator = Operation.from_bargmann([0], [0], rho.ansatz.triple)
>>> assert rho_as_operator >> rho_as_operator.inverse() == Identity([0])
Returns:

The inverse of the transformation.

Raises:
  • NotImplementedError – If the input and output wires have different lengths.

  • NotImplementedError – If the transformation is not in the Bargmann representation.

fock_array(shape=None)[source]

Returns an array representation of this component in the Fock basis with the given shape. If the shape is not given, it defaults to the auto_shape of the component.

Parameters:

shape (int | Sequence[int] | None) – The shape of the returned representation. If shape is given as an int, it is broadcasted to all the dimensions. If not given, it is generated via auto_shape.

Returns:

The Fock representation of this component.

Return type:

array

Raises:

ValueError – If the shape is not valid for the component.

BtoPS

class mrmustard.lab.circuit_components_utils.BtoPS(modes, s)[source]

Bases: Map

The s-parametrized Stratonovich-Weyl kernel as a Map.

Used internally as a Channel for transformations between representations.

Parameters:
  • modes (int | tuple[int, ...]) – The modes of this channel.

  • s (float) – The s parameter of this channel. The case s=-1 corresponds to Husimi, s=0 to Wigner, and s=1 to Glauber P function.

fock_array(shape=None)[source]

Returns an array representation of this component in the Fock basis with the given shape. If the shape is not given, it defaults to the auto_shape of the component.

Parameters:

shape (int | Sequence[int] | None) – The shape of the returned representation. If shape is given as an int, it is broadcasted to all the dimensions. If not given, it is generated via auto_shape.

Returns:

The Fock representation of this component.

Return type:

array

Raises:

ValueError – If the shape is not valid for the component.

TraceOut

class mrmustard.lab.circuit_components_utils.TraceOut(modes)[source]

Bases: CircuitComponent

A circuit component to perform trace-out operations.

It has input wires on both the ket and bra sides, but no output wires. Its representation is the same as that of the identity channel.

>>> from mrmustard.lab import *
>>> from mrmustard import math
>>> # initialize a multi-mode state
>>> state = Coherent(0, alpha=1) >> Coherent(1, alpha=1) >> Coherent(2, alpha=1)
>>> # trace out some of the modes
>>> assert state >> TraceOut(0) == (Coherent(1, alpha=1) >> Coherent(2, alpha=1)).dm()
>>> assert state >> TraceOut((1, 2)) == Coherent(0, alpha=1).dm()
>>> # use the trace out to estimate expectation values of operators
>>> op = Dgate(0, alpha=1)
>>> expectation = state.dm().contract(op) >> TraceOut((0, 1, 2))
>>> assert math.allclose(expectation, state.expectation(op))
Parameters:

modes (int | tuple[int, ...]) – The modes to trace out.