Skip to content

Commit

Permalink
Apply new deprecation decorators to quantum_info folder (Qiskit#9873)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano authored and giacomoRanieri committed Apr 16, 2023
1 parent 1c5f2bd commit 22c949b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 50 deletions.
9 changes: 2 additions & 7 deletions qiskit/quantum_info/operators/symplectic/pauli_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# pylint: disable=invalid-name

from typing import Dict
from warnings import warn

import numpy as np

Expand All @@ -25,6 +24,7 @@
from qiskit.quantum_info.operators.mixins import AdjointMixin, generate_apidocs
from qiskit.quantum_info.operators.scalar_op import ScalarOp
from qiskit.quantum_info.operators.symplectic.pauli import Pauli
from qiskit.utils.deprecation import deprecate_func


class PauliTable(BaseOperator, AdjointMixin):
Expand Down Expand Up @@ -127,6 +127,7 @@ class PauliTable(BaseOperator, AdjointMixin):
`arXiv:quant-ph/0406196 <https://arxiv.org/abs/quant-ph/0406196>`_
"""

@deprecate_func(additional_msg="Instead, use the class PauliList", since="0.23.0", pending=True)
def __init__(self, data):
"""Initialize the PauliTable.
Expand All @@ -140,12 +141,6 @@ def __init__(self, data):
The input array is not copied so multiple Pauli tables
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,
stacklevel=2,
)
if isinstance(data, (np.ndarray, list)):
self._array = np.asarray(data, dtype=bool)
elif isinstance(data, str):
Expand Down
17 changes: 9 additions & 8 deletions qiskit/quantum_info/operators/symplectic/pauli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
PauliList utility functions.
"""

import warnings
from qiskit.quantum_info.operators.symplectic.pauli_list import PauliList
from qiskit.utils.deprecation import deprecate_arg


@deprecate_arg(
"pauli_basis",
since="0.22",
additional_msg=(
"The argument ``pauli_list`` has no effect as the function always returns a PauliList."
),
)
def pauli_basis(num_qubits, weight=False, pauli_list=None):
"""Return the ordered PauliTable or PauliList for the n-qubit Pauli basis.
Expand All @@ -30,13 +37,7 @@ def pauli_basis(num_qubits, weight=False, pauli_list=None):
Returns:
PauliList: the Paulis for the basis
"""
if pauli_list is not None:
warnings.warn(
"The `pauli_list` kwarg is deprecated as of Qiskit Terra 0.22 and "
"no longer has an effect as `pauli_basis` always returns a PauliList.",
DeprecationWarning,
stacklevel=2,
)
del pauli_list
pauli_1q = PauliList(["I", "X", "Y", "Z"])
if num_qubits == 1:
return pauli_1q
Expand Down
8 changes: 3 additions & 5 deletions qiskit/quantum_info/operators/symplectic/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import numpy as np
from numpy.random import default_rng

from qiskit.utils.deprecation import deprecate_function
from qiskit.utils.deprecation import deprecate_func

from .clifford import Clifford
from .pauli import Pauli
Expand Down Expand Up @@ -103,10 +103,8 @@ def random_pauli_table(num_qubits, size=1, seed=None):
return PauliTable(table)


@deprecate_function(
"The random_stabilizer_table function is deprecated as of Qiskit Terra 0.22.0 "
"and will be removed no sooner than 3 months after the release date. "
"Use random_pauli_list method instead.",
@deprecate_func(
additional_msg="Instead, use the function ``random_pauli_list``.",
since="0.22.0",
)
def random_stabilizer_table(num_qubits, size=1, seed=None):
Expand Down
10 changes: 2 additions & 8 deletions qiskit/quantum_info/operators/symplectic/stabilizer_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
Symplectic Stabilizer Table Class
"""

from warnings import warn

import numpy as np

from qiskit.exceptions import QiskitError
from qiskit.quantum_info.operators.custom_iterator import CustomIterator
from qiskit.quantum_info.operators.mixins import AdjointMixin, generate_apidocs
from qiskit.quantum_info.operators.symplectic.pauli_table import PauliTable
from qiskit.utils.deprecation import deprecate_func


