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 Qudit phase gate, Z_d #194

Merged
merged 7 commits into from
Jul 30, 2024
Merged

Add Qudit phase gate, Z_d #194

merged 7 commits into from
Jul 30, 2024

Conversation

lanafs
Copy link
Collaborator

@lanafs lanafs commented Jun 20, 2024

arxiv.org/abs/2008.00959 describes the Z_d gate as one of three gates that comprise a "universal gate set" for qudit computing.

The commit implements the Z_d gate using cirq.ops.eigen_gate.EigenGate as a base.

@lanafs lanafs linked an issue Jun 20, 2024 that may be closed by this pull request
@lanafs lanafs requested a review from dstrain115 June 21, 2024 18:51
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! A few comments!

@@ -12,6 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#


from typing import (
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: all on one line looks better to me, but I am not sure if the formatter is doing this.

@@ -51,6 +59,53 @@ def _circuit_diagram_info_(self, args):
return f"X({self.source_state}_{self.destination_state})"


class QuditRzGate(cirq.ops.eigen_gate.EigenGate):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would just use cirq.EigenGate in case package names change.

radians: The phase shift applied to basis d-1, measured in radians.
"""

_eigencomponents: Dict[int, List[Tuple[float, np.ndarray]]] = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having _eignencomponents and _eigen_components seems confusing.

assert np.isclose(phase_rads / np.pi, rz._exponent)
rz_unitary = cirq.unitary(rz)
assert np.allclose(cirq.unitary(rz), expected_unitary)
assert np.allclose(np.eye(len(rz_unitary)), rz_unitary.dot(rz_unitary.T.conj()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd feel more comfortable if we had a test on the action of the QuditRzGate too. Can we test the qudit equivalent of HZH and make sure it is equivalent to X?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's make this a follow-up PR until the qudit Hadamard PR issue gets resolved.

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

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

Some minor comments, then LGTM.

For a qudit of dimensionality d, shifts the phase of |phased_state> by radians.

Args:
dimension: Dimension of the qudits: for instance, a dimension of 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: would probably change the second colon to a period (then capitalize "For")

(np.pi * 4 / 3, np.pi * 2 / 3, 0, 1),
],
)
def test_X_HZH_qudit_identity(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this function repeated twice?

@lanafs lanafs merged commit db96dbd into quantumlib:main Jul 30, 2024
6 checks passed
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.

Implement phase rotation gate for Qudits
2 participants