예제 #1
0
 def test_raise_compose_different_dim(self):
     """Test composing incompatible errors raises exception"""
     error0 = QuantumError([np.diag([1, 1, 1,
                                     -1])])  # 2-qubit coherent error
     error1 = QuantumError([np.diag([1, -1])])  # 1-qubit coherent error
     self.assertRaises(NoiseError, lambda: error0.compose(error1))
     self.assertRaises(NoiseError, lambda: error1.compose(error0))
예제 #2
0
 def test_compose_with_different_type_of_operator(self):
     """Test compose with Kraus operator."""
     noise_x = QuantumError([((IGate(), [0]), 0.9), ((XGate(), [0]), 0.1)])
     meas_kraus = Kraus([np.diag([1, 0]),
                         np.diag([0, 1])])
     actual = noise_x.compose(meas_kraus)
     expected = QuantumError([([(IGate(), [0]), (meas_kraus.to_instruction(), [0])], 0.9),
                              ([(XGate(), [0]), (meas_kraus.to_instruction(), [0])], 0.1)])
     self.assertEqual(actual, expected)
예제 #3
0
 def test_compose_one_with_different_num_qubits(self):
     """Test compose errors with different number of qubits."""
     noise_1q = QuantumError([((IGate(), [0]), 0.9), ((XGate(), [0]), 0.1)])
     noise_2q = QuantumError([((IGate(), [0]), 0.8), ((XGate(), [1]), 0.2)])
     actual = noise_1q.compose(noise_2q)
     expected = QuantumError([([(IGate(), [0]), (IGate(), [0])], 0.9 * 0.8),
                              ([(IGate(), [0]), (XGate(), [1])], 0.9 * 0.2),
                              ([(XGate(), [0]), (IGate(), [0])], 0.1 * 0.8),
                              ([(XGate(), [0]), (XGate(), [1])], 0.1 * 0.2)])
     self.assertEqual(actual, expected)
예제 #4
0
 def test_compose(self):
     """Test compose two quantum errors."""
     noise_x = QuantumError([((IGate(), [0]), 0.9), ((XGate(), [0]), 0.1)])
     noise_y = QuantumError([((IGate(), [0]), 0.8), ((YGate(), [0]), 0.2)])
     actual = noise_x.compose(noise_y)
     expected = QuantumError([([(IGate(), [0]), (IGate(), [0])], 0.9 * 0.8),
                              ([(IGate(), [0]), (YGate(), [0])], 0.9 * 0.2),
                              ([(XGate(), [0]), (IGate(), [0])], 0.1 * 0.8),
                              ([(XGate(), [0]), (YGate(), [0])], 0.1 * 0.2)])
     self.assertEqual(actual, expected)
예제 #5
0
    def test_compose_both_unitary_standard_gates(self):
        """Test compose of two unitary standard gate errors"""
        unitaries0 = self.mixed_unitary_error([0.9, 0.1], ['z', 's'])
        unitaries1 = self.mixed_unitary_error([0.6, 0.4], ['x', 'y'])
        error0 = QuantumError(unitaries0, standard_gates=True)
        error1 = QuantumError(unitaries1, standard_gates=True)
        error = error0.compose(error1)
        target = SuperOp(Kraus(unitaries0)).compose(Kraus(unitaries1))

        for j in range(4):
            circ, _ = error.error_term(j)
            self.assertIn(circ[0]['name'], ['s', 'x', 'y', 'z'])
            self.assertEqual(circ[0]['qubits'], [0])
        self.assertEqual(SuperOp(error), target)