Skip to content

Commit 939fb6e

Browse files
committed
Add support for arbitrary angles to IonQ native MS Gate
1 parent 86a9017 commit 939fb6e

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

cirq-ionq/cirq_ionq/ionq_native_gates.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,35 +179,38 @@ def __pow__(self, power):
179179
class MSGate(cirq.Gate):
180180
r"""The Mølmer–Sørensen (MS) gate is a two qubit gate native to trapped ions.
181181
182-
The unitary matrix of this gate for parameters $\phi_0$ and $\phi_1$ is
182+
The unitary matrix of this gate for parameters $\phi_0$, $\phi_1$ and $\theta is
183183
184184
$$
185-
\frac{1}{\sqrt{2}}
186185
\begin{bmatrix}
187-
1 & 0 & 0 & -ie^{-i2\pi(\phi_0+\phi_1)} \\
188-
0 & 1 & -ie^{-i2\pi(\phi_0-\phi_1)} & 0 \\
189-
0 & -ie^{i2\pi(\phi_0-\phi_1)} & 1 & 0 \\
190-
-ie^{i2\pi(\phi_0+\phi_1)} & 0 & 0 & 1 \\
186+
cos{\theta} & 0 & 0 & -i*e^{-i*2*\pi(\phi_0+\phi_1)}*sin{\theta} \\
187+
0 & cos{\theta} & -i*e^{-i*2*\pi(\phi_0-\phi_1)}*sin{\theta} & 0 \\
188+
0 & -i*e^{i*2*\pi(\phi_0-\phi_1)}*sin(\theta) & cos{\theta} & 0 \\
189+
-i*e^{i*2*\pi(\phi_0+\phi_1)}*sin{\theta} & 0 & 0 & cos{\theta}
191190
\end{bmatrix}
192191
$$
193192
194193
See [IonQ best practices](https://ionq.com/docs/getting-started-with-native-gates){:external}.
195194
"""
196195

197-
def __init__(self, *, phi0, phi1):
196+
def __init__(self, *, phi0, phi1, theta=0.25):
198197
self.phi0 = phi0
199198
self.phi1 = phi1
199+
self.theta = theta
200200

201201
def _unitary_(self) -> np.ndarray:
202-
diag = 1 / math.sqrt(2)
202+
theta = self.theta
203203
phi0 = self.phi0
204204
phi1 = self.phi1
205+
diag = np.cos(2 * math.pi * theta)
206+
sin = np.sin(2 * math.pi * theta)
207+
205208
return np.array(
206209
[
207-
[diag, 0, 0, diag * -1j * cmath.exp(-1j * 2 * math.pi * (phi0 + phi1))],
208-
[0, diag, diag * -1j * cmath.exp(-1j * 2 * math.pi * (phi0 - phi1)), 0],
209-
[0, diag * -1j * cmath.exp(1j * 2 * math.pi * (phi0 - phi1)), diag, 0],
210-
[diag * -1j * cmath.exp(1j * 2 * math.pi * (phi0 + phi1)), 0, 0, diag],
210+
[diag, 0, 0, sin * -1j * cmath.exp(-1j * 2 * math.pi * (phi0 + phi1))],
211+
[0, diag, sin * -1j * cmath.exp(-1j * 2 * math.pi * (phi0 - phi1)), 0],
212+
[0, sin * -1j * cmath.exp(1j * 2 * math.pi * (phi0 - phi1)), diag, 0],
213+
[sin * -1j * cmath.exp(1j * 2 * math.pi * (phi0 + phi1)), 0, 0, diag],
211214
]
212215
)
213216

@@ -232,7 +235,7 @@ def __repr__(self) -> str:
232235
return f'cirq_ionq.MSGate(phi0={self.phi0!r}, phi1={self.phi1!r})'
233236

234237
def _json_dict_(self) -> Dict[str, Any]:
235-
return cirq.obj_to_dict_helper(self, ['phi0', 'phi1'])
238+
return cirq.obj_to_dict_helper(self, ['phi0', 'phi1', 'theta'])
236239

237240
def _value_equality_values_(self) -> Any:
238241
return (self.phi0, self.phi1)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cirq_type": "MSGate",
33
"phi0": 0.1,
4-
"phi1": 0.55
4+
"phi1": 0.55,
5+
"theta": 0.25
56
}

cirq-ionq/cirq_ionq/serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _serialize_gpi2_gate(self, gate: GPI2Gate, targets: Sequence[int]) -> Option
205205
return {'gate': 'gpi2', 'target': targets[0], 'phase': gate.phase}
206206

207207
def _serialize_ms_gate(self, gate: MSGate, targets: Sequence[int]) -> Optional[dict]:
208-
return {'gate': 'ms', 'targets': targets, 'phases': gate.phases}
208+
return {'gate': 'ms', 'targets': targets, 'phases': gate.phases, 'angle': gate.theta}
209209

210210
def _serialize_cnot_pow_gate(
211211
self, gate: cirq.CNotPowGate, targets: Sequence[int]

cirq-ionq/cirq_ionq/serializer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_serialize_native_gates():
267267
'circuit': [
268268
{'gate': 'gpi', 'target': 0, 'phase': 0.1},
269269
{'gate': 'gpi2', 'target': 1, 'phase': 0.2},
270-
{'gate': 'ms', 'targets': [1, 2], 'phases': [0.3, 0.4]},
270+
{'gate': 'ms', 'targets': [1, 2], 'phases': [0.3, 0.4], 'angle': 0.25},
271271
],
272272
},
273273
metadata={},

0 commit comments

Comments
 (0)