Encodings

Amplitude Encoding

class AmplitudeEncoding(n_features=2)[source]

Bases: qlearnkit.encodings.encoding_map.EncodingMap

Amplitude Encoding map

Creates a generic Encoding Map for classical data of size n_features

Parameters

n_features – number of features (default: 2)

construct_circuit(x)[source]

Constructs circuit for amplitude encoding

Parameters

x – 1D classical data vector to be encoded must satisfy len(x) == num_features

Return type

QuantumCircuit

state_vector(x)[source]

The encoding of a state via amplitude encoding operates as follows: given a quantum state \(\psi\), it processes the data such that

Parameters

x – the classical data

Returns

(np.array) encoded quantum state

Angle Encoding

class AngleEncoding(n_features=2, rotation='Y', scaling=1.5707963267948966)[source]

Bases: qlearnkit.encodings.encoding_map.EncodingMap

Angle Encoding algorithm. Assumes data is feature-normalized.

Parameters
  • rotation – the direction admitted values: X, Y, Z

  • scaling – scaling factor for normalized input data. The default scaling \(\pi/2\) does not induce a relative phase difference.

construct_circuit(x)[source]
Parameters

x (np.array) – The input data to encode

Return type

QuantumCircuit

Returns

The circuit that encodes x. Assumes data is feature-normalized. Assumes every element in x is in [0, 1]

state_vector(x)[source]

The encoding of a state via angle encoding, operating a rotation around the rotation axis.

Parameters

x (np.array) – The input data to encode

Returns

The state vector representation of x after angle encoding

Return type

np.array

Basis Encoding

class BasisEncoding(n_features=2)[source]

Bases: qlearnkit.encodings.encoding_map.EncodingMap

Initializes Basis Encoding Map

construct_circuit(x)[source]

Retrieves the quantum circuit encoding via Basis Encoding

Parameters

x – the data vector to encode

Return type

QuantumCircuit

Returns

the quantum encoding circuit

Note

All data values must be either 1s or 0s

Encoding Map

class EncodingMap(n_features=2)[source]

Bases: abc.ABC

Abstract Base class for qlearnkit encoding maps

Creates a generic Encoding Map for classical data of size n_features

Parameters

n_features – number of features (default: 2)

abstract construct_circuit(x)[source]

construct and return quantum circuit encoding data

Return type

QuantumCircuit

property num_qubits

getter for number of qubits

property num_features

getter for number of features