class StabilizerTable(PauliTable, AdjointMixin):
Expand Down Expand Up @@ -170,6 +169,7 @@ class StabilizerTable(PauliTable, AdjointMixin):
`arXiv:quant-ph/0406196 <https://arxiv.org/abs/quant-ph/0406196>`_
"""

@deprecate_func(additional_msg="Instead, use the class PauliList", since="0.23.0", pending=True)
def __init__(self, data, phase=None):
"""Initialize the StabilizerTable.
Expand All @@ -185,12 +185,6 @@ def __init__(self, data, phase=None):
The input array is not copied so multiple Pauli and Stabilizer tables
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,
stacklevel=2,
)
if isinstance(data, str) and phase is None:
pauli, phase = StabilizerTable._from_label(data)
elif isinstance(data, StabilizerTable):
Expand Down
14 changes: 4 additions & 10 deletions qiskit/quantum_info/synthesis/clifford_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
Circuit synthesis for the Clifford class.
"""

import warnings
from qiskit.synthesis.clifford import (
synth_clifford_ag,
synth_clifford_bm,
synth_clifford_greedy,
)
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
additional_msg="Instead, use the function qiskit.synthesis.synth_clifford_full.", since="0.23.0"
)
def decompose_clifford(clifford, method=None):
"""DEPRECATED: Decompose a Clifford operator into a QuantumCircuit.
Expand Down Expand Up @@ -51,15 +54,6 @@ def decompose_clifford(clifford, method=None):
`arXiv:2105.02291 [quant-ph] <https://arxiv.org/abs/2105.02291>`_
"""
num_qubits = clifford.num_qubits

warnings.warn(
"The decompose_clifford function is deprecated as of Qiskit Terra 0.23.0 "
"and will be removed no sooner than 3 months after the releasedate. "
"Use qiskit.synthesis.synth_clifford_full function instead.",
DeprecationWarning,
stacklevel=2,
)

if method == "AG":
return synth_clifford_ag(clifford)

Expand Down
15 changes: 5 additions & 10 deletions qiskit/quantum_info/synthesis/cnotdihedral_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
Circuit synthesis for the CNOTDihedral class.
"""

import warnings
from qiskit.synthesis.cnotdihedral import (
synth_cnotdihedral_two_qubits,
synth_cnotdihedral_general,
)
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
additional_msg="Instead, use the function qiskit.synthesis.synth_cnotdihedral_full.",
since="0.23.0",
)
def decompose_cnotdihedral(elem):
"""DEPRECATED: Decompose a CNOTDihedral element into a QuantumCircuit.
Expand All @@ -38,15 +42,6 @@ def decompose_cnotdihedral(elem):
"""

num_qubits = elem.num_qubits

warnings.warn(
"The decompose_cnotdihedral function is deprecated as of Qiskit Terra 0.23.0 "
"and will be removed no sooner than 3 months after the releasedate. "
"Use qiskit.synthesis.synth_cnotdihedral_full function instead.",
DeprecationWarning,
stacklevel=2,
)

if num_qubits < 3:
return synth_cnotdihedral_two_qubits(elem)

Expand Down
4 changes: 2 additions & 2 deletions qiskit/quantum_info/synthesis/two_qubit_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
OneQubitEulerDecomposer,
DEFAULT_ATOL,
)
from qiskit.utils.deprecation import deprecate_arguments
from qiskit.utils.deprecation import deprecate_arg


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1085,7 +1085,7 @@ def decomp3_supercontrolled(self, target):

return U3r, U3l, U2r, U2l, U1r, U1l, U0r, U0l

@deprecate_arguments({"target": "unitary"}, since="0.23.0")
@deprecate_arg("target", new_alias="unitary", since="0.23.0")
def __call__(
self,
unitary: Union[Operator, np.ndarray],
Expand Down

0 comments on commit 22c949b

Please sign in to comment.