def test_kraus_error(self): """Test Kraus error when input is list instead of numpy array""" A0 = [[1, 0], [0, np.sqrt(1 - 0.3)]] A1 = [[0, 0], [0, np.sqrt(0.3)]] kraus_mats = [A0, A1] actual = kraus_error(kraus_mats) expected_circ = QuantumCircuit(1) expected_circ.append(qi.Kraus(kraus_mats), [0]) circ, p = actual.error_term(0) self.assertEqual(circ, expected_circ) self.assertEqual(p, 1)
def test_kraus_error(self): """Test Kraus error when input is list instead of numpy array""" A0 = [[1, 0], [0, np.sqrt(1 - 0.3)]] A1 = [[0, 0], [0, np.sqrt(0.3)]] targets = [A0, A1] error = kraus_error(targets) circ, p = error.error_term(0) self.assertEqual(p, 1) kraus = circ[0] self.assertEqual(kraus['name'], 'kraus') self.assertEqual(kraus['qubits'], [0]) for op in kraus['params']: self.remove_if_found(op, targets) self.assertEqual(targets, [], msg="Incorrect kraus QuantumError")
def test_noise_models_equal(self): """Test two noise models are Equal""" roerror = [[0.9, 0.1], [0.5, 0.5]] error1 = kraus_error([np.diag([1, 0]), np.diag([0, 1])]) error2 = pauli_error([("I", 0.5), ("Z", 0.5)]) model1 = NoiseModel() model1.add_all_qubit_quantum_error(error1, ['u3'], False) model1.add_quantum_error(error1, ['u3'], [2], False) with self.assertWarns(DeprecationWarning): model1.add_nonlocal_quantum_error(error1, ['cx'], [0, 1], [3], False) model1.add_all_qubit_readout_error(roerror, False) model1.add_readout_error(roerror, [0], False) model2 = NoiseModel() model2.add_all_qubit_quantum_error(error2, ['u3'], False) model2.add_quantum_error(error2, ['u3'], [2], False) with self.assertWarns(DeprecationWarning): model2.add_nonlocal_quantum_error(error2, ['cx'], [0, 1], [3], False) model2.add_all_qubit_readout_error(roerror, False) model2.add_readout_error(roerror, [0], False) self.assertEqual(model1, model2)