Skip to content

Commit

Permalink
Setting noise_info to false in GenericBackendV2 creates issues later …
Browse files Browse the repository at this point in the history
…in the transpiler pipeline (#12769)

* up

* fix

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <[email protected]>

* lint

---------

Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
sbrandhsn and ElePT authored Jul 26, 2024
1 parent 4ec51d1 commit edf0b53
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
4 changes: 3 additions & 1 deletion qiskit/providers/fake_provider/generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ def _build_generic_target(self):
noise_params = self._get_noise_defaults(name, gate.num_qubits)
self._add_noisy_instruction_to_target(gate, noise_params, calibration_inst_map)
else:
self._target.add_instruction(gate, properties=None, name=name)
qarg_set = self._coupling_map if gate.num_qubits > 1 else range(self.num_qubits)
props = {(qarg,) if isinstance(qarg, int) else qarg: None for qarg in qarg_set}
self._target.add_instruction(gate, properties=props, name=name)

if self._control_flow:
self._target.add_instruction(IfElseOp, name="if_else")
Expand Down
61 changes: 59 additions & 2 deletions test/python/providers/fake_provider/test_generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.quantum_info import Operator
from qiskit.transpiler import CouplingMap
from qiskit.exceptions import QiskitError
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from test import QiskitTestCase # pylint: disable=wrong-import-order


Expand Down Expand Up @@ -57,12 +59,67 @@ def test_calibration_no_noise_info(self):

def test_no_noise(self):
"""Test no noise info when parameter is false"""
backend = GenericBackendV2(num_qubits=2, noise_info=False)
backend = GenericBackendV2(
num_qubits=5, coupling_map=CouplingMap.from_line(5), noise_info=False
)
qc = QuantumCircuit(5)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(1, 4)
qc.cx(3, 0)
qc.cx(2, 4)
qc_res = generate_preset_pass_manager(optimization_level=2, backend=backend).run(qc)
self.assertTrue(Operator.from_circuit(qc_res).equiv(qc))
self.assertEqual(backend.target.qubit_properties, None)

def test_no_noise_fully_connected(self):
"""Test no noise info when parameter is false"""
backend = GenericBackendV2(num_qubits=5, noise_info=False)
qc = QuantumCircuit(5)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(1, 4)
qc.cx(3, 0)
qc.cx(2, 4)
qc_res = generate_preset_pass_manager(optimization_level=2, backend=backend).run(qc)
self.assertTrue(Operator.from_circuit(qc_res).equiv(qc))
self.assertEqual(backend.target.qubit_properties, None)

def test_no_info(self):
"""Test no noise info when parameter is false"""
backend = GenericBackendV2(
num_qubits=5,
coupling_map=CouplingMap.from_line(5),
noise_info=False,
pulse_channels=False,
)
qc = QuantumCircuit(5)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(1, 4)
qc.cx(3, 0)
qc.cx(2, 4)
qc_res = generate_preset_pass_manager(optimization_level=2, backend=backend).run(qc)
self.assertTrue(Operator.from_circuit(qc_res).equiv(qc))
self.assertEqual(backend.target.qubit_properties, None)

def test_no_pulse_channels(self):
"""Test no/empty pulse channels when parameter is false"""
backend = GenericBackendV2(num_qubits=2, pulse_channels=False)
backend = GenericBackendV2(
num_qubits=5, coupling_map=CouplingMap.from_line(5), pulse_channels=False
)
qc = QuantumCircuit(5)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.cx(1, 4)
qc.cx(3, 0)
qc.cx(2, 4)
qc_res = generate_preset_pass_manager(optimization_level=2, backend=backend).run(qc)
self.assertTrue(Operator.from_circuit(qc_res).equiv(qc))
self.assertTrue(len(backend.channels_map) == 0)

def test_operation_names(self):
Expand Down

0 comments on commit edf0b53

Please sign in to comment.