mirror of https://github.com/Qiskit/qiskit.git
Fix printing an empty PauliList (#7712)
* add num.qubits check to be _truncated_str in pauli_list.py - Resolved Issue #7359 * new file: fix-empty-string-pauli-list-init-4d978fb0eaf1bc70.yaml modified: ../../test/python/quantum_info/operators/symplectic/test_pauli_list.py * Added test to test_array_init to test array initialization for empty array * Run black on test_pauli_list.py * Update releasenotes/notes/fix-empty-string-pauli-list-init-4d978fb0eaf1bc70.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com> 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:
parent
02d2d6e705
commit
3ae23373e0
|
@ -192,7 +192,7 @@ class PauliList(BasePauli, LinearMixin, GroupMixin):
|
|||
|
||||
def _truncated_str(self, show_class):
|
||||
stop = self._num_paulis
|
||||
if self.__truncate__:
|
||||
if self.__truncate__ and self.num_qubits > 0:
|
||||
max_paulis = self.__truncate__ // self.num_qubits
|
||||
if self._num_paulis > max_paulis:
|
||||
stop = max_paulis
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed initialization of empty symplectic matrix in :meth:'PauliList.from_symplectic' in :class:'.PauliList' class
|
||||
For example::
|
||||
|
||||
from qiskit.quantum_info.operators import PauliList
|
||||
|
||||
x = np.array([], dtype=bool).reshape((1,0))
|
||||
z = np.array([], dtype=bool).reshape((1,0))
|
||||
pauli_list = PauliList.from_symplectic(x, z)
|
|
@ -80,6 +80,14 @@ class TestPauliListInit(QiskitTestCase):
|
|||
def test_array_init(self):
|
||||
"""Test array initialization."""
|
||||
# Matrix array initialization
|
||||
|
||||
with self.subTest(msg="Empty array"):
|
||||
x = np.array([], dtype=bool).reshape((1, 0))
|
||||
z = np.array([], dtype=bool).reshape((1, 0))
|
||||
pauli_list = PauliList.from_symplectic(x, z)
|
||||
np.testing.assert_equal(pauli_list.z, z)
|
||||
np.testing.assert_equal(pauli_list.x, x)
|
||||
|
||||
with self.subTest(msg="bool array"):
|
||||
z = np.array([[False], [True]])
|
||||
x = np.array([[False], [True]])
|
||||
|
|
Loading…
Reference in New Issue