Skip to content

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
obliviateandsurrender committed Jul 14, 2024
1 parent 9f5f96c commit 123cf43
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
9 changes: 3 additions & 6 deletions pennylane_qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -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)

Expand Down
25 changes: 24 additions & 1 deletion tests/test_noise_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit 123cf43

Please sign in to comment.