Skip to content

Commit

Permalink
merged main and renabled checkmap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewinston committed Sep 30, 2022
1 parent 8ec9259 commit 302320d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion qiskit/transpiler/passes/routing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def route_cf_multiblock(tpass, cf_opnode, current_layout, qregs, root_dag, seed=
updated_dag_block = tpass.run(full_dag_block)
block_dags.append(updated_dag_block)
block_layouts.append(tpass.property_set["final_layout"].copy())
depth_cnt = [bdag.depth() for bdag in block_dags]
depth_cnt = [bdag.depth(recurse=True) for bdag in block_dags]
maxind = np.argmax(depth_cnt)
block_circuits = [None] * len(block_layouts)
p2v = current_layout._p2v
Expand Down
6 changes: 3 additions & 3 deletions qiskit/transpiler/passes/utils/check_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def run(self, dag):
qubit_indices = {bit: index for index, bit in enumerate(dag.qubits)}
# Use dist matrix directly to avoid validation overhead
dist_matrix = self.coupling_map.distance_matrix

cf_ops = dag.op_nodes(op=ControlFlowOp)
for gate in dag.two_qubit_ops():
if dag.has_calibration_for(gate):
if dag.has_calibration_for(gate) or gate in cf_ops:
continue
physical_q0 = qubit_indices[gate.qargs[0]]
physical_q1 = qubit_indices[gate.qargs[1]]
Expand All @@ -67,7 +67,7 @@ def run(self, dag):
)
self.property_set["is_swap_mapped"] = False
return
for cf_instr in dag.op_nodes(op=ControlFlowOp):
for cf_instr in cf_ops:
order = [qubit_indices[bit] for bit in cf_instr.qargs]
for block in cf_instr.op.blocks:
dag_block = circuit_to_dag(block)
Expand Down
49 changes: 25 additions & 24 deletions test/python/transpiler/test_stochastic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ def test_controlflow_pre_if_else_route(self):
expected.barrier(qreg)
expected.measure(qreg, creg[new_order])
self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_pre_if_else_route_post_x(self):
"""test swap with if else controlflow construct; pre-cx and post x"""
Expand Down Expand Up @@ -650,9 +650,9 @@ def test_controlflow_pre_if_else_route_post_x(self):
expected.measure(qreg, creg[new_order])

self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_post_if_else_route(self):
"""test swap with if else controlflow construct; post cx"""
Expand Down Expand Up @@ -694,9 +694,9 @@ def test_controlflow_post_if_else_route(self):
expected.barrier(qreg)
expected.measure(qreg, creg[[1, 0, 2, 3, 4]])
self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_pre_if_else2(self):
"""test swap with if else controlflow construct; cx in if statement"""
Expand Down Expand Up @@ -736,9 +736,9 @@ def test_controlflow_pre_if_else2(self):
expected.measure(qreg, creg[new_order])

self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_intra_if_else_route(self):
"""test swap with if else controlflow construct"""
Expand Down Expand Up @@ -779,9 +779,9 @@ def test_controlflow_intra_if_else_route(self):
new_order = [1, 2, 0, 4, 3]
expected.measure(qreg, creg[new_order])
self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

@data(1, 2)
def test_controlflow_pre_intra_if_else(self, seed):
Expand Down Expand Up @@ -851,9 +851,9 @@ def test_controlflow_pre_intra_if_else(self, seed):
raise ValueError(f"unsupported test seed={seed}")

self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_pre_intra_post_if_else(self):
"""test swap with if else controlflow construct; cx before, in, and after if
Expand Down Expand Up @@ -906,9 +906,9 @@ def test_controlflow_pre_intra_post_if_else(self):
expected.measure(qreg, creg[[2, 4, 0, 3, 1]])

self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

def test_controlflow_no_layout_change(self):
"""test controlflow with no layout change needed"""
Expand Down Expand Up @@ -947,10 +947,11 @@ def test_controlflow_no_layout_change(self):
expected.if_else((creg[0], 0), etrue_body, efalse_body, qreg[[1, 4]], creg)
expected.barrier(qreg)
expected.measure(qreg, creg[[0, 2, 1, 3, 4]])

self.assertEqual(cqc, expected)
# check_map_pass = CheckMap(coupling)
# check_map_pass.run(circuit_to_dag(expected))
# self.assertTrue(check_map_pass.property_set["is_swap_mapped"])
check_map_pass = CheckMap(coupling)
check_map_pass.run(circuit_to_dag(expected))
self.assertTrue(check_map_pass.property_set["is_swap_mapped"])

@data(1, 2, 3)
def test_controlflow_for_loop(self, nloops):
Expand Down

0 comments on commit 302320d

Please sign in to comment.