Skip to content

Commit

Permalink
Add check that decomposition includes qsd2q gates before optimizing them
Browse files Browse the repository at this point in the history
Co-authored-by: jsmallz333 <[email protected]>
  • Loading branch information
jlapeyre and jsmallz333 committed Jun 1, 2023
1 parent 16f1536 commit d40a28b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qiskit/quantum_info/synthesis/qsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ def _apply_a2(circ):
instr, _, _ = instr_context
if instr.name == "qsd2q":
ind2q.append(i)
if not ind2q:
return ccirc
# rolling over diagonals
ind2 = None # lint
for ind1, ind2 in zip(ind2q[0:-1:], ind2q[1::]):
Expand Down
8 changes: 8 additions & 0 deletions test/python/quantum_info/test_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,20 @@ def test_opt_a1a2(self, nqubits):
ccirc.count_ops().get("cx"), (23 / 48) * 4**nqubits - (3 / 2) * 2**nqubits + 4 / 3
)

# 10036
def test_1q_decomposition(self):
"""Test decomposition of single qubit matrix"""
mat = np.array([[0, 1], [1, 0]])
circ = self.qsd(mat)
self.assertEqual(Operator(mat), Operator(circ))

# 10036
def test_2q_with_no_qsd2q(self):
"""Test decomposition of unitary whose decomposition is all "u" and "cx"."""
mat = CXGate().to_matrix()
circ = self.qsd(mat)
self.assertEqual(Operator(mat), Operator(circ))


class TestTwoQubitDecomposeUpToDiagonal(QiskitTestCase):
"""test TwoQubitDecomposeUpToDiagonal class"""
Expand Down

0 comments on commit d40a28b

Please sign in to comment.