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 build filter coupling map with mix ideal/physical targets (backport #11009) #11049

Merged
merged 3 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def build_coupling_map(self, two_q_gate=None, filter_idle_qubits=False):
return None

def _filter_coupling_graph(self):
has_operations = set(itertools.chain.from_iterable(self.qargs))
has_operations = set(itertools.chain.from_iterable(x for x in self.qargs if x is not None))
graph = self._coupling_graph.copy()
to_remove = set(graph.node_indices()).difference(has_operations)
if to_remove:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixed an issue in the :meth:`.Target.build_coupling_map` method when the
``filter_idle_qubits`` argument was set to ``True`` and there was a mix
of fixed width ideal and physical instructions in the target. In these cases
previously the :meth:`.Target.build_coupling_map` would have raised an
exception because it was assuming all instructions in the target were
physical and defined over qubits.
17 changes: 17 additions & 0 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,23 @@ def test_coupling_map(self):
set(self.ibm_target.build_coupling_map().get_edges()),
)

def test_mixed_ideal_target_filtered_coupling_map(self):
target = Target(num_qubits=10)
target.add_instruction(
XGate(), {(qubit,): InstructionProperties(error=0.5) for qubit in range(5)}
)
target.add_instruction(
CXGate(),
{
edge: InstructionProperties(error=0.6)
for edge in CouplingMap.from_line(5, bidirectional=False).get_edges()
},
)
target.add_instruction(SXGate())
coupling_map = target.build_coupling_map(filter_idle_qubits=True)
self.assertEqual(max(coupling_map.physical_qubits), 4)
self.assertEqual(coupling_map.get_edges(), [(0, 1), (1, 2), (2, 3), (3, 4)])


class TestInstructionProperties(QiskitTestCase):
def test_empty_repr(self):
Expand Down