QQuantLib.PE
classical_qpe
This module contains the necessary functions and classes to implement the classical Quantum Phase Estimation with the inverse of the Quantum Fourier Transform. The following references were used:
Brassard, G., Hoyer, P., Mosca, M., & Tapp, A. (2000). Quantum amplitude amplification and estimation. AMS Contemporary Mathematics Series, 305. https://arxiv.org/abs/quant-ph/0005055v1
NEASQC deliverable: D5.1: Review of state-of-the-art for Pricing and Computation of VaR
Author: Gonzalo Ferro Costas & Alberto Manzano Herrero
- class tnbs.BTC_02_AE.QQuantLib.PE.classical_qpe.CQPE(**kwargs)
Bases:
object
Class for using classical Quantum Phase Estimation, with inverse of Quantum Fourier Transformation.
- Parameters:
kwars (dictionary) –
dictionary that allows the configuration of the CQPE algorithm: Implemented keys:
- initial_stateQLM Program
QLM Program with the initial Psi state over the Grover-like operator will be applied Only used if oracle is None
- unitary_operatorQLM gate or routine
Grover-like operator which autovalues want to be calculated Only used if oracle is None
- cbits_numberint
number of classical bits for phase estimation
- qpuQLM solver
solver for simulating the resulting circuits
- shotsint
number of shots for quantum job. If 0 exact probabilities will be computed.
- run()
Creates the quantum phase estimation routine
iterative_quantum_pe
This module contains necessary functions and classes to implement Iterative Quantum Phase Estimation (IQPE). The implementation is based on following paper:
Dobšíček, Miroslav and Johansson, Göran and Shumeiko, Vitaly and Wendin, Göran*. Arbitrary accuracy iterative quantum phase estimation algorithm using a single ancillary qubit: A two-qubit benchmark. Physical Review A 3(76), 2007. https://arxiv.org/abs/quant-ph/0610214
Author: Gonzalo Ferro Costas & Alberto Manzano Herrero
- class tnbs.BTC_02_AE.QQuantLib.PE.iterative_quantum_pe.IQPE(**kwargs)
Bases:
object
Class for using Iterative Quantum Phase Estimation (IQPE) algorithm
- Parameters:
kwars (dictionary) –
dictionary that allows the configuration of the ML-QPE algorithm. Implemented keys:
- initial_stateQLM Program
QLM Program withe the initial Psi state over the Grover-like operator will be applied Only used if oracle is None
- unitary_operatorQLM gate or routine
Grover-like operator whose autovalues want to be calculated Only used if oracle is None
- cbits_numberint
number of classical bits for phase estimation
- qpuQLM solver
solver for simulating the resulting circuits
- shotsint
number of shots for quantum job. If 0 exact probabilities will be computed.
- easybool
If True step_iqpe_easy will be used for each step of the algorithm If False step_iqpe will be used for each step.
- apply_iqpe()
Apply a complete IQPE algorithm
- property cbits_number
creating cbits_number property
- init_iqpe()
Initialize several properties
- iqpe(number_of_cbits=None, shots=None)
This method apply a workflow for executing a complete IQPE algorithm
- Parameters:
number_of_cbits (int (overwrite correspondent property)) – Number of classical bits for storing the phase estimation
shots (int (overwrite correspondent property)) – Number of shots for executing the QLM job
- static measure_classical_bits(result)
Post-process intermediate measurements from a QLM result.
- Parameters:
result (list list with QLM results)
- Returns:
pdf – contains extracted information from intermediate_measurements from a qlm result. Columns:
- BitStringstr.
String with the bits of the measurements done during simulation of the circuit
- BitIntint.
Integer representation of the BitString
- Phifloat.
Angle representation of the BitString between [0,1].
- Probabilityfloat.
Probability of the measurement of the classical bits.
- Return type:
pandas DataFrame
- static post_proccess(input_pdf)
This function uses the results property and add it additional columns that are useful for Amplitude Amplification procedure
- Parameters:
input_pdf (Pandas DataFrame.)
- Returns:
final_results – DataFrame with complete information about the results
- Return type:
Pandas DataFrame
- restart()
Reinitialize several properties for restart purposes
- static run_qprogram(q_prog, q_aux, shots, linalg_qpu)
Executes a complete simulation
- Parameters:
q_prog (QLM Program)
q_aux (QLM qbit) – auxiliary qubit for measuring during all ipe steps
shots (int) – number of shots for simulation
linalg_qpu (QLM solver)
- Returns:
result (QLM result object)
circuit (QLM circuit)
pdf_time (pandas DataFrame) – DataFrame with elapsed time of different parts of the simulation
- static step_iqpe(q_prog, q_gate, q_aux, c_bits, l)
Implements a iterative step of the Iterative Phase Estimation (IPE) algorithm.
- Parameters:
q_prog (QLM program) – QLM Program where the unitary operator will be applied
q_gate (QLM AbstractGate) – QLM implementation of the unitary operator. We want estimate the autovalue theta of this operator
q_aux (QLM qbit) – auxiliary qubit for IPE. This qbit will be the control for application of the unitary operator to the principal bits of the program. Additionally will be the target qubit for the classical bit controlled rotation. This qubit will be reset at the end of the step.
c_bits (list) – list with the classical bits allocated for phase estimation
l (int) – iteration step of the IPE algorithm
- static sumarize(input_pdf, columns=None)
This method summarize the results.
- Parameters:
input_pdf (Pandas DataFrame.)
columns (list) – list with the names of the input DataFrame for summarize
- Returns:
final_results – DataFrame with summary results
- Return type:
Pandas DataFrame
windows_pe
- This module contains different window functions. Based on:
Effects of cosine tapering window on quantum phase estimation. Rendon, Gumaro and Izubuchi, Taku and Kikuchi, Yuta Phys. Rev. D, 106. 2022
Author: Gonzalo Ferro Costas
- tnbs.BTC_02_AE.QQuantLib.PE.windows_pe.cosine_window(number_qubits: int)
Creates a QLM AbstractGate for loading a Cosine Window Function into a quantum state.
- Parameters:
number_qubits (int) – Number of qubits for the quantum AbstractGate
- Returns:
window_state – AbstractGate for loading a cosine
- Return type:
AbstractGate
- tnbs.BTC_02_AE.QQuantLib.PE.windows_pe.kaiser_array(number_qubits, alpha=1e-05)
Creates the probability discretization of a Kaiser window function for a given input of number of qubits and a alpha :param number_qubits: Number of qubits for building the Kaiser window function :type number_qubits: int :param alpha: Parameter for modified Bessel function or order 0. :type alpha: float
- Returns:
pdf – pandas DF with the probability discretization of the Kaiser window function
- Return type:
pandas DataFrame
- tnbs.BTC_02_AE.QQuantLib.PE.windows_pe.kaiser_window(number_qubits, alpha=1e-05)
Creates a QLM AbstractGate for loading a Kaiser Window Function into a quantum state. Uses load_probability function for loading the discretization of the probability of the Kaiser window function.
- Parameters:
number_qubits (int) – Number of qubits for the quantum AbstractGate
alpha (float) – Parameter for modified Bessel function or order 0.
- Returns:
kaiser_state – AbstractGate for loading a Kaiser Window
- Return type:
AbstractGate
- tnbs.BTC_02_AE.QQuantLib.PE.windows_pe.sine_window(number_qubits: int)
Creates a QLM AbstractGate for loading a Sine Window Function into a quantum state.
- Parameters:
number_qubits (int) – Number of qubits for the quantum AbstractGate
- Returns:
window_state – AbstractGate for loading a sine
- Return type:
AbstractGate
- tnbs.BTC_02_AE.QQuantLib.PE.windows_pe.window_selector(window_type, **kwargs)
Selector funcion for window functions
- Parameters:
window_type (str) – String with the desired Window function
kwargs (keyword arguments) – Keyword arguments for configuring window functions. Mandatory: auxiliar_qbits_number. For Kaiser window it is mandatory to provide kaiser_alpha
- Returns:
window gate (AbstractGate) – AbstractGate with the desired window function
last_control_change (Bool) – last_control_change value