PH.mps

ansatz_mps

Parent Hamiltonian ansatz using MPS

tnbs.BTC_04_PH.PH.mps.ansatz_mps.ansatz_mps(nqubits, depth, angles, truncate=True, t_v=None)

Creates the MPS solution of the ansatz for TNBS BTC_04_PH benchmark

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

  • depth (int) – Depth for the ansatz

  • truncate (bool) – Boolean variable for truncate SVD of the 2 qubits ansatz. If truncate is True and t_v is None precision of the float will be used as truncation value

  • t_v (float) – Float for tuncating the SVD of the 2 qubits gates. Only valid if truncate is True,

Returns:

mps_ – list with the angles for the circuit

Return type:

list

tnbs.BTC_04_PH.PH.mps.ansatz_mps.get_angles(depth)

Setting the angles of the ansatz following TNBS procedure

Parameters:

depth (int) – Integer with the depth of the ansatz

Returns:

mps_ – list with the angles for the circuit

Return type:

list

tnbs.BTC_04_PH.PH.mps.ansatz_mps.state_computation(**configuration)

Computes State of the TNBS BTC_04_PH ansatz using MPS.

Parameters:
  • arguments (configuration MUST have following keyword)

  • nqubits (int) – Number of qubits for the ansatz

  • depth (int) – Depth for the ansatz

  • truncate (bool) – Boolean variable for truncate SVD of the 2 qubits ansatz. If truncate is True and t_v is None precision of the float will be used as truncation value

  • t_v (float) – Float for tuncating the SVD of the 2 qubits gates. Only valid if truncate is True,

  • save (bool) – For saving the resulting state

  • folder (string) – Folder for saving the results

Returns:

pdf – DataFrame with the result of the state of the circuit

Return type:

pandas DataFrame

gates_mps

Numpy Implementation of Several Quantum Gates

tnbs.BTC_04_PH.PH.mps.gates_mps.controlz()

Implement a Controlled-Z Gate as a numpy array.

Returns:

cz – Array with the implementation of a c-Z gate

Return type:

numpy array

tnbs.BTC_04_PH.PH.mps.gates_mps.h_gate()

Implement a Haddamard Gate as a numpy array.

Returns:

haddamard – Array with the implementation of a Haddamard gate

Return type:

numpy array

tnbs.BTC_04_PH.PH.mps.gates_mps.phasechange_gate()

Implement a Phase Change Gate as a numpy array.

Returns:

phase – Array with the implementation of a Phase change gate

Return type:

numpy array

tnbs.BTC_04_PH.PH.mps.gates_mps.x_rotation(angle)

Implement a X rotation numpy array.

Parameters:

angle (float) – desired angle for the Z rotation

Returns:

xr – Array with the implementation of a X rotation

Return type:

numpy array

tnbs.BTC_04_PH.PH.mps.gates_mps.z_rotation(angle)

Implement a Z rotation numpy array.

Parameters:

angle (float) – desired angle for the Z rotation

Returns:

zr – Array with the implementation of a Z rotation

Return type:

numpy array

mps

Functions for working with MPS

tnbs.BTC_04_PH.PH.mps.mps.apply_2qubit_gate(tensor1, tensor2, gate=None, truncate=False, t_v=None)

Executes a 2-qubit gate between 2 rank-3 tensors

Notes

The rank-3 tensors MUST HAVE following indexing:

0-o-2

1

Where 1 is the physical leg. Following Computation is done:

-o-o-
| -> -o- -> SVD -> -o- -o-

-o- | |

tnbs.BTC_04_PH.PH.mps.mps.apply_2qubit_gates(qubits, gates, truncate=True, t_v=1e-08)

Apply a circular ladder of Non-Local gates.

Parameters:
  • qubits (list) – MPS representation of a circuit. List where each element is a numpy array

  • gates (list) – list where each element is a matrix representation of non-local gate

  • truncate (bool) – Boolean variable for truncate SVD of the 2 qubits ansatz. If truncate is True and t_v is None precision of the float will be used as truncation value

  • t_v (float) – Float for tuncating the SVD of the 2 qubits gates. Only valid if truncate is True,

Returns:

new_qubits – MPS representation of the resulting circuit of applied the circular ladder of non local gates over the input MPS. Each element of the list is a numpy array

Return type:

list

tnbs.BTC_04_PH.PH.mps.mps.apply_local_gate(mps, gates)

Apply local gates on several rank 3-tensors. For not apply a gate over a tensor a None should be provided.

Notes

