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. 
Continuousvariable 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
orRZ
gates, as defined by therotation
parameter:rotation='X'
uses the features as angles of RX rotationsrotation='Y'
uses the features as angles of RY rotationsrotation='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 infeatures
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 theBasisEmbedding()
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, noninformative constants (zeros) can be padded to
features
. To enable this, the argumentpad
should be set toTrue
.The L2norm of
features
must be one. By default, AmplitudeEmbedding expects a normalized feature vector. The argumentnormalize
can be set toTrue
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
 features (array) – input array of shape

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
 features (array) – Binary input array of shape

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 mostlen(wires)
floats. If there are fewer entries infeatures
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 singlemode 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 ifexecution='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 mostlen(wires)
floats. If there are fewer entries infeatures
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 singlemode 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 ifexecution='phase'