venv/src/simulators/matrix_product_state/matrix_product_state_internal.cpp
//-------------------------------------------------------------------------
// MPS::apply_2_qubit_gate - outline of the algorithm
// 1. Swap qubits A and B until they are consecutive
// 2. Contract MPS_Tensor[A] and MPS_Tensor[B], yielding a temporary four-matrix MPS_Tensor 
//    that represents the entangled states of A and B.
// 3. Apply the gate
// 4. Decompose the temporary MPS_Tensor (using SVD) into U*S*V, where U and V are matrices
//    and S is a diagonal matrix
// 5. U is split by rows to yield two MPS_Tensors representing qubit A (in reshape_U_after_SVD), 
//    V is split by columns to yield two MPS_Tensors representing qubit B (in reshape_V_after_SVD),
//    the diagonal of S becomes the Lambda-vector in between A and B.
//-------------------------------------------------------------------------
:apply_2_qubit_gate - outline of the algorithm
1. Swap qubits A and B until they are consecutive
2. Contract MPS_Tensor[A] and MPS_Tensor[B], yielding a temporary four-matrix MPS_Tensor
that represents the entangled states of A and B.
3. Apply the gate
4. Decompose the temporary MPS_Tensor (using SVD) into U*S*V, where U and V are matrices
and S is a diagonal matrix
5. U is split by rows to yield two MPS_Tensors representing qubit A (in reshape_U_after_SVD),
V is split by columns to yield two MPS_Tensors representing qubit B (in reshape_V_after_SVD),
the diagonal of S becomes the Lambda-vector in between A and B.
: apply_2_qubit_gate - outline of the algorithm 1 . Swap qubits A and B until they are consecutive 2 . Contract MPS_Tensor [ A ] and MPS_Tensor [ B ] yielding a temporary four - matrix MPS_Tensor that represents the entangled states of A and B . 3 . Apply the gate 4 . Decompose the temporary MPS_Tensor ( using SVD ) into U * S * V where U and V are matrices and S is a diagonal matrix 5 . U is split by rows to yield two MPS_Tensors representing qubit A ( in reshape_U_after_SVD ) V is split by columns to yield two MPS_Tensors representing qubit B ( in reshape_V_after_SVD ) the diagonal of S becomes the Lambda - vector in between A and B .
void MPS::apply_2_qubit_gate(uint_t index_A, uint_t index_B, Gates gate_type, const cmatrix_t &mat)
{
  uint_t A = index_A;
  bool swapped = false;
  if (index_B > index_A+1) {
    change_position(index_B, index_A+1);  
  } else if (index_A > 0 && index_B < index_A-1) {
    change_position(index_B, index_A-1);  
  }
  if (index_B < index_A) {
    A = index_A - 1;
    swapped = true;
  }
  common_apply_2_qubit_gate(A, gate_type, mat, swapped);
}
void MPS :: apply_2_qubit_gate ( uint_t index_A , uint_t index_B , Gates gate_type , const cmatrix_t & mat ) { uint_t A = index_A ; bool swapped = false ; if ( index_B > index_A + 1 ) { change_position ( index_B , index_A + 1 ) ; } else if ( index_A > 0 && index_B < index_A - 1 ) { change_position ( index_B , index_A - 1 ) ; } if ( index_B < index_A ) { A = index_A - 1 ; swapped = true ; } common_apply_2_qubit_gate ( A , gate_type , mat , swapped ) ; }
MPS::apply_2_qubit_gate - outline of the algorithm
1.
MPS :: apply_2_qubit_gate - outline of the algorithm 1 .
// We first move the two qubits to be in consecutive positions // If index_B > index_A, we move the qubit at index_B to index_A+1 // If index_B < index_A, we move the qubit at index_B to index_A-1, and then // swap between the qubits // Move B to be right after A // Move B to be right before A