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

better unrolling in preset passmanagers (bp #6133) #6189

Merged
merged 1 commit into from
Apr 9, 2021
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
3 changes: 1 addition & 2 deletions qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,8 @@ def _opt_control(property_set):
if coupling_map and not coupling_map.is_symmetric:
pm1.append(_direction_check)
pm1.append(_direction, condition=_direction_condition)
pm1.append(_unroll)
pm1.append(_reset)
pm1.append(_depth_check + _opt, do_while=_opt_control)
pm1.append(_depth_check + _opt + _unroll, do_while=_opt_control)
pm1.append(_scheduling)

return pm1
1 change: 0 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def _opt_control(property_set):
if coupling_map and not coupling_map.is_symmetric:
pm2.append(_direction_check)
pm2.append(_direction, condition=_direction_condition)
pm2.append(_unroll)
pm2.append(_reset)
pm2.append(_depth_check + _opt + _unroll, do_while=_opt_control)
pm2.append(_scheduling)
Expand Down
1 change: 0 additions & 1 deletion qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def _opt_control(property_set):
if coupling_map and not coupling_map.is_symmetric:
pm3.append(_direction_check)
pm3.append(_direction, condition=_direction_condition)
pm3.append(_unroll)
pm3.append(_reset)
pm3.append(_depth_check + _opt + _unroll, do_while=_opt_control)
pm3.append(_scheduling)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
fixes:
- |
Fixed an issue with the preset pass managers
:class:`~qiskit.transpiler.preset_passmanagers.level_0_pass_manager` and
:class:`~qiskit.transpiler.preset_passmanagers.level_1_pass_manager`
(which corresponds to ``optimization_level`` 0 and 1 for
:func:`~qiskit.compiler.transpile`) where in some cases they would
produce circuits not in the requested basis.
18 changes: 9 additions & 9 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ 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"""
@combine(level=[0, 1, 2, 3], name='level{level}')
def test_respect_basis(self, level):
"""Test that all levels respect 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)
basis_gates = ['id', 'rz', 'sx', 'x', 'cx']
result = transpile(qc, basis_gates=basis_gates,
coupling_map=[[0, 1], [2, 1]],
optimization_level=level)

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)
circuit_ops = set(node.name for node in dag.topological_op_nodes())
self.assertEqual(circuit_ops.union(set(basis_gates)), set(basis_gates))


@ddt
Expand Down