PL.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_01_PL.PL.data_loading.get_qlm_probability(data, load_method, shots, qpu)
Loads an input probability array in a Quantum Circuit, execute it a fixed number of shots and returns the obtained result
- Parameters:
data (np array) – Array with the discretized probability to load into a quantum state
load_method (string) – Load method used for creating the Quantum Circuit
shots (int) – Number of shots the created Quantum Circuit should be measured.
qpu (QPU) – QPU for simulating or executing the Quantum Circuit
- Returns:
result (pandas DataFrame) – Pandas DataFrame with the results of the simulation or execution of the Quantum Circuit
circuit (QLM circuit) – QLM Quantum Circuit generated
quantum_time (float) – Time used for simulating or executing the Quantum Circuit.
- tnbs.BTC_01_PL.PL.data_loading.get_theoric_probability(n_qbits: int, mean: float, sigma: float)
Create discrete Gaussian probability distribution function (PDF) :param n_qbits: Number of qubits for interval discretization :type n_qbits: int :param mean: Mean of the desired Gaussian distribution :type mean: float :param sigma: Standard Deviation of the desired Gaussian distribution. :type sigma: float
- Returns:
x_ (numpy array) – Discretized domain (in 2^n_qbits) for the Gaussian PDF
data (numpy array) – Discretized (in 2^n_qbits) Gaussian PDF
step (float) – discretizaction step of the domain
shots (int) – Number of shots the quantum circuit should be measured
norma (scipy function) – scipy.stats.norm function configured for the desired mean and sigma
- tnbs.BTC_01_PL.PL.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)
- Returns:
routine – Routine with the quantum circuit that loads the input angle in a quantum state. Angle that we load.
- Return type:
qlm QRoutine
- tnbs.BTC_01_PL.PL.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.
- Returns:
routine – Routine with the quantum circuit that loads the input angles in a quantum state.
- Return type:
qlm QRoutine
- tnbs.BTC_01_PL.PL.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.
- Returns:
routine – Routine with the quantum circuit that loads the input angles in a quantum state.
- Return type:
qlm QRoutine
- tnbs.BTC_01_PL.PL.data_loading.load_probability(probability_array: numpy.array, method: str = 'multiplexor', id_name: str = '1732091326442412182')
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_01_PL.PL.data_loading.mask(number_qubits, index)
Transforms the state \(|index\rangle\) into the state \(|11...1\rangle\) of size number qubits.
- Parameters:
number_qubits (int)
index (int)
- Returns:
mask – the gate that we have to apply in order to transform state \(|index\rangle\). Note that it affects all states.
- Return type:
Qlm abstract gate
- tnbs.BTC_01_PL.PL.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.
- Returns:
routine – Routine with the quantum circuit that loads the input angles in a quantum state.
- Return type:
qlm QRoutine
PL.load_probabilities
Mandatory code for softaware implemetation of the Benchmark Test Case of PL kernel
- class tnbs.BTC_01_PL.PL.load_probabilities.LoadProbabilityDensity(**kwargs)
Bases:
object
Probability Loading
- exe()
Execution of workflow
- get_metrics()
Computing Metrics
- get_quantum_pdf()
Computing quantum probability density function
- get_theoric_pdf()
Computing theoretical probability densitiy function
- summary()
Pandas summary
- tnbs.BTC_01_PL.PL.load_probabilities.save(pl_object, folder, name=None)
Function for saving staff
PL.data_extracting
This module contains auxiliary functions for executing QLM programs based on QLM Routines or QLM gates and for post processing results from QLM qpu executions
Authors: Alberto Pedro Manzano Herrero & Gonzalo Ferro Costas
- tnbs.BTC_01_PL.PL.data_extracting.check_list_type(x_input, tipo)
Check if a list x_input is of type tipo :param x_input: :type x_input: list :param tipo: it has to be understandable by numpy :type tipo: data type
- Returns:
y_output – numpy array of type tipo.
- Return type:
np.array
- tnbs.BTC_01_PL.PL.data_extracting.create_qcircuit(prog_q)
Given a QLM program creates a QLM circuit
- Parameters:
prog_q (QLM QProgram)
- Returns:
circuit
- Return type:
QLM circuit
- tnbs.BTC_01_PL.PL.data_extracting.create_qjob(circuit, shots=0, qubits=None)
Given a QLM circuit creates a QLM job
- Parameters:
circuit (QLM circuit)
shots (int) – number of measurmentes
qubits (list) – with the qubits to be measured
- Returns:
job – job for submit to QLM QPU
- Return type:
QLM job
- tnbs.BTC_01_PL.PL.data_extracting.create_qprogram(quantum_gate)
Creates a Quantum Program from an input qlm gate or routine
- Parameters:
quantum_gate (QLM gate or QLM routine)
- Returns:
q_prog – Quantum Program from input QLM gate or routine
- Return type:
QLM Program.
- tnbs.BTC_01_PL.PL.data_extracting.get_results(quantum_object, linalg_qpu, shots: int = 0, qubits: list = None, complete: bool = False)
Function for testing an input gate. This function creates the quantum program for an input gate, the correspondent circuit and job. Execute the job and gets the results
- Parameters:
quantum_object (QLM Gate, Routine or Program)
linalg_qpu (QLM solver)
shots (int) – number of shots for the generated job. if 0 True probabilities will be computed
qubits (list) – list with the qubits for doing the measurement when simulating if None measurement over all allocated qubits will be provided
complete (bool) – for return the complete basis state. Useful when shots is not 0 and all the posible basis states are necessary.
- Returns:
pdf (pandas DataFrame) – DataFrame with the results of the simulation
circuit (QLM circuit)
q_prog (QLM Program.)
job (QLM job)
- tnbs.BTC_01_PL.PL.data_extracting.proccess_qresults(result, qubits, complete=False)
Post Process a QLM results for creating a pandas DataFrame
- Parameters:
result (QLM results from a QLM qpu.) – returned object from a qpu submit
qubits (int) – number of qubits
complete (bool) – for return the complete basis state.
PL.utils
This module contains several auxiliary functions needed by other scripts of the library
Authors: Alberto Pedro Manzano Herrero & Gonzalo Ferro Costas
Fast Walsh-Hadamard Transform is based on mex function written by Chengbo Li@Rice Uni for his TVAL3 algorithm:
https://github.com/dingluo/fwht/blob/master/FWHT.py
- tnbs.BTC_01_PL.PL.utils.bitfield(n_int: int, size: int)
Transforms an int n_int to the corresponding bitfield of size size
- Parameters:
n_int (int) – integer from which we want to obtain the bitfield
size (int) – size of the bitfield
- Returns:
full – bitfield representation of n_int with size size
- Return type:
list of ints
- tnbs.BTC_01_PL.PL.utils.expmod(n_input: int, base: int)
For a pair of integer numbers, performs the decomposition:
\[n_input = base^power+remainder\]- Parameters:
n_input (int) – number to decompose
base (int) – basis
- Returns:
power (int) – power
remainder (int) – remainder
- tnbs.BTC_01_PL.PL.utils.fwht(x_input: numpy.array, ordering: str = 'sequency')
Fast Walsh Hadamard transform of array x_input Works as a wrapper for the different orderings of the Walsh-Hadamard transforms.
- Parameters:
x_input (numpy array)
ordering (string) – desired ordering of the transform
- Returns:
y_output – Fast Walsh Hadamard transform of array x_input in the corresponding ordering
- Return type:
numpy array
- tnbs.BTC_01_PL.PL.utils.fwht_dyadic(x_input: numpy.array)
Fast Walsh-Hadamard Transform of array x_input in dyadic ordering The result is not normalised Based on mex function written by Chengbo Li@Rice Uni for his TVAL3 algorithm. His code is according to the K.G. Beauchamp’s book – Applications of Walsh and Related Functions. :param array: :type array: numpy array
- Returns:
x_output – Fast Walsh Hadamard transform of array x_input.
- Return type:
numpy array
- tnbs.BTC_01_PL.PL.utils.fwht_natural(array: numpy.array)
Fast Walsh-Hadamard Transform of array x in natural ordering The result is not normalised :param array: :type array: numpy array
- Returns:
fast_wh_transform – Fast Walsh Hadamard transform of array x.
- Return type:
numpy array
- tnbs.BTC_01_PL.PL.utils.fwht_sequency(x_input: numpy.array)
Fast Walsh-Hadamard Transform of array x_input in sequence ordering The result is not normalised Based on mex function written by Chengbo Li@Rice Uni for his TVAL3 algorithm. His code is according to the K.G. Beauchamp’s book – Applications of Walsh and Related Functions. :param x_input: :type x_input: numpy array
- Returns:
x_output – Fast Walsh Hadamard transform of array x_input.
- Return type:
numpy array
- tnbs.BTC_01_PL.PL.utils.left_conditional_probability(initial_bins, probability)
This function calculate f(i) according to the Lov Grover and Terry Rudolph 2008 papper: ‘Creating superposition that correspond to efficiently integrable probability distributions’ http://arXiv.org/abs/quant-ph/0208112v1
Given a discretized probability and an initial number of bins the function splits each initial region in 2 equally regions and calculates the conditional probabilities for x is located in the left part of the new regions when x is located in the region that contains the corresponding left region
- Parameters:
initial_bins (int) – Number of initial bins for splitting the input probabilities
probability (np.darray.) – Numpy array with the probabilities to be load. initial_bins <= len(Probability)
- Returns:
left_cond_prob – conditional probabilities of the new initial_bins+1 splits
- Return type:
np.darray