From 0264f06204fccdf4f5eb1f5941191e706950f580 Mon Sep 17 00:00:00 2001 From: ikkoham Date: Wed, 8 Feb 2023 18:57:01 +0900 Subject: [PATCH 1/3] Deprecate PauliTable and StabilizerTable --- .../operators/symplectic/clifford.py | 45 +- .../operators/symplectic/pauli_table.py | 9 +- .../operators/symplectic/stabilizer_table.py | 11 +- ...eprecate-pauli-table-fc6dcdb5eeb6e0c4.yaml | 9 + .../operators/symplectic/test_clifford.py | 11 +- .../operators/symplectic/test_pauli_list.py | 8 +- .../operators/symplectic/test_pauli_table.py | 653 +++++++++----- .../symplectic/test_stabilizer_table.py | 842 +++++++++++------- .../quantum_info/operators/test_random.py | 20 +- 9 files changed, 1001 insertions(+), 607 deletions(-) create mode 100644 releasenotes/notes/deprecate-pauli-table-fc6dcdb5eeb6e0c4.yaml diff --git a/qiskit/quantum_info/operators/symplectic/clifford.py b/qiskit/quantum_info/operators/symplectic/clifford.py index 3773a7b53700..037db8877350 100644 --- a/qiskit/quantum_info/operators/symplectic/clifford.py +++ b/qiskit/quantum_info/operators/symplectic/clifford.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017--2022 +# (C) Copyright IBM 2017--2023 # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -26,6 +26,7 @@ from qiskit.quantum_info.operators.operator import Operator from qiskit.quantum_info.operators.scalar_op import ScalarOp from qiskit.quantum_info.operators.symplectic.base_pauli import _count_y +from qiskit.utils.deprecation import deprecate_function from .base_pauli import BasePauli from .clifford_circuits import _append_circuit, _append_operation @@ -141,7 +142,7 @@ def __init__(self, data, validate=True, copy=True): num_qubits = data.num_qubits self.tableau = Clifford.from_circuit(data).tableau - # DEPRECATE in the future: data is StabilizerTable + # DEPRECATED: data is StabilizerTable elif isinstance(data, StabilizerTable): self.tableau = self._stack_table_phase(data.array, data.phase) num_qubits = data.num_qubits @@ -210,20 +211,40 @@ def copy(self): # pylint: disable=bad-docstring-quotes + @deprecate_function( + "Indexing or iterating through a Clifford object directly is deprecated as of " + "Qiskit Terra 0.24.0 and will be removed no sooner than 3 months after the release date. " + "Instead, index or iterate through the Clifford.tableau attribute." + ) def __getitem__(self, key): """Return a stabilizer Pauli row""" return self.table.__getitem__(key) + @deprecate_function( + "The Clifford.__setitem__ method is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.tableau property instead.", + ) def __setitem__(self, key, value): """Set a stabilizer Pauli row""" self.tableau.__setitem__(key, self._stack_table_phase(value.array, value.phase)) @property + @deprecate_function( + "The Clifford.table attribute is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.stab and Clifford.destab properties instead." + ) def table(self): """Return StabilizerTable""" return StabilizerTable(self.symplectic_matrix, phase=self.phase) @table.setter + @deprecate_function( + "The Clifford.table attribute is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.stab and Clifford.destab properties instead." + ) def table(self, value): """Set the stabilizer table""" # Note this setter cannot change the size of the Clifford @@ -235,6 +256,11 @@ def table(self, value): self.phase = value._table._phase @property + @deprecate_function( + "The Clifford.stabilizer attribute is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.stab properties instead." + ) def stabilizer(self): """Return the stabilizer block of the StabilizerTable.""" array = self.tableau[self.num_qubits : 2 * self.num_qubits, :-1] @@ -242,6 +268,11 @@ def stabilizer(self): return StabilizerTable(array, phase) @stabilizer.setter + @deprecate_function( + "The Clifford.stabilizer is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.stab properties instead." + ) def stabilizer(self, value): """Set the value of stabilizer block of the StabilizerTable""" if not isinstance(value, StabilizerTable): @@ -249,6 +280,11 @@ def stabilizer(self, value): self.tableau[self.num_qubits : 2 * self.num_qubits, :-1] = value.array @property + @deprecate_function( + "The Clifford.destabilzer attribute is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.destab properties instead." + ) def destabilizer(self): """Return the destabilizer block of the StabilizerTable.""" array = self.tableau[0 : self.num_qubits, :-1] @@ -256,6 +292,11 @@ def destabilizer(self): return StabilizerTable(array, phase) @destabilizer.setter + @deprecate_function( + "The Clifford.destabilizer attribute is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use Clifford.destab properties instead." + ) def destabilizer(self, value): """Set the value of destabilizer block of the StabilizerTable""" if not isinstance(value, StabilizerTable): diff --git a/qiskit/quantum_info/operators/symplectic/pauli_table.py b/qiskit/quantum_info/operators/symplectic/pauli_table.py index fc280410b999..84b57368165e 100644 --- a/qiskit/quantum_info/operators/symplectic/pauli_table.py +++ b/qiskit/quantum_info/operators/symplectic/pauli_table.py @@ -28,7 +28,7 @@ class PauliTable(BaseOperator, AdjointMixin): - r"""Symplectic representation of a list Pauli matrices. + r"""DEPRECATED: Symplectic representation of a list Pauli matrices. **Symplectic Representation** @@ -141,9 +141,10 @@ def __init__(self, data): can share the same underlying array. """ warn( - "The PauliTable class has been superseded by PauliList and is pending deprecation. " - "This class will be deprecated in the future release and subsequently removed after that.", - PendingDeprecationWarning, + "The PauliTable class is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the releasedate. " + "Use PauliList class instead.", + DeprecationWarning, stacklevel=2, ) if isinstance(data, (np.ndarray, list)): diff --git a/qiskit/quantum_info/operators/symplectic/stabilizer_table.py b/qiskit/quantum_info/operators/symplectic/stabilizer_table.py index 8b0f62b471ab..08fddf6c7bb6 100644 --- a/qiskit/quantum_info/operators/symplectic/stabilizer_table.py +++ b/qiskit/quantum_info/operators/symplectic/stabilizer_table.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020 +# (C) Copyright IBM 2017, 2023 # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -24,7 +24,7 @@ class StabilizerTable(PauliTable, AdjointMixin): - r"""Symplectic representation of a list Stabilizer matrices. + r"""DEPRECATED: Symplectic representation of a list Stabilizer matrices. **Symplectic Representation** @@ -186,9 +186,10 @@ def __init__(self, data, phase=None): can share the same underlying array. """ warn( - "The StabilizerTable class has been superseded by PauliList and is pending deprecation. " - "This class will be deprecated in the future release and subsequently removed after that.", - PendingDeprecationWarning, + "The StabilizerTable class is deprecated as of Qiskit Terra 0.24.0 " + "and will be removed no sooner than 3 months after the release date. " + "Use PauliList class instead.", + DeprecationWarning, stacklevel=2, ) if isinstance(data, str) and phase is None: diff --git a/releasenotes/notes/deprecate-pauli-table-fc6dcdb5eeb6e0c4.yaml b/releasenotes/notes/deprecate-pauli-table-fc6dcdb5eeb6e0c4.yaml new file mode 100644 index 000000000000..a10b8c87bdd1 --- /dev/null +++ b/releasenotes/notes/deprecate-pauli-table-fc6dcdb5eeb6e0c4.yaml @@ -0,0 +1,9 @@ +--- +deprecations: + - | + The :class:`~qiskit.quantum_info.PauliTable` and :class:`~qiskit.quantum_info.StabilizerTable` + are deprecated and will be removed in a future release. + Instead, the :class:`~qiskit.quantum_info.PauliList` should be used. + With this change, :meth:`~qiskit.quantum_info.Clifford.table` has been deprecated + so that you should operate directly from :meth:`~qiskit.quantum_info.Clifford.tableau` + without it. diff --git a/test/python/quantum_info/operators/symplectic/test_clifford.py b/test/python/quantum_info/operators/symplectic/test_clifford.py index 8009b4541d2b..c8fad81c52c7 100644 --- a/test/python/quantum_info/operators/symplectic/test_clifford.py +++ b/test/python/quantum_info/operators/symplectic/test_clifford.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -191,10 +191,11 @@ def test_append_1_qubit_gate(self): with self.subTest(msg="append gate %s" % gate_name): cliff = Clifford([[1, 0], [0, 1]]) cliff = _append_operation(cliff, gate_name, [0]) - value_table = cliff.table._array - value_phase = cliff.table._phase - value_stabilizer = cliff.stabilizer.to_labels() - value_destabilizer = cliff.destabilizer.to_labels() + with self.assertWarns(DeprecationWarning): + value_table = cliff.table._array + value_phase = cliff.table._phase + value_stabilizer = cliff.stabilizer.to_labels() + value_destabilizer = cliff.destabilizer.to_labels() self.assertTrue(np.all(np.array(value_table == target_table[gate_name]))) self.assertTrue(np.all(np.array(value_phase == target_phase[gate_name]))) self.assertTrue( diff --git a/test/python/quantum_info/operators/symplectic/test_pauli_list.py b/test/python/quantum_info/operators/symplectic/test_pauli_list.py index db38d428afc2..4c03c9fe5f3c 100644 --- a/test/python/quantum_info/operators/symplectic/test_pauli_list.py +++ b/test/python/quantum_info/operators/symplectic/test_pauli_list.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -227,12 +227,14 @@ def test_pauli_table_init(self): def test_stabilizer_table_init(self): """Test table initialization.""" with self.subTest(msg="PauliTable"): - target = StabilizerTable.from_labels(["+II", "-XZ"]) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+II", "-XZ"]) value = PauliList(target) self.assertEqual(value, target) with self.subTest(msg="PauliTable no copy"): - target = StabilizerTable.from_labels(["+YY", "-XZ", "XI"]) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+YY", "-XZ", "XI"]) value = PauliList(target) value[0] = "II" self.assertEqual(value, target) diff --git a/test/python/quantum_info/operators/symplectic/test_pauli_table.py b/test/python/quantum_info/operators/symplectic/test_pauli_table.py index 03f0b8f534bd..5d51aa2071ae 100644 --- a/test/python/quantum_info/operators/symplectic/test_pauli_table.py +++ b/test/python/quantum_info/operators/symplectic/test_pauli_table.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -14,13 +14,14 @@ import unittest from test import combine -from ddt import ddt + import numpy as np +from ddt import ddt from scipy.sparse import csr_matrix from qiskit import QiskitError -from qiskit.test import QiskitTestCase from qiskit.quantum_info.operators.symplectic import PauliTable +from qiskit.test import QiskitTestCase def pauli_mat(label): @@ -48,30 +49,35 @@ def test_array_init(self): # Matrix array initialization with self.subTest(msg="bool array"): target = np.array([[False, False], [True, True]]) - value = PauliTable(target)._array + with self.assertWarns(DeprecationWarning): + value = PauliTable(target)._array self.assertTrue(np.all(value == target)) with self.subTest(msg="bool array no copy"): target = np.array([[False, True], [True, True]]) - value = PauliTable(target)._array + with self.assertWarns(DeprecationWarning): + value = PauliTable(target)._array value[0, 0] = not value[0, 0] self.assertTrue(np.all(value == target)) with self.subTest(msg="bool array raises"): array = np.array([[False, False, False], [True, True, True]]) - self.assertRaises(QiskitError, PauliTable, array) + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, PauliTable, array) def test_vector_init(self): """Test vector initialization.""" # Vector array initialization with self.subTest(msg="bool vector"): target = np.array([False, False, False, False]) - value = PauliTable(target)._array + with self.assertWarns(DeprecationWarning): + value = PauliTable(target)._array self.assertTrue(np.all(value == target)) with self.subTest(msg="bool vector no copy"): target = np.array([False, True, True, False]) - value = PauliTable(target)._array + with self.assertWarns(DeprecationWarning): + value = PauliTable(target)._array value[0, 0] = not value[0, 0] self.assertTrue(np.all(value == target)) @@ -79,42 +85,50 @@ def test_string_init(self): """Test string initialization.""" # String initialization with self.subTest(msg='str init "I"'): - value = PauliTable("I")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("I")._array target = np.array([[False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "X"'): - value = PauliTable("X")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("X")._array target = np.array([[True, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "Y"'): - value = PauliTable("Y")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("Y")._array target = np.array([[True, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "Z"'): - value = PauliTable("Z")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("Z")._array target = np.array([[False, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "IX"'): - value = PauliTable("IX")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("IX")._array target = np.array([[True, False, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "XI"'): - value = PauliTable("XI")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("XI")._array target = np.array([[False, True, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "YZ"'): - value = PauliTable("YZ")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("YZ")._array target = np.array([[False, True, True, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "XIZ"'): - value = PauliTable("XIZ")._array + with self.assertWarns(DeprecationWarning): + value = PauliTable("XIZ")._array target = np.array([[False, False, True, True, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) @@ -122,13 +136,15 @@ def test_table_init(self): """Test table initialization.""" # Pauli Table initialization with self.subTest(msg="PauliTable"): - target = PauliTable.from_labels(["XI", "IX", "IZ"]) - value = PauliTable(target) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XI", "IX", "IZ"]) + value = PauliTable(target) self.assertEqual(value, target) with self.subTest(msg="PauliTable no copy"): - target = PauliTable.from_labels(["XI", "IX", "IZ"]) - value = PauliTable(target) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XI", "IX", "IZ"]) + value = PauliTable(target) value[0] = "II" self.assertEqual(value, target) @@ -140,12 +156,14 @@ def test_array_propertiy(self): """Test array property""" with self.subTest(msg="array"): - pauli = PauliTable("II") + with self.assertWarns(DeprecationWarning): + pauli = PauliTable("II") array = np.zeros([2, 4], dtype=bool) self.assertTrue(np.all(pauli.array == array)) with self.subTest(msg="set array"): - pauli = PauliTable("XX") + with self.assertWarns(DeprecationWarning): + pauli = PauliTable("XX") array = np.zeros([1, 4], dtype=bool) pauli.array = array self.assertTrue(np.all(pauli.array == array)) @@ -153,7 +171,8 @@ def test_array_propertiy(self): with self.subTest(msg="set array raises"): def set_array_raise(): - pauli = PauliTable("XXX") + with self.assertWarns(DeprecationWarning): + pauli = PauliTable("XXX") pauli.array = np.eye(4) return pauli @@ -162,20 +181,24 @@ def set_array_raise(): def test_x_propertiy(self): """Test X property""" with self.subTest(msg="X"): - pauli = PauliTable.from_labels(["XI", "IZ", "YY"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ", "YY"]) array = np.array([[False, True], [False, False], [True, True]], dtype=bool) self.assertTrue(np.all(pauli.X == array)) with self.subTest(msg="set X"): - pauli = PauliTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ"]) val = np.array([[False, False], [True, True]], dtype=bool) pauli.X = val - self.assertEqual(pauli, PauliTable.from_labels(["II", "XY"])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli, PauliTable.from_labels(["II", "XY"])) with self.subTest(msg="set X raises"): def set_x(): - pauli = PauliTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ"]) val = np.array([[False, False, False], [True, True, True]], dtype=bool) pauli.X = val return pauli @@ -185,20 +208,24 @@ def set_x(): def test_z_propertiy(self): """Test Z property""" with self.subTest(msg="Z"): - pauli = PauliTable.from_labels(["XI", "IZ", "YY"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ", "YY"]) array = np.array([[False, False], [True, False], [True, True]], dtype=bool) self.assertTrue(np.all(pauli.Z == array)) with self.subTest(msg="set Z"): - pauli = PauliTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ"]) val = np.array([[False, False], [True, True]], dtype=bool) pauli.Z = val - self.assertEqual(pauli, PauliTable.from_labels(["XI", "ZZ"])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli, PauliTable.from_labels(["XI", "ZZ"])) with self.subTest(msg="set Z raises"): def set_z(): - pauli = PauliTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IZ"]) val = np.array([[False, False, False], [True, True, True]], dtype=bool) pauli.Z = val return pauli @@ -208,7 +235,8 @@ def set_z(): def test_shape_propertiy(self): """Test shape property""" shape = (3, 8) - pauli = PauliTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable(np.zeros(shape)) self.assertEqual(pauli.shape, shape) def test_size_propertiy(self): @@ -216,7 +244,8 @@ def test_size_propertiy(self): with self.subTest(msg="size"): for j in range(1, 10): shape = (j, 8) - pauli = PauliTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable(np.zeros(shape)) self.assertEqual(pauli.size, j) def test_n_qubit_propertiy(self): @@ -224,13 +253,15 @@ def test_n_qubit_propertiy(self): with self.subTest(msg="num_qubits"): for j in range(1, 10): shape = (5, 2 * j) - pauli = PauliTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable(np.zeros(shape)) self.assertEqual(pauli.num_qubits, j) def test_eq(self): """Test __eq__ method.""" - pauli1 = PauliTable.from_labels(["II", "XI"]) - pauli2 = PauliTable.from_labels(["XI", "II"]) + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["II", "XI"]) + pauli2 = PauliTable.from_labels(["XI", "II"]) self.assertEqual(pauli1, pauli1) self.assertNotEqual(pauli1, pauli2) @@ -238,70 +269,86 @@ def test_len_methods(self): """Test __len__ method.""" for j in range(1, 10): labels = j * ["XX"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) self.assertEqual(len(pauli), j) def test_add_methods(self): """Test __add__ method.""" labels1 = ["XXI", "IXX"] labels2 = ["XXI", "ZZI", "ZYZ"] - pauli1 = PauliTable.from_labels(labels1) - pauli2 = PauliTable.from_labels(labels2) - target = PauliTable.from_labels(labels1 + labels2) + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(labels1) + pauli2 = PauliTable.from_labels(labels2) + target = PauliTable.from_labels(labels1 + labels2) self.assertEqual(target, pauli1 + pauli2) def test_add_qargs(self): """Test add method with qargs.""" - pauli1 = PauliTable.from_labels(["IIII", "YYYY"]) - pauli2 = PauliTable.from_labels(["XY", "YZ"]) + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["IIII", "YYYY"]) + pauli2 = PauliTable.from_labels(["XY", "YZ"]) with self.subTest(msg="qargs=[0, 1]"): - target = PauliTable.from_labels(["IIII", "YYYY", "IIXY", "IIYZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIII", "YYYY", "IIXY", "IIYZ"]) self.assertEqual(pauli1 + pauli2([0, 1]), target) with self.subTest(msg="qargs=[0, 3]"): - target = PauliTable.from_labels(["IIII", "YYYY", "XIIY", "YIIZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIII", "YYYY", "XIIY", "YIIZ"]) self.assertEqual(pauli1 + pauli2([0, 3]), target) with self.subTest(msg="qargs=[2, 1]"): - target = PauliTable.from_labels(["IIII", "YYYY", "IYXI", "IZYI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIII", "YYYY", "IYXI", "IZYI"]) self.assertEqual(pauli1 + pauli2([2, 1]), target) with self.subTest(msg="qargs=[3, 1]"): - target = PauliTable.from_labels(["IIII", "YYYY", "YIXI", "ZIYI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIII", "YYYY", "YIXI", "ZIYI"]) self.assertEqual(pauli1 + pauli2([3, 1]), target) def test_getitem_methods(self): """Test __getitem__ method.""" with self.subTest(msg="__getitem__ single"): labels = ["XI", "IY"] - pauli = PauliTable.from_labels(labels) - self.assertEqual(pauli[0], PauliTable(labels[0])) - self.assertEqual(pauli[1], PauliTable(labels[1])) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) + self.assertEqual(pauli[0], PauliTable(labels[0])) + self.assertEqual(pauli[1], PauliTable(labels[1])) with self.subTest(msg="__getitem__ array"): labels = np.array(["XI", "IY", "IZ", "XY", "ZX"]) - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) inds = [0, 3] - self.assertEqual(pauli[inds], PauliTable.from_labels(labels[inds])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli[inds], PauliTable.from_labels(labels[inds])) inds = np.array([4, 1]) - self.assertEqual(pauli[inds], PauliTable.from_labels(labels[inds])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli[inds], PauliTable.from_labels(labels[inds])) with self.subTest(msg="__getitem__ slice"): labels = np.array(["XI", "IY", "IZ", "XY", "ZX"]) - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) self.assertEqual(pauli[:], pauli) - self.assertEqual(pauli[1:3], PauliTable.from_labels(labels[1:3])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli[1:3], PauliTable.from_labels(labels[1:3])) def test_setitem_methods(self): """Test __setitem__ method.""" with self.subTest(msg="__setitem__ single"): labels = ["XI", "IY"] - pauli = PauliTable.from_labels(["XI", "IY"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["XI", "IY"]) pauli[0] = "II" - self.assertEqual(pauli[0], PauliTable("II")) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli[0], PauliTable("II")) pauli[1] = "XX" - self.assertEqual(pauli[1], PauliTable("XX")) + with self.assertWarns(DeprecationWarning): + self.assertEqual(pauli[1], PauliTable("XX")) def raises_single(): # Wrong size Pauli @@ -311,24 +358,28 @@ def raises_single(): with self.subTest(msg="__setitem__ array"): labels = np.array(["XI", "IY", "IZ"]) - pauli = PauliTable.from_labels(labels) - target = PauliTable.from_labels(["II", "ZZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) + target = PauliTable.from_labels(["II", "ZZ"]) inds = [2, 0] pauli[inds] = target self.assertEqual(pauli[inds], target) def raises_array(): - pauli[inds] = PauliTable.from_labels(["YY", "ZZ", "XX"]) + with self.assertWarns(DeprecationWarning): + pauli[inds] = PauliTable.from_labels(["YY", "ZZ", "XX"]) self.assertRaises(Exception, raises_array) with self.subTest(msg="__setitem__ slice"): labels = np.array(5 * ["III"]) - pauli = PauliTable.from_labels(labels) - target = PauliTable.from_labels(5 * ["XXX"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) + target = PauliTable.from_labels(5 * ["XXX"]) pauli[:] = target self.assertEqual(pauli[:], target) - target = PauliTable.from_labels(2 * ["ZZZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(2 * ["ZZZ"]) pauli[1:3] = target self.assertEqual(pauli[1:3], target) @@ -342,8 +393,9 @@ def test_from_labels_1q(self): array = np.array( [[False, False], [False, True], [False, True], [True, False], [True, True]], dtype=bool ) - target = PauliTable(array) - value = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + target = PauliTable(array) + value = PauliTable.from_labels(labels) self.assertEqual(target, value) def test_from_labels_2q(self): @@ -353,8 +405,9 @@ def test_from_labels_2q(self): [[False, False, False, False], [True, True, True, True], [False, True, True, False]], dtype=bool, ) - target = PauliTable(array) - value = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + target = PauliTable(array) + value = PauliTable.from_labels(labels) self.assertEqual(target, value) def test_from_labels_5q(self): @@ -364,30 +417,33 @@ def test_from_labels_5q(self): [10 * [False], 5 * [True] + 5 * [False], 10 * [True], 5 * [False] + 5 * [True]], dtype=bool, ) - target = PauliTable(array) - value = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + target = PauliTable(array) + value = PauliTable.from_labels(labels) self.assertEqual(target, value) def test_to_labels_1q(self): """Test 1-qubit to_labels method.""" - pauli = PauliTable( - np.array( - [[False, False], [False, True], [False, True], [True, False], [True, True]], - dtype=bool, + with self.assertWarns(DeprecationWarning): + pauli = PauliTable( + np.array( + [[False, False], [False, True], [False, True], [True, False], [True, True]], + dtype=bool, + ) ) - ) target = ["I", "Z", "Z", "X", "Y"] value = pauli.to_labels() self.assertEqual(value, target) def test_to_labels_1q_array(self): """Test 1-qubit to_labels method w/ array=True.""" - pauli = PauliTable( - np.array( - [[False, False], [False, True], [False, True], [True, False], [True, True]], - dtype=bool, + with self.assertWarns(DeprecationWarning): + pauli = PauliTable( + np.array( + [[False, False], [False, True], [False, True], [True, False], [True, True]], + dtype=bool, + ) ) - ) target = np.array(["I", "Z", "Z", "X", "Y"]) value = pauli.to_labels(array=True) self.assertTrue(np.all(value == target)) @@ -395,14 +451,16 @@ def test_to_labels_1q_array(self): def test_labels_round_trip(self): """Test from_labels and to_labels round trip.""" target = ["III", "IXZ", "XYI", "ZZZ"] - value = PauliTable.from_labels(target).to_labels() + with self.assertWarns(DeprecationWarning): + value = PauliTable.from_labels(target).to_labels() self.assertEqual(value, target) def test_labels_round_trip_array(self): """Test from_labels and to_labels round trip w/ array=True.""" labels = ["III", "IXZ", "XYI", "ZZZ"] target = np.array(labels) - value = PauliTable.from_labels(labels).to_labels(array=True) + with self.assertWarns(DeprecationWarning): + value = PauliTable.from_labels(labels).to_labels(array=True) self.assertTrue(np.all(value == target)) @@ -413,7 +471,8 @@ def test_to_matrix_1q(self): """Test 1-qubit to_matrix method.""" labels = ["X", "I", "Z", "Y"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -422,7 +481,8 @@ def test_to_matrix_1q_array(self): """Test 1-qubit to_matrix method w/ array=True.""" labels = ["Z", "I", "Y", "X"] target = np.array([pauli_mat(i) for i in labels]) - value = PauliTable.from_labels(labels).to_matrix(array=True) + with self.assertWarns(DeprecationWarning): + value = PauliTable.from_labels(labels).to_matrix(array=True) self.assertTrue(isinstance(value, np.ndarray)) self.assertTrue(np.all(value == target)) @@ -430,7 +490,8 @@ def test_to_matrix_1q_sparse(self): """Test 1-qubit to_matrix method w/ sparse=True.""" labels = ["X", "I", "Z", "Y"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -439,7 +500,8 @@ def test_to_matrix_2q(self): """Test 2-qubit to_matrix method.""" labels = ["IX", "YI", "II", "ZZ"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -448,7 +510,8 @@ def test_to_matrix_2q_array(self): """Test 2-qubit to_matrix method w/ array=True.""" labels = ["ZZ", "XY", "YX", "IZ"] target = np.array([pauli_mat(i) for i in labels]) - value = PauliTable.from_labels(labels).to_matrix(array=True) + with self.assertWarns(DeprecationWarning): + value = PauliTable.from_labels(labels).to_matrix(array=True) self.assertTrue(isinstance(value, np.ndarray)) self.assertTrue(np.all(value == target)) @@ -456,7 +519,8 @@ def test_to_matrix_2q_sparse(self): """Test 2-qubit to_matrix method w/ sparse=True.""" labels = ["IX", "II", "ZY", "YZ"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -465,7 +529,8 @@ def test_to_matrix_5q(self): """Test 5-qubit to_matrix method.""" labels = ["IXIXI", "YZIXI", "IIXYZ"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -474,7 +539,8 @@ def test_to_matrix_5q_sparse(self): """Test 5-qubit to_matrix method w/ sparse=True.""" labels = ["XXXYY", "IXIZY", "ZYXIX"] targets = [pauli_mat(i) for i in labels] - values = PauliTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = PauliTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -486,42 +552,51 @@ class TestPauliTableIteration(QiskitTestCase): def test_enumerate(self): """Test enumerate with PauliTable.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for idx, i in enumerate(pauli): - self.assertEqual(i, PauliTable(labels[idx])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(i, PauliTable(labels[idx])) def test_iter(self): """Test iter with PauliTable.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for idx, i in enumerate(iter(pauli)): - self.assertEqual(i, PauliTable(labels[idx])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(i, PauliTable(labels[idx])) def test_zip(self): """Test zip with PauliTable.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for label, i in zip(labels, pauli): - self.assertEqual(i, PauliTable(label)) + with self.assertWarns(DeprecationWarning): + self.assertEqual(i, PauliTable(label)) def test_label_iter(self): """Test PauliTable label_iter method.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for idx, i in enumerate(pauli.label_iter()): self.assertEqual(i, labels[idx]) def test_matrix_iter(self): """Test PauliTable dense matrix_iter method.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for idx, i in enumerate(pauli.matrix_iter()): self.assertTrue(np.all(i == pauli_mat(labels[idx]))) def test_matrix_iter_sparse(self): """Test PauliTable sparse matrix_iter method.""" labels = ["III", "IXI", "IYY", "YIZ", "XYZ", "III"] - pauli = PauliTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(labels) for idx, i in enumerate(pauli.matrix_iter(sparse=True)): self.assertTrue(isinstance(i, csr_matrix)) self.assertTrue(np.all(i.toarray() == pauli_mat(labels[idx]))) @@ -536,11 +611,13 @@ def test_tensor(self, j): """Test tensor method j={j}.""" labels1 = ["XX", "YY"] labels2 = [j * "I", j * "Z"] - pauli1 = PauliTable.from_labels(labels1) - pauli2 = PauliTable.from_labels(labels2) + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(labels1) + pauli2 = PauliTable.from_labels(labels2) value = pauli1.tensor(pauli2) - target = PauliTable.from_labels([i + j for i in labels1 for j in labels2]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels([i + j for i in labels1 for j in labels2]) self.assertEqual(value, target) @combine(j=range(1, 10)) @@ -548,206 +625,246 @@ def test_expand(self, j): """Test expand method j={j}.""" labels1 = ["XX", "YY"] labels2 = [j * "I", j * "Z"] - pauli1 = PauliTable.from_labels(labels1) - pauli2 = PauliTable.from_labels(labels2) + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(labels1) + pauli2 = PauliTable.from_labels(labels2) value = pauli1.expand(pauli2) - target = PauliTable.from_labels([j + i for j in labels2 for i in labels1]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels([j + i for j in labels2 for i in labels1]) self.assertEqual(value, target) def test_compose_1q(self): """Test 1-qubit compose methods.""" # Test single qubit Pauli dot products - pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) with self.subTest(msg="compose single I"): - target = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["I", "X", "Y", "Z"]) value = pauli.compose("I") self.assertEqual(target, value) with self.subTest(msg="compose single X"): - target = PauliTable.from_labels(["X", "I", "Z", "Y"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["X", "I", "Z", "Y"]) value = pauli.compose("X") self.assertEqual(target, value) with self.subTest(msg="compose single Y"): - target = PauliTable.from_labels(["Y", "Z", "I", "X"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["Y", "Z", "I", "X"]) value = pauli.compose("Y") self.assertEqual(target, value) with self.subTest(msg="compose single Z"): - target = PauliTable.from_labels(["Z", "Y", "X", "I"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["Z", "Y", "X", "I"]) value = pauli.compose("Z") self.assertEqual(target, value) def test_dot_1q(self): """Test 1-qubit dot method.""" # Test single qubit Pauli dot products - pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) with self.subTest(msg="dot single I"): - target = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["I", "X", "Y", "Z"]) value = pauli.dot("I") self.assertEqual(target, value) with self.subTest(msg="dot single X"): - target = PauliTable.from_labels(["X", "I", "Z", "Y"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["X", "I", "Z", "Y"]) value = pauli.dot("X") self.assertEqual(target, value) with self.subTest(msg="dot single Y"): - target = PauliTable.from_labels(["Y", "Z", "I", "X"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["Y", "Z", "I", "X"]) value = pauli.dot("Y") self.assertEqual(target, value) with self.subTest(msg="dot single Z"): - target = PauliTable.from_labels(["Z", "Y", "X", "I"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["Z", "Y", "X", "I"]) value = pauli.dot("Z") self.assertEqual(target, value) def test_qargs_compose_1q(self): """Test 1-qubit compose method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("Z") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("Z") with self.subTest(msg="compose 1-qubit qargs=[0]"): - target = PauliTable.from_labels(["IIZ", "XXY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIZ", "XXY"]) value = pauli1.compose(pauli2, qargs=[0]) self.assertEqual(value, target) with self.subTest(msg="compose 1-qubit qargs=[1]"): - target = PauliTable.from_labels(["IZI", "XYX"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IZI", "XYX"]) value = pauli1.compose(pauli2, qargs=[1]) self.assertEqual(value, target) with self.subTest(msg="compose 1-qubit qargs=[2]"): - target = PauliTable.from_labels(["ZII", "YXX"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZII", "YXX"]) value = pauli1.compose(pauli2, qargs=[2]) self.assertEqual(value, target) def test_qargs_dot_1q(self): """Test 1-qubit dot method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("Z") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("Z") with self.subTest(msg="dot 1-qubit qargs=[0]"): - target = PauliTable.from_labels(["IIZ", "XXY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IIZ", "XXY"]) value = pauli1.dot(pauli2, qargs=[0]) self.assertEqual(value, target) with self.subTest(msg="dot 1-qubit qargs=[1]"): - target = PauliTable.from_labels(["IZI", "XYX"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IZI", "XYX"]) value = pauli1.dot(pauli2, qargs=[1]) self.assertEqual(value, target) with self.subTest(msg="dot 1-qubit qargs=[2]"): - target = PauliTable.from_labels(["ZII", "YXX"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZII", "YXX"]) value = pauli1.dot(pauli2, qargs=[2]) self.assertEqual(value, target) def test_qargs_compose_2q(self): """Test 2-qubit compose method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("ZY") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("ZY") with self.subTest(msg="compose 2-qubit qargs=[0, 1]"): - target = PauliTable.from_labels(["IZY", "XYZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IZY", "XYZ"]) value = pauli1.compose(pauli2, qargs=[0, 1]) self.assertEqual(value, target) with self.subTest(msg="compose 2-qubit qargs=[1, 0]"): - target = PauliTable.from_labels(["IYZ", "XZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IYZ", "XZY"]) value = pauli1.compose(pauli2, qargs=[1, 0]) self.assertEqual(value, target) with self.subTest(msg="compose 2-qubit qargs=[0, 2]"): - target = PauliTable.from_labels(["ZIY", "YXZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZIY", "YXZ"]) value = pauli1.compose(pauli2, qargs=[0, 2]) self.assertEqual(value, target) with self.subTest(msg="compose 2-qubit qargs=[2, 0]"): - target = PauliTable.from_labels(["YIZ", "ZXY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["YIZ", "ZXY"]) value = pauli1.compose(pauli2, qargs=[2, 0]) self.assertEqual(value, target) def test_qargs_dot_2q(self): """Test 2-qubit dot method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("ZY") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("ZY") with self.subTest(msg="dot 2-qubit qargs=[0, 1]"): - target = PauliTable.from_labels(["IZY", "XYZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IZY", "XYZ"]) value = pauli1.dot(pauli2, qargs=[0, 1]) self.assertEqual(value, target) with self.subTest(msg="dot 2-qubit qargs=[1, 0]"): - target = PauliTable.from_labels(["IYZ", "XZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IYZ", "XZY"]) value = pauli1.dot(pauli2, qargs=[1, 0]) self.assertEqual(value, target) with self.subTest(msg="dot 2-qubit qargs=[0, 2]"): - target = PauliTable.from_labels(["ZIY", "YXZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZIY", "YXZ"]) value = pauli1.dot(pauli2, qargs=[0, 2]) self.assertEqual(value, target) with self.subTest(msg="dot 2-qubit qargs=[2, 0]"): - target = PauliTable.from_labels(["YIZ", "ZXY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["YIZ", "ZXY"]) value = pauli1.dot(pauli2, qargs=[2, 0]) self.assertEqual(value, target) def test_qargs_compose_3q(self): """Test 3-qubit compose method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("XYZ") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("XYZ") with self.subTest(msg="compose 3-qubit qargs=None"): - target = PauliTable.from_labels(["XYZ", "IZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XYZ", "IZY"]) value = pauli1.compose(pauli2) self.assertEqual(value, target) with self.subTest(msg="compose 3-qubit qargs=[0, 1, 2]"): - target = PauliTable.from_labels(["XYZ", "IZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XYZ", "IZY"]) value = pauli1.compose(pauli2, qargs=[0, 1, 2]) self.assertEqual(value, target) with self.subTest(msg="compose 3-qubit qargs=[2, 1, 0]"): - target = PauliTable.from_labels(["ZYX", "YZI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZYX", "YZI"]) value = pauli1.compose(pauli2, qargs=[2, 1, 0]) self.assertEqual(value, target) with self.subTest(msg="compose 3-qubit qargs=[1, 0, 2]"): - target = PauliTable.from_labels(["XZY", "IYZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XZY", "IYZ"]) value = pauli1.compose(pauli2, qargs=[1, 0, 2]) self.assertEqual(value, target) def test_qargs_dot_3q(self): """Test 3-qubit dot method with qargs.""" - pauli1 = PauliTable.from_labels(["III", "XXX"]) - pauli2 = PauliTable("XYZ") + with self.assertWarns(DeprecationWarning): + pauli1 = PauliTable.from_labels(["III", "XXX"]) + pauli2 = PauliTable("XYZ") with self.subTest(msg="dot 3-qubit qargs=None"): - target = PauliTable.from_labels(["XYZ", "IZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XYZ", "IZY"]) value = pauli1.dot(pauli2, qargs=[0, 1, 2]) self.assertEqual(value, target) with self.subTest(msg="dot 3-qubit qargs=[0, 1, 2]"): - target = PauliTable.from_labels(["XYZ", "IZY"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XYZ", "IZY"]) value = pauli1.dot(pauli2, qargs=[0, 1, 2]) self.assertEqual(value, target) with self.subTest(msg="dot 3-qubit qargs=[2, 1, 0]"): - target = PauliTable.from_labels(["ZYX", "YZI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["ZYX", "YZI"]) value = pauli1.dot(pauli2, qargs=[2, 1, 0]) self.assertEqual(value, target) with self.subTest(msg="dot 3-qubit qargs=[1, 0, 2]"): - target = PauliTable.from_labels(["XZY", "IYZ"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["XZY", "IYZ"]) value = pauli1.dot(pauli2, qargs=[1, 0, 2]) self.assertEqual(value, target) @@ -760,15 +877,17 @@ def test_sort(self): with self.subTest(msg="1 qubit standard order"): unsrt = ["X", "Z", "I", "Y", "X", "Z"] srt = ["I", "X", "X", "Y", "Z", "Z"] - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort() self.assertEqual(target, value) with self.subTest(msg="1 qubit weight order"): unsrt = ["X", "Z", "I", "Y", "X", "Z"] srt = ["I", "X", "X", "Y", "Z", "Z"] - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort(weight=True) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort(weight=True) self.assertEqual(target, value) with self.subTest(msg="2 qubit standard order"): @@ -794,8 +913,9 @@ def test_sort(self): ] unsrt = srt.copy() np.random.shuffle(unsrt) - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort() self.assertEqual(target, value) with self.subTest(msg="2 qubit weight order"): @@ -824,8 +944,9 @@ def test_sort(self): ] unsrt = srt.copy() np.random.shuffle(unsrt) - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort(weight=True) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort(weight=True) self.assertEqual(target, value) with self.subTest(msg="3 qubit standard order"): @@ -905,8 +1026,9 @@ def test_sort(self): ] unsrt = srt.copy() np.random.shuffle(unsrt) - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort() self.assertEqual(target, value) with self.subTest(msg="3 qubit weight order"): @@ -981,8 +1103,9 @@ def test_sort(self): ] unsrt = srt.copy() np.random.shuffle(unsrt) - target = PauliTable.from_labels(srt) - value = PauliTable.from_labels(unsrt).sort(weight=True) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(srt) + value = PauliTable.from_labels(unsrt).sort(weight=True) self.assertEqual(target, value) def test_unique(self): @@ -990,70 +1113,84 @@ def test_unique(self): with self.subTest(msg="1 qubit"): labels = ["X", "Z", "X", "X", "I", "Y", "I", "X", "Z", "Z", "X", "I"] unique = ["X", "Z", "I", "Y"] - target = PauliTable.from_labels(unique) - value = PauliTable.from_labels(labels).unique() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(unique) + value = PauliTable.from_labels(labels).unique() self.assertEqual(target, value) with self.subTest(msg="2 qubit"): labels = ["XX", "IX", "XX", "II", "IZ", "ZI", "YX", "YX", "ZZ", "IX", "XI"] unique = ["XX", "IX", "II", "IZ", "ZI", "YX", "ZZ", "XI"] - target = PauliTable.from_labels(unique) - value = PauliTable.from_labels(labels).unique() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(unique) + value = PauliTable.from_labels(labels).unique() self.assertEqual(target, value) with self.subTest(msg="10 qubit"): labels = [10 * "X", 10 * "I", 10 * "X"] unique = [10 * "X", 10 * "I"] - target = PauliTable.from_labels(unique) - value = PauliTable.from_labels(labels).unique() + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(unique) + value = PauliTable.from_labels(labels).unique() self.assertEqual(target, value) def test_delete(self): """Test delete method.""" with self.subTest(msg="single row"): for j in range(1, 6): - pauli = PauliTable.from_labels([j * "X", j * "Y"]) - self.assertEqual(pauli.delete(0), PauliTable(j * "Y")) - self.assertEqual(pauli.delete(1), PauliTable(j * "X")) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels([j * "X", j * "Y"]) + self.assertEqual(pauli.delete(0), PauliTable(j * "Y")) + self.assertEqual(pauli.delete(1), PauliTable(j * "X")) with self.subTest(msg="multiple rows"): for j in range(1, 6): - pauli = PauliTable.from_labels([j * "X", j * "Y", j * "Z"]) - self.assertEqual(pauli.delete([0, 2]), PauliTable(j * "Y")) - self.assertEqual(pauli.delete([1, 2]), PauliTable(j * "X")) - self.assertEqual(pauli.delete([0, 1]), PauliTable(j * "Z")) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels([j * "X", j * "Y", j * "Z"]) + self.assertEqual(pauli.delete([0, 2]), PauliTable(j * "Y")) + self.assertEqual(pauli.delete([1, 2]), PauliTable(j * "X")) + self.assertEqual(pauli.delete([0, 1]), PauliTable(j * "Z")) with self.subTest(msg="single qubit"): - pauli = PauliTable.from_labels(["IIX", "IYI", "ZII"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["IIX", "IYI", "ZII"]) value = pauli.delete(0, qubit=True) - target = PauliTable.from_labels(["II", "IY", "ZI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["II", "IY", "ZI"]) self.assertEqual(value, target) value = pauli.delete(1, qubit=True) - target = PauliTable.from_labels(["IX", "II", "ZI"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IX", "II", "ZI"]) self.assertEqual(value, target) value = pauli.delete(2, qubit=True) - target = PauliTable.from_labels(["IX", "YI", "II"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["IX", "YI", "II"]) self.assertEqual(value, target) with self.subTest(msg="multiple qubits"): - pauli = PauliTable.from_labels(["IIX", "IYI", "ZII"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["IIX", "IYI", "ZII"]) value = pauli.delete([0, 1], qubit=True) - target = PauliTable.from_labels(["I", "I", "Z"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["I", "I", "Z"]) self.assertEqual(value, target) value = pauli.delete([1, 2], qubit=True) - target = PauliTable.from_labels(["X", "I", "I"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["X", "I", "I"]) self.assertEqual(value, target) value = pauli.delete([0, 2], qubit=True) - target = PauliTable.from_labels(["I", "Y", "I"]) + with self.assertWarns(DeprecationWarning): + target = PauliTable.from_labels(["I", "Y", "I"]) self.assertEqual(value, target) def test_insert(self): """Test insert method.""" # Insert single row for j in range(1, 10): - pauli = PauliTable(j * "X") - target0 = PauliTable.from_labels([j * "I", j * "X"]) - target1 = PauliTable.from_labels([j * "X", j * "I"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable(j * "X") + target0 = PauliTable.from_labels([j * "I", j * "X"]) + target1 = PauliTable.from_labels([j * "X", j * "I"]) with self.subTest(msg=f"single row from str ({j})"): value0 = pauli.insert(0, j * "I") @@ -1062,21 +1199,26 @@ def test_insert(self): self.assertEqual(value1, target1) with self.subTest(msg=f"single row from PauliTable ({j})"): - value0 = pauli.insert(0, PauliTable(j * "I")) + with self.assertWarns(DeprecationWarning): + value0 = pauli.insert(0, PauliTable(j * "I")) self.assertEqual(value0, target0) - value1 = pauli.insert(1, PauliTable(j * "I")) + with self.assertWarns(DeprecationWarning): + value1 = pauli.insert(1, PauliTable(j * "I")) self.assertEqual(value1, target1) with self.subTest(msg=f"single row from array ({j})"): - value0 = pauli.insert(0, PauliTable(j * "I").array) + with self.assertWarns(DeprecationWarning): + value0 = pauli.insert(0, PauliTable(j * "I").array) self.assertEqual(value0, target0) - value1 = pauli.insert(1, PauliTable(j * "I").array) + with self.assertWarns(DeprecationWarning): + value1 = pauli.insert(1, PauliTable(j * "I").array) self.assertEqual(value1, target1) # Insert multiple rows for j in range(1, 10): - pauli = PauliTable(j * "X") - insert = PauliTable.from_labels([j * "I", j * "Y", j * "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable(j * "X") + insert = PauliTable.from_labels([j * "I", j * "Y", j * "Z"]) target0 = insert + pauli target1 = pauli + insert @@ -1095,8 +1237,9 @@ def test_insert(self): # Insert single column pauli = PauliTable.from_labels(["X", "Y", "Z"]) for i in ["I", "X", "Y", "Z"]: - target0 = PauliTable.from_labels(["X" + i, "Y" + i, "Z" + i]) - target1 = PauliTable.from_labels([i + "X", i + "Y", i + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = PauliTable.from_labels(["X" + i, "Y" + i, "Z" + i]) + target1 = PauliTable.from_labels([i + "X", i + "Y", i + "Z"]) with self.subTest(msg="single-column single-val from str"): value = pauli.insert(0, i, qubit=True) @@ -1105,41 +1248,53 @@ def test_insert(self): self.assertEqual(value, target1) with self.subTest(msg="single-column single-val from PauliTable"): - value = pauli.insert(0, PauliTable(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable(i), qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable(i), qubit=True) self.assertEqual(value, target1) with self.subTest(msg="single-column single-val from array"): - value = pauli.insert(0, PauliTable(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable(i).array, qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable(i).array, qubit=True) self.assertEqual(value, target1) # Insert single column with multiple values - pauli = PauliTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["X", "Y", "Z"]) for i in [("I", "X", "Y"), ("X", "Y", "Z"), ("Y", "Z", "I")]: - target0 = PauliTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) - target1 = PauliTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = PauliTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) + target1 = PauliTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) with self.subTest(msg="single-column multiple-vals from PauliTable"): - value = pauli.insert(0, PauliTable.from_labels(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable.from_labels(i), qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable.from_labels(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable.from_labels(i), qubit=True) self.assertEqual(value, target1) with self.subTest(msg="single-column multiple-vals from array"): - value = pauli.insert(0, PauliTable.from_labels(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable.from_labels(i).array, qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable.from_labels(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable.from_labels(i).array, qubit=True) self.assertEqual(value, target1) # Insert multiple columns from single - pauli = PauliTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["X", "Y", "Z"]) for j in range(1, 5): for i in [j * "I", j * "X", j * "Y", j * "Z"]: - target0 = PauliTable.from_labels(["X" + i, "Y" + i, "Z" + i]) - target1 = PauliTable.from_labels([i + "X", i + "Y", i + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = PauliTable.from_labels(["X" + i, "Y" + i, "Z" + i]) + target1 = PauliTable.from_labels([i + "X", i + "Y", i + "Z"]) with self.subTest(msg="multiple-columns single-val from str"): value = pauli.insert(0, i, qubit=True) @@ -1148,44 +1303,55 @@ def test_insert(self): self.assertEqual(value, target1) with self.subTest(msg="multiple-columns single-val from PauliTable"): - value = pauli.insert(0, PauliTable(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable(i), qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable(i), qubit=True) self.assertEqual(value, target1) with self.subTest(msg="multiple-columns single-val from array"): - value = pauli.insert(0, PauliTable(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable(i).array, qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable(i).array, qubit=True) self.assertEqual(value, target1) # Insert multiple columns multiple row values - pauli = PauliTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["X", "Y", "Z"]) for j in range(1, 5): for i in [ (j * "I", j * "X", j * "Y"), (j * "X", j * "Z", j * "Y"), (j * "Y", j * "Z", j * "I"), ]: - target0 = PauliTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) - target1 = PauliTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = PauliTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) + target1 = PauliTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) with self.subTest(msg="multiple-column multiple-vals from PauliTable"): - value = pauli.insert(0, PauliTable.from_labels(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable.from_labels(i), qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable.from_labels(i), qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable.from_labels(i), qubit=True) self.assertEqual(value, target1) with self.subTest(msg="multiple-column multiple-vals from array"): - value = pauli.insert(0, PauliTable.from_labels(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(0, PauliTable.from_labels(i).array, qubit=True) self.assertEqual(value, target0) - value = pauli.insert(1, PauliTable.from_labels(i).array, qubit=True) + with self.assertWarns(DeprecationWarning): + value = pauli.insert(1, PauliTable.from_labels(i).array, qubit=True) self.assertEqual(value, target1) def test_commutes(self): """Test commutes method.""" # Single qubit Pauli - pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) with self.subTest(msg="commutes single-Pauli I"): value = list(pauli.commutes("I")) target = [True, True, True, True] @@ -1207,7 +1373,8 @@ def test_commutes(self): self.assertEqual(value, target) # 2-qubit Pauli - pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) with self.subTest(msg="commutes single-Pauli II"): value = list(pauli.commutes("II")) target = [True, True, True, True, True] @@ -1251,7 +1418,8 @@ def test_commutes(self): def test_commutes_with_all(self): """Test commutes_with_all method.""" # 1-qubit - pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) with self.subTest(msg="commutes_with_all [I]"): value = list(pauli.commutes_with_all("I")) target = [0, 1, 2, 3] @@ -1273,40 +1441,47 @@ def test_commutes_with_all(self): self.assertEqual(value, target) # 2-qubit Pauli - pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) with self.subTest(msg="commutes_with_all [IX, YI]"): - other = PauliTable.from_labels(["IX", "YI"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["IX", "YI"]) value = list(pauli.commutes_with_all(other)) target = [0, 1, 2] self.assertEqual(value, target) with self.subTest(msg="commutes_with_all [XY, ZZ]"): - other = PauliTable.from_labels(["XY", "ZZ"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "ZZ"]) value = list(pauli.commutes_with_all(other)) target = [0, 3, 4] self.assertEqual(value, target) with self.subTest(msg="commutes_with_all [YX, ZZ]"): - other = PauliTable.from_labels(["YX", "ZZ"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["YX", "ZZ"]) value = list(pauli.commutes_with_all(other)) target = [0, 3, 4] self.assertEqual(value, target) with self.subTest(msg="commutes_with_all [XY, YX]"): - other = PauliTable.from_labels(["XY", "YX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "YX"]) value = list(pauli.commutes_with_all(other)) target = [0, 3, 4] self.assertEqual(value, target) with self.subTest(msg="commutes_with_all [XY, IX]"): - other = PauliTable.from_labels(["XY", "IX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "IX"]) value = list(pauli.commutes_with_all(other)) target = [0] self.assertEqual(value, target) with self.subTest(msg="commutes_with_all [YX, IX]"): - other = PauliTable.from_labels(["YX", "IX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["YX", "IX"]) value = list(pauli.commutes_with_all(other)) target = [0, 1, 2] self.assertEqual(value, target) @@ -1314,7 +1489,8 @@ def test_commutes_with_all(self): def test_anticommutes_with_all(self): """Test anticommutes_with_all method.""" # 1-qubit - pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["I", "X", "Y", "Z"]) with self.subTest(msg="anticommutes_with_all [I]"): value = list(pauli.anticommutes_with_all("I")) target = [] @@ -1336,40 +1512,47 @@ def test_anticommutes_with_all(self): self.assertEqual(value, target) # 2-qubit Pauli - pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) + with self.assertWarns(DeprecationWarning): + pauli = PauliTable.from_labels(["II", "IX", "YI", "XY", "ZZ"]) with self.subTest(msg="anticommutes_with_all [IX, YI]"): - other = PauliTable.from_labels(["IX", "YI"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["IX", "YI"]) value = list(pauli.anticommutes_with_all(other)) target = [3, 4] self.assertEqual(value, target) with self.subTest(msg="anticommutes_with_all [XY, ZZ]"): - other = PauliTable.from_labels(["XY", "ZZ"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "ZZ"]) value = list(pauli.anticommutes_with_all(other)) target = [1, 2] self.assertEqual(value, target) with self.subTest(msg="anticommutes_with_all [YX, ZZ]"): - other = PauliTable.from_labels(["YX", "ZZ"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["YX", "ZZ"]) value = list(pauli.anticommutes_with_all(other)) target = [] self.assertEqual(value, target) with self.subTest(msg="anticommutes_with_all [XY, YX]"): - other = PauliTable.from_labels(["XY", "YX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "YX"]) value = list(pauli.anticommutes_with_all(other)) target = [] self.assertEqual(value, target) with self.subTest(msg="anticommutes_with_all [XY, IX]"): - other = PauliTable.from_labels(["XY", "IX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["XY", "IX"]) value = list(pauli.anticommutes_with_all(other)) target = [] self.assertEqual(value, target) with self.subTest(msg="anticommutes_with_all [YX, IX]"): - other = PauliTable.from_labels(["YX", "IX"]) + with self.assertWarns(DeprecationWarning): + other = PauliTable.from_labels(["YX", "IX"]) value = list(pauli.anticommutes_with_all(other)) target = [] self.assertEqual(value, target) diff --git a/test/python/quantum_info/operators/symplectic/test_stabilizer_table.py b/test/python/quantum_info/operators/symplectic/test_stabilizer_table.py index 05d2d9f59a9b..a77ff14276d7 100644 --- a/test/python/quantum_info/operators/symplectic/test_stabilizer_table.py +++ b/test/python/quantum_info/operators/symplectic/test_stabilizer_table.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -51,30 +51,35 @@ def test_array_init(self): with self.subTest(msg="bool array"): target = np.array([[False, False], [True, True]]) - value = StabilizerTable(target)._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(target)._array self.assertTrue(np.all(value == target)) with self.subTest(msg="bool array no copy"): target = np.array([[False, True], [True, True]]) - value = StabilizerTable(target)._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(target)._array value[0, 0] = not value[0, 0] self.assertTrue(np.all(value == target)) with self.subTest(msg="bool array raises"): array = np.array([[False, False, False], [True, True, True]]) - self.assertRaises(QiskitError, StabilizerTable, array) + with self.assertWarns(DeprecationWarning): + self.assertRaises(QiskitError, StabilizerTable, array) def test_vector_init(self): """Test vector initialization.""" with self.subTest(msg="bool vector"): target = np.array([False, False, False, False]) - value = StabilizerTable(target)._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(target)._array self.assertTrue(np.all(value == target)) with self.subTest(msg="bool vector no copy"): target = np.array([False, True, True, False]) - value = StabilizerTable(target)._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(target)._array value[0, 0] = not value[0, 0] self.assertTrue(np.all(value == target)) @@ -82,42 +87,50 @@ def test_string_init(self): """Test string initialization.""" with self.subTest(msg='str init "I"'): - value = StabilizerTable("I")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("I")._array target = np.array([[False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "X"'): - value = StabilizerTable("X")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("X")._array target = np.array([[True, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "Y"'): - value = StabilizerTable("Y")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("Y")._array target = np.array([[True, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "Z"'): - value = StabilizerTable("Z")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("Z")._array target = np.array([[False, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "IX"'): - value = StabilizerTable("IX")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("IX")._array target = np.array([[True, False, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "XI"'): - value = StabilizerTable("XI")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("XI")._array target = np.array([[False, True, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "YZ"'): - value = StabilizerTable("YZ")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("YZ")._array target = np.array([[False, True, True, True]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) with self.subTest(msg='str init "XIZ"'): - value = StabilizerTable("XIZ")._array + with self.assertWarns(DeprecationWarning): + value = StabilizerTable("XIZ")._array target = np.array([[False, False, True, True, False, False]], dtype=bool) self.assertTrue(np.all(np.array(value == target))) @@ -125,15 +138,17 @@ def test_table_init(self): """Test StabilizerTable initialization.""" with self.subTest(msg="StabilizerTable"): - target = StabilizerTable.from_labels(["XI", "IX", "IZ"]) - value = StabilizerTable(target) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["XI", "IX", "IZ"]) + value = StabilizerTable(target) + self.assertEqual(value, target) with self.subTest(msg="StabilizerTable no copy"): - target = StabilizerTable.from_labels(["XI", "IX", "IZ"]) - value = StabilizerTable(target) - value[0] = "II" - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["XI", "IX", "IZ"]) + value = StabilizerTable(target) + value[0] = "II" + self.assertEqual(value, target) class TestStabilizerTableProperties(QiskitTestCase): @@ -143,14 +158,16 @@ def test_array_property(self): """Test array property""" with self.subTest(msg="array"): - stab = StabilizerTable("II") + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable("II") array = np.zeros([2, 4], dtype=bool) self.assertTrue(np.all(stab.array == array)) with self.subTest(msg="set array"): def set_array(): - stab = StabilizerTable("XXX") + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable("XXX") stab.array = np.eye(4) return stab @@ -160,20 +177,24 @@ def test_x_property(self): """Test X property""" with self.subTest(msg="X"): - stab = StabilizerTable.from_labels(["XI", "IZ", "YY"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ", "YY"]) array = np.array([[False, True], [False, False], [True, True]], dtype=bool) self.assertTrue(np.all(stab.X == array)) with self.subTest(msg="set X"): - stab = StabilizerTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ"]) val = np.array([[False, False], [True, True]], dtype=bool) stab.X = val - self.assertEqual(stab, StabilizerTable.from_labels(["II", "XY"])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab, StabilizerTable.from_labels(["II", "XY"])) with self.subTest(msg="set X raises"): def set_x(): - stab = StabilizerTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ"]) val = np.array([[False, False, False], [True, True, True]], dtype=bool) stab.X = val return stab @@ -183,20 +204,24 @@ def set_x(): def test_z_property(self): """Test Z property""" with self.subTest(msg="Z"): - stab = StabilizerTable.from_labels(["XI", "IZ", "YY"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ", "YY"]) array = np.array([[False, False], [True, False], [True, True]], dtype=bool) self.assertTrue(np.all(stab.Z == array)) with self.subTest(msg="set Z"): - stab = StabilizerTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ"]) val = np.array([[False, False], [True, True]], dtype=bool) stab.Z = val - self.assertEqual(stab, StabilizerTable.from_labels(["XI", "ZZ"])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab, StabilizerTable.from_labels(["XI", "ZZ"])) with self.subTest(msg="set Z raises"): def set_z(): - stab = StabilizerTable.from_labels(["XI", "IZ"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["XI", "IZ"]) val = np.array([[False, False, False], [True, True, True]], dtype=bool) stab.Z = val return stab @@ -206,7 +231,8 @@ def set_z(): def test_shape_property(self): """Test shape property""" shape = (3, 8) - stab = StabilizerTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(np.zeros(shape)) self.assertEqual(stab.shape, shape) def test_size_property(self): @@ -214,7 +240,8 @@ def test_size_property(self): with self.subTest(msg="size"): for j in range(1, 10): shape = (j, 8) - stab = StabilizerTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(np.zeros(shape)) self.assertEqual(stab.size, j) def test_num_qubits_property(self): @@ -222,7 +249,8 @@ def test_num_qubits_property(self): with self.subTest(msg="num_qubits"): for j in range(1, 10): shape = (5, 2 * j) - stab = StabilizerTable(np.zeros(shape)) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(np.zeros(shape)) self.assertEqual(stab.num_qubits, j) def test_phase_property(self): @@ -230,20 +258,23 @@ def test_phase_property(self): with self.subTest(msg="phase"): phase = np.array([False, True, True, False]) array = np.eye(4, dtype=bool) - stab = StabilizerTable(array, phase) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array, phase) self.assertTrue(np.all(stab.phase == phase)) with self.subTest(msg="set phase"): phase = np.array([False, True, True, False]) array = np.eye(4, dtype=bool) - stab = StabilizerTable(array) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array) stab.phase = phase self.assertTrue(np.all(stab.phase == phase)) with self.subTest(msg="set phase raises"): phase = np.array([False, True, False]) array = np.eye(4, dtype=bool) - stab = StabilizerTable(array) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array) def set_phase_raise(): """Raise exception""" @@ -256,15 +287,17 @@ def test_pauli_property(self): with self.subTest(msg="pauli"): phase = np.array([False, True, True, False]) array = np.eye(4, dtype=bool) - stab = StabilizerTable(array, phase) - pauli = PauliTable(array) - self.assertEqual(stab.pauli, pauli) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array, phase) + pauli = PauliTable(array) + self.assertEqual(stab.pauli, pauli) with self.subTest(msg="set pauli"): phase = np.array([False, True, True, False]) array = np.zeros((4, 4), dtype=bool) - stab = StabilizerTable(array, phase) - pauli = PauliTable(np.eye(4, dtype=bool)) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array, phase) + pauli = PauliTable(np.eye(4, dtype=bool)) stab.pauli = pauli self.assertTrue(np.all(stab.array == pauli.array)) self.assertTrue(np.all(stab.phase == phase)) @@ -272,8 +305,9 @@ def test_pauli_property(self): with self.subTest(msg="set pauli"): phase = np.array([False, True, True, False]) array = np.zeros((4, 4), dtype=bool) - stab = StabilizerTable(array, phase) - pauli = PauliTable(np.eye(4, dtype=bool)[1:]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(array, phase) + pauli = PauliTable(np.eye(4, dtype=bool)[1:]) def set_pauli_raise(): """Raise exception""" @@ -283,79 +317,93 @@ def set_pauli_raise(): def test_eq(self): """Test __eq__ method.""" - stab1 = StabilizerTable.from_labels(["II", "XI"]) - stab2 = StabilizerTable.from_labels(["XI", "II"]) - self.assertEqual(stab1, stab1) - self.assertNotEqual(stab1, stab2) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(["II", "XI"]) + stab2 = StabilizerTable.from_labels(["XI", "II"]) + self.assertEqual(stab1, stab1) + self.assertNotEqual(stab1, stab2) def test_len_methods(self): """Test __len__ method.""" for j in range(1, 10): labels = j * ["XX"] - stab = StabilizerTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) self.assertEqual(len(stab), j) def test_add_methods(self): """Test __add__ method.""" labels1 = ["+XXI", "-IXX"] labels2 = ["+XXI", "-ZZI", "+ZYZ"] - stab1 = StabilizerTable.from_labels(labels1) - stab2 = StabilizerTable.from_labels(labels2) - target = StabilizerTable.from_labels(labels1 + labels2) - self.assertEqual(target, stab1 + stab2) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(labels1) + stab2 = StabilizerTable.from_labels(labels2) + target = StabilizerTable.from_labels(labels1 + labels2) + self.assertEqual(target, stab1 + stab2) def test_add_qargs(self): """Test add method with qargs.""" - stab1 = StabilizerTable.from_labels(["+IIII", "-YYYY"]) - stab2 = StabilizerTable.from_labels(["-XY", "+YZ"]) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(["+IIII", "-YYYY"]) + stab2 = StabilizerTable.from_labels(["-XY", "+YZ"]) with self.subTest(msg="qargs=[0, 1]"): - target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-IIXY", "+IIYZ"]) - self.assertEqual(stab1 + stab2([0, 1]), target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-IIXY", "+IIYZ"]) + self.assertEqual(stab1 + stab2([0, 1]), target) with self.subTest(msg="qargs=[0, 3]"): - target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-XIIY", "+YIIZ"]) - self.assertEqual(stab1 + stab2([0, 3]), target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-XIIY", "+YIIZ"]) + self.assertEqual(stab1 + stab2([0, 3]), target) with self.subTest(msg="qargs=[2, 1]"): - target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-IYXI", "+IZYI"]) - self.assertEqual(stab1 + stab2([2, 1]), target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-IYXI", "+IZYI"]) + self.assertEqual(stab1 + stab2([2, 1]), target) with self.subTest(msg="qargs=[3, 1]"): - target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-YIXI", "+ZIYI"]) - self.assertEqual(stab1 + stab2([3, 1]), target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["+IIII", "-YYYY", "-YIXI", "+ZIYI"]) + self.assertEqual(stab1 + stab2([3, 1]), target) def test_getitem_methods(self): """Test __getitem__ method.""" with self.subTest(msg="__getitem__ single"): labels = ["+XI", "-IY"] - stab = StabilizerTable.from_labels(labels) - self.assertEqual(stab[0], StabilizerTable(labels[0])) - self.assertEqual(stab[1], StabilizerTable(labels[1])) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) + self.assertEqual(stab[0], StabilizerTable(labels[0])) + self.assertEqual(stab[1], StabilizerTable(labels[1])) with self.subTest(msg="__getitem__ array"): labels = np.array(["+XI", "-IY", "+IZ", "-XY", "+ZX"]) - stab = StabilizerTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) inds = [0, 3] - self.assertEqual(stab[inds], StabilizerTable.from_labels(labels[inds])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab[inds], StabilizerTable.from_labels(labels[inds])) inds = np.array([4, 1]) - self.assertEqual(stab[inds], StabilizerTable.from_labels(labels[inds])) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab[inds], StabilizerTable.from_labels(labels[inds])) with self.subTest(msg="__getitem__ slice"): labels = np.array(["+XI", "-IY", "+IZ", "-XY", "+ZX"]) - stab = StabilizerTable.from_labels(labels) - self.assertEqual(stab[:], stab) - self.assertEqual(stab[1:3], StabilizerTable.from_labels(labels[1:3])) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) + self.assertEqual(stab[:], stab) + self.assertEqual(stab[1:3], StabilizerTable.from_labels(labels[1:3])) def test_setitem_methods(self): """Test __setitem__ method.""" with self.subTest(msg="__setitem__ single"): labels = ["+XI", "IY"] - stab = StabilizerTable.from_labels(["+XI", "IY"]) - stab[0] = "+II" - self.assertEqual(stab[0], StabilizerTable("+II")) - stab[1] = "-XX" - self.assertEqual(stab[1], StabilizerTable("-XX")) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["+XI", "IY"]) + stab[0] = "+II" + self.assertEqual(stab[0], StabilizerTable("+II")) + stab[1] = "-XX" + self.assertEqual(stab[1], StabilizerTable("-XX")) def raises_single(): # Wrong size Pauli @@ -365,26 +413,31 @@ def raises_single(): with self.subTest(msg="__setitem__ array"): labels = np.array(["+XI", "-IY", "+IZ"]) - stab = StabilizerTable.from_labels(labels) - target = StabilizerTable.from_labels(["+II", "-ZZ"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) + target = StabilizerTable.from_labels(["+II", "-ZZ"]) inds = [2, 0] stab[inds] = target - self.assertEqual(stab[inds], target) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab[inds], target) def raises_array(): - stab[inds] = StabilizerTable.from_labels(["+YY", "-ZZ", "+XX"]) + with self.assertWarns(DeprecationWarning): + stab[inds] = StabilizerTable.from_labels(["+YY", "-ZZ", "+XX"]) self.assertRaises(Exception, raises_array) with self.subTest(msg="__setitem__ slice"): labels = np.array(5 * ["+III"]) - stab = StabilizerTable.from_labels(labels) - target = StabilizerTable.from_labels(5 * ["-XXX"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) + target = StabilizerTable.from_labels(5 * ["-XXX"]) stab[:] = target - self.assertEqual(stab[:], target) - target = StabilizerTable.from_labels(2 * ["+ZZZ"]) - stab[1:3] = target - self.assertEqual(stab[1:3], target) + with self.assertWarns(DeprecationWarning): + self.assertEqual(stab[:], target) + target = StabilizerTable.from_labels(2 * ["+ZZZ"]) + stab[1:3] = target + self.assertEqual(stab[1:3], target) class TestStabilizerTableLabels(QiskitTestCase): @@ -397,9 +450,10 @@ def test_from_labels_1q(self): 3 * [np.array([[False, False], [True, False], [True, True], [False, True]], dtype=bool)] ) phase = np.array(8 * [False] + 4 * [True], dtype=bool) - target = StabilizerTable(array, phase) - value = StabilizerTable.from_labels(labels) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable(array, phase) + value = StabilizerTable.from_labels(labels) + self.assertEqual(target, value) def test_from_labels_2q(self): """Test 2-qubit from_labels method.""" @@ -409,9 +463,10 @@ def test_from_labels_2q(self): dtype=bool, ) phase = np.array([False, True, False]) - target = StabilizerTable(array, phase) - value = StabilizerTable.from_labels(labels) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable(array, phase) + value = StabilizerTable.from_labels(labels) + self.assertEqual(target, value) def test_from_labels_5q(self): """Test 5-qubit from_labels method.""" @@ -421,9 +476,10 @@ def test_from_labels_5q(self): dtype=bool, ) phase = np.array([False, True, False, False]) - target = StabilizerTable(array, phase) - value = StabilizerTable.from_labels(labels) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable(array, phase) + value = StabilizerTable.from_labels(labels) + self.assertEqual(target, value) def test_to_labels_1q(self): """Test 1-qubit to_labels method.""" @@ -431,7 +487,8 @@ def test_to_labels_1q(self): 2 * [np.array([[False, False], [True, False], [True, True], [False, True]], dtype=bool)] ) phase = np.array(4 * [False] + 4 * [True], dtype=bool) - value = StabilizerTable(array, phase).to_labels() + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(array, phase).to_labels() target = ["+I", "+X", "+Y", "+Z", "-I", "-X", "-Y", "-Z"] self.assertEqual(value, target) @@ -441,21 +498,24 @@ def test_to_labels_1q_array(self): 2 * [np.array([[False, False], [True, False], [True, True], [False, True]], dtype=bool)] ) phase = np.array(4 * [False] + 4 * [True], dtype=bool) - value = StabilizerTable(array, phase).to_labels(array=True) + with self.assertWarns(DeprecationWarning): + value = StabilizerTable(array, phase).to_labels(array=True) target = np.array(["+I", "+X", "+Y", "+Z", "-I", "-X", "-Y", "-Z"]) self.assertTrue(np.all(value == target)) def test_labels_round_trip(self): """Test from_labels and to_labels round trip.""" target = ["+III", "-IXZ", "-XYI", "+ZZZ"] - value = StabilizerTable.from_labels(target).to_labels() + with self.assertWarns(DeprecationWarning): + value = StabilizerTable.from_labels(target).to_labels() self.assertEqual(value, target) def test_labels_round_trip_array(self): """Test from_labels and to_labels round trip w/ array=True.""" labels = ["+III", "-IXZ", "-XYI", "+ZZZ"] target = np.array(labels) - value = StabilizerTable.from_labels(labels).to_labels(array=True) + with self.assertWarns(DeprecationWarning): + value = StabilizerTable.from_labels(labels).to_labels(array=True) self.assertTrue(np.all(value == target)) @@ -466,7 +526,8 @@ def test_to_matrix_1q(self): """Test 1-qubit to_matrix method.""" labels = ["+I", "+X", "+Y", "+Z", "-I", "-X", "-Y", "-Z"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -475,7 +536,8 @@ def test_to_matrix_1q_array(self): """Test 1-qubit to_matrix method w/ array=True.""" labels = ["+I", "+X", "+Y", "+Z", "-I", "-X", "-Y", "-Z"] target = np.array([stab_mat(i) for i in labels]) - value = StabilizerTable.from_labels(labels).to_matrix(array=True) + with self.assertWarns(DeprecationWarning): + value = StabilizerTable.from_labels(labels).to_matrix(array=True) self.assertTrue(isinstance(value, np.ndarray)) self.assertTrue(np.all(value == target)) @@ -483,7 +545,8 @@ def test_to_matrix_1q_sparse(self): """Test 1-qubit to_matrix method w/ sparse=True.""" labels = ["+I", "+X", "+Y", "+Z", "-I", "-X", "-Y", "-Z"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -492,7 +555,8 @@ def test_to_matrix_2q(self): """Test 2-qubit to_matrix method.""" labels = ["+IX", "-YI", "-II", "+ZZ"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -501,7 +565,8 @@ def test_to_matrix_2q_array(self): """Test 2-qubit to_matrix method w/ array=True.""" labels = ["-ZZ", "-XY", "+YX", "-IZ"] target = np.array([stab_mat(i) for i in labels]) - value = StabilizerTable.from_labels(labels).to_matrix(array=True) + with self.assertWarns(DeprecationWarning): + value = StabilizerTable.from_labels(labels).to_matrix(array=True) self.assertTrue(isinstance(value, np.ndarray)) self.assertTrue(np.all(value == target)) @@ -509,7 +574,8 @@ def test_to_matrix_2q_sparse(self): """Test 2-qubit to_matrix method w/ sparse=True.""" labels = ["+IX", "+II", "-ZY", "-YZ"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -518,7 +584,8 @@ def test_to_matrix_5q(self): """Test 5-qubit to_matrix method.""" labels = ["IXIXI", "YZIXI", "IIXYZ"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix() + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix() self.assertTrue(isinstance(values, list)) for target, value in zip(targets, values): self.assertTrue(np.all(value == target)) @@ -527,7 +594,8 @@ def test_to_matrix_5q_sparse(self): """Test 5-qubit to_matrix method w/ sparse=True.""" labels = ["-XXXYY", "IXIZY", "-ZYXIX", "+ZXIYZ"] targets = [stab_mat(i) for i in labels] - values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) + with self.assertWarns(DeprecationWarning): + values = StabilizerTable.from_labels(labels).to_matrix(sparse=True) for mat, targ in zip(values, targets): self.assertTrue(isinstance(mat, csr_matrix)) self.assertTrue(np.all(targ == mat.toarray())) @@ -541,16 +609,18 @@ def test_sort(self): with self.subTest(msg="1 qubit"): unsrt = ["X", "-Z", "I", "Y", "-X", "Z"] srt = ["I", "X", "-X", "Y", "-Z", "Z"] - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort() + self.assertEqual(target, value) with self.subTest(msg="1 qubit weight order"): unsrt = ["X", "-Z", "I", "Y", "-X", "Z"] srt = ["I", "X", "-X", "Y", "-Z", "Z"] - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort(weight=True) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort(weight=True) + self.assertEqual(target, value) with self.subTest(msg="2 qubit standard order"): srt_p = [ @@ -580,16 +650,18 @@ def test_sort(self): # Sort with + cases all first in shuffled list srt = [val for pair in zip(srt_p, srt_m) for val in pair] unsrt = unsrt_p + unsrt_m - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort() + self.assertEqual(target, value) # Sort with - cases all first in shuffled list srt = [val for pair in zip(srt_m, srt_p) for val in pair] unsrt = unsrt_m + unsrt_p - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort() + self.assertEqual(target, value) with self.subTest(msg="2 qubit weight order"): srt_p = [ @@ -620,25 +692,28 @@ def test_sort(self): # Sort with + cases all first in shuffled list srt = [val for pair in zip(srt_p, srt_m) for val in pair] unsrt = unsrt_p + unsrt_m - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort(weight=True) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort(weight=True) + self.assertEqual(target, value) # Sort with - cases all first in shuffled list srt = [val for pair in zip(srt_m, srt_p) for val in pair] unsrt = unsrt_m + unsrt_p - target = StabilizerTable.from_labels(srt) - value = StabilizerTable.from_labels(unsrt).sort(weight=True) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(srt) + value = StabilizerTable.from_labels(unsrt).sort(weight=True) + self.assertEqual(target, value) def test_unique(self): """Test unique method.""" with self.subTest(msg="1 qubit"): labels = ["X", "Z", "-I", "-X", "X", "I", "Y", "-I", "-X", "-Z", "Z", "X", "I"] unique = ["X", "Z", "-I", "-X", "I", "Y", "-Z"] - target = StabilizerTable.from_labels(unique) - value = StabilizerTable.from_labels(labels).unique() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(unique) + value = StabilizerTable.from_labels(labels).unique() + self.assertEqual(target, value) with self.subTest(msg="2 qubit"): labels = [ @@ -657,55 +732,61 @@ def test_unique(self): "XI", ] unique = ["XX", "IX", "-XX", "-IZ", "II", "IZ", "ZI", "YX", "ZZ", "XI"] - target = StabilizerTable.from_labels(unique) - value = StabilizerTable.from_labels(labels).unique() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(unique) + value = StabilizerTable.from_labels(labels).unique() + self.assertEqual(target, value) with self.subTest(msg="10 qubit"): labels = [10 * "X", "-" + 10 * "X", "-" + 10 * "X", 10 * "I", 10 * "X"] unique = [10 * "X", "-" + 10 * "X", 10 * "I"] - target = StabilizerTable.from_labels(unique) - value = StabilizerTable.from_labels(labels).unique() - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(unique) + value = StabilizerTable.from_labels(labels).unique() + self.assertEqual(target, value) def test_delete(self): """Test delete method.""" with self.subTest(msg="single row"): for j in range(1, 6): - stab = StabilizerTable.from_labels([j * "X", "-" + j * "Y"]) - self.assertEqual(stab.delete(0), StabilizerTable("-" + j * "Y")) - self.assertEqual(stab.delete(1), StabilizerTable(j * "X")) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels([j * "X", "-" + j * "Y"]) + self.assertEqual(stab.delete(0), StabilizerTable("-" + j * "Y")) + self.assertEqual(stab.delete(1), StabilizerTable(j * "X")) with self.subTest(msg="multiple rows"): for j in range(1, 6): - stab = StabilizerTable.from_labels([j * "X", "-" + j * "Y", j * "Z"]) - self.assertEqual(stab.delete([0, 2]), StabilizerTable("-" + j * "Y")) - self.assertEqual(stab.delete([1, 2]), StabilizerTable(j * "X")) - self.assertEqual(stab.delete([0, 1]), StabilizerTable(j * "Z")) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels([j * "X", "-" + j * "Y", j * "Z"]) + self.assertEqual(stab.delete([0, 2]), StabilizerTable("-" + j * "Y")) + self.assertEqual(stab.delete([1, 2]), StabilizerTable(j * "X")) + self.assertEqual(stab.delete([0, 1]), StabilizerTable(j * "Z")) with self.subTest(msg="single qubit"): - stab = StabilizerTable.from_labels(["IIX", "IYI", "ZII"]) - value = stab.delete(0, qubit=True) - target = StabilizerTable.from_labels(["II", "IY", "ZI"]) - self.assertEqual(value, target) - value = stab.delete(1, qubit=True) - target = StabilizerTable.from_labels(["IX", "II", "ZI"]) - self.assertEqual(value, target) - value = stab.delete(2, qubit=True) - target = StabilizerTable.from_labels(["IX", "YI", "II"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["IIX", "IYI", "ZII"]) + value = stab.delete(0, qubit=True) + target = StabilizerTable.from_labels(["II", "IY", "ZI"]) + self.assertEqual(value, target) + value = stab.delete(1, qubit=True) + target = StabilizerTable.from_labels(["IX", "II", "ZI"]) + self.assertEqual(value, target) + value = stab.delete(2, qubit=True) + target = StabilizerTable.from_labels(["IX", "YI", "II"]) + self.assertEqual(value, target) with self.subTest(msg="multiple qubits"): - stab = StabilizerTable.from_labels(["IIX", "IYI", "ZII"]) - value = stab.delete([0, 1], qubit=True) - target = StabilizerTable.from_labels(["I", "I", "Z"]) - self.assertEqual(value, target) - value = stab.delete([1, 2], qubit=True) - target = StabilizerTable.from_labels(["X", "I", "I"]) - self.assertEqual(value, target) - value = stab.delete([0, 2], qubit=True) - target = StabilizerTable.from_labels(["I", "Y", "I"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["IIX", "IYI", "ZII"]) + value = stab.delete([0, 1], qubit=True) + target = StabilizerTable.from_labels(["I", "I", "Z"]) + self.assertEqual(value, target) + value = stab.delete([1, 2], qubit=True) + target = StabilizerTable.from_labels(["X", "I", "I"]) + self.assertEqual(value, target) + value = stab.delete([0, 2], qubit=True) + target = StabilizerTable.from_labels(["I", "Y", "I"]) + self.assertEqual(value, target) def test_insert(self): """Test insert method.""" @@ -713,137 +794,167 @@ def test_insert(self): for j in range(1, 10): l_px = j * "X" l_mi = "-" + j * "I" - stab = StabilizerTable(l_px) - target0 = StabilizerTable.from_labels([l_mi, l_px]) - target1 = StabilizerTable.from_labels([l_px, l_mi]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(l_px) + target0 = StabilizerTable.from_labels([l_mi, l_px]) + target1 = StabilizerTable.from_labels([l_px, l_mi]) with self.subTest(msg=f"single row from str ({j})"): - value0 = stab.insert(0, l_mi) - self.assertEqual(value0, target0) - value1 = stab.insert(1, l_mi) - self.assertEqual(value1, target1) + with self.assertWarns(DeprecationWarning): + value0 = stab.insert(0, l_mi) + self.assertEqual(value0, target0) + value1 = stab.insert(1, l_mi) + self.assertEqual(value1, target1) with self.subTest(msg=f"single row from StabilizerTable ({j})"): - value0 = stab.insert(0, StabilizerTable(l_mi)) - self.assertEqual(value0, target0) - value1 = stab.insert(1, StabilizerTable(l_mi)) - self.assertEqual(value1, target1) + with self.assertWarns(DeprecationWarning): + value0 = stab.insert(0, StabilizerTable(l_mi)) + self.assertEqual(value0, target0) + value1 = stab.insert(1, StabilizerTable(l_mi)) + self.assertEqual(value1, target1) # Insert multiple rows for j in range(1, 10): - stab = StabilizerTable(j * "X") - insert = StabilizerTable.from_labels(["-" + j * "I", j * "Y", "-" + j * "Z"]) - target0 = insert + stab - target1 = stab + insert + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable(j * "X") + insert = StabilizerTable.from_labels(["-" + j * "I", j * "Y", "-" + j * "Z"]) + target0 = insert + stab + target1 = stab + insert with self.subTest(msg=f"multiple-rows from StabilizerTable ({j})"): - value0 = stab.insert(0, insert) - self.assertEqual(value0, target0) - value1 = stab.insert(1, insert) - self.assertEqual(value1, target1) + with self.assertWarns(DeprecationWarning): + value0 = stab.insert(0, insert) + self.assertEqual(value0, target0) + value1 = stab.insert(1, insert) + self.assertEqual(value1, target1) # Insert single column - stab = StabilizerTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["X", "Y", "Z"]) for sgn in ["+", "-"]: for i in ["I", "X", "Y", "Z"]: - target0 = StabilizerTable.from_labels([sgn + "X" + i, sgn + "Y" + i, sgn + "Z" + i]) - target1 = StabilizerTable.from_labels([sgn + i + "X", sgn + i + "Y", sgn + i + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = StabilizerTable.from_labels( + [sgn + "X" + i, sgn + "Y" + i, sgn + "Z" + i] + ) + target1 = StabilizerTable.from_labels( + [sgn + i + "X", sgn + i + "Y", sgn + i + "Z"] + ) with self.subTest(msg=f"single-column single-val from str {sgn + i}"): - value = stab.insert(0, sgn + i, qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, sgn + i, qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, sgn + i, qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, sgn + i, qubit=True) + self.assertEqual(value, target1) with self.subTest(msg=f"single-column single-val from StabilizerTable {sgn + i}"): - value = stab.insert(0, StabilizerTable(sgn + i), qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable(sgn + i), qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable(sgn + i), qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable(sgn + i), qubit=True) + self.assertEqual(value, target1) # Insert single column with multiple values - stab = StabilizerTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["X", "Y", "Z"]) for i in [("I", "X", "Y"), ("X", "Y", "Z"), ("Y", "Z", "I")]: - target0 = StabilizerTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) - target1 = StabilizerTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = StabilizerTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) + target1 = StabilizerTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) with self.subTest(msg="single-column multiple-vals from StabilizerTable"): - value = stab.insert(0, StabilizerTable.from_labels(i), qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable.from_labels(i), qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable.from_labels(i), qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable.from_labels(i), qubit=True) + self.assertEqual(value, target1) with self.subTest(msg="single-column multiple-vals from array"): - value = stab.insert(0, StabilizerTable.from_labels(i).array, qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable.from_labels(i).array, qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable.from_labels(i).array, qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable.from_labels(i).array, qubit=True) + self.assertEqual(value, target1) # Insert multiple columns from single - stab = StabilizerTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["X", "Y", "Z"]) for j in range(1, 5): for i in [j * "I", j * "X", j * "Y", j * "Z"]: - target0 = StabilizerTable.from_labels(["X" + i, "Y" + i, "Z" + i]) - target1 = StabilizerTable.from_labels([i + "X", i + "Y", i + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = StabilizerTable.from_labels(["X" + i, "Y" + i, "Z" + i]) + target1 = StabilizerTable.from_labels([i + "X", i + "Y", i + "Z"]) with self.subTest(msg="multiple-columns single-val from str"): - value = stab.insert(0, i, qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, i, qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, i, qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, i, qubit=True) + self.assertEqual(value, target1) with self.subTest(msg="multiple-columns single-val from StabilizerTable"): - value = stab.insert(0, StabilizerTable(i), qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable(i), qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable(i), qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable(i), qubit=True) + self.assertEqual(value, target1) with self.subTest(msg="multiple-columns single-val from array"): - value = stab.insert(0, StabilizerTable(i).array, qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable(i).array, qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable(i).array, qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable(i).array, qubit=True) + self.assertEqual(value, target1) # Insert multiple columns multiple row values - stab = StabilizerTable.from_labels(["X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["X", "Y", "Z"]) for j in range(1, 5): for i in [ (j * "I", j * "X", j * "Y"), (j * "X", j * "Z", j * "Y"), (j * "Y", j * "Z", j * "I"), ]: - target0 = StabilizerTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) - target1 = StabilizerTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) + with self.assertWarns(DeprecationWarning): + target0 = StabilizerTable.from_labels(["X" + i[0], "Y" + i[1], "Z" + i[2]]) + target1 = StabilizerTable.from_labels([i[0] + "X", i[1] + "Y", i[2] + "Z"]) with self.subTest(msg="multiple-column multiple-vals from StabilizerTable"): - value = stab.insert(0, StabilizerTable.from_labels(i), qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable.from_labels(i), qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable.from_labels(i), qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable.from_labels(i), qubit=True) + self.assertEqual(value, target1) with self.subTest(msg="multiple-column multiple-vals from array"): - value = stab.insert(0, StabilizerTable.from_labels(i).array, qubit=True) - self.assertEqual(value, target0) - value = stab.insert(1, StabilizerTable.from_labels(i).array, qubit=True) - self.assertEqual(value, target1) + with self.assertWarns(DeprecationWarning): + value = stab.insert(0, StabilizerTable.from_labels(i).array, qubit=True) + self.assertEqual(value, target0) + value = stab.insert(1, StabilizerTable.from_labels(i).array, qubit=True) + self.assertEqual(value, target1) def test_iteration(self): """Test iteration methods.""" labels = ["+III", "+IXI", "-IYY", "+YIZ", "-ZIZ", "+XYZ", "-III"] - stab = StabilizerTable.from_labels(labels) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(labels) with self.subTest(msg="enumerate"): - for idx, i in enumerate(stab): - self.assertEqual(i, StabilizerTable(labels[idx])) + with self.assertWarns(DeprecationWarning): + for idx, i in enumerate(stab): + self.assertEqual(i, StabilizerTable(labels[idx])) with self.subTest(msg="iter"): - for idx, i in enumerate(iter(stab)): - self.assertEqual(i, StabilizerTable(labels[idx])) + with self.assertWarns(DeprecationWarning): + for idx, i in enumerate(iter(stab)): + self.assertEqual(i, StabilizerTable(labels[idx])) with self.subTest(msg="zip"): - for label, i in zip(labels, stab): - self.assertEqual(i, StabilizerTable(label)) + with self.assertWarns(DeprecationWarning): + for label, i in zip(labels, stab): + self.assertEqual(i, StabilizerTable(label)) with self.subTest(msg="label_iter"): for idx, i in enumerate(stab.label_iter()): @@ -862,199 +973,240 @@ def test_tensor(self): """Test tensor method.""" labels1 = ["-XX", "YY"] labels2 = ["III", "-ZZZ"] - stab1 = StabilizerTable.from_labels(labels1) - stab2 = StabilizerTable.from_labels(labels2) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(labels1) + stab2 = StabilizerTable.from_labels(labels2) - target = StabilizerTable.from_labels(["-XXIII", "XXZZZ", "YYIII", "-YYZZZ"]) - value = stab1.tensor(stab2) - self.assertEqual(value, target) + target = StabilizerTable.from_labels(["-XXIII", "XXZZZ", "YYIII", "-YYZZZ"]) + value = stab1.tensor(stab2) + self.assertEqual(value, target) def test_expand(self): """Test expand method.""" labels1 = ["-XX", "YY"] labels2 = ["III", "-ZZZ"] - stab1 = StabilizerTable.from_labels(labels1) - stab2 = StabilizerTable.from_labels(labels2) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(labels1) + stab2 = StabilizerTable.from_labels(labels2) - target = StabilizerTable.from_labels(["-IIIXX", "IIIYY", "ZZZXX", "-ZZZYY"]) - value = stab1.expand(stab2) - self.assertEqual(value, target) + target = StabilizerTable.from_labels(["-IIIXX", "IIIYY", "ZZZXX", "-ZZZYY"]) + value = stab1.expand(stab2) + self.assertEqual(value, target) def test_compose(self): """Test compose and dot methods.""" # Test single qubit Pauli dot products - stab = StabilizerTable.from_labels(["I", "X", "Y", "Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["I", "X", "Y", "Z"]) # Test single qubit Pauli dot products - stab = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) + with self.assertWarns(DeprecationWarning): + stab = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) with self.subTest(msg="dot single I"): - value = stab.compose("I") - target = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("I") + target = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) + self.assertEqual(target, value) with self.subTest(msg="dot single -I"): - value = stab.compose("-I") - target = StabilizerTable.from_labels(["-I", "-X", "-Y", "-Z", "I", "X", "Y", "Z"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("-I") + target = StabilizerTable.from_labels(["-I", "-X", "-Y", "-Z", "I", "X", "Y", "Z"]) + self.assertEqual(target, value) with self.subTest(msg="dot single I"): - value = stab.dot("I") - target = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("I") + target = StabilizerTable.from_labels(["I", "X", "Y", "Z", "-I", "-X", "-Y", "-Z"]) + self.assertEqual(target, value) with self.subTest(msg="dot single -I"): - value = stab.dot("-I") - target = StabilizerTable.from_labels(["-I", "-X", "-Y", "-Z", "I", "X", "Y", "Z"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("-I") + target = StabilizerTable.from_labels(["-I", "-X", "-Y", "-Z", "I", "X", "Y", "Z"]) + self.assertEqual(target, value) with self.subTest(msg="compose single X"): - value = stab.compose("X") - target = StabilizerTable.from_labels(["X", "I", "-Z", "Y", "-X", "-I", "Z", "-Y"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("X") + target = StabilizerTable.from_labels(["X", "I", "-Z", "Y", "-X", "-I", "Z", "-Y"]) + self.assertEqual(target, value) with self.subTest(msg="compose single -X"): - value = stab.compose("-X") - target = StabilizerTable.from_labels(["-X", "-I", "Z", "-Y", "X", "I", "-Z", "Y"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("-X") + target = StabilizerTable.from_labels(["-X", "-I", "Z", "-Y", "X", "I", "-Z", "Y"]) + self.assertEqual(target, value) with self.subTest(msg="dot single X"): - value = stab.dot("X") - target = StabilizerTable.from_labels(["X", "I", "Z", "-Y", "-X", "-I", "-Z", "Y"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("X") + target = StabilizerTable.from_labels(["X", "I", "Z", "-Y", "-X", "-I", "-Z", "Y"]) + self.assertEqual(target, value) with self.subTest(msg="dot single -X"): - value = stab.dot("-X") - target = StabilizerTable.from_labels(["-X", "-I", "-Z", "Y", "X", "I", "Z", "-Y"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("-X") + target = StabilizerTable.from_labels(["-X", "-I", "-Z", "Y", "X", "I", "Z", "-Y"]) + self.assertEqual(target, value) with self.subTest(msg="compose single Y"): - value = stab.compose("Y") - target = StabilizerTable.from_labels(["Y", "Z", "-I", "-X", "-Y", "-Z", "I", "X"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("Y") + target = StabilizerTable.from_labels(["Y", "Z", "-I", "-X", "-Y", "-Z", "I", "X"]) + self.assertEqual(target, value) with self.subTest(msg="compose single -Y"): - value = stab.compose("-Y") - target = StabilizerTable.from_labels(["-Y", "-Z", "I", "X", "Y", "Z", "-I", "-X"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("-Y") + target = StabilizerTable.from_labels(["-Y", "-Z", "I", "X", "Y", "Z", "-I", "-X"]) + self.assertEqual(target, value) with self.subTest(msg="dot single Y"): - value = stab.dot("Y") - target = StabilizerTable.from_labels(["Y", "-Z", "-I", "X", "-Y", "Z", "I", "-X"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("Y") + target = StabilizerTable.from_labels(["Y", "-Z", "-I", "X", "-Y", "Z", "I", "-X"]) + self.assertEqual(target, value) with self.subTest(msg="dot single -Y"): - value = stab.dot("-Y") - target = StabilizerTable.from_labels(["-Y", "Z", "I", "-X", "Y", "-Z", "-I", "X"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("-Y") + target = StabilizerTable.from_labels(["-Y", "Z", "I", "-X", "Y", "-Z", "-I", "X"]) + self.assertEqual(target, value) with self.subTest(msg="compose single Z"): - value = stab.compose("Z") - target = StabilizerTable.from_labels(["Z", "-Y", "X", "I", "-Z", "Y", "-X", "-I"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("Z") + target = StabilizerTable.from_labels(["Z", "-Y", "X", "I", "-Z", "Y", "-X", "-I"]) + self.assertEqual(target, value) with self.subTest(msg="compose single -Z"): - value = stab.compose("-Z") - target = StabilizerTable.from_labels(["-Z", "Y", "-X", "-I", "Z", "-Y", "X", "I"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.compose("-Z") + target = StabilizerTable.from_labels(["-Z", "Y", "-X", "-I", "Z", "-Y", "X", "I"]) + self.assertEqual(target, value) with self.subTest(msg="dot single Z"): - value = stab.dot("Z") - target = StabilizerTable.from_labels(["Z", "Y", "-X", "I", "-Z", "-Y", "X", "-I"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("Z") + target = StabilizerTable.from_labels(["Z", "Y", "-X", "I", "-Z", "-Y", "X", "-I"]) + self.assertEqual(target, value) with self.subTest(msg="dot single -Z"): - value = stab.dot("-Z") - target = StabilizerTable.from_labels(["-Z", "-Y", "X", "-I", "Z", "Y", "-X", "I"]) - self.assertEqual(target, value) + with self.assertWarns(DeprecationWarning): + value = stab.dot("-Z") + target = StabilizerTable.from_labels(["-Z", "-Y", "X", "-I", "Z", "Y", "-X", "I"]) + self.assertEqual(target, value) def test_compose_qargs(self): """Test compose and dot methods with qargs.""" # Dot product with qargs - stab1 = StabilizerTable.from_labels(["III", "-XXX", "YYY", "-ZZZ"]) + with self.assertWarns(DeprecationWarning): + stab1 = StabilizerTable.from_labels(["III", "-XXX", "YYY", "-ZZZ"]) # 1-qubit qargs - stab2 = StabilizerTable("-Z") + with self.assertWarns(DeprecationWarning): + stab2 = StabilizerTable("-Z") with self.subTest(msg="dot 1-qubit qargs=[0]"): - target = StabilizerTable.from_labels(["-IIZ", "XXY", "YYX", "ZZI"]) - value = stab1.dot(stab2, qargs=[0]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["-IIZ", "XXY", "YYX", "ZZI"]) + value = stab1.dot(stab2, qargs=[0]) + self.assertEqual(value, target) with self.subTest(msg="compose 1-qubit qargs=[0]"): - target = StabilizerTable.from_labels(["-IIZ", "-XXY", "-YYX", "ZZI"]) - value = stab1.compose(stab2, qargs=[0]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["-IIZ", "-XXY", "-YYX", "ZZI"]) + value = stab1.compose(stab2, qargs=[0]) + self.assertEqual(value, target) with self.subTest(msg="dot 1-qubit qargs=[1]"): - target = StabilizerTable.from_labels(["-IZI", "XYX", "YXY", "ZIZ"]) - value = stab1.dot(stab2, qargs=[1]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["-IZI", "XYX", "YXY", "ZIZ"]) + value = stab1.dot(stab2, qargs=[1]) + self.assertEqual(value, target) with self.subTest(msg="compose 1-qubit qargs=[1]"): - value = stab1.compose(stab2, qargs=[1]) - target = StabilizerTable.from_labels(["-IZI", "-XYX", "-YXY", "ZIZ"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.compose(stab2, qargs=[1]) + target = StabilizerTable.from_labels(["-IZI", "-XYX", "-YXY", "ZIZ"]) + self.assertEqual(value, target) - target = StabilizerTable.from_labels(["ZII", "YXX"]) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["ZII", "YXX"]) with self.subTest(msg="dot 1-qubit qargs=[2]"): - value = stab1.dot(stab2, qargs=[2]) - target = StabilizerTable.from_labels(["-ZII", "YXX", "XYY", "IZZ"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[2]) + target = StabilizerTable.from_labels(["-ZII", "YXX", "XYY", "IZZ"]) + self.assertEqual(value, target) with self.subTest(msg="compose 1-qubit qargs=[2]"): - value = stab1.compose(stab2, qargs=[2]) - target = StabilizerTable.from_labels(["-ZII", "-YXX", "-XYY", "IZZ"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.compose(stab2, qargs=[2]) + target = StabilizerTable.from_labels(["-ZII", "-YXX", "-XYY", "IZZ"]) + self.assertEqual(value, target) # 2-qubit qargs - stab2 = StabilizerTable("-ZY") + with self.assertWarns(DeprecationWarning): + stab2 = StabilizerTable("-ZY") with self.subTest(msg="dot 2-qubit qargs=[0, 1]"): - value = stab1.dot(stab2, qargs=[0, 1]) - target = StabilizerTable.from_labels(["-IZY", "-XYZ", "-YXI", "ZIX"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[0, 1]) + target = StabilizerTable.from_labels(["-IZY", "-XYZ", "-YXI", "ZIX"]) + self.assertEqual(value, target) with self.subTest(msg="compose 2-qubit qargs=[0, 1]"): - value = stab1.compose(stab2, qargs=[0, 1]) - target = StabilizerTable.from_labels(["-IZY", "-XYZ", "YXI", "-ZIX"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.compose(stab2, qargs=[0, 1]) + target = StabilizerTable.from_labels(["-IZY", "-XYZ", "YXI", "-ZIX"]) + self.assertEqual(value, target) - target = StabilizerTable.from_labels(["YIZ", "ZXY"]) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["YIZ", "ZXY"]) with self.subTest(msg="dot 2-qubit qargs=[2, 0]"): - value = stab1.dot(stab2, qargs=[2, 0]) - target = StabilizerTable.from_labels(["-YIZ", "-ZXY", "-IYX", "XZI"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[2, 0]) + target = StabilizerTable.from_labels(["-YIZ", "-ZXY", "-IYX", "XZI"]) + self.assertEqual(value, target) with self.subTest(msg="compose 2-qubit qargs=[2, 0]"): - value = stab1.compose(stab2, qargs=[2, 0]) - target = StabilizerTable.from_labels(["-YIZ", "-ZXY", "IYX", "-XZI"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.compose(stab2, qargs=[2, 0]) + target = StabilizerTable.from_labels(["-YIZ", "-ZXY", "IYX", "-XZI"]) + self.assertEqual(value, target) # 3-qubit qargs - stab2 = StabilizerTable("-XYZ") + with self.assertWarns(DeprecationWarning): + stab2 = StabilizerTable("-XYZ") - target = StabilizerTable.from_labels(["XYZ", "IZY"]) + with self.assertWarns(DeprecationWarning): + target = StabilizerTable.from_labels(["XYZ", "IZY"]) with self.subTest(msg="dot 3-qubit qargs=None"): - value = stab1.dot(stab2, qargs=[0, 1, 2]) - target = StabilizerTable.from_labels(["-XYZ", "-IZY", "-ZIX", "-YXI"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[0, 1, 2]) + target = StabilizerTable.from_labels(["-XYZ", "-IZY", "-ZIX", "-YXI"]) + self.assertEqual(value, target) with self.subTest(msg="dot 3-qubit qargs=[0, 1, 2]"): - value = stab1.dot(stab2, qargs=[0, 1, 2]) - target = StabilizerTable.from_labels(["-XYZ", "-IZY", "-ZIX", "-YXI"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[0, 1, 2]) + target = StabilizerTable.from_labels(["-XYZ", "-IZY", "-ZIX", "-YXI"]) + self.assertEqual(value, target) with self.subTest(msg="dot 3-qubit qargs=[2, 1, 0]"): - value = stab1.dot(stab2, qargs=[2, 1, 0]) - target = StabilizerTable.from_labels(["-ZYX", "-YZI", "-XIZ", "-IXY"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.dot(stab2, qargs=[2, 1, 0]) + target = StabilizerTable.from_labels(["-ZYX", "-YZI", "-XIZ", "-IXY"]) + self.assertEqual(value, target) with self.subTest(msg="compose 3-qubit qargs=[2, 1, 0]"): - value = stab1.compose(stab2, qargs=[2, 1, 0]) - target = StabilizerTable.from_labels(["-ZYX", "-YZI", "-XIZ", "-IXY"]) - self.assertEqual(value, target) + with self.assertWarns(DeprecationWarning): + value = stab1.compose(stab2, qargs=[2, 1, 0]) + target = StabilizerTable.from_labels(["-ZYX", "-YZI", "-XIZ", "-IXY"]) + self.assertEqual(value, target) if __name__ == "__main__": diff --git a/test/python/quantum_info/operators/test_random.py b/test/python/quantum_info/operators/test_random.py index 1b9c21f5119f..2837711a020f 100644 --- a/test/python/quantum_info/operators/test_random.py +++ b/test/python/quantum_info/operators/test_random.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2020. +# (C) Copyright IBM 2017, 2023. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -203,12 +203,13 @@ def test_not_global_seed(self): @ddt class TestPauliTwoDesignTable(QiskitTestCase): - """Testing random_pauli_table function.""" + """DEPRECATED: Testing random_pauli_table function.""" @combine(num_qubits=[1, 2, 3, 4, 5, 10, 50, 100, 200, 250], size=[1, 10, 100]) def test_valid(self, num_qubits, size): """Test random_pauli_table {num_qubits}-qubits, size {size}.""" - value = random_pauli_table(num_qubits, size=size) + with self.assertWarns(DeprecationWarning): + value = random_pauli_table(num_qubits, size=size) with self.subTest(msg="Test type"): self.assertIsInstance(value, PauliTable) with self.subTest(msg="Test num_qubits"): @@ -219,17 +220,20 @@ def test_valid(self, num_qubits, size): def test_fixed_seed(self): """Test fixing seed fixes output""" seed = 1532 - value1 = random_pauli_table(10, size=10, seed=seed) - value2 = random_pauli_table(10, size=10, seed=seed) + with self.assertWarns(DeprecationWarning): + value1 = random_pauli_table(10, size=10, seed=seed) + value2 = random_pauli_table(10, size=10, seed=seed) self.assertEqual(value1, value2) def test_not_global_seed(self): """Test fixing random_hermitian seed is locally scoped.""" seed = 314159 test_cases = 100 - random_pauli_table(10, size=10, seed=seed) + with self.assertWarns(DeprecationWarning): + random_pauli_table(10, size=10, seed=seed) rng_before = np.random.randint(1000, size=test_cases) - random_pauli_table(10, seed=seed) + with self.assertWarns(DeprecationWarning): + random_pauli_table(10, seed=seed) rng_after = np.random.randint(1000, size=test_cases) self.assertFalse(np.all(rng_before == rng_after)) @@ -302,7 +306,7 @@ def test_fixed_seed(self): with self.assertWarns(DeprecationWarning): value1 = random_stabilizer_table(10, size=10, seed=seed) value2 = random_stabilizer_table(10, size=10, seed=seed) - self.assertEqual(value1, value2) + self.assertEqual(value1, value2) def test_not_global_seed(self): """Test fixing random_hermitian seed is locally scoped.""" From f0cb7c857dec1a60e4a584e42f3761ab46b25fac Mon Sep 17 00:00:00 2001 From: Ikko Hamamura Date: Wed, 22 Feb 2023 18:30:37 +0900 Subject: [PATCH 2/3] Update qiskit/quantum_info/operators/symplectic/pauli_table.py Co-authored-by: Julien Gacon --- qiskit/quantum_info/operators/symplectic/pauli_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit/quantum_info/operators/symplectic/pauli_table.py b/qiskit/quantum_info/operators/symplectic/pauli_table.py index 84b57368165e..79465c742ba4 100644 --- a/qiskit/quantum_info/operators/symplectic/pauli_table.py +++ b/qiskit/quantum_info/operators/symplectic/pauli_table.py @@ -142,7 +142,7 @@ def __init__(self, data): """ warn( "The PauliTable class is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the releasedate. " + "and will be removed no sooner than 3 months after the release date. " "Use PauliList class instead.", DeprecationWarning, stacklevel=2, From b130faccd9d6a8486469e20be2c27c9adb76b609 Mon Sep 17 00:00:00 2001 From: ikkoham Date: Wed, 12 Apr 2023 16:11:06 +0900 Subject: [PATCH 3/3] use deprecate_func instead of deprecate_function --- .../operators/symplectic/clifford.py | 63 +++++++++---------- .../operators/symplectic/pauli_table.py | 2 +- .../operators/symplectic/stabilizer_table.py | 2 +- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/qiskit/quantum_info/operators/symplectic/clifford.py b/qiskit/quantum_info/operators/symplectic/clifford.py index dd51ddc7ad39..6ccee9043750 100644 --- a/qiskit/quantum_info/operators/symplectic/clifford.py +++ b/qiskit/quantum_info/operators/symplectic/clifford.py @@ -26,7 +26,7 @@ from qiskit.quantum_info.operators.operator import Operator from qiskit.quantum_info.operators.scalar_op import ScalarOp from qiskit.quantum_info.operators.symplectic.base_pauli import _count_y -from qiskit.utils.deprecation import deprecate_function +from qiskit.utils.deprecation import deprecate_func from .base_pauli import BasePauli from .clifford_circuits import _append_circuit, _append_operation @@ -214,39 +214,34 @@ def copy(self): # pylint: disable=bad-docstring-quotes - @deprecate_function( - "Indexing or iterating through a Clifford object directly is deprecated as of " - "Qiskit Terra 0.24.0 and will be removed no sooner than 3 months after the release date. " - "Instead, index or iterate through the Clifford.tableau attribute." + @deprecate_func( + since="0.24.0", + additional_msg="Instead, index or iterate through the Clifford.tableau attribute.", ) def __getitem__(self, key): """Return a stabilizer Pauli row""" return self.table.__getitem__(key) - @deprecate_function( - "The Clifford.__setitem__ method is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.tableau property instead.", - ) + @deprecate_func(since="0.24.0", additional_msg="Use Clifford.tableau property instead.") def __setitem__(self, key, value): """Set a stabilizer Pauli row""" self.tableau.__setitem__(key, self._stack_table_phase(value.array, value.phase)) @property - @deprecate_function( - "The Clifford.table attribute is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.stab and Clifford.destab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.stab and Clifford.destab properties instead.", + is_property=True, ) def table(self): """Return StabilizerTable""" return StabilizerTable(self.symplectic_matrix, phase=self.phase) @table.setter - @deprecate_function( - "The Clifford.table attribute is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.stab and Clifford.destab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.stab and Clifford.destab properties instead.", + is_property=True, ) def table(self, value): """Set the stabilizer table""" @@ -259,10 +254,10 @@ def table(self, value): self.phase = value._table._phase @property - @deprecate_function( - "The Clifford.stabilizer attribute is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.stab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.stab properties instead.", + is_property=True, ) def stabilizer(self): """Return the stabilizer block of the StabilizerTable.""" @@ -271,10 +266,10 @@ def stabilizer(self): return StabilizerTable(array, phase) @stabilizer.setter - @deprecate_function( - "The Clifford.stabilizer is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.stab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.stab properties instead.", + is_property=True, ) def stabilizer(self, value): """Set the value of stabilizer block of the StabilizerTable""" @@ -283,10 +278,10 @@ def stabilizer(self, value): self.tableau[self.num_qubits : 2 * self.num_qubits, :-1] = value.array @property - @deprecate_function( - "The Clifford.destabilzer attribute is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.destab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.destab properties instead.", + is_property=True, ) def destabilizer(self): """Return the destabilizer block of the StabilizerTable.""" @@ -295,10 +290,10 @@ def destabilizer(self): return StabilizerTable(array, phase) @destabilizer.setter - @deprecate_function( - "The Clifford.destabilizer attribute is deprecated as of Qiskit Terra 0.24.0 " - "and will be removed no sooner than 3 months after the release date. " - "Use Clifford.destab properties instead." + @deprecate_func( + since="0.24.0", + additional_msg="Use Clifford.destab properties instead.", + is_property=True, ) def destabilizer(self, value): """Set the value of destabilizer block of the StabilizerTable""" diff --git a/qiskit/quantum_info/operators/symplectic/pauli_table.py b/qiskit/quantum_info/operators/symplectic/pauli_table.py index 4775327e94ae..92faac92f753 100644 --- a/qiskit/quantum_info/operators/symplectic/pauli_table.py +++ b/qiskit/quantum_info/operators/symplectic/pauli_table.py @@ -127,7 +127,7 @@ class PauliTable(BaseOperator, AdjointMixin): `arXiv:quant-ph/0406196 `_ """ - @deprecate_func(additional_msg="Instead, use the class PauliList", since="0.23.0", pending=True) + @deprecate_func(additional_msg="Instead, use the class PauliList", since="0.24.0") def __init__(self, data): """Initialize the PauliTable. diff --git a/qiskit/quantum_info/operators/symplectic/stabilizer_table.py b/qiskit/quantum_info/operators/symplectic/stabilizer_table.py index bbd936387650..00e717b7a20a 100644 --- a/qiskit/quantum_info/operators/symplectic/stabilizer_table.py +++ b/qiskit/quantum_info/operators/symplectic/stabilizer_table.py @@ -169,7 +169,7 @@ class StabilizerTable(PauliTable, AdjointMixin): `arXiv:quant-ph/0406196 `_ """ - @deprecate_func(additional_msg="Instead, use the class PauliList", since="0.23.0", pending=True) + @deprecate_func(additional_msg="Instead, use the class PauliList", since="0.24.0") def __init__(self, data, phase=None): """Initialize the StabilizerTable.