-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ControlFlowOp with parameterized body is not parameterized #12624
Comments
I'm not sure what, if any, the intended behaviour was, really - I had forgotten this method even existed. I'm not 100% certain what the best path is here. I very roughly lean towards leaving it as-is and documenting the behaviour clearly, because as you say, it'd be a breaking change, and the problem has been around ever since control flow was first introduced. That said, I forgot the method even existed, so I clearly don't really know how it's being used. If there's a clear compelling use case for making it have the new behaviour, we can go that way. |
I'm fine with only updating documentation (or maybe deprecate and overwrite with NotImplemented). Sometime this can be useful for payload validation, e.g. checking if all unbound parameters are operands of allowed gate type. However, this method is just a syntactic sugar of inst.operation.is_parameterized() == any(isinstance(p, ParameterExpression) for p in inst.operation.params) and I don't think the readability of the code is improved so much. But if we write validation logic with this method, the method is called very frequently, and if we implement this with Rust, probably we can get some performance gain. |
The same problem happens with This leads to problems when using gradient estimators from Qiskit Algorithms on circuits with controlled parameterised gates: the check in https://github.com/qiskit-community/qiskit-algorithms/blob/7f598a8fbf9ca0adb5a4521af5acad9a7137ef5d/qiskit_algorithms/gradients/utils.py#L302 unexpectedly returns false. |
What should we add?
When I test parameterization of below control flow, I would expect it is parameterized.
But I get False because is_parameterized function is defined in
Instruction
and it only tests againstParameterExpression
type. ControlFlowOp must overwrite the method to recursively check parameterization of its body.I'm not sure if this is expected behavior. If we change current behavior this is indeed an API break and we should be very careful.
The text was updated successfully, but these errors were encountered: