Skip to content

Commit

Permalink
v32 removals (#4301)
Browse files Browse the repository at this point in the history
* v32 removals

* fix

* remove deprecation test

* remove additional failing test

* Update doc/releases/changelog-dev.md

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>

* rename _zyz_decomposition_old to _rot_decomposition

---------

Co-authored-by: Matthew Silverman <matthews@xanadu.ai>
  • Loading branch information
albi3ro and timmysilv authored Jul 5, 2023
1 parent 454134e commit 7bc6255
Show file tree
Hide file tree
Showing 37 changed files with 131 additions and 1,514 deletions.
113 changes: 57 additions & 56 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,20 @@ Deprecations
Pending deprecations
--------------------

* The ``grouping_type`` and ``grouping_method`` arguments of ``qchem.molecular_hamiltonian()`` are deprecated.

- Deprecated in v0.31
- Will be removed in v0.32

Instead, simply construct a new instance of ``Hamiltonian`` with the grouping specified:

.. code-block:: python
H, qubits = molecular_hamiltonian(symbols, coordinates)
grouped_h = qml.Hamiltonian(
H.coeffs,
H.ops,
grouping_type=grouping_type,
method=grouping_method,
)
* ``zyz_decomposition`` and ``xyx_decomposition`` are deprecated, use ``one_qubit_decomposition`` with a rotations
keyword instead.

- Deprecated in v0.31
- Will be removed in v0.32

* The ``do_queue`` keyword argument in ``qml.operation.Operator`` is deprecated. This affects
all child classes, such as ``Operation``, ``Observable``, ``SymbolicOp`` and more. Instead of
setting ``do_queue=False``, use the ``qml.QueuingManager.stop_recording()`` context.

- Deprecated in v0.31
- Will be removed in v0.32

* ``LieAlgebraOptimizer`` has been renamed. Please use ``RiemannianGradientOptimizer`` instead.

- Deprecated in v0.31
- Will be removed in v0.32

* The ``Operation.base_name`` property is deprecated. Please use ``Operator.name`` or ``type(obj).__name__`` instead.

- Still accessible in v0.31
- Removed in v0.32

* ``qml.math.reduced_dm`` has been deprecated. Please use ``qml.math.reduce_dm`` or ``qml.math.reduce_statevector`` instead.

- Still accessible in v0.31
- Removed in v0.32

* ``qml.math.purity``, ``qml.math.vn_entropy``, ``qml.math.mutual_info``, ``qml.math.fidelity``,
``qml.math.relative_entropy``, and ``qml.math.max_entropy`` no longer support state vectors as
input. Please call ``qml.math.dm_from_state_vector`` on the input before passing to any of these functions.

- Still accepted in v0.31
- Removed in v0.32

* The ``qml.specs`` dictionary will no longer support direct key access to certain keys. Instead
these quantities can be accessed as fields of the new ``Resources`` object saved under
``specs_dict["resources"]``:

- ``num_operations`` will no longer be supported, use ``specs_dict["resources"].num_gates``
- ``num_used_wires`` will no longer be supported, use ``specs_dict["resources"].num_wires``
- ``gate_types`` will no longer be supported, use ``specs_dict["resources"].gate_types``
- ``gate_sizes`` will no longer be supported, use ``specs_dict["resources"].gate_sizes``
- ``depth`` will no longer be supported, use ``specs_dict["resources"].depth``

These keys are still accessible in v0.31 and will be removed in v0.32.

* ``QuantumScript``'s ``name`` keyword argument and property are deprecated.
This also affects ``QuantumTape`` and ``OperationRecorder``.

- Deprecated in v0.31
- Will be removed in v0.32

* The ``observables`` argument in ``QubitDevice.statistics`` is deprecated. Please use ``circuit``
instead. Using a list of observables in ``QubitDevice.statistics`` is deprecated. Please use a
``QuantumTape`` instead.
Expand Down Expand Up @@ -122,6 +66,63 @@ Pending deprecations
Completed deprecation cycles
----------------------------

* The ``qml.specs`` dictionary longer supports direct key access to certain keys. Instead
these quantities can be accessed as fields of the new ``Resources`` object saved under
``specs_dict["resources"]``:

- ``num_operations`` is no longer supported, use ``specs_dict["resources"].num_gates``
- ``num_used_wires`` is no longer supported, use ``specs_dict["resources"].num_wires``
- ``gate_types`` is no longer supported, use ``specs_dict["resources"].gate_types``
- ``gate_sizes`` is no longer supported, use ``specs_dict["resources"].gate_sizes``
- ``depth`` is no longer supported, use ``specs_dict["resources"].depth``

These keys were still accessible in v0.31 and removed in v0.32.

* ``qml.math.reduced_dm`` has been removed. Please use ``qml.math.reduce_dm`` or ``qml.math.reduce_statevector`` instead.

- Still accessible in v0.31
- Removed in v0.32

* ``QuantumScript``'s ``name`` keyword argument and property are removed.
This also affects ``QuantumTape`` and ``OperationRecorder``.

- Deprecated in v0.31
- Removed in v0.32

* The ``Operation.base_name`` property is removed. Please use ``Operator.name`` or ``type(obj).__name__`` instead.

- Still accessible in v0.31
- Removed in v0.32

* ``LieAlgebraOptimizer`` has been renamed. Please use ``RiemannianGradientOptimizer`` instead.

- Deprecated in v0.31
- Removed in v0.32


* The ``grouping_type`` and ``grouping_method`` arguments of ``qchem.molecular_hamiltonian()`` are removed.

- Deprecated in v0.31
- Removed in v0.32

Instead, simply construct a new instance of ``Hamiltonian`` with the grouping specified:

.. code-block:: python
H, qubits = molecular_hamiltonian(symbols, coordinates)
grouped_h = qml.Hamiltonian(
H.coeffs,
H.ops,
grouping_type=grouping_type,
groupingmethod=grouping_method,
)
* ``zyz_decomposition`` and ``xyx_decomposition`` are removed, use ``one_qubit_decomposition`` with a rotations
keyword instead.

- Deprecated in v0.31
- Removed in v0.32

* The ``qml.utils.sparse_hamiltonian`` function has been removed. ``~.Hamiltonian.sparse_matrix`` should be used instead.

- Deprecated in v0.29
Expand Down
1 change: 0 additions & 1 deletion doc/introduction/interfaces/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ use the provided optimizers:
~pennylane.AdagradOptimizer
~pennylane.AdamOptimizer
~pennylane.GradientDescentOptimizer
~pennylane.LieAlgebraOptimizer
~pennylane.MomentumOptimizer
~pennylane.NesterovMomentumOptimizer
~pennylane.QNGOptimizer
Expand Down
25 changes: 24 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@

<h3>Breaking changes 💔</h3>

* The `grouping_type` and `grouping_method` keyword arguments are removed from `qchem.molecular_hamiltonian`.

* `zyz_decomposition` and `xyx_decomposition` are removed. Use `one_qubit_decomposition` instead.

* `LieAlgebraOptimizer` has been removed. Use `RiemannianGradientOptimizer` instead.

* `Operation.base_name` has been removed.

* `QuantumScript.name` has been removed.

* `qml.math.reduced_dm` has been removed. Use `qml.math.reduce_dm` or `qml.math.reduce_statevector` instead.

* The ``qml.specs`` dictionary longer supports direct key access to certain keys. Instead
these quantities can be accessed as fields of the new ``Resources`` object saved under
``specs_dict["resources"]``:

- ``num_operations`` is no longer supported, use ``specs_dict["resources"].num_gates``
- ``num_used_wires`` is no longer supported, use ``specs_dict["resources"].num_wires``
- ``gate_types`` is no longer supported, use ``specs_dict["resources"].gate_types``
- ``gate_sizes`` is no longer supported, use ``specs_dict["resources"].gate_sizes``
- ``depth`` is no longer supported, use ``specs_dict["resources"].depth``

<h3>Deprecations 👋</h3>

<h3>Documentation 📝</h3>
Expand All @@ -21,4 +43,5 @@

This release contains contributions from (in alphabetical order):

Matthew Silverman
Christina Lee,
Matthew Silverman
2 changes: 0 additions & 2 deletions pennylane/math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
marginal_prob,
mutual_info,
purity,
reduced_dm,
reduce_dm,
reduce_statevector,
relative_entropy,
Expand Down Expand Up @@ -153,7 +152,6 @@ def __getattr__(name):
"ones_like",
"purity",
"reduce_dm",
"reduced_dm",
"relative_entropy",
"reduce_statevector",
"requires_grad",
Expand Down
68 changes: 2 additions & 66 deletions pennylane/math/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def reduce_dm(density_matrix, indices, check_state=False, c_dtype="complex128"):
Returns:
tensor_like: Density matrix of size ``(2**len(indices), 2**len(indices))`` or ``(batch_dim, 2**len(indices), 2**len(indices))``
.. seealso:: :func:`pennylane.math.reduce_statevector`, :func:`pennylane.qinfo.transforms.reduced_dm`,
and :func:`pennylane.density_matrix`
.. seealso:: :func:`pennylane.math.reduce_statevector`, and :func:`pennylane.density_matrix`
**Example**
Expand Down Expand Up @@ -436,8 +435,7 @@ def reduce_statevector(state, indices, check_state=False, c_dtype="complex128"):
Returns:
tensor_like: Density matrix of size ``(2**len(indices), 2**len(indices))`` or ``(batch_dim, 2**len(indices), 2**len(indices))``
.. seealso:: :func:`pennylane.math.reduce_dm`, :func:`pennylane.qinfo.transforms.reduced_dm`,
and :func:`pennylane.density_matrix`
.. seealso:: :func:`pennylane.math.reduce_dm` and :func:`pennylane.density_matrix`
**Example**
Expand Down Expand Up @@ -550,68 +548,6 @@ def dm_from_state_vector(state, check_state=False, c_dtype="complex128"):
)


