Skip to content
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/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _opt_control(property_set):
pm2.append(_direction_check)
pm2.append(_direction, condition=_direction_condition)
pm2.append(_reset)
pm2.append(_depth_check + _opt, do_while=_opt_control)
pm2.append(_depth_check + _opt + _unroll, do_while=_opt_control)
if scheduling_method:
pm2.append(_scheduling)

Expand Down
19 changes: 19 additions & 0 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from test import combine
from ddt import ddt, data

import numpy as np

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit import Qubit
from qiskit.compiler import transpile, assemble
Expand Down Expand Up @@ -85,6 +87,23 @@ def test_level0_keeps_reset(self):
result = transpile(circuit, basis_gates=None, optimization_level=0)
self.assertEqual(result, circuit)

def test_level2_respects_basis(self):
"""Test that level2 with commutative cancellation respects basis"""
qc = QuantumCircuit(3)
qc.h(0)
qc.h(1)
qc.cp(np.pi / 8, 0, 1)
qc.cp(np.pi / 4, 0, 2)
result = transpile(qc, basis_gates=['id', 'rz', 'sx', 'x', 'cx'],
optimization_level=2)

dag = circuit_to_dag(result)
op_nodes = [node.name for node in dag.topological_op_nodes()]
# Assert no u1 or rx gates from commutative cancellation end up in
# end up in the output since they're not in the target basis gates
self.assertNotIn('u1', op_nodes)
self.assertNotIn('rx', op_nodes)


@ddt
class TestTranspileLevels(QiskitTestCase):
Expand Down