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

Fix qubit filtering in BackendV2Converter with add_delay #10015

Merged
merged 1 commit into from
Apr 25, 2023
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
9 changes: 5 additions & 4 deletions qiskit/providers/backend_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ def convert_to_target(
target = None
if custom_name_mapping is not None:
name_mapping.update(custom_name_mapping)
faulty_qubits = set()
# Parse from properties if it exsits
if properties is not None:
if filter_faulty:
faulty_qubits = set(properties.faulty_qubits())
qubit_properties = qubit_props_list_from_props(properties=properties)
target = Target(num_qubits=configuration.n_qubits, qubit_properties=qubit_properties)
# Parse instructions
Expand Down Expand Up @@ -137,9 +140,6 @@ def convert_to_target(
target.acquire_alignment = configuration.timing_constraints.get("acquire_alignment")
# If a pulse defaults exists use that as the source of truth
if defaults is not None:
faulty_qubits = set()
if filter_faulty and properties is not None:
faulty_qubits = set(properties.faulty_qubits())
inst_map = defaults.instruction_schedule_map
for inst in inst_map.instructions:
for qarg in inst_map.qubits_with_instruction(inst):
Expand Down Expand Up @@ -174,7 +174,8 @@ def convert_to_target(
)
if add_delay and "delay" not in target:
target.add_instruction(
name_mapping["delay"], {(bit,): None for bit in range(target.num_qubits)}
name_mapping["delay"],
{(bit,): None for bit in range(target.num_qubits) if bit not in faulty_qubits},
)
return target

Expand Down
21 changes: 21 additions & 0 deletions test/python/providers/test_fake_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,27 @@ def test_filter_faulty_qubits_backend_v2_converter(self):
for qarg in v2_backend.target.qargs:
self.assertNotIn(i, qarg)

def test_filter_faulty_qubits_backend_v2_converter_with_delay(self):
"""Test faulty qubits in v2 conversion."""
backend = FakeWashington()
# Get properties dict to make it easier to work with the properties API
# is difficult to edit because of the multiple layers of nesting and
# different object types
props_dict = backend.properties().to_dict()
for i in range(62, 67):
non_operational = {
"date": datetime.datetime.utcnow(),
"name": "operational",
"unit": "",
"value": 0,
}
props_dict["qubits"][i].append(non_operational)
backend._properties = BackendProperties.from_dict(props_dict)
v2_backend = BackendV2Converter(backend, filter_faulty=True, add_delay=True)
for i in range(62, 67):
for qarg in v2_backend.target.qargs:
self.assertNotIn(i, qarg)

def test_filter_faulty_qubits_and_gates_backend_v2_converter(self):
"""Test faulty gates and qubits."""
backend = FakeWashington()
Expand Down