Skip to content
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 global-phase support to control-flow builders #10800

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

jakelishman
Copy link
Member

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.

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.
@jakelishman jakelishman added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Sep 8, 2023
@jakelishman jakelishman added this to the 0.45.0 milestone Sep 8, 2023
@jakelishman jakelishman requested a review from a team as a code owner September 8, 2023 13:55
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this seems straightforward enough

Comment on lines +2439 to +2440
if self._control_flow_scopes:
return self._control_flow_scopes[-1].global_phase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a necessary part of the interface being added in this PR, but is there really a use case for:

with qc.while_loop((qc.clbits[1], False)):
    qc.h(0)
    print(qc.global_phase)

It seems pretty esoteric. But it's good we handle it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically you wouldn't need to actually get the global_phase for your own use, but things like __iadd__, which is a fairly natural way of writing things, use both a get and a set by default.

@mtreinish mtreinish added this pull request to the merge queue Oct 11, 2023
Merged via the queue into Qiskit:main with commit dbc3e32 Oct 11, 2023
@jakelishman jakelishman deleted the control-flow-builder-gphase branch October 11, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants