BTC_04_PH.PH

PH.ansatzes

This module contains all functions needed for creating QLM implementation for the ansatz of the Parent Hamiltonian paper:

Fumiyoshi Kobayashi and Kosuke Mitarai and Keisuke Fujii Parent Hamiltonian as a benchmark problem for variational quantum eigensolvers Physical Review A, 105, 5, 2002 https://doi.org/10.1103%2Fphysreva.105.052415

Authors: Gonzalo Ferro

class tnbs.BTC_04_PH.PH.ansatzes.SolveCircuit(qlm_circuit, **kwargs)

Bases: object

get_job_results(jobid)

Given a Jobid retrieve the result and procces output

run()

Solve Circuit

save_parameters()

Saving Parameters

save_state()

Saving State

save_time()
submit()

Submit circuit

tnbs.BTC_04_PH.PH.ansatzes.angles_ansatz01(circuit, pdf_parameters=None)

Create the angles for ansatz01

Parameters
  • circuit (QLM circuit) – QLM circuit with the parametrized ansatzes

  • parameters (pandas DataFrame) – For providing the parameters to the circuit. If None is provide the parameters are set using som formula

Returns

  • circuit (QLM circuit) – QLM circuit with the parameters fixed

  • pdf_parameters (pandas DataFrame) – DataFrame with the values of the parameters

tnbs.BTC_04_PH.PH.ansatzes.ansatz_qlm_01(nqubits=7, depth=3)

Implements QLM version of the Parent Hamiltonian Ansatz using parametric Circuit

Parameters
  • nqubits (int) – number of qubits for the ansatz

  • depth (int) – number of layers for the parametric circuit

Returns

  • qprog (QLM Program) – QLM program with the ansatz implementation in parametric format

  • theta (list) – list with the name of the variables of the QLM Program

tnbs.BTC_04_PH.PH.ansatzes.ansatz_qlm_02(nqubits, depth=3)

Implements QLM version of the Parent Hamiltonian Ansatz using parametric Circuit

Parameters
  • nqubits (int) – number of qubits for the ansatz

  • depth (int) – number of layers for the parametric circuit

Returns

  • qprog (QLM Program) – QLM program with the ansatz implementation in parametric format

  • theta (list) – list with the name of the variables of the QLM Program

tnbs.BTC_04_PH.PH.ansatzes.ansatz_selector(ansatz, **kwargs)

Function for selecting an ansatz

Parameters
  • ansatz (text) – The desired ansatz

  • kwargs (keyword arguments) – Different keyword arguments for configurin the ansazt, like nqubits or depth

Returns

circuit – The atos myqlm circuit implementation of the input ansatz

Return type

Atos myqlm circuit

tnbs.BTC_04_PH.PH.ansatzes.getting_job(**configuration)

For getting a job from QLM. Configuration need to have following keys: nqubits, job_id, save, filename

tnbs.BTC_04_PH.PH.ansatzes.proccess_qresults(result, qubits, complete=True)

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.

tnbs.BTC_04_PH.PH.ansatzes.run_ansatz(**configuration)

For creating an ansatz and solving it

tnbs.BTC_04_PH.PH.ansatzes.solving_circuit(qlm_state, nqubit, reverse=True)

Solving a complete qlm circuit

Parameters
  • qlm_circuit (QLM circuit) – qlm circuit to solve

  • nqubit (int) – number of qubits of the input circuit

  • qlm_qpu (QLM qpu) – QLM qpu for solving the circuit

  • reverse (True) – This is for ordering the state from left to right If False the order will be form right to left

Returns

state – DataFrame with the complete simulation of the circuit

Return type

pandas DataFrame

tnbs.BTC_04_PH.PH.ansatzes.submit_circuit(qlm_circuit, qlm_qpu)

Solving a complete qlm circuit

Parameters
  • qlm_circuit (QLM circuit) – qlm circuit to solve

  • qlm_qpu (QLM qpu) – QLM qpu for solving the circuit

PH.parent_hamiltonian

Complete implementation of the Parent Hamiltonian following:

Fumiyoshi Kobayashi and Kosuke Mitarai and Keisuke Fujii Parent Hamiltonian as a benchmark problem for variational quantum eigensolvers Physical Review A, 105, 5, 2002 https://doi.org/10.1103%2Fphysreva.105.052415

Author: Gonzalo Ferro

class tnbs.BTC_04_PH.PH.parent_hamiltonian.PH(amplitudes, t_invariant=False, **kwargs)

Bases: object

Class for doing Parent Hamiltonian Computations

