Skip to content

Commit

Permalink
Add future facing test for shared classical bits between components
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Mar 23, 2023
1 parent 1829d05 commit 78bdfb0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import sys
import math
import unittest

from logging import StreamHandler, getLogger
from unittest.mock import patch
Expand Down Expand Up @@ -2150,6 +2151,50 @@ def _visit_block(circuit, qubit_mapping=None):
qubit_mapping={qubit: index for index, qubit in enumerate(tqc.qubits)},
)

@unittest.skip("Skip until separate_dag() works only considering the classical component")
def test_disjoint_control_flow_shared_classical(self):
"""Test circuit with classical data dependency between conencted components."""
creg = ClassicalRegister(19)
qc = QuantumCircuit(25)
qc.add_register(creg)
qc.h(0)
for i in range(19):
qc.cx(0, i + 1)
qc.measure(i, creg[i])
with qc.if_test((creg, 0)):
qc.h(20)
qc.ecr(20, 21)
qc.ecr(20, 22)
qc.ecr(20, 23)
qc.ecr(20, 24)
target = self.backend.target
target.add_instruction(Reset(), {(i,): None for i in range(target.num_qubits)})
target.add_instruction(IfElseOp, name="if_else")
tqc = transpile(qc, target=target)
edges = set(target.build_coupling_map().graph.edge_list())

def _visit_block(circuit, qubit_mapping=None):
for instruction in circuit:
if instruction.operation.name == "barrier":
continue
qargs = tuple(qubit_mapping[x] for x in instruction.qubits)
self.assertTrue(target.instruction_supported(instruction.operation.name, qargs))
if isinstance(instruction.operation, ControlFlowOp):
for block in instruction.operation.blocks:
new_mapping = {
inner: qubit_mapping[outer]
for outer, inner in zip(instruction.qubits, block.qubits)
}
_visit_block(block, new_mapping)
elif len(qargs) == 2:
self.assertIn(qargs, edges)
self.assertIn(instruction.operation.name, target)

_visit_block(
tqc,
qubit_mapping={qubit: index for index, qubit in enumerate(tqc.qubits)},
)

# Add level 0 and 1 when TrivialLayout supports disjoint coupling maps
# Tagged as slow until #9834 is fixed
@slow_test
Expand Down

0 comments on commit 78bdfb0

Please sign in to comment.