PennyLaneAI / PennyLaneAI/catalyst

[BUG] Gradient verification fails if there is a `Prod` operation somewhere in the circuit

Open
#976 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
234
Forks
84
Avg merge
2d 15h
Merged PRs (30d)
66

Description

For the following circuit, gradient verification fails:

@qml.qjit
def f(params, x):

    @qml.qnode(dev, diff_method="parameter-shift")
    def circuit(params, x):
        qml.IQPEmbedding(x, wires=range(3), n_repeats=1)
        qml.StronglyEntanglingLayers(params["weights"], wires=range(3), imprimitive=qml.CZ)
        return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

    return catalyst.grad(circuit)(params, x)
>>> x = jnp.array([0.1, 0.2, 0.3])
>>> params = {"weights": jnp.ones([3, 3, 3])}
>>> f(params, x)
File catalyst/device/verification.py:238, in validate_observables_parameter_shift.<locals>._obs_checker(obs)
    237 def _obs_checker(obs):
--> 238     if obs and obs.grad_method not in {"A", None}:
    239         raise DifferentiableCompileError(
    240             f"{obs.name} does not support analytic differentiation"
    241         )

AttributeError: 'Prod' object has no attribute 'grad_method'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the circuit from the issue, then inspect catalyst/device/verification.py at validate_observables_parameter_shift and its _obs_checker function. Ensure gradient verification handles the Prod observable without raising AttributeError, and confirm the example completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.