Skip to content

Commit

Permalink
Improve test for mapping
Browse files Browse the repository at this point in the history
Not super important, but was an open todo.
  • Loading branch information
Ectras committed Mar 26, 2024
1 parent 801f8b9 commit 158faa6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/tools/test_mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""""""
from src.provider import Accelerator, IBMQBackend

from src.provider import IBMQBackend
from src.tools import map_circuit
from tests.helpers import create_ghz

Expand All @@ -8,7 +9,19 @@ def test_map_circuit() -> None:
"""_summary_"""
circuit = create_ghz(5)
backend = IBMQBackend.BELEM
accelerator = Accelerator(backend)
circuit, _ = map_circuit(circuit, accelerator.backend)
# TODO better assertion
assert circuit.num_qubits == 5
circuit, _ = map_circuit(circuit, backend)

# Check the mapped circuit against the backend's coupling map
edges = backend.value().coupling_map.get_edges()
for [_, qubits, _] in circuit.data:
indices = [circuit.find_bit(qubit).index for qubit in qubits]
if len(indices) == 1:
# Single qubit gates are always possible
continue
elif len(indices) == 2:
# Check if the two qubits are indeed physically connected
[a, b] = indices
assert (a, b) in edges
else:
# Don't know how multi-qubit gates are handled in the coupling map
raise NotImplementedError

0 comments on commit 158faa6

Please sign in to comment.