Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting noise_info to false in GenericBackendV2 creates issues later in the transpiler pipeline #12769

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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")
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
Loading