PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.35k stars 603 forks source link

Allow qml.cond to support passing operations #4100

Closed trbromley closed 1 year ago

trbromley commented 1 year ago

Feature details

The qml.cond function is used as part of the mid-circuit meausurement functionality in PennyLane. Currently, the signature is qml.cond(condition, true_fn, false_fn), where true_fn and false_fn are quantum functions.

We would like qml.cond to accept operations in addition to quantum functions. The quantum function style can be useful in some cases, but having to then call qml.cond can feel a little counter-intuitive - instead the user might just want to pass the operation directly.

Implementation

We would like it to be possible to do:

qml.cond(m_0, qml.RY(par, wires=0), qml.RX(par, wires=0))

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

Similar functionality is supported in qml.adjoint.

trbromley commented 1 year ago

Closing this as we have decided that it is not such a good idea - it would be introducing a UI that is not compatible with cond-like functions in other libraries.