Skip to content

Commit 14d61c8

Browse files
radumargpavoljuhas
andauthored
Compile to ZZ gate instead of MS for Forte backends when transpiling to native IonQ gates (#6973)
* Use ZZ gate instead of MS when commpiling to native IonQ gates for forte backends. * Fixing CI errors. * Move code around. * Add parathesis to exception. * NotImplemented -> NotImplementedError * return -> raise --------- Co-authored-by: Pavol Juhas <juhas@google.com>
1 parent d589bfc commit 14d61c8

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

cirq-ionq/cirq_ionq/ionq_native_target_gateset.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from cirq import linalg
2424
from cirq import ops
2525

26-
from cirq_ionq.ionq_native_gates import GPIGate, GPI2Gate, MSGate
26+
from cirq_ionq.ionq_native_gates import GPIGate, GPI2Gate, MSGate, ZZGate
2727

2828

2929
class IonqNativeGatesetBase(cirq.TwoQubitCompilationTargetGateset):
@@ -121,13 +121,7 @@ def _hadamard(self, qubit):
121121
return [GPI2Gate(phi=0.25).on(qubit), GPIGate(phi=0).on(qubit)]
122122

123123
def _cnot(self, *qubits):
124-
return [
125-
GPI2Gate(phi=1 / 4).on(qubits[0]),
126-
MSGate(phi0=0, phi1=0).on(qubits[0], qubits[1]),
127-
GPI2Gate(phi=1 / 2).on(qubits[1]),
128-
GPI2Gate(phi=1 / 2).on(qubits[0]),
129-
GPI2Gate(phi=-1 / 4).on(qubits[0]),
130-
]
124+
raise NotImplementedError()
131125

132126
def decompose_all_to_all_connect_ccz_gate(
133127
self, ccz_gate: 'cirq.CCZPowGate', qubits: Tuple['cirq.Qid', ...]
@@ -199,13 +193,21 @@ def __init__(self, *, atol: float = 1e-8):
199193
def __repr__(self) -> str:
200194
return f'cirq_ionq.AriaNativeGateset(atol={self.atol})'
201195

196+
def _cnot(self, *qubits):
197+
return [
198+
GPI2Gate(phi=1 / 4).on(qubits[0]),
199+
MSGate(phi0=0, phi1=0).on(qubits[0], qubits[1]),
200+
GPI2Gate(phi=1 / 2).on(qubits[1]),
201+
GPI2Gate(phi=1 / 2).on(qubits[0]),
202+
GPI2Gate(phi=-1 / 4).on(qubits[0]),
203+
]
204+
202205

203206
class ForteNativeGateset(IonqNativeGatesetBase):
204207
"""Target IonQ native gateset for compiling circuits.
205208
206209
The gates forming this gateset are:
207-
GPIGate, GPI2Gate, MSGate
208-
Note: in the future ZZGate might be added here.
210+
GPIGate, GPI2Gate, ZZGate
209211
"""
210212

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

219221
def __repr__(self) -> str:
220222
return f'cirq_ionq.ForteNativeGateset(atol={self.atol})'
223+
224+
def _cnot(self, *qubits):
225+
return [
226+
GPI2Gate(phi=0).on(qubits[1]),
227+
GPIGate(phi=-0.125).on(qubits[1]),
228+
GPI2Gate(phi=0.5).on(qubits[1]),
229+
ZZGate(theta=0.25).on(qubits[0], qubits[1]),
230+
GPI2Gate(phi=0.75).on(qubits[0]),
231+
GPIGate(phi=0.125).on(qubits[0]),
232+
GPI2Gate(phi=0.5).on(qubits[0]),
233+
GPI2Gate(phi=1.25).on(qubits[1]),
234+
GPIGate(phi=0.5).on(qubits[1]),
235+
GPI2Gate(phi=0.5).on(qubits[1]),
236+
]

cirq-ionq/cirq_ionq/ionq_native_target_gateset_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def test_equality_aria():
4949
eq = cirq.testing.EqualsTester()
5050
eq.add_equality_group(AriaNativeGateset(atol=1e-6))
5151
eq.add_equality_group(AriaNativeGateset(atol=1e-5))
52+
53+
54+
def test_equality_forte():
55+
eq = cirq.testing.EqualsTester()
5256
eq.add_equality_group(ForteNativeGateset(atol=1e-6))
5357
eq.add_equality_group(ForteNativeGateset(atol=1e-5))
5458

0 commit comments

Comments
 (0)