From 123cf4312b22940415a03fc5f855a1373ac208d7 Mon Sep 17 00:00:00 2001 From: obliviateandsurrender Date: Sun, 14 Jul 2024 19:51:48 -0400 Subject: [PATCH] minor tweaks --- pennylane_qiskit/converter.py | 9 +++------ tests/test_noise_models.py | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pennylane_qiskit/converter.py b/pennylane_qiskit/converter.py index e0119472..2bbf107b 100644 --- a/pennylane_qiskit/converter.py +++ b/pennylane_qiskit/converter.py @@ -1094,11 +1094,11 @@ def load_noise_model(noise_model, **kwargs) -> qml.NoiseModel: >>> error_1 = noise.depolarizing_error(0.001, 1) # 1-qubit noise >>> error_2 = noise.depolarizing_error(0.01, 2) # 2-qubit noise >>> noise_model = noise.NoiseModel() - >>> noise_model.add_all_qubit_quantum_error(error_1, ['rz', 'ry']) # rz/ry gates get error_1 - >>> noise_model.add_all_qubit_quantum_error(error_2, ['cx']) # cx gates get error_2 + >>> noise_model.add_all_qubit_quantum_error(error_1, ['rz', 'ry']) + >>> noise_model.add_all_qubit_quantum_error(error_2, ['cx']) >>> load_noise_model(noise_model) NoiseModel({ - OpIn(['RZ', 'RY']): DepolarizingChannel(p=0.0007499999999999174) + OpIn(['RZ', 'RY']): DepolarizingChannel(p=0.00075) OpIn(['CNOT']): QubitChannel(Klist=Tensor(16, 4, 4)) }) @@ -1129,17 +1129,14 @@ def load_noise_model(noise_model, **kwargs) -> qml.NoiseModel: equivalent_pl_noise_model = qml.NoiseModel({c0: n0, c1: n1}) """ - qerror_dmap, _ = _build_noise_model_map(noise_model, **kwargs) model_map = {} for error, wires_map in qerror_dmap.items(): conditions = [] - cwires = [] for wires, operations in wires_map.items(): cond = qml.noise.op_in(operations) if wires != AnyWires: cond &= WiresIn(wires) - cwires.append(wires) conditions.append(cond) fcond = reduce(lambda cond1, cond2: cond1 | cond2, conditions) diff --git a/tests/test_noise_models.py b/tests/test_noise_models.py index c59ac23a..166a5c10 100644 --- a/tests/test_noise_models.py +++ b/tests/test_noise_models.py @@ -209,7 +209,7 @@ def test_build_model_map(self, depol1, depol2, exc_pop): ], ) def test_thermal_gate_times(self, t_times, gate_times): - """Tests that a quantum error can be correctly converted into a PennyLane QubitChannel.""" + """Tests that thermal relaxation computation uses provided gate times.""" pl_channels, pl_vals = [], [] noise_model = noise.NoiseModel() @@ -228,3 +228,26 @@ def test_thermal_gate_times(self, t_times, gate_times): assert list(model_map.keys()) == pl_channels assert list(model_map.values()) == pl_vals + + @pytest.mark.parametrize( + "combination, p_error", + [ + (lambda err1, err2: err1.compose(err2), 0.052), + (lambda err1, err2: err1.tensor(err2), 0.037), + (lambda err1, err2: err1.expand(err2), 0.094), + ], + ) + def test_composition_error_ops(self, combination, p_error): + """Tests that combination of quantum errors can be correctly converted into a PennyLane QubitChannel.""" + + bit_flip = noise.pauli_error([("X", p_error), ("I", 1 - p_error)]) + phase_flip = noise.pauli_error([("Z", p_error), ("I", 1 - p_error)]) + + combined_error = combination(bit_flip, phase_flip) + pl_op_from_qiskit = _build_qerror_op(combined_error) + + choi_mat1 = _kraus_to_choi(Kraus(combined_error)) + choi_mat2 = _kraus_to_choi( + Kraus(list(pl_op_from_qiskit.compute_kraus_matrices(*pl_op_from_qiskit.data))) + ) + assert np.allclose(choi_mat1, choi_mat2)