def reduced_dm(state, indices, check_state=False, c_dtype="complex128"):
"""Compute the reduced density matrix from a state vector or a density matrix. It supports all interfaces (Numpy,
Autograd, Torch, Tensorflow and Jax).
Args:
state (tensor_like): ``(2**N)`` state vector or ``(2**N, 2**N)`` density matrix.
indices (Sequence(int)): List of indices in the considered subsystem.
check_state (bool): If True, the function will check the state validity (shape and norm).
c_dtype (str): Complex floating point precision type.
Returns:
tensor_like: Reduced density matrix of size ``(2**len(indices), 2**len(indices))``
**Example**
>>> x = [1, 0, 1, 0] / np.sqrt(2)
>>> reduced_dm(x, indices=[0])
[[0.5+0.j 0.5+0.j]
[0.5+0.j 0.5+0.j]]
>>> reduced_dm(x, indices=[1])
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]]
>>> y = tf.Variable([1, 0, 0, 0], dtype=tf.complex128)
>>> reduced_dm(y, indices=[1])
tf.Tensor(
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]], shape=(2, 2), dtype=complex128)
>>> z = [[0.5, 0, 0.0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]]
>>> reduced_dm(z, indices=[0])
[[0.5+0.j 0.0+0.j]
[0.0+0.j 0.5+0.j]]
>>> reduced_dm(z, indices=[1])
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]]
>>> y_mat_tf = tf.Variable([[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=tf.complex128)
>>> reduced_dm(y_mat_tf, indices=[1])
tf.Tensor(
[[1.+0.j 0.+0.j]
[0.+0.j 0.+0.j]], shape=(2, 2), dtype=complex128)
.. seealso:: :func:`pennylane.qinfo.transforms.reduced_dm` and :func:`pennylane.density_matrix`
"""
warnings.warn(
"reduced_dm has been deprecated. Please use reduce_statevector or reduce_dm instead",
UserWarning,
)

