encoding_protocols

This module contains the Python class Encoding for loading input data (as NumPy arrays) in the amplitudes of a quantum state using different encoding protocols. Given a probability density and a function arrays discretized over n qubits the following encodings can be used by setting the encoding variable properly:

Square encoding (encoding=0).

The procedure loads the scalar product of the density and the function arrays into the probability of a fixed state. Uses n+1 qubits. Only can load positive-defined functions

Square encoding with 2 additional qubits (encoding=1).

The procedure loads the scalar product of the density and the function arrays into the amplitude of a fixed state. Uses n+2 qubits. Can load negative-defined functions

Direct encoding (encoding=2).

The procedure loads the scalar product of the density and the function arrays into the amplitude of a fixed state. Can load negative-defined functions

Authors: Alberto Pedro Manzano Herrero & Gonzalo Ferro

class QQuantLib.DL.encoding_protocols.Encoding(array_function, array_probability=None, encoding=None, **kwargs)

Class for data encoding into the quantum circuit.

Parameters:
  • array_function (numpy array) – numpy array with the desired function for encoding into the Quantum Circuit. The following conditions must be satisfied: len(array_function) = 2^n and max(array_function) <= 1.0.

  • array_probability (numpy array) – numpy array with the desired probability for encoding into the Quantum Circuit. If None is provided uniform distribution will be used. The following conditions must be satisfied: len(array_probability)= 2^n. sum(array_probability)<= 1.0. len(array_function) == len(array_probability)

  • encoding (int) – Selecting the encode protocol: 0 for square encoding, 1 for square encoding with 2 additional qubits and 2 for Direct encoding.

  • kwargs (dictionary) – keyword arguments for setting internal configurations

  • multiplexor (kwargs, boolean) – Use multiplexor algorithm for probability loading

property encoding

creating the encoding property

oracle_encoding_0()

Method for creating the oracle. The probability density will be loaded as a probability density using the DL.load_probability function and the function array will be loaded with DL.load_array function. The SQUARE ROOT of the function array will be loaded!.

Notes

The encoding procedure is summarised as:

\[|\Psi\rangle = \mathbf{U}_f\left(I\otimes \mathbf{U}_p \ \right)|0\rangle\otimes|0\rangle_{n}\]

Where \(\mathbf{U}_f\) will encode \(f(x)\) as a function (using DL.load_array function) and \(\mathbf{U}_p\) will encode probability density \(p(x)\) as a probability density (using DL.load_probability)

After this protocol the quantum state is in the form:

\[|\Psi\rangle = \sum_{i=0}^{2^{n}-1}|i\rangle_{n}\otimes \ \sqrt{p(x_i)f(x_i)}|0\rangle \; + \; ...\]
oracle_encoding_1()

Method for creating the oracle. The probability density and the payoff functions will be loaded with the DL.load_array function. In this method a uniform distribution is used for creating the initial superposition of basis states.

Notes

The encoding procedure is summarised as:

\[|\Psi\rangle = \big(I \otimes I \otimes H^{\otimes n}\big) \ \left(\mathbf{U}_f \otimes I \right) \ \left( I \otimes \mathbf{U}_p \right) \big(I \otimes I \ \otimes H^{\otimes n}\big) \ \big(|0\rangle \otimes |0\rangle \otimes|0\rangle_{n}\big)\]

Where \(\mathbf{U}_f\) encodes function \(f(x)\) and \(\mathbf{U}_p\) encodes probability density \(p(x)\). Both will be encoded as functions using the DL.load_array function.

After this protocol the quantum state is in the form:

\[|\Psi\rangle = \frac{1}{2^n} \sum_{i=0}^{2^{n}-1} \ p(x_i)f(x_i) |0\rangle \otimes |0\rangle \otimes \ |0\rangle_n \; + \; ...\]
oracle_encoding_2()

Method for encoding where the probability density will be encoding as probability density using DL.load_probability (or a uniform distribution) and the function with the DL.load_array.

Notes

The encoding procedure is summarised as:

\[|\Psi \rangle = \left(I\otimes \mathbf{U}_p \dagger \right) \ \mathbf{U}_f \left(I\otimes \mathbf{U}_p \right) |0\rangle \ \otimes|0\rangle_{n}\]

Where \(\mathbf{U}_f\) encodes function \(f(x)\) as a function (DL.load_array will be used) and \(\mathbf{U}_p\) encodes probability density \(p(x)\) as a probability density (DL.load_probability will be used)

After this protocol the quantum state is in the form:

\[|\Psi \rangle = \sum_{i=0}^{2^{n}-1} p(x_i) f(x_i) \ |0\rangle \otimes |0\rangle_{n} \; + \; ...\]
reset()

Method for resetting attributes