mm.lab_dev.transformations.Dgate

class mrmustard.lab_dev.transformations.Dgate(modes=None, x=0.0, y=0.0, x_trainable=False, y_trainable=False, x_bounds=(None, None), y_bounds=(None, None))[source]

Bases: Unitary

The displacement gate.

If x and/or y are iterables, their length must be equal to 1 or N. If their length is equal to 1, all the modes share the same parameters.

>>> import numpy as np
>>> from mrmustard.lab_dev import Dgate

>>> unitary = Dgate(modes=[1, 2], x=0.1, y=[0.2, 0.3])
>>> assert unitary.modes == [1, 2]
>>> assert np.allclose(unitary.x.value, [0.1, 0.1])
>>> assert np.allclose(unitary.y.value, [0.2, 0.3])
Parameters:
  • modes (Sequence[int]) – The modes this gate is applied to.

  • x (Union[float, Sequence[float]]) – The displacements along the x axis, which represents position axis in phase space.

  • y (Union[float, Sequence[float]]) – The displacements along the y axis.

  • x_bounds (Tuple[Optional[float], Optional[float]]) – The bounds for the displacement along the x axis.

  • y_bounds (Tuple[Optional[float], Optional[float]]) – The bounds for the displacement along the y axis, which represents momentum axis in phase space.

  • x_trainable (bool) – Whether x is a trainable variable.

  • y_trainable (bool) – Whether y is a trainable variable.

For any \(\bar{\alpha} = \bar{x} + i\bar{y}\) of length \(N\), the \(N\)-mode displacement gate is defined by

\[S = I_N \text{ and } r = \sqrt{2\hbar}\big[\text{Re}(\bar{\alpha}), \text{Im}(\bar{\alpha})\big].\]

Its (A,b,c) triple is given by

\[\begin{split}A &= \begin{bmatrix} O_N & I_N\\ I_N & O_N \end{bmatrix} \\ \\ b &= \begin{bmatrix} \bar{\alpha} & -\bar{\alpha}^* \end{bmatrix} \\ \\ c &= \text{exp}\big(-|\bar{\alpha}^2|/2\big).\end{split}\]

adjoint

The AdjointView of this component.

dual

The DualView of this component.

modes

The sorted list of modes of this component.

n_modes

The number of modes in this component.

name

The name of this component.

parameter_set

The set of parameters characterizing this component.

representation

A representation of this circuit component.

wires

The wires of this component.

adjoint

The AdjointView of this component.

dual

The DualView of this component.

modes

The sorted list of modes of this component.

n_modes

The number of modes in this component.

name

The name of this component.

parameter_set

The set of parameters characterizing this component.

representation
wires

The wires of this component.

light_copy()

Creates a copy of this component by copying every data stored in memory for it by reference, except for its wires, which are copied by value.

on(modes)

Creates a copy of this component that acts on the given modes instead of on the original modes.

to_fock_component([shape])

Returns a circuit component with the same attributes as this component, but with Fock representation.

light_copy()

Creates a copy of this component by copying every data stored in memory for it by reference, except for its wires, which are copied by value.

Return type:

CircuitComponent

on(modes)

Creates a copy of this component that acts on the given modes instead of on the original modes.

Parameters:

modes (Sequence[int]) – The new modes that this component acts on.

Return type:

CircuitComponent

Returns:

The component acting on the specified modes.

Raises:

ValueError – If modes contains more or less modes than the original component.

to_fock_component(shape=None)

Returns a circuit component with the same attributes as this component, but with Fock representation.

Uses the mrmustard.physics.converters.to_fock() method to convert the internal representation.

>>> from mrmustard.physics.converters import to_fock
>>> from mrmustard.lab_dev import Dgate

>>> d = Dgate([1], x=0.1, y=0.1)
>>> d_fock = d.to_fock_component(shape=3)

>>> assert d_fock.name == d.name
>>> assert d_fock.wires == d.wires
>>> assert d_fock.representation == to_fock(d.representation, shape=3)
Parameters:

shape (Union[int, Iterable[int], None]) – The shape of the returned representation. If shape``is given as an ``int, it is broadcasted to all the dimensions. If None, it defaults to the value of AUTOCUTOFF_MAX_CUTOFF in the settings.

Return type:

CircuitComponent