Parameters
  • amplitudes (list) – list with the complete amplitudes of the state of the ansatz

  • kwars (dictionary) –

    dictionary that allows the configuration of the CQPEAE algorithm:

    Implemented keys:

get_density_matrix()

Computes the density matrix asociated with the amplitudes

get_pauli_pdf()

Create pauli dataframe with all the info. Additionally pauli coefficients lower than float precision will be pruned

local_ph()

Computes the local parent hamiltonian

naive_ph()

Computes the parent hamiltonian of agiven ansatz for a full qubit interaction

save()

Saving Staff

tnbs.BTC_04_PH.PH.parent_hamiltonian.get_local_reduced_matrix(state, qb_pos)

Given a MPS representation of a input state and position qubit (qb_pos) computes the minimum local reduced density matrix from qb_pos qubit such that its null space can be computable: i.e. rank(local_rho) < dim(local_rho)

Parameters
  • state (numpy array) – MPS representation of an state

  • qb_pos (int) – position of the qubit for computing the reduced density matrix

Returns

  • local_qubits (list) – list with the qubits affected by the reduced density matrix

  • local_rho (numpy array) – array with the reduced density matrix for the input qbit position

tnbs.BTC_04_PH.PH.parent_hamiltonian.get_null_projectors(array)

Given an input matrix this function computes the matrix of projectors over the null space of the input matrix

Parameters

array (numpy array) – Input matrix for computing the projectors over the null space

Returns

h_null – Matrices with the projectors to the null space of the input array

Return type

numpy array

tnbs.BTC_04_PH.PH.parent_hamiltonian.run_parent_hamiltonian(**configuration)

PH.execution_ph

For executing a VQE quantum step of a ansatz and a given Parent Hamiltonian Author: Gonzalo Ferro

class tnbs.BTC_04_PH.PH.execution_ph.PH_EXE(ansatz, pauli_ph, nqubits, **kwargs)

Bases: object

Class for, given an ansatz and its parent hamiltonian Pauli decompostion, execute a VQE step

Parameters
  • ansatz (QLM circuit) – QLM circuit with the input ansatz

  • n_qubits (int) – number of qubits of the ansatz

  • pauli_ph (pandas DataFrame) – pauli decomposition of the parent Hamiltonian

  • kwars (dictionary) – For configuring the class

run()

Execute VQE step

save()

Saving Staff

tnbs.BTC_04_PH.PH.execution_ph.run_ph_execution(**configuration)

Given an ansatz circuit, the parameters and the Pauli decomposition of the corresponding local PH executes a VQE step for computing the energy of the ansatz under the Hamiltonian that MUST BE near 0

PH.workflow

Complete WorkFlow of a PH VQE Author: Gonzalo Ferro

tnbs.BTC_04_PH.PH.workflow.workflow(**configuration)

PH.contractions

Implementation of reduced density matrix computations and tensor contractions

Author: Gonzalo Ferro

tnbs.BTC_04_PH.PH.contractions.contract_indices(tensor1, tensor2, contraction1, contraction2)

Compute the contraction of 2 input tensors for the input contraction indices.The computation is done by, transposing indices, reshaping and doing matrix multiplication

Parameters
  • tensor1 (numpy array) – first tensor

  • tensor2 (numpy array) – second tensor

  • contraction1 (list) – contraction indices for first tensor

  • contraction2 (list) – contraction indices for second tensor

Returns

rho – Desired reduced density operator in matrix form

Return type

numpy array

tnbs.BTC_04_PH.PH.contractions.contract_indices_string(tensor1, tensor2, contraction_indices)

Compute the contraction of 2 input tensors for the input contraction indices.The computation is done by, transposing indices, reshaping and doing matrix multiplication

Parameters
  • tensor1 (numpy array) – array in MPS format of the state for computing reduced density matrix

  • tensor2 (numpy array) – array in MPS format of the state for computing reduced density matrix

  • contraction_indices (list) – Indices of the MPS state that will be contracted to compute the correspondent reduced density matrix

Returns

rho – Desired reduced density operator in matrix form

Return type

numpy array

tnbs.BTC_04_PH.PH.contractions.reduced_matrix(state, free_indices, contraction_indices)

Compute the reduced density matrix for the input contraction indices The computation is done by, transposing indices, reshaping and doing matrix multiplication

Parameters
  • state (numpy array) – array in MPS format of the state for computing reduced density matrix

  • free_indices (list) – Free indices of the MPS state (this is the qubit that will NOT be traced out)

  • contraction_indices (list) – Indices of the MPS state that will be contracted to compute the correspondent reduced density matrix

