Embeddings

Module name: pennylane.templates.embeddings

This module provides quantum circuit architectures that can embed features into a quantum state. The features are associated with gate parameters, implicitly mapping them into the Hilbert space of the quantum state (see also Schuld & Killoran 2019 [R4]).

Qubit architectures

AngleEmbedding(features, wires[, rotation]) Encodes \(N\) features into the rotation angles of \(n\) qubits, where \(N \leq n\).
AmplitudeEmbedding(features, wires[, pad, …]) Encodes \(2^n\) features into the amplitude vector of \(n\) qubits.
BasisEmbedding(features, wires) Encodes \(n\) binary features into a basis state of \(n\) qubits.

Continuous-variable architectures

SqueezingEmbedding(features, wires[, method, c]) Encodes \(N\) features into the squeezing amplitudes \(r \geq 0\) or phases \(\phi \in [0, 2\pi)\) of \(M\) modes, where \(N\leq M\).
DisplacementEmbedding(features, wires[, …]) Encodes \(N\) features into the displacement amplitudes \(r\) or phases \(\phi\) of \(M\) modes,

Code details

AngleEmbedding(features, wires, rotation='X')[source]

Encodes \(N\) features into the rotation angles of \(n\) qubits, where \(N \leq n\).

The rotations can be chosen as either RX, RY or RZ gates, as defined by the rotation parameter:

  • rotation='X' uses the features as angles of RX rotations
  • rotation='Y' uses the features as angles of RY rotations
  • rotation='Z' uses the features as angles of RZ rotations

The length of features has to be smaller or equal to the number of qubits. If there are fewer entries in features than rotations, the circuit does not apply the remaining rotation gates.

This embedding method can also be used to encode a binary sequence into a basis state. For example, to prepare basis state \(|0,1,1,0\rangle\), choose rotation='X' and use the feature vector \([0, \pi/2, \pi/2, 0]\). Alternatively, one can use the BasisEmbedding() template.

Parameters:
  • features (array) – Input array of shape (N,), where N is the number of input features to embed, with \(N\leq n\)
  • wires (Sequence[int]) – sequence of qubit indices that the template acts on
Keyword Arguments:
 

rotation (str) – Type of rotations used

AmplitudeEmbedding(features, wires, pad=False, normalize=False)[source]

Encodes \(2^n\) features into the amplitude vector of \(n\) qubits.

If the total number of features to embed are less than the \(2^n\) available amplitudes, non-informative constants (zeros) can be padded to features. To enable this, the argument pad should be set to True.

The L2-norm of features must be one. By default, AmplitudeEmbedding expects a normalized feature vector. The argument normalize can be set to True to automatically normalize it.

Note

AmplitudeEmbedding uses PennyLane’s QubitStateVector and only works in conjunction with devices that implement this function.

Parameters:
  • features (array) – input array of shape (2**n,)
  • wires (Sequence[int]) – sequence of qubit indices that the template acts on
  • pad (Boolean) – controls the activation of the padding option
  • normalize (Boolean) – controls the activation of automatic normalization
BasisEmbedding(features, wires)[source]

Encodes \(n\) binary features into a basis state of \(n\) qubits.

For example, for features=[0, 1, 0], the quantum system will be prepared in state \(|010 \rangle\).

Note

BasisEmbedding uses PennyLane’s BasisState and only works in conjunction with devices that implement this function.

Parameters:
  • features (array) – Binary input array of shape (n, )
  • wires (Sequence[int]) – sequence of qubit indices that the template acts on
SqueezingEmbedding(features, wires, method='amplitude', c=0.1)[source]

Encodes \(N\) features into the squeezing amplitudes \(r \geq 0\) or phases \(\phi \in [0, 2\pi)\) of \(M\) modes, where \(N\leq M\).

The mathematical definition of the squeezing gate is given by the operator

\[S(z) = \exp\left(\frac{r}{2}\left(e^{-i\phi}\a^2 -e^{i\phi}{\ad}^{2} \right) \right),\]

where \(\a\) and \(\ad\) are the bosonic creation and annihilation operators.

features has to be an array of at most len(wires) floats. If there are fewer entries in features than wires, the circuit does not apply the remaining squeezing gates.

Parameters:
  • features (array) – Array of features of size (N,)
  • wires (Sequence[int]) – sequence of mode indices that the template acts on
Keyword Arguments:
 
  • method (str) – 'phase' encodes the input into the phase of single-mode squeezing, while 'amplitude' uses the amplitude
  • c (float) – value of the phase of all squeezing gates if execution='amplitude', or the amplitude of all squeezing gates if execution='phase'
DisplacementEmbedding(features, wires, method='amplitude', c=0.1)[source]
Encodes \(N\) features into the displacement amplitudes \(r\) or phases \(\phi\) of \(M\) modes,
where \(N\leq M\).

The mathematical definition of the displacement gate is given by the operator

\[D(\alpha) = \exp(r (e^{i\phi}\ad -e^{-i\phi}\a)),\]

where \(\a\) and \(\ad\) are the bosonic creation and annihilation operators.

features has to be an array of at most len(wires) floats. If there are fewer entries in features than wires, the circuit does not apply the remaining displacement gates.

Parameters:
  • features (array) – Array of features of size (N,)
  • wires (Sequence[int]) – sequence of mode indices that the template acts on
Keyword Arguments:
 
  • method (str) – 'phase' encodes the input into the phase of single-mode displacement, while 'amplitude' uses the amplitude
  • c (float) – value of the phase of all displacement gates if execution='amplitude', or the amplitude of all displacement gates if execution='phase'