The rank-3 tensor MUST HAVE following indexing:

0-o-2

1

Where 1 is the physical leg.

The computation done is:

-o- -o- … -o-
| |

o o o | | |

Parameters:
  • mps (list) – Each element is a rank-3 tensor from a MPS

  • gates (list) – Each element is a local gate

Returns:

o_qubits – Each element is the resulting rank-3 tensor

Return type:

list

tnbs.BTC_04_PH.PH.mps.mps.compose_mps(mps)

Given an input MPS it computes the final Tensor

Parameters:

mps (list) – list where each element is a rank-3 tensor that conforms de MPS

Returns:

tensor – numpy array with the correspondient tensor

Return type:

np.array

tnbs.BTC_04_PH.PH.mps.mps.contract_indices_one_tensor(tensor, contractions)

For an input tensor executes indices contractions by pair. The computation is done by contracting each para of indices with its corresponding identity matrix. EXAMPLE: contractions = [(1, 5), (3, 4)] Index 1 will be contracted with indice 5 and index 3 with index 4

Parameters:
  • tensor (numpy array) – input tensor

  • contractions (list) – each element is a tuple of the indices to be contracted

Returns:

tensor – Desired tensor with the corresponding contractions done

Return type:

numpy array

tnbs.BTC_04_PH.PH.mps.mps.contraction_physical_legs(tensor)

Executes the contraction of the physical legs of the input rank-3 tensor with its complex conjugate. Physical Legs MUST BE 1

Parameters:

tensor (np array) – Numpy array with a rank-3 tensor. Physical Legs MUST BE 1

tnbs.BTC_04_PH.PH.mps.mps.mpo_contraction(tensor_1, tensor_2)

Contraction of 2 input tensors (npo tensors) with corresponding adjust of dimension for computing density matrices. The input tensors MUST be rank 4 or 2 tensors.

Notes

Rank-4 tensor: | Rank-2 tensor:
  • o - | - o - | |

Parameters:
  • tensor_1 (np array) – First input 4 or 2 rank tensor

  • tensor_2 (np array) – Second input 4 or 2 rank tensor

Returns:

step – output rank 4 or 2 tensor

Return type:

np array

tnbs.BTC_04_PH.PH.mps.mps.my_svd(array, truncate=False, t_v=None)

Execute SVD.

Parameters:
  • array (np.array) – Arry with matrix for SVD

  • truncate (Bool) – For truncating SVD. If t_v is None then the truncation will be using float prcision of the system

  • t_v (float) – In truncate is True then the t_v float will use as truncation threshold

Returns:

u_, s, vh – numpy arrays with the SVD of the input array

Return type:

np.arrays

parent_hamiltonian_mps

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.mps.parent_hamiltonian_mps.PH_MPS(mps, 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_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

save()

Saving Staff

tnbs.BTC_04_PH.PH.mps.parent_hamiltonian_mps.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.mps.parent_hamiltonian_mps.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.mps.parent_hamiltonian_mps.reduced_rho_mps(mps, free_indices, contraction_indices)

Computes reduced density matrix by contracting first the MPS with NON contracted legs. Then compute the contraction of the MPS with contracted legs. Finally Contract the result of the Non Contracted operations with the Contracted Ones for getting the desired reduced density matrix. Try to alternate MPS contraction of states (free legs) with MPO contractions (contracted legs)

Parameters:
  • mps (list) – MPS representation of the state whose reduced density matrix want to be computed. Each element is a rank-3 tensor represented by a numpy array

  • free_indices (list) – List of the free index for computing the reduced density matrix

  • contraction_indices (list) – List with the contraction indices for computing the reduced density matrix. This qubits will be traced out.

Returns:

tensor_out – Array with the desired reduced density matrix

Return type:

np.array

tnbs.BTC_04_PH.PH.mps.parent_hamiltonian_mps.run_parent_hamiltonian(**configuration)

Computes Parent Hamiltonian for an ansatz

Parameters:
  • used (configuration is a kwargs. Following keys are the)

  • nqubits (*) – number of the qubits for the BTC ansatz

  • depth (*) – depth for the BTC ansatz

  • truncate (*) – for truncating the SVD. Float precision will be used as cuttoff

  • save (*) – for saving the results

  • folder (*) – Folder for storing the results.

Returns:

  • pauli_pdf (pandas DataFrame) – DataFrame with the Pauli decomposition of hte PH

  • pdf_angles (pandas DataFrame) – DataFrame with the angles for the BTC ansatz.