PH.parent_hamiltonian
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.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.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.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.parent_hamiltonian.run_parent_hamiltonian(**configuration)
launch_parent_hamiltonian
For launching a VQE quantum step execution Author: Gonzalo Ferro
- tnbs.BTC_04_PH.PH.parent_hamiltonian.launch_parent_hamiltonian.run_id(**configuration)
pauli
This module contains all functions needed for creating the Pauli decomposition of a Hamiltonian
Author: Gonzalo Ferro
- tnbs.BTC_04_PH.PH.parent_hamiltonian.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.parent_hamiltonian.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.parent_hamiltonian.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.parent_hamiltonian.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
contractions
Implementation of reduced density matrix computations and tensor contractions
Author: Gonzalo Ferro
- tnbs.BTC_04_PH.PH.parent_hamiltonian.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, reshapin and doing matrix multiplication. Tensor legs can be of different dimension. BE AWARE: Order in contraction indices it is very important: contraction1 = [1, 2, 5] contraction2 = [2, 0, 6] -> Contractions will be: [1-2, 2-0, 5-6] But if contraction2 = [0, 2, 6] then contraction will be: [1-0, 2-2,5-6] If both contraction indices are empty then the tensors will be glued
- 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.parent_hamiltonian.contractions.contract_indices_old(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.parent_hamiltonian.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.parent_hamiltonian.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.parent_hamiltonian.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