Skip to content

Commit

Permalink
Minor fixes for 0.36 release (#5633)
Browse files Browse the repository at this point in the history
As name says. See commit descriptions for details about changes.
  • Loading branch information
mudit2812 authored May 3, 2024
1 parent 5a66aaa commit 76edb60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
14 changes: 7 additions & 7 deletions doc/news/new_opmath.rst
Original file line number Diff line number Diff line change
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,16 +341,16 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions pennylane/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@
with newer, more general arithmetic operators. These consist of :class:`~pennylane.ops.op_math.Prod`,
:class:`~pennylane.ops.op_math.Sum` and :class:`~pennylane.ops.op_math.SProd`. By default, using dunder
methods (eg. ``+``, ``-``, ``@``, ``*``) to combine operators with scalars or other operators will
create :class:`~pennylane.Hamiltonian`'s and :class:`~.Tensor`'s. If you would like to switch dunders to
return newer arithmetic operators, the ``operation`` module provides the following helper functions:
create the aforementioned newer operators. To toggle the dunders to return the older arithmetic operators,
the ``operation`` module provides the following helper functions:
.. currentmodule:: pennylane.operation
Expand Down
2 changes: 1 addition & 1 deletion pennylane/pauli/dla/structure_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def structure_constants(
we should have :math:`f^0_{1, 3} = -2`, which is indeed the case.
>>> adjoint_rep[0, 1, 3]
-2.
-2.0
We can also look at the overall adjoint action of the first element :math:`G_0 = X_{0} \otimes X_{1}` of the DLA on other elements.
In particular, at :math:`\left(\text{ad}(iG_0)\right)_{\alpha, \beta} = f^0_{\alpha, \beta}`, which corresponds to the following matrix.
Expand Down
6 changes: 3 additions & 3 deletions pennylane/templates/subroutines/fable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FABLE(Operation):
.. code-block:: python
input_matrix= np.array([[0.1, 0.2],[0.3, -0.2]])
input_matrix = np.array([[0.1, 0.2],[0.3, -0.2]])
dev = qml.device('default.qubit', wires=3)
@qml.qnode(dev)
def example_circuit():
Expand All @@ -56,7 +56,7 @@ def example_circuit():
We can see that the input matrix has been block encoded in the matrix of the circuit:
>>> s = int(qml.math.ceil(qml.math.log2(max(len(input_matrix), len(input_matrix[0])))))
>>> s = int(np.ceil(np.log2(max(len(input_matrix), len(input_matrix[0])))))
>>> expected = 2**s * qml.matrix(example_circuit)().real[0 : 2**s, 0 : 2**s]
>>> print(f"Block-encoded matrix:\n{expected}")
Block-encoded matrix:
Expand All @@ -68,7 +68,7 @@ def example_circuit():
When given a :math:`(N \times M)` matrix, the matrix is padded with zeroes
until it is of :math:`(N \times N)` dimension, where :math:`N` is equal to :math:`2^n`,
and :math:`n` is an integer. It is also assumed that the values
of the input matrix are within [-1, 1]. Apply a subnormalization factor if needed.
of the input matrix are within :math:`[-1, 1]`. Apply a subnormalization factor if needed.
"""

num_wires = AnyWires
Expand Down
6 changes: 5 additions & 1 deletion tests/pauli/test_pauli_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ def f(x, y):
assert qml.math.allclose(gy, pw2_mat)

@pytest.mark.jax
def test_dense_matrix_jax(self):
@pytest.mark.parametrize("use_jit", [True, False])
def test_dense_matrix_jax(self, use_jit):
"""Test calculating and differentiating the matrix with jax."""

import jax
Expand All @@ -1272,6 +1273,9 @@ def f(x, y):
H = x * _pw1 + y * _pw2
return H.to_mat()

if use_jit:
f = jax.jit(f)

x = jax.numpy.array(0.1 + 0j)
y = jax.numpy.array(0.2 + 0j)

Expand Down

0 comments on commit 76edb60

Please sign in to comment.