PennyLaneAI / PennyLaneAI/catalyst

The new `qml.cond` does not work on single gates

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

Nobody has claimed this yet.

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

Description

qml.cond can be used with the typical Catalyst conditional:

def true_fn():
  qml.RY(0.7, wires=0)

qml.cond(x < 0.9, true_fn)()

But what doesn't work is the common PennyLane usage pattern for conditioning a single gate:

qml.cond(pred, qml.RY)(0.7, wires=0)
-> if true_fn.__code__.co_argcount != 0:
     raise TypeError("Conditional 'True' function is not allowed to have any arguments")

AttributeError: type object 'PauliX' has no attribute '__code__'

The reason is that branch functions are not allowed to have arguments in Catalyst, although in this case there is also the check itself that fails.

In addition, the argument type would likely be restricted to JAX-compatible types, even if we did allow arguments.

The issue is somewhat related to similar bugs with seen with functionals like adjoint and ctrl in the PennyLane interface not working with all argument types that PL users might use.

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

Start with the qml.cond entry point and reproduce the single-gate example using qml.RY. Compare that path with the shown true_fn form and determine the intended handling of gate objects and branch arguments. Done means the single-gate conditioning behavior is defined and the reported AttributeError is resolved, with the relevant behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.