BTC_03_QPE.QPE

QPE.qpe_rz

Class for executing QPE on a R_z^n operator

Author: Gonzalo Ferro

class tnbs.BTC_03_QPE.QPE.qpe_rz.QPE_RZ(**kwargs)

Bases: object

Probability Loading

exe()

Execution of workflow

get_metrics()

Computing Metrics

quantum_distribution()

Computes the quantum distribution of Rz eigenvalues

summary()

Pandas summary

theoretical_distribution()

Computes the theoretical distribution of Rz eigenvalues

QPE.rz_lib

All mandatory functions for executing theoretical and atos qlm simulation for computing eigenvalues of a R_z^n operator

Author: Gonzalo Ferro

tnbs.BTC_03_QPE.QPE.rz_lib.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_03_QPE.QPE.rz_lib.computing_shots(pdf)

Compute the number of shots. The main idea is that the samples for the lowest degeneracy eigenvalues will be enough. In this case enough is that that we measured an eigenvalue that will have an error from respect to the theoretical one lower than the discretization precision at least 100 times

Parameters

pdf (pandas DataFrame) – DataFrame with the theoretical eigenvalues

Returns

shots – number of shots for QPE algorithm

Return type

int

tnbs.BTC_03_QPE.QPE.rz_lib.get_qpu(qpu=None)

Function for selecting solver.

Parameters
  • qpu (str) –

  • qlmass (*) –

  • python (*) –

  • c (*) –

Returns

linal_qpu

Return type

solver for quantum jobs

tnbs.BTC_03_QPE.QPE.rz_lib.make_histogram(eigenvalues, discretization)

Given an input list of eigenvalues compute the correspondent histogram using a bins = 2^discretization

Parameters
  • eigenvalues (list) – List with the eigenvalues

  • discretization (int) – Histogram discretization parameter: The number of bins for the histogram will be: 2^discretization

Returns

pdf – Pandas Dataframe with the 2^m bin frequency histogram for the input list of eigenvalues. Columns * lambda : bin discretization for eigenvalues based on the discretization input * Probability: probability of finding any eigenvalue inside of the correspoondent lambda bin

Return type

pandas DataFrame

tnbs.BTC_03_QPE.QPE.rz_lib.qpe_rz_qlm(angles, auxiliar_qbits_number, shots=0, qpu=None)

Computes the Quantum Phase Estimation for a Rz Kronecker product

Parameters
  • angles (list) – list with the angles that are applied to each qubit of the circuit

  • auxiliar_qbits_number (int) – number of auxiliary qubits for doing QPE

  • shots (int) – number of shots for getting the results. 0 for exact solution

  • qpu (Atos QLM QPU object) – QLM QPU for solving the circuit

Returns

  • results (pandas DataFrame) – pandas DataFrame with the distribution of the eigenvalues with a bin discretization of 2^auxiliar_qbits_number * lambda : bin discretization for eigenvalues based on the discretization input (auxiliar_qbits_number input) * Probability: probability of finding any eigenvalue inside of the correspoondent lambda bin

  • qft_pe (CQPE object)

tnbs.BTC_03_QPE.QPE.rz_lib.rz_angles(thetas)

Creates a QLM abstract Gate with a R_z^n operator of an input array of angles

Parameters

thetas (array) – Array with the angles of the R_z^n operator

Returns

r_z_n – AbstractGate with the implementation of R_z_^n of the input angles

Return type

QLM AbstractGate

tnbs.BTC_03_QPE.QPE.rz_lib.rz_eigenv_from_state(state, angles)

For a fixed input state and the angles of the R_z^n operator compute the correspondent eigenvalue.

Parameters
  • state (np.array) – Array with the binary representation of the input state

  • angles (np.array) – Array with the angles for the R_z^n operator.

Returns

lambda_ – The eigenvalue for the input state of the R_z^n operator with the input angles

Return type

float

tnbs.BTC_03_QPE.QPE.rz_lib.rz_eigv(angles)

Computes the complete list of eigenvalues for a R_z^n operator for an input list of angles Provides the histogram between [0,1] with a bin of 2**discretization for the distribution of eigenvalues of a R_z^n operator for a given list of angles.

Parameters

angles (np.array) – Array with the angles for the R_z^n operator.

Returns

pdf – DataFrame with all the eigenvalues of the R_z^n operator for the input list angles. Columns * States : Eigenstates of the Rz^n operator (least significant bit is leftmost) * Int_lsb_left : Integer conversion of the state (leftmost lsb) * Int_lsb_rightt : Integer conversion of the state (rightmost lsb) * Eigenvalues : correspondent eigenvalue

Return type

pandas DataFrame

QPE.rz_qlm

Author: Gonzal Ferro

tnbs.BTC_03_QPE.QPE.rz_qlm.qpe_rz_qlm(angles, auxiliar_qbits_number, shots=0, qpu=None)

Computes the Quantum Phase Estimation for a Rz Kroneckr product

Parameters
  • angles (list) – list with the angles that are applied to each qubit of the circuit

  • auxiliar_qbits_number (int) – number of auxiliar qubits for doing QPE

  • shots (int) – number of shots for gettiong the results. 0 for exact solution

  • qpu (Atos QLM QPU object) – QLM QPU for solving the circuit

Returns

  • results (pandas DataFrame) – pandas DataFrame with the distribution of the eigenvalues with a bin discretization of 2^auxiliar_qbits_number * lambda : bin discretization for eigenvalues based on the discretization input (auxiliar_qbits_number input) * Probability: probability of finding any eigenvalue inside of the correspoondent lambda bin

  • qft_pe (CQPE object)

tnbs.BTC_03_QPE.QPE.rz_qlm.rz_angles(thetas)

Creates a QLM abstract Gate with a R_z^n operator of an input array of angles

Parameters

thetas (array) – Array with the angles of the R_z^n operator

Returns

r_z_n – AbstractGate with the implementation of R_z_^n of the input angles

Return type

QLM AbstractGate

QPE.qpe

Mandatory functions for performing classical QPE Author: Gonzal Ferro

class tnbs.BTC_03_QPE.QPE.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

tnbs.BTC_03_QPE.QPE.qpe.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_03_QPE.QPE.qpe.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_03_QPE.QPE.qpe.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_03_QPE.QPE.qpe.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_03_QPE.QPE.qpe.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_03_QPE.QPE.qpe.load_qn_gate(qlm_gate, n_times)

Create an AbstractGate by applying an input gate n times

Parameters
  • qlm_gate (QLM gate) – QLM gate that will be applied n times

  • n_times (int) – number of times the qlm_gate will be applied

tnbs.BTC_03_QPE.QPE.qpe.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.