Skip to content

Commit

Permalink
Add zero-qubit tests of Pauli.apply_layout
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed May 13, 2024
1 parent 49e96fa commit 5cdaf81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fixes:
- |
Fixed :meth:`~.SparsePauliOp.apply_layout` to work correctly with zero-qubit operators.
Fixed :meth:`.SparsePauliOp.apply_layout` to work correctly with zero-qubit operators.
23 changes: 23 additions & 0 deletions test/python/quantum_info/operators/symplectic/test_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,29 @@ def test_apply_layout_duplicate_indices(self):
with self.assertRaises(QiskitError):
op.apply_layout(layout=[0, 0], num_qubits=3)

def test_apply_layout_zero_qubit(self):
"""Test apply_layout with a zero-qubit operator"""
with self.subTest("default"):
op = Pauli("")
res = op.apply_layout(layout=None, num_qubits=5)
self.assertEqual(Pauli("IIIII"), res)
with self.subTest("phase -1j"):
op = Pauli("-i")
res = op.apply_layout(layout=None, num_qubits=5)
self.assertEqual(Pauli("-iIIIII"), res)
with self.subTest("phase -1"):
op = Pauli("-")
res = op.apply_layout(layout=None, num_qubits=5)
self.assertEqual(Pauli("-IIIII"), res)
with self.subTest("phase 1j"):
op = Pauli("i")
res = op.apply_layout(layout=None, num_qubits=5)
self.assertEqual(Pauli("iIIIII"), res)
with self.subTest("layout"):
op = Pauli("")
res = op.apply_layout(layout=[], num_qubits=5)
self.assertEqual(Pauli("IIIII"), res)


if __name__ == "__main__":
unittest.main()

0 comments on commit 5cdaf81

Please sign in to comment.