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

Typo in docstring for GPI2 gate #6639

Closed
oschwarze opened this issue Jun 7, 2024 · 5 comments · Fixed by #6694
Closed

Typo in docstring for GPI2 gate #6639

oschwarze opened this issue Jun 7, 2024 · 5 comments · Fixed by #6694
Assignees
Labels
kind/docs Documentation related problems, ideas, requests

Comments

@oschwarze
Copy link

There seems to be a typo in the docstring for the GPI2 gate:

@cirq.value.value_equality
class GPI2Gate(cirq.Gate):
r"""The GPI2 gate is a single qubit gate representing a pi/2 pulse.
The unitary matrix of this gate is
$$
\frac{1}{\sqrt{2}}
\begin{bmatrix}
1 & -i e^{-i \phi} \\
-i e^{-i \phi} & 1
\end{bmatrix}
$$
See [IonQ best practices](https://ionq.com/docs/getting-started-with-native-gates){:external}.
"""
def __init__(self, *, phi):
self.phi = phi
def _unitary_(self) -> np.ndarray:
top = -1j * cmath.exp(self.phase * 2 * math.pi * -1j)
bot = -1j * cmath.exp(self.phase * 2 * math.pi * 1j)
return np.array([[1, top], [bot, 1]]) / math.sqrt(2)
@property
def phase(self) -> float:
return self.phi
def __str__(self) -> str:
return 'GPI2'
def _circuit_diagram_info_(
self, args: 'cirq.CircuitDiagramInfoArgs'
) -> Union[str, 'protocols.CircuitDiagramInfo']:
return protocols.CircuitDiagramInfo(wire_symbols=(f'GPI2({self.phase!r})',))
def _num_qubits_(self) -> int:
return 1
def __repr__(self) -> str:
return f'cirq_ionq.GPI2Gate(phi={self.phi!r})'
def _json_dict_(self) -> Dict[str, Any]:
return cirq.obj_to_dict_helper(self, ['phi'])
def _value_equality_values_(self) -> Any:
return self.phi
def __pow__(self, power):
if power == 1:
return self
if power == -1:
return GPI2Gate(phi=self.phi + 0.5)
return NotImplemented

according to https://ionq.com/docs/getting-started-with-native-gates, the 10-component int the matrix should be $-i \exp{i \phi}$ and not $-i\exp(-i \phi)$

@NoureldinYosri NoureldinYosri added the triage/discuss Needs decision / discussion, bring these up during Cirq Cynque label Jul 3, 2024
@dstrain115
Copy link
Collaborator

Cirq cycn: Ionq folks, can you comment whether this should be positive or negative signed?

@pavoljuhas
Copy link
Collaborator

TODO(@pavoljuhas) - contact ionq folks about this

@senecameeks senecameeks added triage/needs-more-evidence [feature requests] this seems plausible but maintainers are not convinced about the use cases yet kind/docs Documentation related problems, ideas, requests labels Jul 31, 2024
@pavoljuhas
Copy link
Collaborator

pavoljuhas commented Jul 31, 2024

The suggestion looks good given the unitary matrix below - however the docstring seems to be missing the 2π factor.

def _unitary_(self) -> np.ndarray:
top = -1j * cmath.exp(self.phase * 2 * math.pi * -1j)
bot = -1j * cmath.exp(self.phase * 2 * math.pi * 1j)
return np.array([[1, top], [bot, 1]]) / math.sqrt(2)

@Cynocracy or @splch - can you please confirm?

@Cynocracy
Copy link
Contributor

Cynocracy commented Jul 31, 2024

@pavoljuhas can confirm, updating the comment to match the unitary function* sgtm.

The 2pi factor comes from, aiui, the phase argument being expressed in units of turns, and should be present in the doc string as well, if phi there is intended to be the phase argument

pavoljuhas added a commit to pavoljuhas/Cirq that referenced this issue Aug 1, 2024
Make documented unitary expressions equal to the code below.

Fixes quantumlib#6639
@pavoljuhas
Copy link
Collaborator

@Cynocracy - thanks for a quick response. Can you PTAL at #6694?

@pavoljuhas pavoljuhas removed triage/discuss Needs decision / discussion, bring these up during Cirq Cynque triage/needs-more-evidence [feature requests] this seems plausible but maintainers are not convinced about the use cases yet labels Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/docs Documentation related problems, ideas, requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants