-
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
Add Expr
support to the control-flow builders
#10400
Add Expr
support to the control-flow builders
#10400
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 5602359644
💛 - Coveralls |
487a0f7
to
cf2170b
Compare
This is generally relatively straightforwards; anywhere where we examine the resources used by an operation, we need to update to account for classical resources potentially being tied up in `ControlFlowOp` fields in `Expr` nodes as well. This also has the side effect of fixing a bug where a nested `SwitchCaseOp.target` wasn't considered in the scope building for _all_ control-flow operations, which could incorrectly cause some registers to be missed in outer scopes.
cf2170b
to
a650dae
Compare
Now rebased over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few small comments.
*, | ||
in_loop: bool, | ||
label: Optional[str] = None, | ||
): | ||
self.circuit = circuit | ||
self.target = target | ||
self._target = target | ||
if isinstance(target, Clbit): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really a comment to be addressed in this PR, but did we consider just always lifting the conditions and targets to Expr
? I suppose that'd be a breaking change since then self.{target,condition}
would be an Expr
rather than what the user provided. But it'd at least remove this series of checks which we currently require all over the place!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did consider it, but wanted to minimise potential API breakage for the old paths, since the intent is likely to deprecate/remove the bare form.
expected = QuantumCircuit(qr, clbits, cr1, cr2, cr3, cr4) | ||
expected.for_loop(range(3), None, for_body, [qr[0]], clbits + list(cr1)) | ||
|
||
self.assertEqual(canonicalize_control_flow(test), canonicalize_control_flow(expected)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need the canonicalize_control_flow
-ing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, but I didn't want to make that change in the same PR, since there's a whole bunch of places where it could be removed.
* Add `Expr` support to the control-flow builders This is generally relatively straightforwards; anywhere where we examine the resources used by an operation, we need to update to account for classical resources potentially being tied up in `ControlFlowOp` fields in `Expr` nodes as well. This also has the side effect of fixing a bug where a nested `SwitchCaseOp.target` wasn't considered in the scope building for _all_ control-flow operations, which could incorrectly cause some registers to be missed in outer scopes. * Remove out-of-date comment
Summary
This is generally relatively straightforwards; anywhere where we examine the resources used by an operation, we need to update to account for classical resources potentially being tied up in
ControlFlowOp
fields inExpr
nodes as well.This also has the side effect of fixing a bug where a nested
SwitchCaseOp.target
wasn't considered in the scope building for all control-flow operations, which could incorrectly cause some registers to be missed in outer scopes.Details and comments
Fix #10398.
Close #10228.
Depends on #10367.
Additional feature changelog in #10331.