Beispiel #1
0
    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 = WeightedPauliOperator(
            paulis=[[1.0, Pauli.from_label('IIIZZZ')]])
        ref_qterm_b1 = WeightedPauliOperator(
            paulis=[[1.0, Pauli.from_label('IZZIIZ')]])
        ref_qterm_b2 = WeightedPauliOperator(
            paulis=[[1.0, Pauli.from_label('ZIZIZI')]])
        ref_qterm_b3 = WeightedPauliOperator(
            paulis=[[1.0, Pauli.from_label('ZZIZII')]])

        self.assertEqual(
            qterm_b0, ref_qterm_b0,
            "\n{} vs \n{}".format(qterm_b0.print_details(),
                                  ref_qterm_b0.print_details()))
        self.assertEqual(
            qterm_b1, ref_qterm_b1,
            "\n{} vs \n{}".format(qterm_b1.print_details(),
                                  ref_qterm_b1.print_details()))
        self.assertEqual(
            qterm_b2, ref_qterm_b2,
            "\n{} vs \n{}".format(qterm_b2.print_details(),
                                  ref_qterm_b2.print_details()))
        self.assertEqual(
            qterm_b3, ref_qterm_b3,
            "\n{} vs \n{}".format(qterm_b3.print_details(),
                                  ref_qterm_b3.print_details()))
Beispiel #2
0
    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 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('IIIIIX')]])
        ref_qterm_a02 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('IIIIXZ')]])
        ref_qterm_a03 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('IIIXZZ')]])
        ref_qterm_a12 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('IIXIZZ')]])
        ref_qterm_a13 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('IXZZIZ')]])
        ref_qterm_a23 = WeightedPauliOperator(paulis=[[1.0, Pauli.from_label('XZZZZI')]])

        self.assertEqual(qterm_a01, ref_qterm_a01, "\n{} vs \n{}".format(
            qterm_a01.print_details(), ref_qterm_a01.print_details()))
        self.assertEqual(qterm_a02, ref_qterm_a02, "\n{} vs \n{}".format(
            qterm_a02.print_details(), ref_qterm_a02.print_details()))
        self.assertEqual(qterm_a03, ref_qterm_a03, "\n{} vs \n{}".format(
            qterm_a03.print_details(), ref_qterm_a03.print_details()))
        self.assertEqual(qterm_a12, ref_qterm_a12, "\n{} vs \n{}".format(
            qterm_a12.print_details(), ref_qterm_a12.print_details()))
        self.assertEqual(qterm_a13, ref_qterm_a13, "\n{} vs \n{}".format(
            qterm_a13.print_details(), ref_qterm_a13.print_details()))
        self.assertEqual(qterm_a23, ref_qterm_a23, "\n{} vs \n{}".format(
            qterm_a23.print_details(), ref_qterm_a23.print_details()))
Beispiel #3
0
    def test_simplify_same_paulis(self):
        """ simplify same paulis test """
        pauli_a = 'IXYZ'
        pauli_b = 'IXYZ'
        coeff_a = 0.5
        coeff_b = 0.5
        pauli_term_a = [coeff_a, Pauli.from_label(pauli_a)]
        pauli_term_b = [coeff_b, Pauli.from_label(pauli_b)]
        op_a = WeightedPauliOperator(paulis=[pauli_term_a, pauli_term_b])

        self.assertEqual(1, len(op_a.paulis), "{}".format(op_a.print_details()))
        self.assertEqual(1, len(op_a.basis))
        self.assertEqual(0, op_a.basis[0][1][0])