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

Implement the inverse of IonQ native gates #5889

Merged
merged 15 commits into from Sep 28, 2022

Conversation

yitchen-tim
Copy link
Contributor

Implement the inverse of IonQ's native gates, GPIGate, GPI2Gate and MSGate, by implementing __pow__ method for power==-1.

@google-cla
Copy link

google-cla bot commented Sep 26, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@CirqBot CirqBot added the size: M 50< lines changed <250 label Sep 26, 2022
@viathor
Copy link
Collaborator

viathor commented Sep 26, 2022

Thank you for this PR, Tim! Please address the failing automated checks.

@yitchen-tim
Copy link
Contributor Author

My code has passed the test, but there are other parts I didn't touch that fail the tests. There is another PR #5891 to fix the failing tests. I will update this PR after #5891 is merged.

]
],
)
def test_gate_inverse(gate, target, phases):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since all targets are identity, you should be able to compute the appropriate matrix inside the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

for p in [0, 0.1, 0.4, math.pi / 2, math.pi, 2 * math.pi]
]
+ [
(ionq.MSGate, numpy.identity(4), {"phi0": p0, "phi1": p1}) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would it take not to ignore type checks? (Applies throughout.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into how other contributors handled the same issue. Fixed now, and the ignores are removed.

"""Tests that the inverse of natives gate are correct."""
mat = cirq.protocols.unitary(gate)
mat_inverse = cirq.protocols.unitary(gate**-1)
num_qubits = mat.shape[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, this isn't the number of qubits. It's the Hilbert space dimension, which is two to the power number of qubits. Perhaps

dim = mat.shape[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the catch! Fixed.

@viathor viathor added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Sep 28, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Sep 28, 2022
@viathor
Copy link
Collaborator

viathor commented Sep 28, 2022

Thank you, Tim! :-)

@CirqBot CirqBot merged commit ff81f80 into quantumlib:master Sep 28, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Sep 28, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Implement the inverse of IonQ's native gates, GPIGate, GPI2Gate and MSGate, by implementing `__pow__` method for `power==-1`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants