Skip to content

Commit

Permalink
Daily rc sync to master (#5650)
Browse files Browse the repository at this point in the history
Automatic sync from the release candidate to master during a feature
freeze.

---------

Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Co-authored-by: Vincent Michaud-Rioux <vincentm@nanoacademic.com>
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Co-authored-by: lillian542 <38584660+lillian542@users.noreply.github.com>
Co-authored-by: Pietropaolo Frisoni <pietropaolo.frisoni@xanadu.ai>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Korbinian Kottmann <43949391+Qottmann@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
Co-authored-by: Diksha Dhawan <40900030+ddhawan11@users.noreply.github.com>
Co-authored-by: Isaac De Vlugt <isaacdevlugt@gmail.com>
Co-authored-by: Diego <67476785+DSGuala@users.noreply.github.com>
Co-authored-by: trbromley <brotho02@gmail.com>
Co-authored-by: GitHub Actions Bot <>
  • Loading branch information
17 people authored May 6, 2024
1 parent b6e9658 commit 8707c57
Show file tree
Hide file tree
Showing 25 changed files with 1,005 additions and 601 deletions.
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
# built documents.

import pennylane
pennylane.Hamiltonian = pennylane.ops.Hamiltonian

# The full version, including alpha/beta/rc tags.
release = pennylane.__version__
Expand Down
56 changes: 30 additions & 26 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@ deprecations are listed below.
Pending deprecations
--------------------

New operator arithmetic deprecations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The v0.36 release completes the main phase of PennyLane's switchover to an updated approach for handling
arithmetic operations between operators, check out the :ref:`Updated operators <new_opmath>` page
for more details. The old system is still accessible via :func:`~.disable_new_opmath`. However, the
old system will be removed in an upcoming release and should be treated as deprecated. The following
functionality will explicitly raise a deprecation warning when used:

* ``op.ops`` and ``op.coeffs`` will be deprecated in the future. Use
:meth:`~.Operator.terms` instead.

- Added and deprecated for ``Sum`` and ``Prod`` instances in v0.35

* Accessing ``qml.ops.Hamiltonian`` is deprecated because it points to the old version of the class
that may not be compatible with the new approach to operator arithmetic. Instead, using
``qml.Hamiltonian`` is recommended because it dispatches to the :class:`~.LinearCombination` class
when the new approach to operator arithmetic is enabled. This will allow you to continue to use
``qml.Hamiltonian`` with existing code without needing to make any changes.

- Use of ``qml.ops.Hamiltonian`` is deprecated in v0.36

* Accessing terms of a tensor product (e.g., ``op = X(0) @ X(1)``) via ``op.obs`` is deprecated with new operator arithmetic.
A user should use :class:`op.operands <~.CompositeOp>` instead.

- Deprecated in v0.36

Other deprecations
~~~~~~~~~~~~~~~~~~

* PennyLane Lightning and Catalyst will no longer support ``manylinux2014`` (GLIBC 2.17) compatibile Linux operating systems, and will be migrated to ``manylinux_2_28`` (GLIBC 2.28). See `pypa/manylinux <https://github.com/pypa/manylinux>`_ for additional details.

- Last supported version of ``manylinux2014`` with v0.36
Expand All @@ -35,32 +65,6 @@ Pending deprecations
- Deprecated in v0.36
- Will be removed in v0.37

New operator arithmetic deprecations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* ``op.ops`` and ``op.coeffs`` will be deprecated in the future. Use ``op.terms()`` instead.

- Added and deprecated for ``Sum`` and ``Prod`` instances in v0.35

* Accessing ``qml.ops.Hamiltonian`` with new operator arithmetic enabled is deprecated. Using ``qml.Hamiltonian``
with new operator arithmetic enabled now returns a ``LinearCombination`` instance. Some functionality
may not work as expected, and use of the Hamiltonian class with the new operator arithmetic will not
be supported in future releases of PennyLane.

You can update your code to the new operator arithmetic by using ``qml.Hamiltonian`` instead of importing
the Hamiltonian class directly or via ``qml.ops.Hamiltonian``. When the new operator arithmetic is enabled,
``qml.Hamiltonian`` will access the new corresponding implementation.

Alternatively, to continue accessing the legacy functionality, you can use
``qml.operation.disable_new_opmath()``.

- Deprecated in v0.36

* Accessing terms of a tensor product ``op = X(0) @ X(1)`` via ``op.obs`` is deprecated with new operator arithmetic.
A user should use ``op.operands`` instead.

- Deprecated in v0.36

Completed deprecation cycles
----------------------------

Expand Down
36 changes: 18 additions & 18 deletions doc/news/new_opmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Summary of the update
* The underlying system for performing arithmetic with operators has been changed. Arithmetic can be carried out using
standard Python operations like ``+``, ``*`` and ``@`` or via arithmetic functions located in :mod:`~.op_math`.

* You can now easily access Pauli operators via :class:`~.I`, :class:`~.X`, :class:`~.Y`, and :class:`~.Z`.
* You can now easily access Pauli operators via :obj:`~.pennylane.I`, :obj:`~.pennylane.X`, :obj:`~.pennylane.Y`, and :obj:`~.pennylane.Z`.

>>> from pennylane import I, X, Y, Z
>>> X(0)
X(0)

The original long-form names :class:`~.Identity`, :class:`~.PauliX`, :class:`~.PauliY`, and :class:`~.PauliZ` remain available and are functionally equivalent to ``I``, ``X``, ``Y``, and ``Z``, but
The original long-form names :class:`~.Identity`, :class:`~.PauliX`, :class:`~.PauliY`, and :class:`~.PauliZ` remain available and are functionally equivalent to :obj:`~.pennylane.I`, :obj:`~.pennylane.X`, :obj:`~.pennylane.Y`, and :obj:`~.pennylane.Z`, but
use of the short-form names is now recommended.

* Operators in PennyLane can have a backend Pauli representation, which can be used to perform faster operator arithmetic. Now, the Pauli
Expand All @@ -60,7 +60,7 @@ Summary of the update
>>> type(op.pauli_rep)
pennylane.pauli.pauli_arithmetic.PauliSentence

You can transform the ``PauliSentence`` back to a suitable ``Operator`` via the :meth:`~.pennylane.ops.PauliSentence.operation` or :meth:`~.pennylane.ops.PauliSentence.hamiltonian` method.
You can transform the :class:`~.pennylane.pauli.PauliSentence` back to a suitable :class:`~.pennylane.operation.Operator` via the :meth:`~pennylane.pauli.PauliSentence.operation` or :meth:`~pennylane.pauli.PauliSentence.hamiltonian` method.

>>> op.pauli_rep.operation()
X(0) + Y(0)
Expand Down Expand Up @@ -111,8 +111,8 @@ Summary of the update
+--------------------------------------------+----------------------+---------------------------+


The three main new opmath classes :class:`~.pennylane.ops.SProd`, :class:`~.pennylane.ops.Prod`, and :class:`~.pennylane.ops.Sum` have already been around for a while.
E.g., :func:`~.pennylane.dot` has always returned a :class:`~.pennylane.ops.Sum` instance.
The three main new opmath classes :class:`~.pennylane.ops.op_math.SProd`, :class:`~.pennylane.ops.op_math.Prod`, and :class:`~.pennylane.ops.op_math.Sum` have already been around for a while.
E.g., :func:`~.pennylane.dot` has always returned a :class:`~.pennylane.ops.op_math.Sum` instance.

**Usage**

Expand Down Expand Up @@ -161,8 +161,8 @@ Summary of the update

**qml.Hamiltonian**

The legacy classes :class:`~.pennylane.operation.Tensor` and :class:`~.Hamiltonian` will soon be deprecated.
:class:`~.ops.LinearCombination` offers the same API as :class:`~.Hamiltonian` but works well with new opmath classes.
The legacy classes :class:`~.pennylane.operation.Tensor` and :class:`~.pennylane.Hamiltonian` will soon be deprecated.
:class:`~.ops.op_math.LinearCombination` offers the same API as :class:`~.pennylane.Hamiltonian` but works well with new opmath classes.

Depending on whether or not new opmath is active, ``qml.Hamiltonian`` will return either of the two classes.

Expand Down Expand Up @@ -231,7 +231,7 @@ To help identify a fix, select the option below that describes your situation.
:title: Sharp bits about the qml.Hamiltonian dispatch
:href: sharp-bits-hamiltonian

One of the reasons that :class:`~.ops.LinearCombination` exists is that the old Hamiltonian class is not compatible with new opmath tensor products.
One of the reasons that :class:`~.ops.op_math.LinearCombination` exists is that the old Hamiltonian class is not compatible with new opmath tensor products.
We can try to instantiate an old ``qml.ops.Hamiltonian`` class with a ``X(0) @ X(1)`` tensor product, which returns a :class:`~.pennylane.ops.Prod` instance with new opmath enabled.

>>> qml.operation.active_new_opmath() # confirm opmath is active (by default)
Expand All @@ -245,7 +245,7 @@ To help identify a fix, select the option below that describes your situation.
>>> qml.Hamiltonian([0.5], [X(0) @ X(1)])
0.5 * (X(0) @ X(1))

The API of :class:`~.ops.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables or simplify upon initialization.
The API of :class:`~.ops.op_math.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables or simplify upon initialization.

>>> H1 = qml.Hamiltonian([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True)
>>> H2 = qml.ops.LinearCombination([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True)
Expand Down Expand Up @@ -326,11 +326,11 @@ To help identify a fix, select the option below that describes your situation.
.. code-block:: python3
# in some test file
with qml.operation.disable_new_opmath():
with qml.operation.disable_new_opmath_cm():
legacy_ham_example = qml.Hamiltonian(coeffs, ops) # creates a Hamiltonian instance
@pytest.mark.usefixtures("use_legacy_opmath")
@pytest.marl.parametrize("ham", [legacy_ham_example])
@pytest.mark.parametrize("ham", [legacy_ham_example])
def test_qml_hamiltonian_legacy_opmath(ham):
assert isinstance(ham, qml.Hamiltonian) # True
assert isinstance(ham, qml.ops.Hamiltonian) # True
Expand All @@ -341,23 +341,23 @@ To help identify a fix, select the option below that describes your situation.
ham_example = qml.Hamiltonian(coeffs, ops) # creates a LinearCombination instance
@pytest.mark.usefixtures("use_legacy_opmath")
@pytest.marl.parametrize("ham", [ham_example])
def test_qml_hamiltonian_legacy_opmath(ham):
@pytest.mark.usefixtures("use_new_opmath")
@pytest.mark.parametrize("ham", [ham_example])
def test_qml_hamiltonian_new_opmath(ham):
assert isinstance(ham, qml.Hamiltonian) # True
assert not isinstance(ham, qml.ops.Hamiltonian) # True
@pytest.mark.usefixtures("use_legacy_opmath")
@pytest.marl.parametrize("ham", [ham_example])
@pytest.mark.parametrize("ham", [ham_example])
def test_qml_hamiltonian_legacy_opmath(ham):
# Most likely you wanted to test things with an Hamiltonian instance
# Most likely you wanted to test things with a Hamiltonian instance
legacy_ham_example = convert_to_legacy_H(ham)
assert isinstance(legacy_ham_example, qml.ops.Hamiltonian) # True
assert isinstance(legacy_ham_example, qml.Hamiltonian) # True because we are in legacy opmath context
assert not isinstance(legacy_ham_example, qml.ops.LinearCombination) # True
For all that, keep in mind that ``qml.Hamiltonian`` points to :class:`~Hamiltonian` and :class:`LinearCombination` depending on the status of ``qml.operation.active_new_opmath()``.
So if you want to test something specifically for the old :class:`~Hamiltonian`` class, use ``qml.ops.Hamiltonian`` instead.
For all that, keep in mind that ``qml.Hamiltonian`` points to :class:`~pennylane.Hamiltonian` and :class:`LinearCombination` depending on the status of ``qml.operation.active_new_opmath()``.
So if you want to test something specifically for the old :class:`~pennylane.Hamiltonian`` class, use ``qml.ops.Hamiltonian`` instead.

.. details::
:title: Sharp bits about the nesting structure of new opmath instances
Expand Down
Loading

0 comments on commit 8707c57

Please sign in to comment.