quairkit.ansatz.encoding

The source file of encoding layers for classical data, including - Basic encoding - Amplitude encoding - Angle encoding - IQP encoding

class quairkit.ansatz.encoding.BasisEncoding(data, qubits_idx)

Basis encoding for classical data.

Encodes an integer into a computational basis state:

\[U_{\text{basic}}|0\rangle^{\otimes n} = |x\rangle\]

where \(x\) is the integer to be encoded.

Parameters:
qubits_idx : List[int]

Indices of the qubits on which the encoding is applied.

data : int | List[int] | Tensor

Integer to be encoded (must be in [0, 2**n_qubits - 1]). If batched, must be List[int], torch.Tensor.

class quairkit.ansatz.encoding.AmplitudeEncoding(vector, qubits_idx)

Amplitude encoding for classical data.

Encodes a vector into quantum state amplitudes:

\[U_{\text{amp}}|0\rangle^{\otimes n} = \sum_{i=0}^{d-1} x_i |i\rangle\]

where \(\mathbf{x}\) is the normalized input vector.

Parameters:
vector : Tensor

Input vector to be encoded. If batched, size must be 2^n_qubits * batch_size

qubits_idx : List[int]

Indices of the qubits on which the encoding is applied.

class quairkit.ansatz.encoding.AngleEncoding(angles, qubits_idx, rotation='RY')

Angle encoding for classical data.

Encodes classical data into rotation angles:

\[|x\rangle = U_{\text{angle}} |0\rangle^{\otimes n} = \bigotimes_{i=1}^{n} R_{\alpha}(\theta_i)|0\rangle^{\otimes n}\]

where \(\alpha \in \{X, Y, Z\}\) and \(\theta_i\) are input angles.

Parameters:
angles : Tensor

Input vector of angles. If batched, size must be num_qubits * batch_size

qubits_idx : List[int]

Indices of the qubits on which the encoding is applied.

rotation : str

Type of rotation gate (‘RY’, ‘RZ’, or ‘RX’).

class quairkit.ansatz.encoding.IQPEncoding(features, set_entanglement, qubits_idx, depth)

Instantaneous Quantum Polynomial (IQP) encoding.

Implements the encoding:

\[U_{\text{IQP}} = \left( \prod_{(i,j)\in S} R_{z_i z_j}(x_ix_j) \bigotimes_{k=1}^{n} R_z(x_k) H^{\otimes n}\right)^r\]

where \(x\) is the integer to be encoded, \(S\) is the set containing all pairs of qubits to be entangled using \(R_{zz}\) gates, and \(r\) is the depth of the circuit.

Parameters:
features : Tensor

Input vector for encoding. If batched, size must be num_qubits * batch_size

set_entanglement : List[List[int]]

the set containing all pairs of qubits to be entangled using RZZ gates

qubits_idx : List[int]

Indices of the qubits on which the encoding is applied.

depth : int

Number of depth