Skip to content

The new qml.cond does not work on single gates #449

Open
@dime10

Description

@dime10

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfrontendPull requests that update the frontend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions