diff --git a/qiskit/providers/fake_provider/generic_backend_v2.py b/qiskit/providers/fake_provider/generic_backend_v2.py index 0da1df7eab65..5a7e1a29aa4f 100644 --- a/qiskit/providers/fake_provider/generic_backend_v2.py +++ b/qiskit/providers/fake_provider/generic_backend_v2.py @@ -406,7 +406,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") diff --git a/test/python/providers/fake_provider/test_generic_backend_v2.py b/test/python/providers/fake_provider/test_generic_backend_v2.py index 33bf57cf3903..70ac50f659c9 100644 --- a/test/python/providers/fake_provider/test_generic_backend_v2.py +++ b/test/python/providers/fake_provider/test_generic_backend_v2.py @@ -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 @@ -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):