# Cast as a c_dtype array
state = cast(state, dtype=c_dtype)
len_state = state.shape[0]
# State vector
if state.shape == (len_state,):
return reduce_statevector(state, indices, check_state)

return reduce_dm(state, indices, check_state)


def purity(state, indices, check_state=False, c_dtype="complex128"):
r"""Computes the purity of a density matrix.
Expand Down
9 changes: 0 additions & 9 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,15 +1659,6 @@ def parameter_frequencies(self):
"and parameter frequencies can not be computed as no generator is defined."
)

@property
def base_name(self):
"""Holdover from when in-place inversion changed then name. To be removed."""
warnings.warn(
"Operation.base_name is deprecated. Please use type(obj).__name__ or obj.name instead.",
UserWarning,
)
return self.__class__.__name__

def __init__(self, *params, wires=None, do_queue=None, id=None):
super().__init__(*params, wires=wires, do_queue=do_queue, id=id)

Expand Down
9 changes: 0 additions & 9 deletions pennylane/ops/op_math/adjoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
This submodule defines the symbolic operation that indicates the adjoint of an operator.
"""
from functools import wraps
import warnings

import pennylane as qml
from pennylane.math import conj, moveaxis, transpose
Expand Down Expand Up @@ -338,14 +337,6 @@ class AdjointOperation(Operation):
class can be removed.
"""

@property
def base_name(self):
warnings.warn(
"Operation.base_name is deprecated. Please use type(obj).__name__ or obj.name instead.",
UserWarning,
)
return self._name

@property
def name(self):
return self._name
Expand Down
8 changes: 0 additions & 8 deletions pennylane/ops/op_math/controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,6 @@ def __init__(
# Make sure grad_recipe is an iterable of correct length instead of None
self.grad_recipe = [None] * self.num_params

@property
def base_name(self):
warnings.warn(
"Operation.base_name is deprecated. Please use type(obj).__name__ or obj.name instead.",
UserWarning,
)
return f"C({self.base.base_name})"

@property
def name(self):
return self._name
Expand Down
8 changes: 0 additions & 8 deletions pennylane/ops/op_math/pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ class PowOperation(Operation):
# until we add gradient support
grad_method = None

@property
def base_name(self):
warnings.warn(
"Operation.base_name is deprecated. Please use type(obj).__name__ or obj.name instead.",
UserWarning,
)
return self._name

@property
def name(self):
return self._name
Expand Down
2 changes: 0 additions & 2 deletions pennylane/optimize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from .adam import AdamOptimizer
from .adaptive import AdaptiveOptimizer
from .gradient_descent import GradientDescentOptimizer
from .lie_algebra import LieAlgebraOptimizer
from .momentum import MomentumOptimizer
from .nesterov_momentum import NesterovMomentumOptimizer
from .riemannian_gradient import RiemannianGradientOptimizer
Expand All @@ -39,7 +38,6 @@
"AdamOptimizer",
"AdaptiveOptimizer",
"GradientDescentOptimizer",
"LieAlgebraOptimizer",
"MomentumOptimizer",
"NesterovMomentumOptimizer",
"RMSPropOptimizer",
Expand Down
Loading

0 comments on commit 7bc6255

Please sign in to comment.