Skip to content

Controlled GlobalPhase is ZGate #1113

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

Closed
wants to merge 1 commit into from

Conversation

mpharrigan
Copy link
Collaborator

@mpharrigan mpharrigan commented Jul 9, 2024

The single-bit control of a global phase is ZGate.

More basic gates #1109

@mpharrigan mpharrigan requested a review from tanujkhattar July 9, 2024 00:54
Comment on lines +89 to +90
exponent: float = np.real_if_close(np.log(self.coefficient) / (np.pi * 1.0j)).item() # type: ignore
bloq = ZPowGate(exponent=exponent, eps=self.eps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please handle the case when self.coefficient is symbolic

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also have an override where we return a ZGate instead of ZPowGate if exponent is 1 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good question, and I think it's part of a broader issue. How do we handle cases where you can express the same "thing" (unitary) via different bloq+attribute combinations? I think the answer is to keep things as non-magical as possible when constructing bloqs and handle overlap in the bloq analysis functions. Happy to discuss more.

For this PR in particular: since ZPowGate(exponent=1) is a valid bloq, I'll leave as-is.

I'll handle symbolic coefficient

return super().get_ctrl_system(ctrl_spec=ctrl_spec)

# Otherwise, it's a ZPowGate
exponent: float = np.real_if_close(np.log(self.coefficient) / (np.pi * 1.0j)).item() # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

this wouldn't work when self.coefficient is symbolic. Maybe we should update this to self.exponent to match the other rotation gates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks.

Did you want to change the semantics to just store the exponent directly as the attribute or just change the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

the former, then we can safely pass self.exponent to ZPowGate. But would require updating all call sites. Based on a preliminary scan, most of them are 1j, -1j, -1 and would simplify SU2:

bb.add(GlobalPhase(coefficient=-exp(1j * self.global_shift), eps=self.eps / 4))

I'm happy to take this PR if you'd like.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please :)

@anurudhp
Copy link
Contributor

can be closed: this change was merged #1117

@mpharrigan
Copy link
Collaborator Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants