QQuantLib.DL

QQuantLib.DL.data_loading

This module contains all the functions in order to load data into the quantum state. There are two implementations for the loading of a function:

  • one based on brute force

  • one based on multiplexors.

The implementation of the multiplexors is a non-recursive version of:

V.V. Shende, S.S. Bullock, and I.L. Markov. Synthesis of quantum-logic circuits. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems, 25(6):1000–1010, Jun 2006 arXiv:quant-ph/0406176v5

Authors: Alberto Pedro Manzano Herrero & Gonzalo Ferro

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_angle(number_qubits: int, index: int, angle: float)

Creates an QLM Abstract Gate that apply a rotation of a given angle into a auxiliary qubit controlled by a given state of the measurement basis. Direct QLM multi controlled rotations were used for the implementation.

Notes

\[|\Psi\rangle = \sum_{j=0}^{2^n-1}\alpha_j|j\rangle\otimes|0\rangle\]
\[\mathcal{load\_angle}(\theta, |i\rangle)|\Psi\rangle \ =\sum_{j=0, j\ne i}^{2^n-1}\alpha_j|j\rangle\otimes|0\rangle+ \ \alpha_i|i\rangle\otimes\big(\cos(\theta)|0\rangle+\sin(\theta) \ |1\rangle\big)\]
Parameters
  • number_qubits (int) – Number of qubits for the control register. The arity of the gate is number_qubits+1.

  • index (int) – Index of the state that we control.

  • angle (float) – Angle that we load.

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_angles(angles: numpy.array, method: str = 'multiplexor')

This function serves as an interface for the two different implementations of multi controlled rotations: load_angles_brute_force and multiplexor_RY.

Notes

\[|\Psi\rangle = \sum_{j=0}^{2^n-1}\alpha_j|j\rangle\otimes|0\rangle\]
\[\mathcal{load\_angles}([\theta_j]_{j=0,1,2...2^n-1})|\Psi\rangle \ =\sum_{j=0}^{2^n-1}\alpha_j|j\rangle\otimes \ \big(\cos(\theta_j)|0\rangle+\sin(\theta_j)|1\rangle\big)\]
Parameters
  • angles (numpy array) – Angles to load in the circuit. The arity of the gate is: int(np.log2(len(angle)))+1.

  • method (string) – Method used in the loading. Default method.

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_angles_brute_force(angles: numpy.array)

Given a list of angles this function creates a QLM routine that applies rotations of each angle of the list, over an auxiliary qubit, controlled by the different states of the measurement basis. Direct QLM multi controlled rotations were used for the implementation.

Notes

\[|\Psi\rangle = \sum_{j=0}^{2^n-1}\alpha_j|j\rangle\otimes|0\rangle\]
\[\mathcal{load\_angles\_brute\_force} \ ([\theta_j]_{j=0,1,2...2^n-1}) |\Psi\rangle=\sum_{j=0}^{2^n-1} \ \alpha_j|j\rangle\otimes\big(\cos(\theta_j)|0\rangle+ \ \sin(\theta_j)|1\rangle\big)\]
Parameters

angles (numpy array) – Angles to load in the circuit. The arity of the gate is: int(np.log2(len(angle)))+1.

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_array(function_array: numpy.array, method: str = 'multiplexor', id_name: str = '1696594288254356269')

Creates a QLM AbstractGate for loading a normalised array into a quantum state.

Parameters
  • function_array (numpy array) – Numpy array with the normalised array to load. The arity of of the gate is int(np.log2(len(probability_array)))+1.

  • method (str) –

    type of loading method used:

    multiplexor : with quantum Multiplexors brute_force : using multicontrolled rotations by state

  • id_name (str) – name for the Abstract Gate

Returns

f_gate – AbstractGate customized for loading a normalised array

Return type

AbstractGate

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_pf(p_gate, f_gate)

Create a QLM AbstractGate for applying two given operators consecutively. The operator to implement is: p_gate*f_gate

Parameters
  • p_gate (QLM AbstractGate) – Customized AbstractGate for loading probability distribution.

  • f_gate (QLM AbstractGate) – Customized AbstractGatel for loading integral of a function f(x)

Returns

pf_gate

Return type

AbstractGate

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.load_probability(probability_array: numpy.array, method: str = 'multiplexor', id_name: str = '1696594288254366969')

Creates a QLM Abstract gate for loading a given discretized probability distribution using Quantum Multiplexors.

Parameters
  • probability_array (numpy array) – Numpy array with the discretized probability to load. The arity of of the gate is int(np.log2(len(probability_array))).

  • method (str) –

    type of loading method used:

    multiplexor : with quantum Multiplexors brute_force : using multicontrolled rotations by state

  • id_name (str) – name for the Abstract Gate

Returns

P_Gate – Customized Abstract Gate for Loading Probability array using Quantum Multiplexors

Return type

AbstractGate

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.multiplexor_ry(angles: numpy.array, ordering: str = 'sequency')

Given a list of angles this functions creates a QLM routine that applies rotations of each angle of the list, over an auxiliary qubit, controlled by the different states of the measurement basis. The multi-controlled rotations were implemented using Quantum Multiplexors.

Notes

\[|\Psi\rangle = \sum_{j=0}^{2^n-1}\alpha_j|j\rangle\otimes|0\rangle\]
\[\mathcal{multiplexor\_RY} \ ([\theta_j]_{j=0,1,2...2^n-1})|\Psi\rangle = \sum_{j=0}^{2^n-1} \ \alpha_j|j\rangle\otimes\big(\cos(\theta_j)|0\rangle+\sin(\theta_j)|1\rangle\big)\]
Parameters

angles (numpy array) –

Angles to load in the circuit. The arity of the gate is:

int(np.log2(len(angle)))+1.

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.step_array(index: int, size: int)

Creates are routine which loads an array of size “size”. This array has ones up to but not included the index position. The rest of the values are zero. This is why it is called step_array.

Parameters
  • index (int) – position where the step is produced

  • size (int) – size of the array. It has to be a power of 2

Returns

step_function_gate – gate which loads the corresponding array. Note that the arity is: np.log2(size)+1

Return type

Abstract Gate

tnbs.BTC_02_AE.QQuantLib.DL.data_loading.uniform_distribution(number_qubits: int)

Function to load a uniform distribution in a quantum circuit.

Notes

\[\mathcal{H}^{\otimes n}|\Psi\rangle\]
Parameters

number_qubits (int) – Arity of the output gate.

QQuantLib.DL.encoding_protocols

This module contains a class for selecting data encoding protocols

Authors: Alberto Pedro Manzano Herrero & Gonzalo Ferro

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

Bases: object

Class for data encoding into the quantum circuit.

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

run()

Execute the computations