PennyLaneAI / PennyLaneAI/catalyst
The new `qml.cond` does not work on single gates
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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