def test_bksf_edge_op_bi(self): """Test bksf mapping, edge operator bi""" edge_matrix = np.triu(np.ones((4, 4))) edge_list = np.array( np.nonzero(np.triu(edge_matrix) - np.diag(np.diag(edge_matrix)))) qterm_b0 = edge_operator_bi(edge_list, 0) qterm_b1 = edge_operator_bi(edge_list, 1) qterm_b2 = edge_operator_bi(edge_list, 2) qterm_b3 = edge_operator_bi(edge_list, 3) ref_qterm_b0 = Operator(paulis=[[1.0, Pauli.from_label('IIIZZZ')]]) ref_qterm_b1 = Operator(paulis=[[1.0, Pauli.from_label('IZZIIZ')]]) ref_qterm_b2 = Operator(paulis=[[1.0, Pauli.from_label('ZIZIZI')]]) ref_qterm_b3 = Operator(paulis=[[1.0, Pauli.from_label('ZZIZII')]]) self.assertEqual( qterm_b0, ref_qterm_b0, "\n{} vs \n{}".format(qterm_b0.print_operators(), ref_qterm_b0.print_operators())) self.assertEqual( qterm_b1, ref_qterm_b1, "\n{} vs \n{}".format(qterm_b1.print_operators(), ref_qterm_b1.print_operators())) self.assertEqual( qterm_b2, ref_qterm_b2, "\n{} vs \n{}".format(qterm_b2.print_operators(), ref_qterm_b2.print_operators())) self.assertEqual( qterm_b3, ref_qterm_b3, "\n{} vs \n{}".format(qterm_b3.print_operators(), ref_qterm_b3.print_operators()))
def test_zero_elimination(self): pauli_a = 'IXYZ' coeff_a = 0.0 pauli_term_a = [coeff_a, Pauli.from_label(pauli_a)] op_a = Operator(paulis=[pauli_term_a]) self.assertEqual(1, len(op_a.paulis), "{}".format(op_a.print_operators())) op_a.zeros_coeff_elimination() self.assertEqual(0, len(op_a.paulis), "{}".format(op_a.print_operators()))
def test_bksf_edge_op_aij(self): """Test bksf mapping, edge operator aij""" edge_matrix = np.triu(np.ones((4, 4))) edge_list = np.array(np.nonzero(np.triu(edge_matrix) - np.diag(np.diag(edge_matrix)))) qterm_a01 = edge_operator_aij(edge_list, 0, 1) qterm_a02 = edge_operator_aij(edge_list, 0, 2) qterm_a03 = edge_operator_aij(edge_list, 0, 3) qterm_a12 = edge_operator_aij(edge_list, 1, 2) qterm_a13 = edge_operator_aij(edge_list, 1, 3) qterm_a23 = edge_operator_aij(edge_list, 2, 3) ref_qterm_a01 = Operator(paulis=[[1.0, Pauli.from_label('IIIIIX')]]) ref_qterm_a02 = Operator(paulis=[[1.0, Pauli.from_label('IIIIXZ')]]) ref_qterm_a03 = Operator(paulis=[[1.0, Pauli.from_label('IIIXZZ')]]) ref_qterm_a12 = Operator(paulis=[[1.0, Pauli.from_label('IIXIZZ')]]) ref_qterm_a13 = Operator(paulis=[[1.0, Pauli.from_label('IXZZIZ')]]) ref_qterm_a23 = Operator(paulis=[[1.0, Pauli.from_label('XZZZZI')]]) self.assertEqual(qterm_a01, ref_qterm_a01, "\n{} vs \n{}".format( qterm_a01.print_operators(), ref_qterm_a01.print_operators())) self.assertEqual(qterm_a02, ref_qterm_a02, "\n{} vs \n{}".format( qterm_a02.print_operators(), ref_qterm_a02.print_operators())) self.assertEqual(qterm_a03, ref_qterm_a03, "\n{} vs \n{}".format( qterm_a03.print_operators(), ref_qterm_a03.print_operators())) self.assertEqual(qterm_a12, ref_qterm_a12, "\n{} vs \n{}".format( qterm_a12.print_operators(), ref_qterm_a12.print_operators())) self.assertEqual(qterm_a13, ref_qterm_a13, "\n{} vs \n{}".format( qterm_a13.print_operators(), ref_qterm_a13.print_operators())) self.assertEqual(qterm_a23, ref_qterm_a23, "\n{} vs \n{}".format( qterm_a23.print_operators(), ref_qterm_a23.print_operators()))