Skip to content

Compile to ZZ gate instead of MS for Forte backends when transpiling to native IonQ gates #6973

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

Merged
merged 8 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions cirq-ionq/cirq_ionq/ionq_native_target_gateset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from cirq import linalg
from cirq import ops

from cirq_ionq.ionq_native_gates import GPIGate, GPI2Gate, MSGate
from cirq_ionq.ionq_native_gates import GPIGate, GPI2Gate, MSGate, ZZGate


class IonqNativeGatesetBase(cirq.TwoQubitCompilationTargetGateset):
Expand Down Expand Up @@ -121,13 +121,7 @@
return [GPI2Gate(phi=0.25).on(qubit), GPIGate(phi=0).on(qubit)]

def _cnot(self, *qubits):
return [
GPI2Gate(phi=1 / 4).on(qubits[0]),
MSGate(phi0=0, phi1=0).on(qubits[0], qubits[1]),
GPI2Gate(phi=1 / 2).on(qubits[1]),
GPI2Gate(phi=1 / 2).on(qubits[0]),
GPI2Gate(phi=-1 / 4).on(qubits[0]),
]
raise NotImplementedError()

Check warning on line 124 in cirq-ionq/cirq_ionq/ionq_native_target_gateset.py

View check run for this annotation

Codecov / codecov/patch

cirq-ionq/cirq_ionq/ionq_native_target_gateset.py#L124

Added line #L124 was not covered by tests

def decompose_all_to_all_connect_ccz_gate(
self, ccz_gate: 'cirq.CCZPowGate', qubits: Tuple['cirq.Qid', ...]
Expand Down Expand Up @@ -199,13 +193,21 @@
def __repr__(self) -> str:
return f'cirq_ionq.AriaNativeGateset(atol={self.atol})'

def _cnot(self, *qubits):
return [
GPI2Gate(phi=1 / 4).on(qubits[0]),
MSGate(phi0=0, phi1=0).on(qubits[0], qubits[1]),
GPI2Gate(phi=1 / 2).on(qubits[1]),
GPI2Gate(phi=1 / 2).on(qubits[0]),
GPI2Gate(phi=-1 / 4).on(qubits[0]),
]


class ForteNativeGateset(IonqNativeGatesetBase):
"""Target IonQ native gateset for compiling circuits.

The gates forming this gateset are:
GPIGate, GPI2Gate, MSGate
Note: in the future ZZGate might be added here.
GPIGate, GPI2Gate, ZZGate
"""

def __init__(self, *, atol: float = 1e-8):
Expand All @@ -214,7 +216,21 @@
Args:
atol: A limit on the amount of absolute error introduced by the decomposition.
"""
super().__init__(GPIGate, GPI2Gate, MSGate, ops.MeasurementGate, atol=atol)
super().__init__(GPIGate, GPI2Gate, ZZGate, ops.MeasurementGate, atol=atol)

def __repr__(self) -> str:
return f'cirq_ionq.ForteNativeGateset(atol={self.atol})'

def _cnot(self, *qubits):
return [
GPI2Gate(phi=0).on(qubits[1]),
GPIGate(phi=-0.125).on(qubits[1]),
GPI2Gate(phi=0.5).on(qubits[1]),
ZZGate(theta=0.25).on(qubits[0], qubits[1]),
GPI2Gate(phi=0.75).on(qubits[0]),
GPIGate(phi=0.125).on(qubits[0]),
GPI2Gate(phi=0.5).on(qubits[0]),
GPI2Gate(phi=1.25).on(qubits[1]),
GPIGate(phi=0.5).on(qubits[1]),
GPI2Gate(phi=0.5).on(qubits[1]),
]
4 changes: 4 additions & 0 deletions cirq-ionq/cirq_ionq/ionq_native_target_gateset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def test_equality_aria():
eq = cirq.testing.EqualsTester()
eq.add_equality_group(AriaNativeGateset(atol=1e-6))
eq.add_equality_group(AriaNativeGateset(atol=1e-5))


def test_equality_forte():
eq = cirq.testing.EqualsTester()
eq.add_equality_group(ForteNativeGateset(atol=1e-6))
eq.add_equality_group(ForteNativeGateset(atol=1e-5))

Expand Down