From 1471f3b069b8b4375d83788eeaddab34873ae489 Mon Sep 17 00:00:00 2001 From: DanPuzzuoli Date: Tue, 12 Mar 2024 09:24:41 -0700 Subject: [PATCH 1/5] adding deprecation warning for Array class, and upgrade note --- qiskit_dynamics/array/array.py | 29 +++++++++++++++++-- ...ch-array-deprecation-fb945946caba447a.yaml | 9 ++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml diff --git a/qiskit_dynamics/array/array.py b/qiskit_dynamics/array/array.py index 0559fc242..9571d2511 100644 --- a/qiskit_dynamics/array/array.py +++ b/qiskit_dynamics/array/array.py @@ -9,9 +9,11 @@ # Any modifications or derivative works of this code must retain this # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. +# pylint: disable=invalid-name,global-statement """Array Class""" +import warnings import copy from functools import wraps from types import BuiltinMethodType, MethodType @@ -25,9 +27,29 @@ __all__ = ["Array"] +_deprecation_raised = False + + +def _array_deprecation_warn(): + global _deprecation_raised + if not _deprecation_raised: + warnings.warn( + """The array and dispatch submodules of Qiskit Dynamics have been deprecated as of + version 0.5.0. The use of the Array class is no longer required to work with different + array libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide + entry on using different array libraries with Qiskit Dynamics. Users can now work + directly with the supported array type of their choice, without the need to wrap them to + enable dispatching. The array and dispatch submodules will be removed in version 0.6.0. + """, + DeprecationWarning, + stacklevel=3, + ) + _deprecation_raised = True + class Array(NDArrayOperatorsMixin): - """Qiskit array class. + """Qiskit array class. This class is deprecated as of version 0.5.0 and will be removed in + version 0.6.0. This class provides a Numpy compatible wrapper to supported Python array libraries. Supported backends are ``"numpy"`` and ``"jax"``. @@ -55,7 +77,7 @@ def __init__( Raises: ValueError: If input cannot be converted to an :class:`Array`. """ - + _array_deprecation_warn() # Check if we can override setattr and # set _data and _backend directly if ( @@ -108,6 +130,7 @@ def backend(self, value: str): @classmethod def set_default_backend(cls, backend: Union[str, None]): """Set the default array backend.""" + _array_deprecation_warn() if backend is not None: Dispatch.validate_backend(backend) Dispatch.DEFAULT_BACKEND = backend @@ -115,11 +138,13 @@ def set_default_backend(cls, backend: Union[str, None]): @classmethod def default_backend(cls) -> str: """Return the default array backend.""" + _array_deprecation_warn() return Dispatch.DEFAULT_BACKEND @classmethod def available_backends(cls) -> Set[str]: """Return a tuple of available array backends.""" + _array_deprecation_warn() return Dispatch.REGISTERED_BACKENDS def __repr__(self): diff --git a/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml b/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml new file mode 100644 index 000000000..ba2e89ad0 --- /dev/null +++ b/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml @@ -0,0 +1,9 @@ +--- +upgrade: + - | + The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version + 0.5.0. The use of the ``Array`` class is no longer required to work with different array + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on + using different array libraries with Qiskit Dynamics. Users can now work directly with the + supported array type of their choice, without the need to wrap them to enable dispatching. The + ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. \ No newline at end of file From 28bce486a649771802cbf342f04ac560c0b9b88e Mon Sep 17 00:00:00 2001 From: DanPuzzuoli Date: Tue, 12 Mar 2024 09:34:20 -0700 Subject: [PATCH 2/5] fixing jax optimization tutorial --- docs/tutorials/optimizing_pulse_sequence.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/tutorials/optimizing_pulse_sequence.rst b/docs/tutorials/optimizing_pulse_sequence.rst index 1d3fd629e..2c3f25191 100644 --- a/docs/tutorials/optimizing_pulse_sequence.rst +++ b/docs/tutorials/optimizing_pulse_sequence.rst @@ -254,10 +254,6 @@ entry on :ref:`JAX-compatible pulse schedules Date: Tue, 12 Mar 2024 09:47:47 -0700 Subject: [PATCH 3/5] suppressing warnigns in Array docs, adding deprecation warnings at the module level documentation for array and dispatch --- qiskit_dynamics/array/__init__.py | 16 ++++++++++++++++ qiskit_dynamics/arraylias/__init__.py | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/qiskit_dynamics/array/__init__.py b/qiskit_dynamics/array/__init__.py index a33c15cef..260f7ab8f 100644 --- a/qiskit_dynamics/array/__init__.py +++ b/qiskit_dynamics/array/__init__.py @@ -19,6 +19,16 @@ .. currentmodule:: qiskit_dynamics.array + +.. warning:: + + The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version + 0.5.0. The use of the ``Array`` class is no longer required to work with different array + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on + using different array libraries with Qiskit Dynamics. Users can now work directly with the + supported array type of their choice, without the need to wrap them to enable dispatching. The + ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. + This module contains an :class:`Array` class that wraps N-dimensional array objects from different libraries. It enables working with different array libraries through a common NumPy-based interface, along with other functionality for writing array-library agnostic code. @@ -41,6 +51,12 @@ Basic Usage ----------- +.. jupyter-execute:: + :hide-code: + # suppress deprecation warnings + import warnings + warnings.filterwarnings('ignore', category=DeprecationWarning) + When using the default ``numpy`` backend :class:`Array`, objects can be used interchangably with ``numpy.ndarray``. When ``numpy`` functions are applied to an :class:`Array` object the return type will be an :class:`Array` instead of an ``numpy.ndarray``. diff --git a/qiskit_dynamics/arraylias/__init__.py b/qiskit_dynamics/arraylias/__init__.py index 3aedfe27c..745f29521 100644 --- a/qiskit_dynamics/arraylias/__init__.py +++ b/qiskit_dynamics/arraylias/__init__.py @@ -19,6 +19,15 @@ .. currentmodule:: qiskit_dynamics.arraylias +.. warning:: + + The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version + 0.5.0. The use of the ``Array`` class is no longer required to work with different array + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on + using different array libraries with Qiskit Dynamics. Users can now work directly with the + supported array type of their choice, without the need to wrap them to enable dispatching. The + ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. + This module contains Qiskit Dynamics-global extensions of the default NumPy and SciPy aliases provided by `Arraylias `_. These are used to manage dispatching of array operations for the different array types supported by Qiskit Dynamics. They From 18874c55ffdcbb4f8bb7a8022ee40985e33e7fcc Mon Sep 17 00:00:00 2001 From: DanPuzzuoli Date: Tue, 12 Mar 2024 10:12:34 -0700 Subject: [PATCH 4/5] fixing warnings filter for docs --- qiskit_dynamics/array/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qiskit_dynamics/array/__init__.py b/qiskit_dynamics/array/__init__.py index 260f7ab8f..4dbb8f76a 100644 --- a/qiskit_dynamics/array/__init__.py +++ b/qiskit_dynamics/array/__init__.py @@ -53,9 +53,10 @@ .. jupyter-execute:: :hide-code: + # suppress deprecation warnings import warnings - warnings.filterwarnings('ignore', category=DeprecationWarning) + warnings.simplefilter('ignore', category=DeprecationWarning) When using the default ``numpy`` backend :class:`Array`, objects can be used interchangably with ``numpy.ndarray``. When ``numpy`` functions are applied to an :class:`Array` object the return type From c81ca796e547f3f821b487738df3486374cebe0e Mon Sep 17 00:00:00 2001 From: DanPuzzuoli Date: Fri, 15 Mar 2024 07:42:00 -0700 Subject: [PATCH 5/5] adding link in deprecation text --- qiskit_dynamics/array/__init__.py | 9 +++++---- qiskit_dynamics/arraylias/__init__.py | 9 --------- qiskit_dynamics/dispatch/__init__.py | 14 ++++++++++++-- ...ispatch-array-deprecation-fb945946caba447a.yaml | 9 +++++---- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/qiskit_dynamics/array/__init__.py b/qiskit_dynamics/array/__init__.py index 4dbb8f76a..ddab9a769 100644 --- a/qiskit_dynamics/array/__init__.py +++ b/qiskit_dynamics/array/__init__.py @@ -24,10 +24,11 @@ The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version 0.5.0. The use of the ``Array`` class is no longer required to work with different array - libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on - using different array libraries with Qiskit Dynamics. Users can now work directly with the - supported array type of their choice, without the need to wrap them to enable dispatching. The - ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the :ref:`user guide entry + on using different array libraries with Qiskit Dynamics `. + Users can now work directly with the supported array type of their choice, without the need to + wrap them to enable dispatching. The ``array`` and ``dispatch`` submodules will be removed in + version 0.6.0. This module contains an :class:`Array` class that wraps N-dimensional array objects from different libraries. It enables working with different array libraries through a common NumPy-based interface, diff --git a/qiskit_dynamics/arraylias/__init__.py b/qiskit_dynamics/arraylias/__init__.py index 745f29521..3aedfe27c 100644 --- a/qiskit_dynamics/arraylias/__init__.py +++ b/qiskit_dynamics/arraylias/__init__.py @@ -19,15 +19,6 @@ .. currentmodule:: qiskit_dynamics.arraylias -.. warning:: - - The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version - 0.5.0. The use of the ``Array`` class is no longer required to work with different array - libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on - using different array libraries with Qiskit Dynamics. Users can now work directly with the - supported array type of their choice, without the need to wrap them to enable dispatching. The - ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. - This module contains Qiskit Dynamics-global extensions of the default NumPy and SciPy aliases provided by `Arraylias `_. These are used to manage dispatching of array operations for the different array types supported by Qiskit Dynamics. They diff --git a/qiskit_dynamics/dispatch/__init__.py b/qiskit_dynamics/dispatch/__init__.py index 3a7a9e0ee..ab3a8e755 100644 --- a/qiskit_dynamics/dispatch/__init__.py +++ b/qiskit_dynamics/dispatch/__init__.py @@ -19,8 +19,18 @@ .. currentmodule:: qiskit_dynamics.dispatch -This module contains dispatch methods used by the -:class:`~qiskit_dynamics.array.Array` class. +.. warning:: + + The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version + 0.5.0. The use of the ``Array`` class is no longer required to work with different array + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the :ref:`user guide entry + on using different array libraries with Qiskit Dynamics `. + Users can now work directly with the supported array type of their choice, without the need to + wrap them to enable dispatching. The ``array`` and ``dispatch`` submodules will be removed in + version 0.6.0. + + +This module contains dispatch methods used by the :class:`~qiskit_dynamics.array.Array` class. Dispatch Functions diff --git a/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml b/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml index ba2e89ad0..0fbe684cc 100644 --- a/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml +++ b/releasenotes/notes/dispatch-array-deprecation-fb945946caba447a.yaml @@ -3,7 +3,8 @@ upgrade: - | The ``array`` and ``dispatch`` submodules of Qiskit Dynamics have been deprecated as of version 0.5.0. The use of the ``Array`` class is no longer required to work with different array - libraries in Qiskit Dynamics, and is broken in some cases. Refer to the user guide entry on - using different array libraries with Qiskit Dynamics. Users can now work directly with the - supported array type of their choice, without the need to wrap them to enable dispatching. The - ``array`` and ``dispatch`` submodules will be removed in version 0.6.0. \ No newline at end of file + libraries in Qiskit Dynamics, and is broken in some cases. Refer to the :ref:`user guide entry + on using different array libraries with Qiskit Dynamics `. + Users can now work directly with the supported array type of their choice, without the need to + wrap them to enable dispatching. The ``array`` and ``dispatch`` submodules will be removed in + version 0.6.0. \ No newline at end of file