Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Yushao Chen (Jerry) <[email protected]>
  • Loading branch information
albi3ro and JerryChen97 authored Jan 15, 2025
1 parent ebdf867 commit 9c785ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* The coefficients of observables now have improved differentiability.
[(#6598)](https://github.com/PennyLaneAI/pennylane/pull/6598)

* An informative error is raised in a qnode with `diff_method=None` is differentiated.
* An informative error is raised when a `QNode` with `diff_method=None` is differentiated.
[(#6770)](https://github.com/PennyLaneAI/pennylane/pull/6770)

<h3>Breaking changes 💔</h3>
Expand Down
10 changes: 6 additions & 4 deletions pennylane/workflow/jacobian_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,22 @@ def execute_and_compute_jacobian(self, tapes: QuantumScriptBatch) -> tuple[Resul

class NoGradients(JacobianProductCalculator):
"""A jacobian product calculator that raises errors when a vjp or jvp is requested."""

Check notice on line 215 in pennylane/workflow/jacobian_products.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/workflow/jacobian_products.py#L215

Trailing whitespace (trailing-whitespace)
error_msg = "Derivatives cannot be calculated with diff_method=None"

def compute_jacobian(self, tapes: QuantumScriptBatch) -> tuple:
raise qml.QuantumFunctionError("Derivatives cannot be calculated with diff_method=None")
raise qml.QuantumFunctionError(NoGradients.error_msg)

def compute_vjp(self, tapes: QuantumScriptBatch, dy: Sequence[Sequence[TensorLike]]) -> tuple:
raise qml.QuantumFunctionError("Derivatives cannot be calculated with diff_method=None")
raise qml.QuantumFunctionError(NoGradients.error_msg)

def execute_and_compute_jvp(
self, tapes: QuantumScriptBatch, tangents: Sequence[Sequence[TensorLike]]
) -> tuple[ResultBatch, tuple]:
raise qml.QuantumFunctionError("Derivatives cannot be calculated with diff_method=None")
raise qml.QuantumFunctionError(NoGradients.error_msg)

def execute_and_compute_jacobian(self, tapes: QuantumScriptBatch) -> tuple[ResultBatch, tuple]:
raise qml.QuantumFunctionError("Derivatives cannot be calculated with diff_method=None")
raise qml.QuantumFunctionError(NoGradients.error_msg)


class TransformJacobianProducts(JacobianProductCalculator):
Expand Down
3 changes: 2 additions & 1 deletion tests/gradients/core/test_pulse_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,8 @@ def test_constant_commuting(self, t):
assert qml.math.allclose(res, exp_grad)
r = qml.execute([tape], dev, None)
# Effective rotation parameters
assert qml.math.isclose(r, jnp.cos(2 * p[0]) * jnp.cos(2 * p[1]))
exp = jnp.cos(2 * p[0]) * jnp.cos(2 * p[1])
assert qml.math.isclose(r, exp)
jax.clear_caches()

@pytest.mark.slow
Expand Down

0 comments on commit 9c785ce

Please sign in to comment.