def test_dot(self): """Test dot 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_y.dot(noise_x) # reversed order of compose 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)
def test_dot_both_unitary_standard_gates(self): """Test dot 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.dot(error1) target = SuperOp(Kraus(unitaries0)).dot(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)