Fix bug in circuit decompose (#8364)

* fix bug in circuit decompose

* add test

* Update test/python/circuit/test_circuit_operations.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Kevin J. Sung 2022-07-19 13:36:36 -04:00 committed by GitHub
parent 6dd0d69ec9
commit 77535607f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -128,9 +128,7 @@ class Decompose(TransformationPass):
node.name in gates or any(fnmatch(node.name, p) for p in strings_list)
):
return True
elif not has_label and ( # check if Gate type given
any(isinstance(node.op, op) for op in gate_type_list)
):
elif any(isinstance(node.op, op) for op in gate_type_list): # check if Gate type given
return True
else:
return False

View File

@ -0,0 +1,4 @@
---
fixes:
- Fixed a bug in :meth:`.QuantumCircuit.decompose` that caused the
`gates_to_decompose` argument to be handled incorrectly.

View File

@ -1265,3 +1265,10 @@ class TestCircuitPrivateOperations(QiskitTestCase):
instruction = test._pop_previous_instruction_in_scope()
self.assertEqual(list(last_instructions), [instruction])
self.assertEqual({y}, set(test.parameters))
def test_decompose_gate_type(self):
"""Test decompose specifying gate type."""
circuit = QuantumCircuit(1)
circuit.append(SGate(label="s_gate"), [0])
decomposed = circuit.decompose(gates_to_decompose=SGate)
self.assertNotIn("s", decomposed.count_ops())