Add global-phase support to control-flow builders #10800
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This formalises the concept of global phase within control-flow scopes, and teaches the control-flow builders to treat modifications to the global phase as being conditional on the control-flow block being entered.
Details and comments
I turned this up during trying to write #10786, and felt like we needed a formalisation of what we treat "global phase" as during control-flow scopes.
This PR defines the "global phase" of a block as "the amount by which the phase of all program qubits will be advanced if this block is taken", which I think is consistent with how we have been de facto treating this via basis-translator recursion into control-flow blocks. For the most part, this shouldn't be observable in an actual execution of a quantum program, but you could say take a single shot of a statevector simulation, and this interpretation would cause the resultant statevector to have a well-defined global phase consistent with our existent conventions.