Returns

rho – Desired reduced density operator in matrix form

Return type

numpy array

tnbs.BTC_04_PH.PH.contractions.reduced_matrix_string(state, free_indices, contraction_indices)

Compute the reduced density matrix for the input contraction indices The computation is done by using np.einsum. Limited to 52 indices.

Parameters
  • state (numpy array) – array in MPS format of the state for computing reduced density matrix

  • free_indices (list) – Free indices of the MPS state (this is the qubit that will NOT be traced out)

  • contraction_indices (list) – Indices of the MPS state that will be contracted to compute the correspondent reduced density matrix

Returns

matriz_rho – Desired reduced density operator in matrix form

Return type

numpy array

PH.pauli

This module contains all functions needed for creating the Pauli decomposition of a Hamiltonian

Author: Gonzalo Ferro

tnbs.BTC_04_PH.PH.pauli.pauli_decomposition(array, dimension, jobs=-1)

Creates the Pauli Decomposition of an input matrix

Parameters
  • array (numpy array) – input array for doing the Pauli decomposition

  • dimension (int) – dimension for creating the corresponding basis of Kronecker products of Pauli basis

  • = int (jobs) – For speed up the coefficients computations. Number of parallel computations.

Returns

  • coefs (list) – Coefficients of the different Pauli matrices decomposition

  • strings_pauli (list) – list with the complete Pauli string decomposition

tnbs.BTC_04_PH.PH.pauli.pauli_inner_product(array, pauli_list, dimension)

Given an input matrix and a Kronecker Pauli matrix product computes its inner product. Under the hood it computes the Frobenius norm of the complex conjugate of the matrix by the given Kronecker Pauli matrix product.

Parameters
  • array (numpy array) – Input array for getting the inner product

  • pauli_list (list) – list with the indices to compute the Kronecker product of the corresponding Pauli matrices.Each element of the list must be a number between 0 and 3 corresponding to the Pauli matrix following convention from pauli_operators function

  • dimension (int) – For doing the normalisation corresponding to the dimension of the matrices

Returns

inner_product – Resulting inner product

Return type

float

tnbs.BTC_04_PH.PH.pauli.pauli_operators(pauli_index)

Return the correspondent Pauli matrix.

Parameters

pauli_index (int) – Number for selecting the Pauli matrix: 0 -> identity, 1-> X, 2-> Y, 3 -> Z

Returns

2x2 Pauli Matrix

Return type

pauli = np.array

tnbs.BTC_04_PH.PH.pauli.pauli_strings(pauli_list)

Provides the Pauli strings of the input list.

Parameters

pauli_list (list) – list with the ints of the Pauli matrices. See pauli_operators for the mapping

Returns

string_pauli – correspondent Pauli strings of the input

Return type

str

PH.utils_ph

Utils for PH benchmark test case Author: Gonzalo Ferro

tnbs.BTC_04_PH.PH.utils_ph.combination_for_dictionary(input_dict)

Creates a list of dictionaries with all the posible combination of the input dictionary.

Parameters

input_dict (python dictionary) – python dictionary where each key value MUST be a list. For each value of a list a new dictioanry will be created

Returns

list_of_dictionaries – A list with all posible combination of dictionaries from the input dictionary

Return type

list of python dictionaries

tnbs.BTC_04_PH.PH.utils_ph.combination_for_list(input_list)

For each dictionary of the list the function creates all posible combinations. All the posible combinations are concatenated.

Parameters

input_list (list of python dictionary) – The values of each key of the each python dictionary MUST BE lists.

Returns

combo_list – A list with the concatenation of all posible combinations for each dictionary of the input_list

Return type

list of python dictionaries

tnbs.BTC_04_PH.PH.utils_ph.create_folder(folder_name)

Check if folder exist. If not the function creates it

Parameters

folder_name (str) – Name of the folder

Returns

folder_name – Name of the folder

Return type

str

tnbs.BTC_04_PH.PH.utils_ph.get_filelist(folder)

Look inside of a folder for files delete final part and get non repeated files

tnbs.BTC_04_PH.PH.utils_ph.get_info_basefn(base_fn)
tnbs.BTC_04_PH.PH.utils_ph.get_qpu(qpu=None)

Function for selecting solver.

Parameters

qpu (str) –

  • qlmass: for trying to use QLM as a Service connection

    to CESGA QLM

  • python: for using PyLinalg simulator.

  • c: for using CLinalg simulator

  • mps: for using mps

Returns

linal_qpu

Return type

solver for quantum jobs