def test_dot_both_kraus(self):
     """Test dot of two kraus errors"""
     a_0 = np.array([[1, 0], [0, np.sqrt(1 - 0.3)]], dtype=complex)
     a_1 = np.array([[0, 0], [0, np.sqrt(0.3)]], dtype=complex)
     b_0 = np.array([[1, 0], [0, np.sqrt(1 - 0.5)]], dtype=complex)
     b_1 = np.array([[0, 0], [0, np.sqrt(0.5)]], dtype=complex)
     # Use quantum channels for reference
     target = SuperOp(Kraus([b_0, b_1]).compose(Kraus([a_0, a_1])))
     # dot method
     error = QuantumError([a_0, a_1]).dot(QuantumError([b_0, b_1]))
     kraus, prob = error.error_term(0)
     self.assertEqual(prob, 1)
     self.assertEqual(kraus[0]['name'], 'kraus')
     self.assertEqual(kraus[0]['qubits'], [0])
     error_superop = SuperOp(Kraus(kraus[0]['params']))
     self.assertEqual(target,
                      error_superop,
                      msg="Incorrect kraus dot method")
     # * method
     error = QuantumError([a_0, a_1]) * QuantumError([b_0, b_1])
     kraus, prob = error.error_term(0)
     self.assertEqual(prob, 1)
     self.assertEqual(kraus[0]['name'], 'kraus')
     self.assertEqual(kraus[0]['qubits'], [0])
     error_superop = SuperOp(Kraus(kraus[0]['params']))
     self.assertEqual(target,
                      error_superop,
                      msg="Incorrect kraus dot method")
Example #2
0
 def test_compose_both_kraus(self):
     """Test composition of two kraus errors"""
     A0 = np.array([[1, 0], [0, np.sqrt(1 - 0.3)]], dtype=complex)
     A1 = np.array([[0, 0], [0, np.sqrt(0.3)]], dtype=complex)
     B0 = np.array([[1, 0], [0, np.sqrt(1 - 0.5)]], dtype=complex)
     B1 = np.array([[0, 0], [0, np.sqrt(0.5)]], dtype=complex)
     # Use quantum channels for reference
     target = SuperOp(Kraus([A0, A1]).compose(Kraus([B0, B1])))
     error = QuantumError([A0, A1]).compose(QuantumError([B0, B1]))
     kraus, p = error.error_term(0)
     self.assertEqual(p, 1)
     self.assertEqual(kraus[0]['name'], 'kraus')
     self.assertEqual(kraus[0]['qubits'], [0])
     error_superop = SuperOp(Kraus(kraus[0]['params']))
     self.assertEqual(target, error_superop, msg="Incorrect compose kraus")
Example #3
0
 def test_compose_both_kraus(self):
     """Test composition of two kraus errors"""
     A0 = np.array([[1, 0], [0, np.sqrt(1 - 0.3)]])
     A1 = np.array([[0, 0], [0, np.sqrt(0.3)]])
     B0 = np.array([[1, 0], [0, np.sqrt(1 - 0.5)]])
     B1 = np.array([[0, 0], [0, np.sqrt(0.5)]])
     error = QuantumError([A0, A1]).compose(QuantumError([B0, B1]))
     kraus, p = error.error_term(0)
     targets = [np.dot(B0, A0), np.dot(B0, A1),
                np.dot(B1, A0), np.dot(B1, A1)]
     self.assertEqual(p, 1)
     self.assertEqual(kraus[0]['name'], 'kraus')
     self.assertEqual(kraus[0]['qubits'], [0])
     for op in kraus[0]['params']:
         self.remove_if_found(op, targets)
     self.assertEqual(targets, [], msg="Incorrect compose kraus")
Example #4
0
 def test_expand_both_kraus(self):
     """Test expand of two kraus errors"""
     A0 = np.array([[1, 0], [0, np.sqrt(1 - 0.3)]], dtype=complex)
     A1 = np.array([[0, 0], [0, np.sqrt(0.3)]], dtype=complex)
     B0 = np.array([[1, 0], [0, np.sqrt(1 - 0.5)]], dtype=complex)
     B1 = np.array([[0, 0], [0, np.sqrt(0.5)]], dtype=complex)
     error = QuantumError([A0, A1]).expand(QuantumError([B0, B1]))
     kraus, p = error.error_term(0)
     targets = [
         np.kron(B0, A0),
         np.kron(B1, A0),
         np.kron(B0, A1),
         np.kron(B1, A1)
     ]
     self.assertEqual(p, 1)
     self.assertEqual(kraus[0]['name'], 'kraus')
     self.assertEqual(kraus[0]['qubits'], [0, 1])
     for op in kraus[0]['params']:
         self.remove_if_found(op, targets)
     self.assertEqual(targets, [], msg="Incorrect expand kraus")